Skip to content

Instantly share code, notes, and snippets.

@ahonor
Created July 28, 2012 00:17
Show Gist options
  • Save ahonor/3191169 to your computer and use it in GitHub Desktop.
Save ahonor/3191169 to your computer and use it in GitHub Desktop.
ImportServiceTests
package com.dtolabs
import grails.test.mixin.*
import grails.test.GrailsUnitTestCase
import org.springframework.core.io.Resource
import org.springframework.core.io.ClassPathResource
/**
* See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/
@TestFor(ImportService)
@Mock([Project, Attribute, Filter, NodeType, NodeTypeRelationship,
Node, NodeValue, NodeAttribute, ChildNode])
class ImportServiceTests {
void testValidate() {
service.validate(
asInputStream("/import/example2.xml"),
asInputStream("/import/yana.xsd"))
}
void testParse() {
Project project = new Project(name:'test1', description:'desc').save()
new Filter(project: project, dataType: "String", regex: ".*").save()
new Filter(project: project, dataType: "URL", regex: ".*").save()
service.parse(asInputStream("/import/example2.xml"), project)
def arch = Attribute.findByProjectAndName(project, "arch")
assertEquals("Attribute name did not match", arch.name, "arch")
def host = NodeType.findByProjectAndName(project, "Host")
assertEquals("NodeType name did not match", host.name, "Host")
def pkg = NodeType.findByProjectAndName(project, "Package")
assertEquals("NodeType name did not match", pkg.name, "Package")
def svc = NodeType.findByProjectAndName(project, "Service")
assertEquals("NodeType name did not match", svc.name, "Service")
def site = NodeType.findByProjectAndName(project, "Site")
assertEquals("NodeType name did not match", site.name, "Site")
}
private InputStream asInputStream(String filename) {
Resource resource = new ClassPathResource(filename, getClass().classLoader)
File f = resource.getFile()
return new FileInputStream(f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment