Where is IntegrationSpec in Grails 3 - grails

In middle of upgrading to Grails 3.0.1. All good except for integration testing which worked well in 2.4.4.
I've noticed grails.test.spock.IntegrationSpec is not there in org.grails:grails-test:3.0.1 any more.
Tried extending spock.lang.Specification and running via Gradle integrationTest task however it didn't seems to inject Spring resources. Also tried #Integration getting same error, additionally complained by GGTS:
General error during canonicalization: Provider "data" not installed java.nio.file.FileSystemNotFoundException: Provider "data" not installed at java.nio.file.Paths.get(Paths.java:147) at
org.grails.io.support.MainClassFinder.searchMainClass(MainClassFinder.groovy:37) at
org.grails.compiler.injection.test.IntegrationTestMixinTransformation.visit(IntegrationTestMixinTransformation.groovy:82) at
org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:150) at org.codehaus.groovy.transform.ASTTransformationVisitor
...
So I'm wondering if IntegrationSpec still exists in 3.0. How should I get it work?

Alright, figured out #Integration should be applied and to resolve the compilation error I had to specify #Integration(applicationClass = Application.class) because somehow the IDE couldn't find Application class. Of course the test case should extend Specification.
#Autowired to be used for objects that need to be injected into your test classes. Can't use #Autowired in conjunction with #Shared, which you can do in 2.x.

Related

Grails 2.4.4 and joda-time plugin not working

I have been struggling with this for 2 days now and everything I've read so far does not seem to work. Is it possible to use the joda-time plugin with Grails 2.4.4? Has anyone done this? I created a brand new 2.4.4 application, made a domain class, and just added the joda-time plugin and I get the following error at run time
Error evaluating ORM mappings block for domain [Domain Name Here]: No such property: org for class: org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder
I've tried versions of the plugin up to 1.6-SNAPSHOT but nothing seems to work.

Does Spock plugin support in grails 3.0.5

I am new to use this spock plugin.So want to know about spock which version is supported by Grails 3.0.5. Actually using groovy 2.4.4 version.
Please help me out.
Why you want to know spock version? It is bundled in the grails so no need to configure it. Just create new test using some of grails commands like grails create-unit-test or create domain or controller and test for it will be created.
Basic dependencies for spock tests are added when creating new application/plugin (testCompile "org.grails:grails-plugin-testing"). In your case grails will use this spock: org.spockframework:spock-core:1.0-groovy-2.4 but again you don't need to worry about.

controllers integration test grails3: services are not getting injected

I am upgrading a grails app from 2.4.3 to 3.0.8.
There are a lot of integration tests which are using grails.util.GrailsWebUtil.bindMockWebRequest(grailsApplication.mainContext) following by controller.method call. But I discovered that grails.util.GrailsWebUtil doesn't contain bindMockWebRequest method anymore, seems like it has been replaced with grails.util.GrailsWebMockUtil, alright, but all services declared in controller are not getting injected into the class. I could use grails.test.spock.IntegrationSpec but this class has also been removed from grails3. There is a suggestion to use functional tests for integration test of controllers, but this solution doesn't work for me, I'm not itching to implement all these tests as functional, or inject dependencies manually into controller instances, how can I fix it?
Use grails.test.mixin.integration.Integration annotation instead of grails.test.spock.IntegrationSpec class extension.
And move the integration tests to src/integration-test/groovy.
I'm upgrading from Grails 2.5.1 to 3.2.4. One of my integration tests could not find the service I injected with def xxxService. I included the service in the #Mock list. XxxServiceIntegrationSpec extends Specification.
I know this does not quite relate to testing controllers, but maybe it helps?
We had dozones of controller integration in our old grails 2.x app. When we migrated to grails 3, we wanted to keep it, can not throw them and write functional tests from scratch.
Here I have blogged about it Integration testing controllers with Grails 3
The basic steps are
- setup mock request and response
- set current controller name
- rest mock request and response at the end of the test
See the above blog post for a complete example.
Hope it helps.
For anyone still looking for a solution to this (I had the same problem), I found this example really useful:
https://github.com/albertodeavila/testingGrails3

Grails 3 and Spring Security Plugin

I've just recently started working with Grails, and I'd like to test out the Spring Security Plugin. I'm using Grails v3.0.0RC2, and I'm finding it difficult to come across accurate documentation for it with a lot of things.
I'm looking at the Grails page for the Spring Security Plugin, located at http://grails.org/plugin/spring-security-core, and it tells me to add the following to grails-app/conf/BuildConfig
plugins {
…
compile ':spring-security-core:2.0-RC4'
…
}
Now, Grails 3 has done away with the BuildConfig, and moved over to using Gradle. So I figured I could just that compile line to my "dependencies" section in build.gradle and it would work, like so:
dependencies{
...
compile:":spring-security-core:2.0-RC4"
}
However, that did not work. I get the error "Could not find :spring-security-core:2.0-RC4...".
Then I figured, 'Hey, it's a plugin, let me try prefacing it with "org.grails.plugins" like I see elsewhere in the build.gradle file:
dependencies{
...
compile:"org.grails.plugins:spring-security-core:2.0-RC4"
}
And still no go.
I have gotten it to compile by adding the dependency found on search.maven.org, like so:
dependencies{
...
compile 'org.springframework.security:spring-security-core:4.0.0.RELEASE'
}
But I don't think thats the proper way to do, because Grails documentation says I should have access to the command
grails s2-quickstart
once the plugin is installed, which I do not when I do it using the Maven repo.
I'm sure there's a simple configuration error I'm making, as I'm very new to both Grails, Spring, and Gradle, so I appreciate any help that can be provided.
The Spring Secuirty core plugin for Grails is not Grails 3 compatible. However, since Grails 3 is based on Spring Boot you can use the Spring Security Starter for Spring Boot instead.
This has been discussed on the Grails developers mailing list and going forward many Grails plugins will not be moved to Grails 3 and instead will be replaced by pure Spring solutions.
Update
Since this question was originally asked there has been a Spring Security plugin created for Grails 3.x. It can be found here: https://bintray.com/grails/plugins/spring-security-core/view
The "Spring Security Starter for Spring Boot" is a good starting point, but if you want to save yourself some time trying to figure out how to get it to work with Grails, check out this helpful blog post.
I wrote the blog post #Jamie referenced in his answer and I added a new blog post describing how to use the Gorm domain classes from Spring-Security-Core plugin from Grails 2.
dependencies {
...
compile 'org.grails.plugins:spring-security-core:3.0.4'
...
}
This is what I used and it worked for me

Grails + Gpars.memoize().. how to do memoization?

I can't seem to figure out how to do memoization in Grails. According to the GPars docs it should be as simple as
def c = { x -> x*2 }.memoize() or ... .gmemoize()
But all i seem to get is compilation errors and stacktraces thrown. Has anyone successfully used gpars with grails?
Grails up until 1.4.0m1 bundled an old version of gpars (0.9) that didn't include memoization. Since Grails preferes the bundled libs to the user-specified ones, you never get a chance to see the memoization methods.
To my best knowledge the Grails master branch has already fixed that and gives users the freedom to choose a GPars version they like.
We are currently successfully using GPars data flow concurrency in a Grails 1.3.7 application. GPars is defined as a basic jar dependency in BuildConfig.groovy, we are not using the GPars Grails plugin.

Resources