Skip to content

Instantly share code, notes, and snippets.

@ahonor
Created July 27, 2012 23:16
Show Gist options
  • Select an option

  • Save ahonor/3190987 to your computer and use it in GitHub Desktop.

Select an option

Save ahonor/3190987 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)
class ImportServiceTests extends GrailsUnitTestCase {
void testValidate() {
final ImportService svc = new ImportService()
svc.validate(
asInputStream("/import/example2.xml"),
asInputStream("/import/yana.xsd"))
}
void testParse() {
mockDomain(Project)
Project project = new Project(name:'test1',description:'desc').save()
final ImportService svc = new ImportService()
svc.parse(asInputStream("/import/example2.xml"), project)
}
def InputStream asInputStream(String filename) {
Resource resource = new ClassPathResource(filename, getClass().classLoader)
File f = resource.getFile()
return new FileInputStream(f)
}
}
@ahonor

ahonor commented Jul 27, 2012

Copy link
Copy Markdown
Author

$GRAILS_HOME/bin/grails test-app unit: ImportService
| Running 2 unit tests... 2 of 2
| Failure: testParse(com.dtolabs.ImportServiceTests)
| java.lang.NullPointerException: Cannot invoke method addGrailsClass() on null object
at grails.test.GrailsUnitTestCase.mockDomain(GrailsUnitTestCase.groovy:145)
at grails.test.GrailsUnitTestCase.mockDomain(GrailsUnitTestCase.groovy:141)
at com.dtolabs.ImportServiceTests.testParse(ImportServiceTests.groovy:28)
| Completed 2 unit tests, 1 failed in 2485ms
| Tests FAILED - view reports in target/test-reports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment