Move stub runner server features to main module

This commit is contained in:
Dave Syer
2016-07-16 15:02:53 +01:00
parent 5681cd1d55
commit 5f662bc526
18 changed files with 152 additions and 154 deletions

View File

@@ -20,7 +20,6 @@
<modules>
<module>spring-cloud-contract-stub-runner</module>
<module>spring-cloud-contract-stub-runner-jetty</module>
<module>spring-cloud-contract-stub-runner-boot</module>
<module>spring-cloud-contract-stub-runner-messaging</module>
</modules>

View File

@@ -1,54 +0,0 @@
=== Stub Runner Boot
Spring Cloud Contract Verifier Stub Runner Boot is a Spring Boot application that exposes REST endpoints to
trigger the messaging labels and to access started WireMock servers.
One of the usecases is to run some smoke (end to end) tests on a deployed application. You can read
more about this in the http://toomuchcoding.com/blog/2015/09/27/microservice-deployment/["Microservice Deployment" article at Too Much Coding blog.]
==== How to use it?
Just add the
[source,groovy,indent=0]
----
compile "org.springframework.cloud:stub-runner-boot:${verifierVersion}"
----
and a messaging implementation:
[source,groovy,indent=0]
----
// for Apache Camel
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-camel:${verifierVersion}"
// for Spring Integration
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-integration:${verifierVersion}"
// for Spring Cloud Stream
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-stream:${verifierVersion}"
----
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/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBootSpec.groovy[tags=boot_usage]
----

View File

@@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-stub-runner-build</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-contract-stub-runner-boot</artifactId>
<packaging>jar</packaging>
<name>Spring Cloud Contract Stub Runner Boot</name>
<description>Spring Cloud Contract Stub Runner Boot</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-stub-runner</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-wiremock</artifactId>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.solidsoft.spock</groupId>
<artifactId>spock-global-unroll</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,3 +0,0 @@
# Auto Configuration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration

View File

@@ -1,2 +0,0 @@
stubrunner.stubs.repository.root: classpath:m2repo/repository/
stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:bootService

View File

@@ -177,4 +177,59 @@ or `DiscoveryClient` directly, to call those stubbed servers instead of calling
You can match the artifactId of the stub with the name of your app by using the `stubrunner.stubs.idsToServiceIds:` map.
You can disable Stub Runner Ribbon support by providing: `stubrunner.cloud.ribbon.enabled` equal to `false`
You can disable Stub Runner support by providing: `stubrunner.cloud.enabled` equal to `false`
You can disable Stub Runner support by providing: `stubrunner.cloud.enabled` equal to `false`
=== Stub Runner Boot
Spring Cloud Contract Verifier Stub Runner Boot is a Spring Boot application that exposes REST endpoints to
trigger the messaging labels and to access started WireMock servers.
One of the usecases is to run some smoke (end to end) tests on a deployed application. You can read
more about this in the http://toomuchcoding.com/blog/2015/09/27/microservice-deployment/["Microservice Deployment" article at Too Much Coding blog.]
==== How to use it?
Just add the
[source,groovy,indent=0]
----
compile "org.springframework.cloud:stub-runner"
----
and (optionally) a messaging implementation:
[source,groovy,indent=0]
----
// for Apache Camel
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-camel"
// for Spring Integration
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-integration"
// for Spring Cloud Stream
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-stream"
----
Build a fat-jar with `@EnableStubRunnerServer` 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/org/springframework/cloud/contract/stubrunner/boot/StubRunnerBootSpec.groovy[tags=boot_usage]
----

View File

@@ -81,6 +81,11 @@
<artifactId>cglib</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed 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
*
* http://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 org.springframework.cloud.contract.stubrunner.server;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration;
import org.springframework.context.annotation.Import;
/**
* @author Dave Syer
*
*/
/**
* Annotation to enable a Stub runner server.
* @author Spencer Gibb
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({HttpStubsController.class, TriggerController.class, StubRunnerConfiguration.class})
public @interface EnableStubRunnerServer {
}

View File

@@ -14,29 +14,21 @@
* limitations under the License.
*/
package org.springframework.cloud.contract.stubrunner.boot;
package org.springframework.cloud.contract.stubrunner.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration;
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessageBuilder;
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging;
import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessageBuilder;
import org.springframework.cloud.contract.verifier.messaging.noop.NoOpContractVerifierMessaging;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Marcin Grzejszczak
*/
@SpringBootApplication
@AutoConfigureAfter(StubRunnerConfiguration.class)
public class StubRunnerBoot {
public static void main(String[] args) {
SpringApplication.run(StubRunnerBoot.class, args);
}
@Configuration
public class StubRunnerBackupAutoConfiguration {
@Bean
@ConditionalOnMissingBean

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2013-2016 the original author or authors.
*
* Licensed 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
*
* http://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 org.springframework.cloud.contract.stubrunner.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author Marcin Grzejszczak
*/
@SpringBootApplication
@EnableStubRunnerServer
public class StubRunnerBoot {
public static void main(String[] args) {
SpringApplication.run(StubRunnerBoot.class, args);
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.contract.stubrunner.boot;
package org.springframework.cloud.contract.stubrunner.server;
import java.util.Collection;
import java.util.Collections;

View File

@@ -3,3 +3,6 @@ org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner=\
org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration,\
org.springframework.cloud.contract.stubrunner.spring.cloud.StubRunnerSpringCloudAutoConfiguration,\
org.springframework.cloud.contract.stubrunner.spring.cloud.ribbon.StubRunnerRibbonAutoConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.contract.stubrunner.server.StubRunnerBackupAutoConfiguration

View File

@@ -14,14 +14,14 @@
* limitations under the License.
*/
package org.springframework.cloud.contract.stubrunner.boot
package org.springframework.cloud.contract.stubrunner.server
import groovy.json.JsonSlurper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.context.SpringBootContextLoader
import org.springframework.cloud.contract.stubrunner.StubRunning
import org.springframework.cloud.stream.annotation.EnableBinding
import org.springframework.context.annotation.Configuration
import org.springframework.test.context.ContextConfiguration
@@ -33,9 +33,8 @@ import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc
* @author Marcin Grzejszczak
*/
// tag::boot_usage[]
@ContextConfiguration(classes = [StubRunnerBootSpec, StubRunnerBoot], loader = SpringBootContextLoader)
@EnableBinding
@Configuration
@ContextConfiguration(classes = StubRunnerBoot, loader = SpringBootContextLoader)
@IntegrationTest("spring.cloud.zookeeper.enabled=false")
class StubRunnerBootSpec extends Specification {
@Autowired StubRunning stubRunning

View File

@@ -1,5 +1,5 @@
stubrunner.stubs.repository.root: classpath:m2repo/repository/
stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer
stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework.cloud.contract.verifier.stubs:bootService
stubrunner.stubs.idsToServiceIds:
ivyNotation: someValueInsideYourCode