Skip to content

Instantly share code, notes, and snippets.

@ahonor
Created July 27, 2012 23:28
Show Gist options
  • Save ahonor/3191022 to your computer and use it in GitHub Desktop.
Save ahonor/3191022 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)
class ImportServiceTests extends GroovyTestCase {
void testValidate() {
service.validate(
asInputStream("/import/example2.xml"),
asInputStream("/import/yana.xsd"))
}
void testParse() {
Project project = new Project(name:'test1',description:'desc')
assertNotNull("Could not instantiate Project", project)
project.save()
service.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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment