Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable consul in test #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
@@ -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 {

Expand Down
2 changes: 2 additions & 0 deletions ex02/solution/clubs/src/main/groovy/clubs/Application.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package clubs

import groovy.transform.CompileStatic
import io.micronaut.runtime.Micronaut

@CompileStatic
class Application {

static void main(String... args) {
Expand Down
2 changes: 2 additions & 0 deletions ex02/solution/clubs/src/main/groovy/clubs/api/ClubsApi.groovy
Original file line number Diff line number Diff line change
@@ -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("/")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}
5 changes: 4 additions & 1 deletion ex02/solution/clubs/src/main/groovy/clubs/domain/Club.groovy
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package clubs.domain

import grails.gorm.annotation.Entity
import groovy.transform.CompileStatic
import org.grails.datastore.gorm.GormEntity

@CompileStatic
@Entity
class Club {
class Club implements GormEntity<Club> {

String name
String stadium
Expand Down
4 changes: 4 additions & 0 deletions ex02/solution/clubs/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
consul:
client:
registration:
enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -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<Club> 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>
Expand All @@ -34,12 +34,14 @@ class ClubControllerSpec extends Specification {
List<Club> 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'
Expand Down
28 changes: 14 additions & 14 deletions ex02/solution/clubs/src/test/groovy/clubs/ClubServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<Club> 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[]
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fixtures

import groovy.transform.CompileStatic
import io.micronaut.runtime.Micronaut

@CompileStatic
class Application {

static void main(String... args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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("/")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package fixtures.clubs

class Club {
import groovy.transform.CompileStatic

@CompileStatic
class Club {
String name
String stadium

}
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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[]
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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<Fixture> {

//tag::fields[]
ObjectId id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ abstract class FixtureService {
//GORM operations
abstract Fixture save(@Valid Fixture fixture)
abstract List<Fixture> findAll()
abstract Number count()
//end::gorm-operations[]

//tag::to-view[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fixtures.view

import groovy.transform.CompileStatic

@CompileStatic
class FixtureView {

//tag::fields[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
consul:
client:
registration:
enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down