I have a controller that takes in a file as part of the parameter. I'm wondering how can I test this?
my controller action:
def save () {
def colorInstance = new Color(params.color)
CommonsMultipartFile file = request.getFile('color.filename')
fileUploadService.upload(colorInstance, file, "foldername")
if (requestInstance.save(flush: true)) {
withFormat {
html {redirect(action: "list") }
js {render "test"}
}
}
}
I've started with something like this:...
import org.junit.Before
import grails.test.mixin.Mock
import grails.test.mixin.TestFor
@TestFor(ColorController)
@Mock(Color)
class ColorControllerTests {
@Before
void setUp() {
controller.fileUploadService = new FileUploadService
}
}
Question
- I can't figure out how to test the
CommonsMultipartFile
for file upload. - Also, this test case will sit in
unit
test folder. How can I execute it?