Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goeh committed Jul 30, 2012
1 parent ba06cc5 commit a782ad2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 51 deletions.
Expand Up @@ -4,15 +4,19 @@ import grails.test.*
import org.springframework.core.io.ClassPathResource
import org.apache.commons.io.IOUtils

class QrcodeControllerTests extends GrailsUnitTestCase {
class QrcodeControllerTests extends ControllerUnitTestCase {
QrCodeService qrCodeService

void testSimpleRender() {
def qrcodeController = new QrcodeController()
qrcodeController.qrCodeService = qrCodeService
qrcodeController.request.parameters = [text:'test',size:'30']
qrcodeController.index()
byte[] out = qrcodeController.response.contentAsByteArray
controller.qrCodeService = qrCodeService
controller.params.text = 'test'
controller.params.size = '30'
controller.index()

assertEquals "image/png", controller.response.contentType
assertEquals 200, controller.response.status

byte[] out = controller.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.png").getInputStream()
Expand Down
@@ -1,53 +1,12 @@
package org.codehaus.groovy.grails.plugins.qrcode

import grails.test.GrailsUnitTestCase
import org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletResponse
import grails.test.GroovyPagesTestCase

class QrcodeTagLibTests extends GrailsUnitTestCase {

StringWriter out
def qrCodeService
def controller
def action
def attributes

protected void setUp() {
super.setUp()
out = new StringWriter()
QrcodeTagLib.metaClass.out = out
QrcodeTagLib.metaClass.createLink = { attrs ->
controller = attrs.controller
action = attrs.action
attributes = attrs.params
}
QrcodeController.metaClass.params = [:]
QrcodeController.metaClass.response = new GrailsMockHttpServletResponse()
}

protected void tearDown() {
super.tearDown()
def remove = GroovySystem.metaClassRegistry.&removeMetaClass
remove QrcodeTagLib
remove QrcodeController
}
class QrcodeTagLibTests extends GroovyPagesTestCase {

void testImage() {
QrcodeTagLib qr = new QrcodeTagLib()

qr.image(height: "100", width: "100", text: "TEST TEXT")

assertEquals "qrcode", controller
assertEquals "text", action
assertEquals "100", attributes.s
assertEquals "TEST TEXT", attributes.text

def ctl = new QrcodeController(params: attributes)
ctl.qrCodeService = qrCodeService
ctl.text()
assertEquals "image/png", ctl.response.contentType
assertEquals 200, ctl.response.status

// reset "out" buffer
out.getBuffer().setLength(0)
def template = '<qrcode:image height="100" width="100" text="TEST TEXT"/>'
assert applyTemplate(template) == '<img class="qrcode " alt="TEST TEXT" src="/qrcode/text?text=TEST+TEXT&s=100"/>'
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a782ad2

Please sign in to comment.