Commit 3a7af2c8 by Dave Syer

Generate some stubs, yay!

parent 26c7c362
......@@ -27,6 +27,8 @@
<spring-cloud-commons.version>1.3.0.BUILD-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>1.4.0.BUILD-SNAPSHOT</spring-cloud-config.version>
<spring-cloud-stream.version>Ditmars.BUILD-SNAPSHOT</spring-cloud-stream.version>
<!-- Has to be a stable version (not one that depends on this version of netflix): -->
<spring-cloud-contract.version>1.1.2.BUILD-SNAPSHOT</spring-cloud-contract.version>
<!-- Plugin versions -->
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
......@@ -72,6 +74,12 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-contract</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-dependencies</artifactId>
<version>${project.version}</version>
<type>pom</type>
......@@ -106,6 +114,13 @@
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-dependencies</artifactId>
<version>${spring-cloud-contract.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
<version>${netty.version}</version>
......
......@@ -97,10 +97,27 @@
<artifactId>xstream</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- Only needed at compile time -->
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-restassured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-wiremock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
......@@ -116,7 +133,7 @@
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<!-- Serves *only* to filter the wro.xml so it can get an absolute
<!-- Serves *only* to filter the wro.xml so it can get an absolute
path for the project -->
<id>copy-resources</id>
<phase>validate</phase>
......@@ -133,6 +150,25 @@
</resources>
</configuration>
</execution>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
......@@ -168,6 +204,30 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2013-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.netflix.eureka.server.doc;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.filter.Filter;
import com.jayway.restassured.specification.RequestSpecification;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.contract.wiremock.restdocs.WireMockSnippet;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.cloud.netflix.eureka.server.doc.AbstractDocumentationTests.Application;
import org.springframework.context.annotation.Configuration;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.restdocs.restassured.RestAssuredRestDocumentation;
import org.springframework.restdocs.restassured.RestDocumentationFilter;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.restassured.operation.preprocess.RestAssuredPreprocessors.modifyUris;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT, value = {
"spring.jmx.enabled=true", "management.security.enabled=false" })
@DirtiesContext
public abstract class AbstractDocumentationTests {
@LocalServerPort
private int port = 0;
@Rule
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(
"target/generated-snippets");
private RestDocumentationFilter filter(String name) {
return RestAssuredRestDocumentation.document(name,
preprocessRequest(modifyUris().host("eureka.example.com").removePort(),
prettyPrint()),
preprocessResponse(prettyPrint()));
}
private RequestSpecification document(Filter... filters) {
return document(null, filters);
}
private RequestSpecification document(Object body, Filter... filters) {
RequestSpecBuilder builder = new RequestSpecBuilder()
.addFilter(documentationConfiguration(this.restDocumentation).snippets()
.withAdditionalDefaults(new WireMockSnippet()));
for (Filter filter : filters) {
builder = builder.addFilter(filter);
}
RequestSpecification spec = builder.setPort(this.port).build();
if (body != null) {
spec.contentType("application/json").body(body, new EurekaObjectMapper());
}
return spec;
}
protected RequestSpecification assure(String name, Object body) {
RestDocumentationFilter filter = filter(name);
return RestAssured.given(document(body, filter)).filter(filter);
}
protected RequestSpecification assure(String name) {
RestDocumentationFilter filter = filter(name);
return RestAssured.given(document(filter)).filter(filter);
}
protected RequestSpecification assure() {
return assure("{method-name}");
}
@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
protected static class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).properties(
"spring.application.name=eureka", "management.security.enabled=false",
"eureka.client.registerWithEureka=true").run(args);
}
}
}
/*
* Copyright 2013-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.netflix.eureka.server.doc;
import com.netflix.appinfo.ApplicationInfoManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.emptyIterable;
@RunWith(SpringJUnit4ClassRunner.class)
public class EmptyAppsTests extends AbstractDocumentationTests {
@Autowired
private EurekaInstanceConfigBean instanceConfig;
@Autowired
private ApplicationInfoManager applicationInfoManager;
@Test
public void addApp() throws Exception {
instanceConfig.setAppname("foo");
instanceConfig.setInstanceId("unique-id");
instanceConfig.setHostname("foo.example.com");
applicationInfoManager.initComponent(instanceConfig);
assure("add-app", applicationInfoManager.getInfo()).when()
.post("/eureka/apps/FOO").then().assertThat().statusCode(is(204));
assure("delete-app").when()
.delete("/eureka/apps/FOO/{id}",
applicationInfoManager.getInfo().getInstanceId())
.then().assertThat().statusCode(is(200));
}
@Test
public void emptyApps() {
assure().when().accept("application/json").get("/eureka/apps").then().assertThat()
.body("applications.application", emptyIterable()).statusCode(is(200));
}
}
/*
* Copyright 2016-2017 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.netflix.eureka.server.doc;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.ws.rs.core.MediaType;
import com.jayway.restassured.mapper.ObjectMapperDeserializationContext;
import com.jayway.restassured.mapper.ObjectMapperSerializationContext;
import com.netflix.discovery.converters.EntityBodyConverter;
final class EurekaObjectMapper
implements com.jayway.restassured.mapper.ObjectMapper {
private EntityBodyConverter converter = new EntityBodyConverter();
@Override
public Object serialize(ObjectMapperSerializationContext context) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
converter.write(context.getObjectToSerialize(), out,
MediaType.APPLICATION_JSON_TYPE);
}
catch (IOException e) {
throw new IllegalStateException("Cannot serialize", e);
}
return out.toByteArray();
}
@Override
public Object deserialize(
ObjectMapperDeserializationContext context) {
try {
return converter.read(
context.getDataToDeserialize().asInputStream(),
context.getType(), MediaType.APPLICATION_JSON_TYPE);
}
catch (IOException e) {
throw new IllegalStateException("Cannot deserialize", e);
}
}
}
\ No newline at end of file
/*
* Copyright 2013-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.netflix.eureka.server.doc;
import com.netflix.appinfo.ApplicationInfoManager;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.hasSize;
@RunWith(SpringJUnit4ClassRunner.class)
public class RegisteredAppsTests extends AbstractDocumentationTests {
@Autowired
private EurekaInstanceConfigBean instanceConfig;
@Autowired
private EurekaClientConfigBean clientConfig;
@Autowired
private ApplicationInfoManager applicationInfoManager;
@Autowired
private ApplicationEventPublisher publisher;
private static CloudEurekaClient client;
@Before
public void setUp() throws Exception {
if (client == null) {
instanceConfig.setAppname("foo");
instanceConfig.setLeaseRenewalIntervalInSeconds(1);
applicationInfoManager.initComponent(instanceConfig);
clientConfig.setInitialInstanceInfoReplicationIntervalSeconds(0);
clientConfig.setRegisterWithEureka(true);
client = new CloudEurekaClient(applicationInfoManager, clientConfig,
publisher);
// Give registration a chance to work
while (client.getLastSuccessfulHeartbeatTimePeriod() < 0) {
Thread.sleep(100L);
}
}
}
@AfterClass
public static void cleanUp() {
if (client != null) {
client.shutdown();
}
}
@Test
public void registeredApps() throws Exception {
assure().accept("application/json").when().get("/eureka/apps").then().assertThat()
.body("applications.application", hasSize(1)).statusCode(is(200));
}
}
server.port=8761
server.port=${local.server.port:8761}
spring.application.name=eureka
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
\ No newline at end of file
eureka.client.fetchRegistry=false
logging.level.org.springframework.web.client=DEBUG
logging.level.com.netflix.discovery=DEBUG
\ No newline at end of file
......@@ -29,7 +29,6 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-verifier</artifactId>
<version>${spring-cloud-contract.version}</version>
</dependency>
</dependencies>
</project>
......@@ -14,7 +14,6 @@
<description>Spring Cloud Netflix Hystrix Stream</description>
<properties>
<main.basedir>${basedir}/..</main.basedir>
<spring-cloud-contract.version>1.0.5.RELEASE</spring-cloud-contract.version>
</properties>
<dependencies>
<dependency>
......@@ -79,7 +78,11 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-contract</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment