diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/ExpandSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/ExpandSpec.groovy index 7dfe5befdf5..461faeef833 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/ExpandSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/ExpandSpec.groovy @@ -19,6 +19,8 @@ package grails.plugin.json.view import tools.jackson.databind.json.JsonMapper +import grails.plugin.json.view.expand.Player +import grails.plugin.json.view.expand.Team import grails.plugin.json.view.test.JsonRenderResult import grails.plugin.json.view.test.JsonViewTest import org.grails.datastore.mapping.core.Session @@ -45,10 +47,10 @@ class ExpandSpec extends Specification implements JsonViewTest, GrailsUnitTest { def player = new Player(name: 'Cantona', team: teamProxy) def templateText = ''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.expand.Player + @Field Player player - + json g.render(player) ''' @@ -89,10 +91,8 @@ class ExpandSpec extends Specification implements JsonViewTest, GrailsUnitTest { def player = new Player(name: 'Cantona', team: teamProxy) def templateText = ''' - import grails.plugin.json.view.* - @Field Map map - + json g.render(map) ''' @@ -125,7 +125,7 @@ class ExpandSpec extends Specification implements JsonViewTest, GrailsUnitTest { def player = new Player(name: 'Cantona', team: teamProxy) def templateText = ''' - import grails.plugin.json.view.* + import grails.plugin.json.view.expand.Player model { Player player } @@ -192,11 +192,11 @@ class ExpandSpec extends Specification implements JsonViewTest, GrailsUnitTest { when: 'The domain is rendered with expand parameters' JsonRenderResult result = render(''' - import grails.plugin.json.view.* + import grails.plugin.json.view.expand.Player model { Player player } - + json jsonapi.render(player, [expand: 'team']) ''', [player: player]) diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/HalEmbeddedSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/HalEmbeddedSpec.groovy index f108e394528..78bd3947692 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/HalEmbeddedSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/HalEmbeddedSpec.groovy @@ -20,6 +20,9 @@ package grails.plugin.json.view import tools.jackson.databind.json.JsonMapper import grails.gorm.annotation.Entity +import grails.plugin.json.view.halembedded.Person +import grails.plugin.json.view.halembedded.Player +import grails.plugin.json.view.halembedded.Team import grails.plugin.json.view.test.JsonViewTest import spock.lang.Shared import spock.lang.Specification @@ -48,10 +51,10 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { when: 'hal.embedded(..) is used with a map' def result = render(''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.halembedded.Team + @Field Team team - + json { hal.links(self: team, captain: team.captain) hal.inline(team) @@ -91,10 +94,10 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { when: 'hal.embedded(..) is used with a map' def result = render(''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.halembedded.Team + @Field Team team - + json { hal.links(self: team, captain: team.captain) } @@ -131,10 +134,10 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { when: 'hal.embedded(..) is used with a map' def result = render(''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.halembedded.Team + @Field Team team - + json { hal.embedded(players:team.players) hal.inline(team) @@ -183,10 +186,10 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { when: 'hal.embedded(..) is used with a map' def result = render(''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.halembedded.Team + @Field Team team - + json { hal.embedded(players:team.players) } @@ -232,10 +235,10 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { when: 'hal.embedded(..) is used with a map' def result = render(''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.halembedded.Player + @Field List players - + json { hal.embedded(players:players) total 1 @@ -280,7 +283,7 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { def team = new Team(captain: captain, name: 'Manchester United', players: [player]) team.id = 1L def result = render(''' - import grails.plugin.json.view.* + import grails.plugin.json.view.halembedded.Team model { Team team } @@ -333,11 +336,10 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { def player = new Player(id: 1L, name: 'Cantona') player.id = 1L def captain = new Player(name: 'Keane') - captain.id == 1L def team = new Team(captain: captain, name: 'Manchester United', players: [player]) team.id = 1L def result = render(''' - import grails.plugin.json.view.* + import grails.plugin.json.view.halembedded.Team model { Team team } @@ -388,7 +390,7 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { player.id = 1L team.id = 1L def result = render(''' - import grails.plugin.json.view.* + import grails.plugin.json.view.halembedded.Player model { Player player } @@ -423,14 +425,18 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { given: 'A domain class with embedded associations' mappingContext.addPersistentEntities(Person, Parent) def p = new Person(name: 'Robert') - p.homeAddress = new Address(postCode: '12345') - p.otherAddresses = [new Address(postCode: '6789'), new Address(postCode: '54321')] + p.homeAddress = new grails.plugin.json.view.halembedded.Address(postCode: '12345') + p.otherAddresses = [ + new grails.plugin.json.view.halembedded.Address(postCode: '6789'), + new grails.plugin.json.view.halembedded.Address(postCode: '54321') + ] p.nickNames = ['Rob', 'Bob'] def parent = new Parent(name: 'Joe', person: p) when: 'hal.render(..) is used' def result = render(''' - import grails.plugin.json.view.* + import grails.plugin.json.view.Parent + model { Parent parent } @@ -477,4 +483,4 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest { class Parent { String name Person person -} \ No newline at end of file +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/IncludeAssociationsSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/IncludeAssociationsSpec.groovy index f81b3366252..0cd8e66da6c 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/IncludeAssociationsSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/IncludeAssociationsSpec.groovy @@ -18,6 +18,8 @@ */ package grails.plugin.json.view +import grails.plugin.json.view.include.Player +import grails.plugin.json.view.include.Team import grails.plugin.json.view.test.JsonViewTest import org.grails.testing.GrailsUnitTest import spock.lang.Specification @@ -34,7 +36,7 @@ class IncludeAssociationsSpec extends Specification implements JsonViewTest, Gra when: "A collection type is rendered" def renderResult = render(''' import groovy.transform.* -import grails.plugin.json.view.* +import grails.plugin.json.view.include.Player @Field Collection players diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/IterableRenderSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/IterableRenderSpec.groovy index f74bd9e37ad..72661d201dd 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/IterableRenderSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/IterableRenderSpec.groovy @@ -19,6 +19,8 @@ package grails.plugin.json.view import tools.jackson.databind.json.JsonMapper +import grails.plugin.json.view.iterable.Player +import grails.plugin.json.view.iterable.Team import grails.views.ViewException import grails.views.json.test.JsonViewUnitTest import spock.lang.Shared @@ -40,10 +42,10 @@ class IterableRenderSpec extends Specification implements JsonViewUnitTest { when: 'A collection type is rendered' def renderResult = render(''' import groovy.transform.* - import grails.plugin.json.view.* - + import grails.plugin.json.view.iterable.Player + @Field Collection players - + json g.render(players) ''', [players: players]) @@ -58,10 +60,10 @@ class IterableRenderSpec extends Specification implements JsonViewUnitTest { when: 'A collection type is rendered' def renderResult = render(''' import groovy.transform.* - import grails.plugin.json.view.* - + import grails.plugin.json.view.iterable.Player + @Field Collection players - + json hal.render(players) ''', [players: players]) @@ -102,10 +104,10 @@ class IterableRenderSpec extends Specification implements JsonViewUnitTest { when: 'A collection type is rendered' def renderResult = render(''' import groovy.transform.* - import grails.plugin.json.view.* - + import grails.plugin.json.view.iterable.Player + @Field Collection players - + json jsonapi.render(players) ''', [players: players]) { uri = '/foo' @@ -147,10 +149,10 @@ class IterableRenderSpec extends Specification implements JsonViewUnitTest { when: 'A collection type is rendered' def renderResult = render(''' import groovy.transform.* - import grails.plugin.json.view.* - + import grails.plugin.json.view.iterable.Player + @Field Collection players - + json jsonapi.render(players) ''', [players: players]) { uri = '/foo' @@ -204,10 +206,10 @@ class IterableRenderSpec extends Specification implements JsonViewUnitTest { when: 'A collection type is rendered total must be greater than max (10)' def renderResult = render(''' import groovy.transform.* - import grails.plugin.json.view.* - + import grails.plugin.json.view.iterable.Player + @Field Collection players - + json jsonapi.render(players, [pagination: [resource: Player, total: 11]]) ''', [players: players], { uri = '/foo' @@ -264,10 +266,10 @@ class IterableRenderSpec extends Specification implements JsonViewUnitTest { when: 'A collection type is rendered total must be greater than max (10)' def renderResult = render(''' import groovy.transform.* - import grails.plugin.json.view.* - + import grails.plugin.json.view.iterable.Player + @Field Collection players - + json jsonapi.render(players, [pagination: [resource: Player, total: 11, max: 5]]) ''', [players: players]) { uri = '/foo' @@ -324,10 +326,10 @@ class IterableRenderSpec extends Specification implements JsonViewUnitTest { when: 'A collection type is rendered total must be greater than max (10)' render(''' import groovy.transform.* - import grails.plugin.json.view.* - + import grails.plugin.json.view.iterable.Player + @Field Collection players - + json jsonapi.render(players, [pagination: [total: 11]]) ''', [players: players]) { uri = '/foo' diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/MapRenderSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/MapRenderSpec.groovy index 6527a9fb621..6a2e63ef018 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/MapRenderSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/MapRenderSpec.groovy @@ -19,6 +19,9 @@ package grails.plugin.json.view import tools.jackson.databind.json.JsonMapper +import grails.plugin.json.view.maprender.Player +import grails.plugin.json.view.maprender.PlayerWithAge +import grails.plugin.json.view.maprender.Team import grails.plugin.json.view.test.JsonViewTest import grails.testing.gorm.DataTest import grails.validation.Validateable @@ -44,7 +47,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' def renderResult = render(templateText, [map: [foo: 'bar', version: 'one']]) @@ -60,7 +63,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' def renderResult = render(templateText, [map: [foo: 'bar', version: 'one', 'errors': ['test1']]]) @@ -77,7 +80,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' @@ -97,7 +100,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' @@ -140,7 +143,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' @@ -170,7 +173,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' @@ -208,7 +211,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' @@ -241,7 +244,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map, [excludes: ['player1','player2.name']]) ''' @@ -273,7 +276,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map, [excludes: ['players.name']]) ''' @@ -308,7 +311,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map) ''' @@ -330,7 +333,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { List list } - + json g.render(list) ''' @@ -357,7 +360,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map, [includes: ['a', 'b']]) ''' @@ -372,7 +375,7 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { model { Map map } - + json g.render(map, [includes: ['a', 'd']]) ''' renderResult = render(templateText, [map: [a: '1', b: '2', c: '3', d: '4']]) @@ -396,4 +399,4 @@ class MapRenderSpec extends Specification implements JsonViewTest, DataTest { String name List errors } -} \ No newline at end of file +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/NullRenderingSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/NullRenderingSpec.groovy index 990121a3914..a9223683776 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/NullRenderingSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/NullRenderingSpec.groovy @@ -19,6 +19,8 @@ package grails.plugin.json.view import tools.jackson.databind.json.JsonMapper +import grails.plugin.json.view.nullrendering.Child +import grails.plugin.json.view.nullrendering.Player import grails.plugin.json.view.test.JsonViewTest import spock.lang.Shared import spock.lang.Specification @@ -31,12 +33,12 @@ class NullRenderingSpec extends Specification implements JsonViewTest { void 'test rendering nulls with a domain'() { given: def templateText = ''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.nullrendering.Player + model { Player player } - + json g.render(player) ''' @@ -51,12 +53,12 @@ class NullRenderingSpec extends Specification implements JsonViewTest { void 'test rendering nulls with a domain (renderNulls = true)'() { given: def templateText = ''' - import grails.plugin.json.view.* - + import grails.plugin.json.view.nullrendering.Player + model { Player player } - + json g.render(player, [renderNulls: true]) ''' @@ -74,7 +76,7 @@ class NullRenderingSpec extends Specification implements JsonViewTest { model { Map map } - + json g.render(map) ''' @@ -92,13 +94,13 @@ class NullRenderingSpec extends Specification implements JsonViewTest { model { Object obj } - + json g.render(obj) ''' when: mappingContext.addPersistentEntity(Player) - def renderResult = render(templateText, [obj: new Child2()]) + def renderResult = render(templateText, [obj: new Child()]) then: 'No fields are rendered because they are null' renderResult.jsonText == '{}' @@ -110,15 +112,15 @@ class NullRenderingSpec extends Specification implements JsonViewTest { model { Object obj } - + json g.render(obj, [renderNulls: true]) ''' when: mappingContext.addPersistentEntity(Player) - def renderResult = render(templateText, [obj: new Child2()]) + def renderResult = render(templateText, [obj: new Child()]) then: objectMapper.readTree(renderResult.jsonText) == objectMapper.readTree('{"name": null, "parent": null}') } -} \ No newline at end of file +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/TemplateInheritanceSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/TemplateInheritanceSpec.groovy index 0b75ef0d76d..dc00536268d 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/TemplateInheritanceSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/TemplateInheritanceSpec.groovy @@ -25,6 +25,9 @@ import spock.lang.Specification /** * Created by graemerocher on 24/05/16. */ +// Intentionally uses JsonViewHelperSpec's Player/Circular rather than spec-local copies: the +// child2/child4/circular .gson templates under grails-app/views import +// grails.plugin.json.view.Player/.Circular directly, so the model here must be that same class. class TemplateInheritanceSpec extends Specification implements JsonViewTest { void "test extending another template"() { diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiHandleAssociationsSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiHandleAssociationsSpec.groovy index b1648bc92f9..b2b5a332b8e 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiHandleAssociationsSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiHandleAssociationsSpec.groovy @@ -19,6 +19,7 @@ package grails.plugin.json.view.api import grails.persistence.Entity +import grails.plugin.json.view.api.handleassociations.Author import grails.plugin.json.view.test.JsonRenderResult import grails.plugin.json.view.test.JsonViewTest import groovy.json.JsonException @@ -71,4 +72,3 @@ class PublishedBook { class Publisher { String name } - diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiSpec.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiSpec.groovy index afbc012a013..1592e69fe7f 100644 --- a/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiSpec.groovy +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/JsonApiSpec.groovy @@ -24,37 +24,23 @@ import grails.plugin.json.view.test.JsonRenderResult import grails.plugin.json.view.test.JsonViewTest import grails.validation.Validateable import org.grails.testing.GrailsUnitTest -import org.grails.validation.ConstraintEvalUtils import spock.lang.Shared import spock.lang.Specification class JsonApiSpec extends Specification implements JsonViewTest, GrailsUnitTest { - // Cache the static field helper interface for performance - private static final Class STATIC_FIELD_HELPER = Class.forName('grails.validation.Validateable$Trait$StaticFieldHelper') - @Shared JsonMapper objectMapper = JsonMapper.builder().build() void setup() { - ConstraintEvalUtils.clearDefaultConstraints() - clearConstraintsMapCache(SuperHero) + SuperHero.clearConstraintsMapCache() mappingContext.addPersistentEntities(Widget, Author, Book, ResearchPaper) } void cleanup() { - ConstraintEvalUtils.clearDefaultConstraints() - clearConstraintsMapCache(SuperHero) - } - - /** - * Clears the private static constraintsMapInternal field in the Validateable trait. - */ - private static void clearConstraintsMapCache(Class clazz) { - if (STATIC_FIELD_HELPER.isAssignableFrom(clazz)) { - def setterMethod = clazz.getMethod('grails_validation_Validateable__constraintsMapInternal$set', Map) - setterMethod.invoke(null, (Map) null) - } + // Leaves SuperHero's cached constraints map clean for whichever spec runs next in this + // fork, rather than relying solely on the reset in setup() above. + SuperHero.clearConstraintsMapCache() } void 'test simple case'() { diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/handleassociations/Fixtures.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/handleassociations/Fixtures.groovy new file mode 100644 index 00000000000..4004ba22a66 --- /dev/null +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/api/handleassociations/Fixtures.groovy @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.plugin.json.view.api.handleassociations + +import grails.persistence.Entity + +// Own copy of grails.plugin.json.view.api.JsonApiSpec's Author fixture so that +// JsonApiHandleAssociationsSpec doesn't silently bind to another spec's @Entity classes via +// same-package resolution (see PR #16033 review discussion). +@Entity +class Author { + String name +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/expand/Fixtures.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/expand/Fixtures.groovy new file mode 100644 index 00000000000..4dadb1d7b11 --- /dev/null +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/expand/Fixtures.groovy @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.plugin.json.view.expand + +import grails.persistence.Entity + +// Own copy of grails.plugin.json.view.JsonViewHelperSpec's Team/Player fixtures so that +// ExpandSpec doesn't silently bind to another spec's @Entity classes via same-package +// resolution (see PR #16033 review discussion). +@Entity +class Team { + String name + Player captain + List players + List titles + @SuppressWarnings('unused') + static hasMany = [players: Player] +} + +@Entity +class Player { + Long version + String name + @SuppressWarnings('unused') + static belongsTo = [team: Team] + + static constraints = { + name nullable: false + } +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/halembedded/Fixtures.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/halembedded/Fixtures.groovy new file mode 100644 index 00000000000..9b5e17ce58d --- /dev/null +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/halembedded/Fixtures.groovy @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.plugin.json.view.halembedded + +import grails.gorm.annotation.Entity + +// Own copies of grails.plugin.json.view.JsonViewHelperSpec's Team/Player and +// grails.plugin.json.view.EmbeddedAssociationsSpec's Person/Address fixtures so that +// HalEmbeddedSpec doesn't silently bind to another spec's @Entity classes via +// same-package resolution (see PR #16033 review discussion). +@Entity +class Team { + String name + Player captain + List players + List titles + @SuppressWarnings('unused') + static hasMany = [players: Player] +} + +@Entity +class Player { + Long version + String name + @SuppressWarnings('unused') + static belongsTo = [team: Team] + + static constraints = { + name nullable: false + } +} + +@Entity +class Person { + String name + Address homeAddress + List
otherAddresses = [] + List nickNames = [] + + @SuppressWarnings('unused') + static embedded = ['homeAddress', 'otherAddresses'] +} + +class Address { + String postCode +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/include/Fixtures.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/include/Fixtures.groovy new file mode 100644 index 00000000000..c7859206628 --- /dev/null +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/include/Fixtures.groovy @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.plugin.json.view.include + +import grails.persistence.Entity + +// Own copy of grails.plugin.json.view.JsonViewHelperSpec's Team/Player fixtures so that +// IncludeAssociationsSpec doesn't silently bind to another spec's @Entity classes via +// same-package resolution (see PR #16033 review discussion). +@Entity +class Team { + String name + Player captain + List players + List titles + @SuppressWarnings('unused') + static hasMany = [players: Player] +} + +@Entity +class Player { + Long version + String name + @SuppressWarnings('unused') + static belongsTo = [team: Team] + + static constraints = { + name nullable: false + } +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/iterable/Fixtures.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/iterable/Fixtures.groovy new file mode 100644 index 00000000000..7d2d6875e23 --- /dev/null +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/iterable/Fixtures.groovy @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.plugin.json.view.iterable + +import grails.persistence.Entity + +// Own copy of grails.plugin.json.view.JsonViewHelperSpec's Team/Player fixtures so that +// IterableRenderSpec doesn't silently bind to another spec's @Entity classes via +// same-package resolution (see PR #16033 review discussion). +@Entity +class Team { + String name + Player captain + List players + List titles + @SuppressWarnings('unused') + static hasMany = [players: Player] +} + +@Entity +class Player { + Long version + String name + @SuppressWarnings('unused') + static belongsTo = [team: Team] + + static constraints = { + name nullable: false + } +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/maprender/Fixtures.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/maprender/Fixtures.groovy new file mode 100644 index 00000000000..3805fec9207 --- /dev/null +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/maprender/Fixtures.groovy @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.plugin.json.view.maprender + +import grails.persistence.Entity + +// Own copy of grails.plugin.json.view.JsonViewHelperSpec's Team/Player/PlayerWithAge fixtures +// so that MapRenderSpec doesn't silently bind to another spec's @Entity classes via +// same-package resolution (see PR #16033 review discussion). +@Entity +class Team { + String name + Player captain + List players + List titles + @SuppressWarnings('unused') + static hasMany = [players: Player] +} + +@Entity +class Player { + Long version + String name + @SuppressWarnings('unused') + static belongsTo = [team: Team] + + static constraints = { + name nullable: false + } +} + +@Entity +class PlayerWithAge { + String name + int age +} diff --git a/grails-views-gson/src/test/groovy/grails/plugin/json/view/nullrendering/Fixtures.groovy b/grails-views-gson/src/test/groovy/grails/plugin/json/view/nullrendering/Fixtures.groovy new file mode 100644 index 00000000000..30bffbcf798 --- /dev/null +++ b/grails-views-gson/src/test/groovy/grails/plugin/json/view/nullrendering/Fixtures.groovy @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package grails.plugin.json.view.nullrendering + +import grails.persistence.Entity + +// Own copy of grails.plugin.json.view.JsonViewHelperSpec's Team/Player fixtures, and a POGO +// standing in for grails.plugin.json.view.PogoDeepRenderingSpec's Child2, so that +// NullRenderingSpec doesn't silently bind to another spec's fixture classes via +// same-package resolution (see PR #16033 review discussion). +@Entity +class Team { + String name + Player captain + List players + List titles + @SuppressWarnings('unused') + static hasMany = [players: Player] +} + +@Entity +class Player { + Long version + String name + @SuppressWarnings('unused') + static belongsTo = [team: Team] + + static constraints = { + name nullable: false + } +} + +class Child { + String name + Object parent +}