Skip to content

Commit

Permalink
simple test for the controller compares binary output of the controll…
Browse files Browse the repository at this point in the history
…er to the expected png in the file system
  • Loading branch information
Shawn Hartsock committed Mar 14, 2012
1 parent 9799317 commit ad36b23
Showing 1 changed file with 25 additions and 0 deletions.
@@ -0,0 +1,25 @@
package org.codehaus.groovy.grails.plugins.qrcode

import grails.test.*
import org.springframework.core.io.ClassPathResource
import org.apache.commons.io.IOUtils

class QrcodeControllerTests extends GrailsUnitTestCase {
QrCodeRendererService qrCodeRendererService

void testSimpleRender() {
def qrcodeController = new QrcodeController()
qrcodeController.qrCodeRendererService = qrCodeRendererService
qrcodeController.request.parameters = [text:'test',size:'30']
qrcodeController.index()
byte[] out = qrcodeController.response.contentAsByteArray
// a 30 by 30 png image of the word "test" in a QRCode
InputStream pngIn =
new ClassPathResource("org/codehaus/groovy/grails/plugins/qrcode/qrcode_test.png").getInputStream()
byte[] png = IOUtils.toByteArray(pngIn)

assert png != null

assert Arrays.equals(png,out)
}
}

0 comments on commit ad36b23

Please sign in to comment.