Created
July 27, 2012 23:16
-
-
Save ahonor/3190987 to your computer and use it in GitHub Desktop.
ImportServiceTests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$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