From 2696569a854728d2ad217165c773361e92ca48b0 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 27 Apr 2016 16:39:11 +0200 Subject: [PATCH] Stub Runner Spring Boot version (#248) fixes #247 --- .../bootSimple/gradle.properties | 4 +- .../messagingProject/build.gradle | 8 +- .../messagingProject/gradle.properties | 4 +- gradle.properties | 3 +- samples/messaging-camel/build.gradle | 4 +- samples/messaging-integration/build.gradle | 6 +- samples/messaging-spring/build.gradle | 4 +- samples/messaging-stream/build.gradle | 2 +- settings.gradle | 1 + stub-runner/stub-runner-boot/README.adoc | 51 ++++++++++ stub-runner/stub-runner-boot/build.gradle | 22 +++++ .../boot/HttpStubsController.groovy | 38 ++++++++ .../stubrunner/boot/StubRunnerBoot.groovy | 15 +++ .../stubrunner/boot/TriggerController.groovy | 59 +++++++++++ .../main/resources/META-INF/spring.factories | 3 + .../stubrunner/boot/StubRunnerBootSpec.groovy | 92 ++++++++++++++++++ .../src/test/resources/application.yml | 2 + .../0.0.1-SNAPSHOT/maven-metadata-local.xml | 12 +++ .../streamService-0.0.1-SNAPSHOT-stubs.jar | Bin 0 -> 1746 bytes .../streamService-0.0.1-SNAPSHOT.pom | 9 ++ .../streamService/maven-metadata-local.xml | 12 +++ .../stubrunner/junit/AccurestRule.java | 5 + .../stub-runner-messaging-camel/build.gradle | 2 +- .../build.gradle | 4 +- .../stub-runner-messaging-stream/build.gradle | 2 +- .../stub-runner-spring-cloud/build.gradle | 2 +- stub-runner/stub-runner-spring/build.gradle | 4 +- .../stubrunner/BatchStubRunner.groovy | 16 ++- .../accurest/stubrunner/RunningStubs.groovy | 5 +- .../stubrunner/StubConfiguration.groovy | 7 +- .../accurest/stubrunner/StubRunner.groovy | 5 + .../stubrunner/StubRunnerExecutor.groovy | 9 +- .../accurest/stubrunner/StubTrigger.groovy | 7 ++ .../stubrunner/BatchStubRunnerSpec.groovy | 3 +- 34 files changed, 391 insertions(+), 31 deletions(-) create mode 100644 stub-runner/stub-runner-boot/README.adoc create mode 100644 stub-runner/stub-runner-boot/build.gradle create mode 100644 stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/HttpStubsController.groovy create mode 100644 stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBoot.groovy create mode 100644 stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/TriggerController.groovy create mode 100644 stub-runner/stub-runner-boot/src/main/resources/META-INF/spring.factories create mode 100644 stub-runner/stub-runner-boot/src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy create mode 100644 stub-runner/stub-runner-boot/src/test/resources/application.yml create mode 100644 stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml create mode 100644 stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar create mode 100644 stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT.pom create mode 100644 stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata-local.xml diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties index c484dce638..03c9b16bb8 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/gradle.properties @@ -1,4 +1,6 @@ groupId=com.ofg jacksonMapper=1.9.13 restAssuredVersion=2.4.0 -springVersion=4.1.7.RELEASE \ No newline at end of file +springVersion=4.1.7.RELEASE + +springBootVersion=1.3.3.RELEASE \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle index a4a2ae6524..5fffa182b2 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/build.gradle @@ -46,14 +46,14 @@ repositories { dependencies { compile "org.codehaus.groovy:groovy-all:2.4.5" - compile 'org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE' - compile 'org.springframework.boot:spring-boot-starter-actuator:1.3.3.RELEASE' - compile 'org.springframework.boot:spring-boot-starter-integration:1.3.3.RELEASE' + compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" + compile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}" compile fileTree(dir: messagingLibsDir, include: '*.jar') testCompile "org.spockframework:spock-spring:1.0-groovy-2.4" - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile "ch.qos.logback:logback-classic:1.1.2" } diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties index 47ede0913e..6910517f7c 100644 --- a/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/messagingProject/gradle.properties @@ -1,4 +1,6 @@ groupId=io.codearte jacksonMapper=1.9.13 restAssuredVersion=2.9.0 -springVersion=4.2.3.RELEASE \ No newline at end of file +springVersion=4.2.3.RELEASE + +springBootVersion=1.3.3.RELEASE \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 14988fcafe..7181615caf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,5 @@ nexusPassword = wiremockVersion = 2.0.10-beta jsonassertVersion = 0.2.2 -BOM_VERSION=Brixton-1.0.0.RC1 \ No newline at end of file +BOM_VERSION=Brixton-1.0.0.RC1 +springBootVersion=1.3.3.RELEASE \ No newline at end of file diff --git a/samples/messaging-camel/build.gradle b/samples/messaging-camel/build.gradle index bc1c2750b3..3484906ce6 100644 --- a/samples/messaging-camel/build.gradle +++ b/samples/messaging-camel/build.gradle @@ -11,7 +11,7 @@ repositories { dependencies { compile project(':accurest-core') - compile 'org.springframework.boot:spring-boot-starter-actuator:1.3.3.RELEASE' + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" compile 'org.apache.camel:camel-spring-boot-starter:2.17.0' compile 'org.apache.camel:camel-jms:2.17.0' compile 'org.apache.activemq:activemq-camel:5.12.1' @@ -19,7 +19,7 @@ dependencies { compile 'org.apache.camel:camel-jackson:2.17.0' testCompile project(':accurest-messaging-root:accurest-messaging-camel') - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') } diff --git a/samples/messaging-integration/build.gradle b/samples/messaging-integration/build.gradle index d583c1e803..94be6d9087 100644 --- a/samples/messaging-integration/build.gradle +++ b/samples/messaging-integration/build.gradle @@ -11,11 +11,11 @@ repositories { dependencies { compile project(':accurest-core') - compile 'org.springframework.boot:spring-boot-starter-actuator:1.3.3.RELEASE' - compile 'org.springframework.boot:spring-boot-starter-integration:1.3.3.RELEASE' + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" + compile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}" testCompile project(':accurest-messaging-root:accurest-messaging-integration') - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') } diff --git a/samples/messaging-spring/build.gradle b/samples/messaging-spring/build.gradle index a422f0a484..e1bb4de06e 100644 --- a/samples/messaging-spring/build.gradle +++ b/samples/messaging-spring/build.gradle @@ -11,14 +11,14 @@ repositories { dependencies { compile project(':accurest-core') - compile 'org.springframework.boot:spring-boot-starter-actuator:1.3.3.RELEASE' + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" compile 'org.springframework:spring-jms:4.2.3.RELEASE' compile 'org.apache.activemq:activemq-broker:5.12.1' compile 'org.apache.activemq:activemq-pool:5.12.1' testCompile project(':accurest-messaging-root:accurest-messaging-core') - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') } diff --git a/samples/messaging-stream/build.gradle b/samples/messaging-stream/build.gradle index 69a151237c..5f94330b61 100644 --- a/samples/messaging-stream/build.gradle +++ b/samples/messaging-stream/build.gradle @@ -11,7 +11,7 @@ repositories { dependencies { compile project(':accurest-core') - compile 'org.springframework.boot:spring-boot-starter-actuator:1.3.3.RELEASE' + compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}" compile 'org.springframework.cloud:spring-cloud-stream-binder-rabbit:1.0.0.RC2' testCompile project(':accurest-messaging-root:accurest-messaging-stream') diff --git a/settings.gradle b/settings.gradle index da50942a1e..7c598a3401 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,6 +8,7 @@ include ':accurest-messaging:accurest-messaging-camel' include ':stub-runner:stub-runner' include ':stub-runner:stub-runner-spring' +include ':stub-runner:stub-runner-boot' include ':stub-runner:stub-runner-spring-cloud' include ':stub-runner:stub-runner-junit' diff --git a/stub-runner/stub-runner-boot/README.adoc b/stub-runner/stub-runner-boot/README.adoc new file mode 100644 index 0000000000..352e073f07 --- /dev/null +++ b/stub-runner/stub-runner-boot/README.adoc @@ -0,0 +1,51 @@ +=== Stub Runner Boot + +Accurest Stub Runner Boot is a Spring Boot application that exposes REST endpoints to +trigger the messaging labels and to access started WireMock servers. + +==== How to use it? + +Just add the + +[source,groovy,indent=0] +---- +compile "io.codearte.accurest:stub-runner-boot:${accurestVersion}" +---- + +and a messaging implementation: + +[source,groovy,indent=0] +---- +// for Apache Camel +compile "io.codearte.accurest:accurest-messaging-camel:${accurestVersion}" +// for Spring Integration +compile "io.codearte.accurest:accurest-messaging-integration:${accurestVersion}" +// for Spring Cloud Stream +compile "io.codearte.accurest:accurest-messaging-stream:${accurestVersion}" +---- + +Build a fat-jar and you're ready to go! + +For the properties check the *Stub Runner Spring* section. + +==== Endpoints + +===== HTTP + +- GET `/stubs` - returns a list of all running stubs in `ivy:integer` notation +- GET `/stubs/{ivy}` - returns a port for the given `ivy` notation (when calling the endpoint `ivy` can also be `artifactId` only) + +===== Messaging + +For Messaging + +- GET `/triggers` - returns a list of all running labels in `ivy : [ label1, label2 ...]` notation +- POST `/triggers/{label}` - executes a trigger with `label` +- POST `/triggers/{ivy}/{label}` - executes a trigger with `label` for the given `ivy` notation (when calling the endpoint `ivy` can also be `artifactId` only) + +==== Example + +[source,groovy,indent=0] +---- +include::src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy[tags=boot_usage] +---- \ No newline at end of file diff --git a/stub-runner/stub-runner-boot/build.gradle b/stub-runner/stub-runner-boot/build.gradle new file mode 100644 index 0000000000..a10236151b --- /dev/null +++ b/stub-runner/stub-runner-boot/build.gradle @@ -0,0 +1,22 @@ +repositories { + mavenLocal() + jcenter() + maven { + url "http://repo.spring.io/snapshot" + } + maven { + url "http://repo.spring.io/milestone" + } +} + +dependencies { + compile project(':stub-runner-root:stub-runner-spring') + compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" + + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" + testCompile project(':stub-runner-root:stub-runner-messaging-root:stub-runner-messaging-stream') + testCompile 'com.jayway.restassured:spring-mock-mvc:2.9.0' + testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { + exclude(group: 'org.codehaus.groovy') + } +} \ No newline at end of file diff --git a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/HttpStubsController.groovy b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/HttpStubsController.groovy new file mode 100644 index 0000000000..9a4806edc9 --- /dev/null +++ b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/HttpStubsController.groovy @@ -0,0 +1,38 @@ +package io.codearte.accurest.stubrunner.boot + +import io.codearte.accurest.stubrunner.StubRunning +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +/** + * @author Marcin Grzejszczak + */ +@RestController +@RequestMapping("/stubs") +class HttpStubsController { + + private final StubRunning stubRunning + + @Autowired + HttpStubsController(StubRunning stubRunning) { + this.stubRunning = stubRunning + } + + @RequestMapping + Map stubs() { + return stubRunning.runStubs().toIvyToPortMapping() + } + + @RequestMapping(path = "/{ivy:.*}") + ResponseEntity stub(@PathVariable String ivy) { + Integer port = stubRunning.runStubs().getPort(ivy) + if (port) { + return ResponseEntity.ok(port) + } + return new ResponseEntity(HttpStatus.NOT_FOUND) + } +} diff --git a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBoot.groovy b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBoot.groovy new file mode 100644 index 0000000000..d3ec34a69e --- /dev/null +++ b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBoot.groovy @@ -0,0 +1,15 @@ +package io.codearte.accurest.stubrunner.boot + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication + +/** + * @author Marcin Grzejszczak + */ +@SpringBootApplication +class StubRunnerBoot { + + static void main(String[] args) { + SpringApplication.run(StubRunnerBoot.class, args); + } +} diff --git a/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/TriggerController.groovy b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/TriggerController.groovy new file mode 100644 index 0000000000..7bb1a002f7 --- /dev/null +++ b/stub-runner/stub-runner-boot/src/main/groovy/io/codearte/accurest/stubrunner/boot/TriggerController.groovy @@ -0,0 +1,59 @@ +package io.codearte.accurest.stubrunner.boot + +import groovy.util.logging.Slf4j +import io.codearte.accurest.stubrunner.StubFinder +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +import static org.springframework.web.bind.annotation.RequestMethod.GET +import static org.springframework.web.bind.annotation.RequestMethod.POST + +/** + * @author Marcin Grzejszczak + */ +@RestController +@RequestMapping("/triggers") +@Slf4j +class TriggerController { + + private final StubFinder stubFinder + + @Autowired + TriggerController(StubFinder stubFinder) { + this.stubFinder = stubFinder + } + + @RequestMapping(method = POST, path = "/{label:.*}") + ResponseEntity>> trigger(@PathVariable String label) { + return respond(label) { + stubFinder.trigger(label) + } + } + + @RequestMapping(method = POST, path = "/{ivyNotation:.*}/{label:.*}") + ResponseEntity>> triggerByArtifact(@PathVariable String ivyNotation, @PathVariable String label) { + return respond(label) { + stubFinder.trigger(ivyNotation, label) + } + } + + @RequestMapping(method = GET) + Map> labels() { + return stubFinder.labels() + } + + private ResponseEntity>> respond(String label, Closure closure) { + try { + closure() + return ResponseEntity.ok().body() + } catch (Exception e) { + log.debug("Exception occurred while trying to return [$label] label", e) + return new ResponseEntity>>(stubFinder.labels(), HttpStatus.NOT_FOUND) + } + } + +} diff --git a/stub-runner/stub-runner-boot/src/main/resources/META-INF/spring.factories b/stub-runner/stub-runner-boot/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..1f6ec12f3e --- /dev/null +++ b/stub-runner/stub-runner-boot/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configuration +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +io.codearte.accurest.stubrunner.spring.StubRunnerConfiguration diff --git a/stub-runner/stub-runner-boot/src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy b/stub-runner/stub-runner-boot/src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy new file mode 100644 index 0000000000..2c7f041e89 --- /dev/null +++ b/stub-runner/stub-runner-boot/src/test/groovy/io/codearte/accurest/stubrunner/boot/StubRunnerBootSpec.groovy @@ -0,0 +1,92 @@ +package io.codearte.accurest.stubrunner.boot + +import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc +import groovy.json.JsonSlurper +import io.codearte.accurest.stubrunner.StubRunning +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.test.context.ContextConfiguration +import spock.lang.Specification + +/** + * @author Marcin Grzejszczak + */ +// tag::boot_usage[] +@ContextConfiguration(classes = StubRunnerBoot, loader = SpringApplicationContextLoader) +class StubRunnerBootSpec extends Specification { + + @Autowired StubRunning stubRunning + + def setup() { + RestAssuredMockMvc.standaloneSetup(new HttpStubsController(stubRunning), + new TriggerController(stubRunning)) + } + + def 'should return a list of running stub servers in "ivy:port" notation'() { + when: + String response = RestAssuredMockMvc.get('/stubs').body.asString() + then: + def root = new JsonSlurper().parseText(response) + root.'io.codearte.accurest.stubs:streamService:stubs' instanceof Integer + } + + def 'should return a port on which a [#stubId] stub is running'() { + when: + def response = RestAssuredMockMvc.get("/stubs/${stubId}") + then: + response.statusCode == 200 + response.body.as(Integer) > 0 + where: + stubId << ['io.codearte.accurest.stubs:streamService:stubs', 'io.codearte.accurest.stubs:streamService', 'streamService'] + } + + def 'should return 404 when missing stub was called'() { + when: + def response = RestAssuredMockMvc.get("/stubs/a:b:c:d") + then: + response.statusCode == 404 + } + + def 'should return a list of messaging labels that can be triggered'() { + when: + String response = RestAssuredMockMvc.get('/triggers').body.asString() + then: + response == '''{"io.codearte.accurest.stubs:streamService:stubs":["delete_book","return_book_1","return_book_2"]}''' + } + + def 'should trigger a messaging label'() { + given: + StubRunning stubRunning = Mock() + RestAssuredMockMvc.standaloneSetup(new HttpStubsController(stubRunning), new TriggerController(stubRunning)) + when: + def response = RestAssuredMockMvc.post("/triggers/delete_book") + then: + response.statusCode == 200 + and: + 1 * stubRunning.trigger('delete_book') + } + + def 'should trigger a messaging label for a stub with [#stubId] ivy notation'() { + given: + StubRunning stubRunning = Mock() + RestAssuredMockMvc.standaloneSetup(new HttpStubsController(stubRunning), new TriggerController(stubRunning)) + when: + def response = RestAssuredMockMvc.post("/triggers/$stubId/delete_book") + then: + response.statusCode == 200 + and: + 1 * stubRunning.trigger(stubId, 'delete_book') + where: + stubId << ['io.codearte.accurest.stubs:streamService:stubs', 'io.codearte.accurest.stubs:streamService', 'streamService'] + } + + def 'should return when trigger is missing'() { + when: + def response = RestAssuredMockMvc.post("/triggers/missing_label") + then: + response.statusCode == 404 + response.body.asString() == '''{"io.codearte.accurest.stubs:streamService:stubs":["delete_book","return_book_1","return_book_2"]}''' + } +// end::boot_usage[] + +} diff --git a/stub-runner/stub-runner-boot/src/test/resources/application.yml b/stub-runner/stub-runner-boot/src/test/resources/application.yml new file mode 100644 index 0000000000..154bfe1b6a --- /dev/null +++ b/stub-runner/stub-runner-boot/src/test/resources/application.yml @@ -0,0 +1,2 @@ +stubrunner.stubs.repository.root: classpath:m2repo/repository/ +stubrunner.stubs.ids: io.codearte.accurest.stubs:streamService \ No newline at end of file diff --git a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml new file mode 100644 index 0000000000..bad844ba2a --- /dev/null +++ b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + io.codearte.accurest.stubs + streamService + 0.0.1-SNAPSHOT + + + true + + 20160409062112 + + diff --git a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/0.0.1-SNAPSHOT/streamService-0.0.1-SNAPSHOT-stubs.jar new file mode 100644 index 0000000000000000000000000000000000000000..86c61d52ec4b9571f84240dc880daa2e9e5f5b71 GIT binary patch literal 1746 zcmWIWW@h1HVBp|j&|{wF!2kqIAOZ+Df!NnI#8KDN&rP41Apk|;rh2A#(m(~0KrDi+ z(AUw=)6F$FM9W7$;qWfsl_EwJwREYr^0ql^9WtID{d1|?MEQiV35J8Cn-Na zJ1DiJv?wn%#ZWK3C_lffGBkvffjM}xRJbn?msW5yFtWU0W?%plroF!0O%4JM=U=an z*mH(UwdCzI5m~3!4|=PuXZ|qUxSLJs-}kb$dB%Ip^P{@5gEY1tjkxx8$;BHHGwt?e zE&5(lc3HvtiT8o3$i(xGi|2lc2y=<8Y-rf}ID6AP7961ES=3gdP0N#N2%2wI|U9La*jX!q(RaC(+5Y9PgfcBZ3DHgq-FmR zWAvPN|JzN?y$AZ5FPj&CoqwGl6n~H~i2{bnd$}npyMf_h#YkM37$JvA3@|)GF~g*_ z*B=xnN6)`r{=tmx>B8jgi|PelEsbtjW3_b0>l5#!Jbv6Q4qw6NXwW{>{Qcf|*F-7kF%T)__5$Z$tq9dMOLv*$5$!1-ViU9XS-^z{K3m zw=Nygy&0l$souP^NlvURE&cwNCDBG4b_?3J&9y1I(6;to<)Y^?$Il*Yc)D6ZOlr$g zlMKTLTNR~J6n`DJXe|-toB6OW+TX9%dDE|-(ng!D+;v^5Y#R=jYUaBLD(Tf9v~6-c zKT~s;&Xkmb#jZQGo*qB>M3v8AG5>MCrb(UEOzVob2ZnO#9{t3I$lzLNB>`GS%S|jO z$jnPG24^%zCJ|=bXL*rE(CSWgY zSRsWCT0w(s8)n8uw(TX*Qf%%;whfVufwqCNF&^76a{{t$Y`~Hbmu=|z0%#W~UtqBd omUghEIB-A$)6QQ + + 4.0.0 + io.codearte.accurest.stubs + streamService + 0.0.1-SNAPSHOT + pom + diff --git a/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata-local.xml b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata-local.xml new file mode 100644 index 0000000000..dc32790f53 --- /dev/null +++ b/stub-runner/stub-runner-boot/src/test/resources/m2repo/repository/io/codearte/accurest/stubs/streamService/maven-metadata-local.xml @@ -0,0 +1,12 @@ + + + io.codearte.accurest.stubs + streamService + 0.0.1-SNAPSHOT + + + 0.0.1-SNAPSHOT + + 20160409062112 + + diff --git a/stub-runner/stub-runner-junit/src/main/groovy/io/codearte/accurest/stubrunner/junit/AccurestRule.java b/stub-runner/stub-runner-junit/src/main/groovy/io/codearte/accurest/stubrunner/junit/AccurestRule.java index 52178ecc01..7f29aaab71 100644 --- a/stub-runner/stub-runner-junit/src/main/groovy/io/codearte/accurest/stubrunner/junit/AccurestRule.java +++ b/stub-runner/stub-runner-junit/src/main/groovy/io/codearte/accurest/stubrunner/junit/AccurestRule.java @@ -182,4 +182,9 @@ public class AccurestRule implements TestRule, StubFinder { public boolean trigger() { return stubFinder.trigger(); } + + @Override + public Map> labels() { + return stubFinder.labels(); + } } diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/build.gradle b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/build.gradle index 31a1bf7460..d2c9ee5d07 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/build.gradle +++ b/stub-runner/stub-runner-messaging/stub-runner-messaging-camel/build.gradle @@ -18,7 +18,7 @@ dependencies { testCompile 'org.apache.camel:camel-jms:2.17.0' testCompile 'org.apache.activemq:activemq-camel:5.12.1' testCompile 'org.apache.activemq:activemq-pool:5.12.1' - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') } diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/build.gradle b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/build.gradle index 89699fedfe..fa82813497 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/build.gradle +++ b/stub-runner/stub-runner-messaging/stub-runner-messaging-integration/build.gradle @@ -14,8 +14,8 @@ dependencies { compile project(':accurest-messaging-root:accurest-messaging-integration') compile 'org.springframework.integration:spring-integration-java-dsl:[1.1.2.RELEASE,)' - testCompile 'org.springframework.boot:spring-boot-starter-integration:1.3.3.RELEASE' - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-integration:${springBootVersion}" + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') } diff --git a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/build.gradle b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/build.gradle index 20d6bac9f4..661f96ced1 100644 --- a/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/build.gradle +++ b/stub-runner/stub-runner-messaging/stub-runner-messaging-stream/build.gradle @@ -15,7 +15,7 @@ dependencies { compile 'org.springframework.integration:spring-integration-java-dsl:[1.1.2.RELEASE,)' testCompile 'org.springframework.cloud:spring-cloud-stream-test-support:1.0.0.RC2' - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') } diff --git a/stub-runner/stub-runner-spring-cloud/build.gradle b/stub-runner/stub-runner-spring-cloud/build.gradle index 6b394afa9a..08e64bfd9c 100644 --- a/stub-runner/stub-runner-spring-cloud/build.gradle +++ b/stub-runner/stub-runner-spring-cloud/build.gradle @@ -14,7 +14,7 @@ dependencies { testCompile 'org.springframework.cloud:spring-cloud-starter-zookeeper-discovery:1.0.0.RC1' testCompile 'org.apache.curator:curator-test:2.9.1' testCompile 'io.reactivex:rxjava:1.1.1' - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile "org.springframework:spring-web:4.2.5.RELEASE" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') diff --git a/stub-runner/stub-runner-spring/build.gradle b/stub-runner/stub-runner-spring/build.gradle index f05eb40a0d..a020e5d80d 100644 --- a/stub-runner/stub-runner-spring/build.gradle +++ b/stub-runner/stub-runner-spring/build.gradle @@ -11,8 +11,8 @@ dependencies { } testCompile 'cglib:cglib-nodep:2.2' testCompile 'org.objenesis:objenesis:2.1' - testCompile 'org.springframework.boot:spring-boot-starter:1.3.3.RELEASE' - testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.3.RELEASE' + testCompile "org.springframework.boot:spring-boot-starter:${springBootVersion}" + testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude(group: 'org.codehaus.groovy') } diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunner.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunner.groovy index 16ef82b2fe..c2c20567dd 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunner.groovy +++ b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/BatchStubRunner.groovy @@ -51,7 +51,7 @@ class BatchStubRunner implements StubRunning { @Override Map> getAccurestContracts() { return stubRunners.inject([:]) { Map> map, StubRunner stubRunner -> - map.putAll(stubRunner.accurestContracts) + map.putAll(stubRunner.accurestContracts ?: [:]) return map } as Map> } @@ -74,9 +74,7 @@ class BatchStubRunner implements StubRunning { } private String ivyToLabels() { - return (getAccurestContracts().collectEntries { - [(it.key.toColonSeparatedDependencyNotation()) : it.value.collect { it.label }] - } as Map>).entrySet().collect { + return labels().entrySet().collect { "Dependency [${it.key}] has labels ${it.value}]" }.join('\n') } @@ -108,6 +106,16 @@ class BatchStubRunner implements StubRunning { } } + @Override + Map> labels() { + return stubRunners.inject([:]) { Map> map, StubRunner stubRunner -> + if (stubRunner) { + map.putAll(stubRunner.labels() ?: [:]) + } + return map + } as Map> + } + @Override void close() throws IOException { stubRunners.each { diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/RunningStubs.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/RunningStubs.groovy index 6c1d683fba..1483b81926 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/RunningStubs.groovy +++ b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/RunningStubs.groovy @@ -2,7 +2,6 @@ package io.codearte.accurest.stubrunner import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode - /** * Structure representing executed stubs. Contains the configuration of each stub * together with the port on which its executed. @@ -68,6 +67,10 @@ class RunningStubs { return namesAndPorts.keySet().collect { it.artifactId } as Set } + Map toIvyToPortMapping() { + return namesAndPorts.collectEntries { [(it.key.toColonSeparatedDependencyNotation()) : it.value] } as Map + } + @Override String toString() { return namesAndPorts.collect { diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubConfiguration.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubConfiguration.groovy index a4eea495dd..fa22eae5a7 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubConfiguration.groovy +++ b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubConfiguration.groovy @@ -4,7 +4,6 @@ import groovy.transform.CompileDynamic import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import io.codearte.accurest.stubrunner.util.StringUtils - /** * Represents a configuration of a single stub. The stub can be described * by groupId:artifactId:classifier notation @@ -76,4 +75,10 @@ public class StubConfiguration { } return [splitString[0], splitString[1]] as String[] } + + + @Override + public String toString() { + return toColonSeparatedDependencyNotation() + } } \ No newline at end of file diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunner.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunner.groovy index 91a5174775..6f7a458c5d 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunner.groovy +++ b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunner.groovy @@ -89,6 +89,11 @@ class StubRunner implements StubRunning { return localStubRunner.trigger() } + @Override + Map> labels() { + return localStubRunner.labels() + } + private void registerShutdownHook() { Runnable stopAllServers = { this.close() } Runtime.runtime.addShutdownHook(new Thread(stopAllServers)) diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutor.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutor.groovy index 20649d03ae..c7c0fe1dd7 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutor.groovy +++ b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubRunnerExecutor.groovy @@ -82,7 +82,7 @@ class StubRunnerExecutor implements StubFinder { } private boolean triggerForDsls(Collection dsls, String labelName) { - Collection matchingDsls = dsls.findAll { it.label == labelName} + Collection matchingDsls = dsls.findAll { it.label == labelName } if (matchingDsls.empty) { return false } @@ -100,6 +100,13 @@ class StubRunnerExecutor implements StubFinder { return true } + @Override + Map> labels() { + return getAccurestContracts().collectEntries { + [(it.key.toColonSeparatedDependencyNotation()) : it.value.collect { it.label }] + } as Map> + } + private void sendMessageIfApplicable(GroovyDsl groovyDsl) { if (!groovyDsl.outputMessage) { return diff --git a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy index cee1acebec..bd5ec1e30e 100644 --- a/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy +++ b/stub-runner/stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubTrigger.groovy @@ -28,4 +28,11 @@ interface StubTrigger { * @return true - if managed to run a trigger */ boolean trigger() + + /** + * Returns a mapping of ivy notation of a dependency to all the labels it has. + * + * Feature related to messaging. + */ + Map> labels() } \ No newline at end of file diff --git a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerSpec.groovy b/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerSpec.groovy index 19fbb1227e..0013801aa8 100644 --- a/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerSpec.groovy +++ b/stub-runner/stub-runner/src/test/groovy/io/codearte/accurest/stubrunner/BatchStubRunnerSpec.groovy @@ -1,6 +1,5 @@ package io.codearte.accurest.stubrunner -import io.codearte.accurest.dsl.GroovyDsl import spock.lang.Specification class BatchStubRunnerSpec extends Specification { @@ -37,7 +36,7 @@ class BatchStubRunnerSpec extends Specification { StubRunner runner = Mock(StubRunner) runner.findStubUrl("group", "knownArtifact") >> KNOWN_STUB_URL runner.findStubUrl("group", "unknownArtifact") >> null - runner.accurestContracts >> [(new StubConfiguration('a', 'b', 'c')): [GroovyDsl.make { outputMessage { label 'foo' } }]] + runner.labels() >> ['a:b:c' : ['foo']] return [runner] }