From 9c88b3edad4792f9411e09508e57dcf5cfd42821 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:32:03 +0200 Subject: [PATCH 1/8] disable consul in test --- ex02/solution/clubs/src/main/resources/application-test.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ex02/solution/clubs/src/main/resources/application-test.yml diff --git a/ex02/solution/clubs/src/main/resources/application-test.yml b/ex02/solution/clubs/src/main/resources/application-test.yml new file mode 100644 index 0000000..b52778e --- /dev/null +++ b/ex02/solution/clubs/src/main/resources/application-test.yml @@ -0,0 +1,4 @@ +consul: + client: + registration: + enabled: false \ No newline at end of file From 75a9698baa732cc5a97a568edb34805763b584db Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:33:26 +0200 Subject: [PATCH 2/8] Use old and remove magic numbers from test --- .../groovy/clubs/ClubControllerSpec.groovy | 12 ++++---- .../test/groovy/clubs/ClubServiceSpec.groovy | 28 +++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ex02/solution/clubs/src/test/groovy/clubs/ClubControllerSpec.groovy b/ex02/solution/clubs/src/test/groovy/clubs/ClubControllerSpec.groovy index 182b427..eac63b2 100644 --- a/ex02/solution/clubs/src/test/groovy/clubs/ClubControllerSpec.groovy +++ b/ex02/solution/clubs/src/test/groovy/clubs/ClubControllerSpec.groovy @@ -16,12 +16,12 @@ class ClubControllerSpec extends Specification { @Shared @AutoCleanup EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer) @Shared ClubsClient client = embeddedServer.applicationContext.getBean(ClubsClient) @Shared ClubService service = embeddedServer.applicationContext.getBean(ClubService) - @Shared Long id + @Shared List clubs = [] @Transactional // <1> void setupSpec() { - id = service.save("Real Madrid CF", "Santiago Bernabeu").id - service.save("FC Barcelona", "Camp Nou") + clubs << service.save("Real Madrid CF", "Santiago Bernabeu") + clubs << service.save("FC Barcelona", "Camp Nou") } @Transactional // <1> @@ -34,12 +34,14 @@ class ClubControllerSpec extends Specification { List response = client.listClubs() then: - response.size() == 2 + response.size() == clubs.size() } void "test find one"() { + given: + Long realMadridId = clubs.find { it.name == 'Real Madrid CF'}.id when: - Club club = client.show(id) + Club club = client.show(realMadridId) then: club.name == 'Real Madrid CF' diff --git a/ex02/solution/clubs/src/test/groovy/clubs/ClubServiceSpec.groovy b/ex02/solution/clubs/src/test/groovy/clubs/ClubServiceSpec.groovy index 297dc8a..c1d7491 100644 --- a/ex02/solution/clubs/src/test/groovy/clubs/ClubServiceSpec.groovy +++ b/ex02/solution/clubs/src/test/groovy/clubs/ClubServiceSpec.groovy @@ -17,32 +17,32 @@ class ClubServiceSpec extends Specification { @Shared ClubService service = embeddedServer.applicationContext.getBean(ClubService) // <2> void "it can work with clubs"() { - expect: - service.count() == 0 - when: service.save("Real Madrid CF", "Bernabeu") then: - service.count() == 1 + service.count() == old(service.count()) + 1 + service.findAll().size() == old(service.findAll().size()) + 1 + } + + void "it can save and fetch a club"() { + given: + final String name = 'CD Leganes' + final String stadium = 'Butarque' when: - List clubs = service.findAll() + Club savedClub = service.save(name, stadium) then: - clubs.size() == 1 - } - - void "it can show a club"() { - given: - Club club = service.save("CD Leganes", "Butarque") + savedClub.name == name + savedClub.stadium == stadium when: - service.find(club.id) + Club club = service.find(savedClub.id) then: - club.name == "CD Leganes" - club.stadium == "Butarque" + club.name == name + club.stadium == stadium } } //end::spec[] From 95c69510366687c1a4448042a07a41824a49f157 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:39:12 +0200 Subject: [PATCH 3/8] disable consul in test --- .../solution/fixtures/src/main/resources/application-test.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 ex03/solution/fixtures/src/main/resources/application-test.yml diff --git a/ex03/solution/fixtures/src/main/resources/application-test.yml b/ex03/solution/fixtures/src/main/resources/application-test.yml new file mode 100644 index 0000000..b52778e --- /dev/null +++ b/ex03/solution/fixtures/src/main/resources/application-test.yml @@ -0,0 +1,4 @@ +consul: + client: + registration: + enabled: false \ No newline at end of file From 5eae645b34776acd692bad93c15dcb1ea1009301 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:51:28 +0200 Subject: [PATCH 4/8] Annotate with @CompileStatic --- .../fixtures/src/main/groovy/fixtures/Application.groovy | 2 ++ .../src/main/groovy/fixtures/client/FixtureClient.groovy | 2 ++ .../fixtures/src/main/groovy/fixtures/clubs/Club.groovy | 5 +++-- .../fixtures/src/main/groovy/fixtures/clubs/ClubsApi.groovy | 2 ++ .../src/main/groovy/fixtures/clubs/ClubsClient.groovy | 2 ++ .../main/groovy/fixtures/controller/FixtureController.groovy | 2 ++ .../fixtures/src/main/groovy/fixtures/domain/Fixture.groovy | 2 ++ .../src/main/groovy/fixtures/view/FixtureView.groovy | 3 +++ 8 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/Application.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/Application.groovy index 4bc3c53..d9817f4 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/Application.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/Application.groovy @@ -1,7 +1,9 @@ package fixtures +import groovy.transform.CompileStatic import io.micronaut.runtime.Micronaut +@CompileStatic class Application { static void main(String... args) { diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/client/FixtureClient.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/client/FixtureClient.groovy index 25873b0..d25feac 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/client/FixtureClient.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/client/FixtureClient.groovy @@ -1,9 +1,11 @@ package fixtures.client import fixtures.view.FixtureView +import groovy.transform.CompileStatic import io.micronaut.http.annotation.Get import io.micronaut.http.client.Client +@CompileStatic @Client("/") interface FixtureClient { @Get("/") diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/Club.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/Club.groovy index 452076d..aa8c4a6 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/Club.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/Club.groovy @@ -1,8 +1,9 @@ package fixtures.clubs -class Club { +import groovy.transform.CompileStatic +@CompileStatic +class Club { String name String stadium - } \ No newline at end of file diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsApi.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsApi.groovy index eb53e04..5969cd6 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsApi.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsApi.groovy @@ -1,8 +1,10 @@ package fixtures.clubs +import groovy.transform.CompileStatic import io.micronaut.http.annotation.Get import io.reactivex.Maybe +@CompileStatic //tag::class[] interface ClubsApi { @Get("/{id}") diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsClient.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsClient.groovy index bc6f9af..d9c7ac8 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsClient.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/clubs/ClubsClient.groovy @@ -1,8 +1,10 @@ package fixtures.clubs +import groovy.transform.CompileStatic import io.micronaut.http.client.Client //tag::class[] +@CompileStatic @Client("clubs") // <1> interface ClubsClient extends ClubsApi {} //end::class[] diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/controller/FixtureController.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/controller/FixtureController.groovy index 32016e1..9708002 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/controller/FixtureController.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/controller/FixtureController.groovy @@ -2,9 +2,11 @@ package fixtures.controller import fixtures.service.FixtureService import fixtures.view.FixtureView +import groovy.transform.CompileStatic import io.micronaut.http.annotation.Controller import io.micronaut.http.annotation.Get +@CompileStatic @Controller("/") class FixtureController { diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy index b981fce..fc0c0ec 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy @@ -1,8 +1,10 @@ package fixtures.domain import grails.gorm.annotation.Entity +import groovy.transform.CompileStatic import org.bson.types.ObjectId +@CompileStatic @Entity class Fixture { diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/view/FixtureView.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/view/FixtureView.groovy index f3ebb2e..d9103ff 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/view/FixtureView.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/view/FixtureView.groovy @@ -1,5 +1,8 @@ package fixtures.view +import groovy.transform.CompileStatic + +@CompileStatic class FixtureView { //tag::fields[] From 3adbe58f625006fa0219d7bc8ae6bfeb05fd5f97 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:51:35 +0200 Subject: [PATCH 5/8] verify save works --- .../src/main/groovy/fixtures/service/FixtureService.groovy | 1 + .../src/test/groovy/fixtures/FixtureServiceSpec.groovy | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/service/FixtureService.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/service/FixtureService.groovy index 1399e59..0c18375 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/service/FixtureService.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/service/FixtureService.groovy @@ -22,6 +22,7 @@ abstract class FixtureService { //GORM operations abstract Fixture save(@Valid Fixture fixture) abstract List findAll() + abstract Number count() //end::gorm-operations[] //tag::to-view[] diff --git a/ex03/solution/fixtures/src/test/groovy/fixtures/FixtureServiceSpec.groovy b/ex03/solution/fixtures/src/test/groovy/fixtures/FixtureServiceSpec.groovy index fe2f424..f141265 100644 --- a/ex03/solution/fixtures/src/test/groovy/fixtures/FixtureServiceSpec.groovy +++ b/ex03/solution/fixtures/src/test/groovy/fixtures/FixtureServiceSpec.groovy @@ -18,8 +18,12 @@ class FixtureServiceSpec extends Specification { given: Date now = new Date() Fixture fixture = new Fixture(homeClubId: 1, homeScore: 5, awayClubId: 2, awayScore: 0, date: now) + when: fixture = fixtureService.save(fixture) + then: + fixtureService.count() == old(fixtureService.count()) + 1 + when: FixtureView view = fixtureService.toView(fixture).blockingGet() From ce7f7c011901a3a2099b15f0f85bb49e7ef1deb9 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:54:06 +0200 Subject: [PATCH 6/8] Use of GormEntity to aid IDE support. --- ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy | 3 ++- .../fixtures/src/main/groovy/fixtures/domain/Fixture.groovy | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy b/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy index 92c36c1..7b3fc15 100644 --- a/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy +++ b/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy @@ -1,9 +1,10 @@ package clubs.domain import grails.gorm.annotation.Entity +import org.grails.datastore.gorm.GormEntity @Entity -class Club { +class Club implements GormEntity { String name String stadium diff --git a/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy b/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy index fc0c0ec..de87f26 100644 --- a/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy +++ b/ex03/solution/fixtures/src/main/groovy/fixtures/domain/Fixture.groovy @@ -3,10 +3,11 @@ package fixtures.domain import grails.gorm.annotation.Entity import groovy.transform.CompileStatic import org.bson.types.ObjectId +import org.grails.datastore.gorm.GormEntity @CompileStatic @Entity -class Fixture { +class Fixture implements GormEntity { //tag::fields[] ObjectId id From 2bc11b4398a3dd93b30bed6e5f58501681070a17 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:54:46 +0200 Subject: [PATCH 7/8] Annotate with @CompileStatic --- ex02/solution/clubs/src/main/groovy/clubs/Application.groovy | 2 ++ ex02/solution/clubs/src/main/groovy/clubs/api/ClubsApi.groovy | 2 ++ .../clubs/src/main/groovy/clubs/client/ClubsClient.groovy | 2 ++ ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy | 2 ++ 4 files changed, 8 insertions(+) diff --git a/ex02/solution/clubs/src/main/groovy/clubs/Application.groovy b/ex02/solution/clubs/src/main/groovy/clubs/Application.groovy index 0fbe738..a594dda 100644 --- a/ex02/solution/clubs/src/main/groovy/clubs/Application.groovy +++ b/ex02/solution/clubs/src/main/groovy/clubs/Application.groovy @@ -1,7 +1,9 @@ package clubs +import groovy.transform.CompileStatic import io.micronaut.runtime.Micronaut +@CompileStatic class Application { static void main(String... args) { diff --git a/ex02/solution/clubs/src/main/groovy/clubs/api/ClubsApi.groovy b/ex02/solution/clubs/src/main/groovy/clubs/api/ClubsApi.groovy index c7347d7..e8e7139 100644 --- a/ex02/solution/clubs/src/main/groovy/clubs/api/ClubsApi.groovy +++ b/ex02/solution/clubs/src/main/groovy/clubs/api/ClubsApi.groovy @@ -1,8 +1,10 @@ package clubs.api import clubs.domain.Club +import groovy.transform.CompileStatic import io.micronaut.http.annotation.Get +@CompileStatic interface ClubsApi { @Get("/") diff --git a/ex02/solution/clubs/src/main/groovy/clubs/client/ClubsClient.groovy b/ex02/solution/clubs/src/main/groovy/clubs/client/ClubsClient.groovy index 4181708..a52f217 100644 --- a/ex02/solution/clubs/src/main/groovy/clubs/client/ClubsClient.groovy +++ b/ex02/solution/clubs/src/main/groovy/clubs/client/ClubsClient.groovy @@ -1,7 +1,9 @@ package clubs.client import clubs.api.ClubsApi +import groovy.transform.CompileStatic import io.micronaut.http.client.Client +@CompileStatic @Client("/") interface ClubsClient extends ClubsApi {} \ No newline at end of file diff --git a/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy b/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy index 7b3fc15..cd2b4c2 100644 --- a/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy +++ b/ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy @@ -1,8 +1,10 @@ package clubs.domain import grails.gorm.annotation.Entity +import groovy.transform.CompileStatic import org.grails.datastore.gorm.GormEntity +@CompileStatic @Entity class Club implements GormEntity { From 85e5420cd99ea71d5120f4e576dabf7164aefd28 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Tue, 26 Jun 2018 11:55:45 +0200 Subject: [PATCH 8/8] Adds @CompileStatic --- .../src/main/groovy/hello/galaxy/HelloController.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ex01/solution/hello-galaxy/src/main/groovy/hello/galaxy/HelloController.groovy b/ex01/solution/hello-galaxy/src/main/groovy/hello/galaxy/HelloController.groovy index 3943380..2f4d872 100644 --- a/ex01/solution/hello-galaxy/src/main/groovy/hello/galaxy/HelloController.groovy +++ b/ex01/solution/hello-galaxy/src/main/groovy/hello/galaxy/HelloController.groovy @@ -1,9 +1,10 @@ package hello.galaxy +import groovy.transform.CompileStatic import io.micronaut.http.annotation.Controller import io.micronaut.http.annotation.Get - +@CompileStatic @Controller("/hello") class HelloController {