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 @@ -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
Expand All @@ -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)
'''

Expand Down Expand Up @@ -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)
'''

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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<Player> players

json {
hal.embedded(players:players)
total 1
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -477,4 +483,4 @@ class HalEmbeddedSpec extends Specification implements JsonViewTest {
class Parent {
String name
Person person
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Player> players

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Player> players

json g.render(players)
''', [players: players])

Expand All @@ -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<Player> players

json hal.render(players)
''', [players: players])

Expand Down Expand Up @@ -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<Player> players

json jsonapi.render(players)
''', [players: players]) {
uri = '/foo'
Expand Down Expand Up @@ -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<Player> players

json jsonapi.render(players)
''', [players: players]) {
uri = '/foo'
Expand Down Expand Up @@ -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<Player> players

json jsonapi.render(players, [pagination: [resource: Player, total: 11]])
''', [players: players], {
uri = '/foo'
Expand Down Expand Up @@ -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<Player> players

json jsonapi.render(players, [pagination: [resource: Player, total: 11, max: 5]])
''', [players: players]) {
uri = '/foo'
Expand Down Expand Up @@ -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<Player> players

json jsonapi.render(players, [pagination: [total: 11]])
''', [players: players]) {
uri = '/foo'
Expand Down
Loading
Loading