Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ supported options in the cache configuration.
WARNING: Since there is no way to configure "time to live" with this plugin, all
cached items have no timeout and remain cached until either the JVM restarts
(since the backing store is in-memory) or the cache is partially or fully
cleared (by calling a method or action annotated with \@CacheEvict or
cleared (by calling a method or action annotated with @CacheEvict or
programmatically).

If you don't need to supply any configuration to your cache, simply don't include it in the configuration.
Expand Down
4 changes: 2 additions & 2 deletions grails-doc/src/en/guide/cache/cacheUsage/cacheUnitTests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ include::{cacheExampleSourceDir}/grails-app/services/com/demo/BasicCachingServic

[source,groovy]
----
include::{cacheExampleSourceDir}/src/test/groovy/com/demo/BasicCachingServiceNoCacheManagerSpec.groovy[]
include::{cacheExampleSourceDir}/src/test/groovy/com/demo/BasicCachingServiceNoCacheManagerSpec.groovy[tags=basic_declaration]
----

In order for caching to be active when the unit test is running, cache manager
Expand All @@ -38,5 +38,5 @@ test.

[source,groovy]
----
include::{cacheExampleSourceDir}/src/test/groovy/com/demo/BasicCachingServiceSpec.groovy[]
include::{cacheExampleSourceDir}/src/test/groovy/com/demo/BasicCachingServiceSpec.groovy[tags=basic_declaration]
----
6 changes: 3 additions & 3 deletions grails-doc/src/en/guide/testing/unitTesting/annotations.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ applied in conjunction with a fixture annnotation like `@Before` as shown below.
[source,groovy]
.src/test/groovy/grails/testing/spock/RunOnceSpec.groovy
----
include::{sourcedir}/grails-testing-support-core/src/test/groovy/grails/testing/spock/RunOnceSpec.groovy[indent=0]
include::{sourcedir}/grails-testing-support-core/src/test/groovy/grails/testing/spock/RunOnceSpec.groovy[tags=basic_declaration,indent=0]
----

Applying both the `@RunOnce` and `@Before` annotations to a method will yield
Expand All @@ -49,7 +49,7 @@ accomplishing the same behavior that would be accomplished by applying both the
[source,groovy]
.src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy
----
include::{sourcedir}/grails-testing-support-core/src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy[indent=0]
include::{sourcedir}/grails-testing-support-core/src/test/groovy/grails/testing/spock/OnceBeforeSpec.groovy[tags=basic_declaration,indent=0]
----

This is useful in the context of an integration test which wants to reference
Expand All @@ -58,5 +58,5 @@ dependency injected values during setup as shown below.
[source,groovy]
.src/integration-test/groovy/demo/DependencyInjectionSpec.groovy
----
include::{functionalSourceDir}/demo33/src/integration-test/groovy/demo/DependencyInjectionSpec.groovy[indent=0]
include::{functionalSourceDir}/demo33/src/integration-test/groovy/demo/DependencyInjectionSpec.groovy[tags=basic_declaration,indent=0]
----
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ trait to unit test single domain class.
[source,groovy]
.grails-app/domain/demo/Person.groovy
----
include::{functionalSourceDir}/demo33/grails-app/domain/demo/Person.groovy[indent=0]
include::{functionalSourceDir}/demo33/grails-app/domain/demo/Person.groovy[tags=basic_declaration,indent=0]
----

[source,groovy]
.src/test/groovy/demo/PersonSpec.groovy
----
include::{functionalSourceDir}/demo33/src/test/groovy/demo/PersonSpec.groovy[indent=0]
include::{functionalSourceDir}/demo33/src/test/groovy/demo/PersonSpec.groovy[tags=basic_declaration,indent=0]
----

Alternatively, the link:{api}grails/testing/gorm/DataTest.html[`grails.testing.gorm.DataTest`]
Expand All @@ -42,7 +42,7 @@ test. This is useful when mocking more than one Domain class at a time to test p
[source,groovy]
.src/test/groovy/demo/DataTestTraitSpec.groovy
----
include::{functionalSourceDir}/demo33/src/test/groovy/demo/DataTestTraitSpec.groovy[indent=0]
include::{functionalSourceDir}/demo33/src/test/groovy/demo/DataTestTraitSpec.groovy[tags=basic_declaration,indent=0]
----

Another way to express which domain classes should be mocked for this test is
Expand All @@ -51,7 +51,7 @@ to provide a `Class[] getDomainClassesToMock()` method in the test.
[source,groovy]
.src/test/groovy/demo/GetDomainClassesToMockMethodSpec.groovy
----
include::{functionalSourceDir}/demo33/src/test/groovy/demo/GetDomainClassesToMockMethodSpec.groovy[indent=0]
include::{functionalSourceDir}/demo33/src/test/groovy/demo/GetDomainClassesToMockMethodSpec.groovy[tags=basic_declaration,indent=0]
----

When mocking domain classes in a test for another artifact type (like a
Expand All @@ -61,5 +61,5 @@ trait in order to mock the related domain classes.
[source,groovy]
.src/test/groovy/demo/PersonControllerSpec.groovy
----
include::{functionalSourceDir}/demo33/src/test/groovy/demo/PersonControllerSpec.groovy[indent=0]
include::{functionalSourceDir}/demo33/src/test/groovy/demo/PersonControllerSpec.groovy[tags=basic_declaration,indent=0]
----
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The examples assume the following mappings are being used.

[source,groovy]
----
include::{functionalSourceDir}/demo33/grails-app/controllers/demo/UrlMappings.groovy[indent=0]
include::{functionalSourceDir}/demo33/grails-app/controllers/demo/UrlMappings.groovy[tags=basic_declaration,indent=0]
----

=== Getting Started
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

// tag::basic_declaration[]
package com.demo

import grails.testing.services.ServiceUnitTest
Expand All @@ -40,3 +41,4 @@ class BasicCachingServiceNoCacheManagerSpec extends Specification implements Ser
service.invocationCounter == 2
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

// tag::basic_declaration[]
package com.demo

import grails.plugin.cache.CustomCacheKeyGenerator
Expand Down Expand Up @@ -78,3 +79,4 @@ class BasicCachingServiceSpec extends Specification implements ServiceUnitTest<B
service.conditionalInvocationCounter == 3
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

// tag::basic_declaration[]
package demo

class UrlMappings {
Expand All @@ -37,3 +38,4 @@ class UrlMappings {
"404"(view:'/notFound')
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/

// tag::basic_declaration[]
package demo

class Person {
String firstName
String lastName
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

// tag::basic_declaration[]
package demo

import grails.testing.mixin.integration.Integration
Expand All @@ -36,3 +37,4 @@ class DependencyInjectionSpec extends Specification {
helperService != null
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
// tag::basic_declaration[]
package demo

import grails.testing.gorm.DataTest
Expand All @@ -39,3 +40,4 @@ class DataTestTraitSpec extends Specification implements DataTest {
Person.count() == 2
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
// tag::basic_declaration[]
package demo

import grails.testing.gorm.DataTest
Expand All @@ -36,3 +37,4 @@ class GetDomainClassesToMockMethodSpec extends Specification implements DataTest
Person.count() == 2
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
// tag::basic_declaration[]
package demo

import grails.testing.gorm.DataTest
Expand All @@ -41,3 +42,4 @@ class PersonControllerSpec extends Specification implements ControllerUnitTest<P
model.keySet().contains('people')
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
// tag::basic_declaration[]
package demo

import grails.testing.gorm.DomainUnitTest
Expand Down Expand Up @@ -59,3 +60,4 @@ class PersonSpec extends Specification implements DomainUnitTest<Person> {
System.identityHashCode(domain) != id
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
// tag::basic_declaration[]
package grails.testing.spock

import spock.lang.Shared
Expand Down Expand Up @@ -79,3 +80,4 @@ class OnceBeforeSpec extends Specification {
anotherOnceBeforeCounter == 1
}
}
// end::basic_declaration[]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
// tag::basic_declaration[]
package grails.testing.spock

import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -82,3 +83,4 @@ class RunOnceSpec extends Specification {
anotherOnceBeforeCounter == 1
}
}
// end::basic_declaration[]
Loading