diff --git a/services/api_gateway/pom.xml b/services/api_gateway/pom.xml
index 8fe9b1d52..a79baaea8 100644
--- a/services/api_gateway/pom.xml
+++ b/services/api_gateway/pom.xml
@@ -87,6 +87,17 @@
0.1.0-SNAPSHOT
compile
+
+ org.springframework.restdocs
+ spring-restdocs-webtestclient
+ test
+
+
+ org.springframework.restdocs
+ spring-restdocs-asciidoctor
+ test
+
+
diff --git a/services/api_gateway/src/test/com/futurewei/alcor/apigateway/AlcorApiGatewayApplicationTest.java b/services/api_gateway/src/test/java/futurewei/alcor/apigateway/AlcorApiGatewayApplicationTest.java
similarity index 73%
rename from services/api_gateway/src/test/com/futurewei/alcor/apigateway/AlcorApiGatewayApplicationTest.java
rename to services/api_gateway/src/test/java/futurewei/alcor/apigateway/AlcorApiGatewayApplicationTest.java
index 895defd8f..6fa91fbd3 100644
--- a/services/api_gateway/src/test/com/futurewei/alcor/apigateway/AlcorApiGatewayApplicationTest.java
+++ b/services/api_gateway/src/test/java/futurewei/alcor/apigateway/AlcorApiGatewayApplicationTest.java
@@ -17,6 +17,7 @@
package com.futurewei.alcor.apigateway;
import org.junit.Test;
+import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +26,12 @@
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
+import org.junit.Rule;
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
+import org.springframework.restdocs.JUnitRestDocumentation;
+import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
+import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.documentationConfiguration;
+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.assertj.core.api.Assertions.*;
@@ -32,11 +39,22 @@
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"httpbin=http://localhost:${wiremock.server.port}"})
@AutoConfigureWireMock(port = 0)
+@AutoConfigureRestDocs(outputDir = "target/generated-snippets")
public class AlcorApiGatewayApplicationTest {
@Autowired
private WebTestClient webClient;
+ private WebTestClient client;
+
+ @Rule
+ public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
+
+ @Before
+ public void init(){
+ this.client = this.webClient.mutate().filter(documentationConfiguration(restDocumentation)).build();
+ }
+
@Test
public void contextLoads() throws Exception {
//Stubs
@@ -49,12 +67,13 @@ public void contextLoads() throws Exception {
// .withBody("no fallback")
// .withFixedDelay(3000)));
- webClient
+ this.client
.get().uri("/get")
.exchange()
.expectStatus().isOk()
.expectBody()
- .jsonPath("$.headers.Hello").isEqualTo("Alcor");
+ .jsonPath("$.headers.Hello").isEqualTo("Alcor")
+ .consumeWith(document("admin_get"));
// webClient
// .get().uri("/delay/3")
diff --git a/services/mac_manager/pom.xml b/services/mac_manager/pom.xml
index 30799ec9f..ae9e79248 100644
--- a/services/mac_manager/pom.xml
+++ b/services/mac_manager/pom.xml
@@ -84,6 +84,13 @@
+
+
+ org.springframework.restdocs
+ spring-restdocs-mockmvc
+ test
+
+
io.springfox
springfox-swagger2
diff --git a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/controller/MacControllerTest.java b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/controller/MacControllerTest.java
index 6d0d0c9dc..02af21166 100644
--- a/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/controller/MacControllerTest.java
+++ b/services/mac_manager/src/test/java/com/futurewei/alcor/macmanager/controller/MacControllerTest.java
@@ -26,6 +26,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
@@ -38,10 +39,12 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
+@AutoConfigureRestDocs(outputDir = "target/generated-snippets")
public class MacControllerTest {
private static final ObjectMapper om = new ObjectMapper();
public MacState testMacState;
@@ -104,7 +107,8 @@ public String createMacRange(MacRange macRange) {
public void test_index() throws Exception {
this.mockMvc.perform(get("/start.html"))
.andDo(print())
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andDo(document("start"));
}
@Test
@@ -118,7 +122,8 @@ public void test_createMacState() throws Exception {
.content(json)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
- .andDo(print());
+ .andDo(print())
+ .andDo(document("macs_post"));
}
@Test
@@ -127,7 +132,8 @@ public void test_getMacStateByMacAddress() throws Exception {
String strTestMac = createMacState(macState);
this.mockMvc.perform(get("/macs/" + strTestMac))
.andDo(print())
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andDo(document("macs_get"));
}
@Test
@@ -136,7 +142,8 @@ public void test_releaseMacStateByMacAddress() throws Exception {
String strTestMac = createMacState(macState);
this.mockMvc.perform(delete("/macs/" + strTestMac))
.andDo(print())
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andDo(document("macs_delete"));
}
@Test
@@ -154,7 +161,8 @@ public void test_activateMacState() throws Exception {
.content(json)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
- .andDo(print());
+ .andDo(print())
+ .andDo(document("macs_activate"));
}
@Test
@@ -172,7 +180,8 @@ public void test_deactivateMacState() throws Exception {
.content(json)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
- .andDo(print());
+ .andDo(print())
+ .andDo(document("macs_deactive"));
}
@Test
@@ -181,7 +190,8 @@ public void test_getMacRangeByMacRangeId() throws Exception {
String strRangeId = createMacRange(macRange);
this.mockMvc.perform(get("/macs/ranges/" + strRangeId))
.andDo(print())
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andDo(document("macs_range_get"));
}
public void test_getAllMacRanges(@PathVariable String rangeid) throws Exception {
diff --git a/services/private_ip_manager/pom.xml b/services/private_ip_manager/pom.xml
index aaad27417..c694c4aba 100644
--- a/services/private_ip_manager/pom.xml
+++ b/services/private_ip_manager/pom.xml
@@ -65,6 +65,13 @@
AlcorCommonLib
0.1.0-SNAPSHOT
+
+
+ org.springframework.restdocs
+ spring-restdocs-mockmvc
+ test
+
+
diff --git a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/controller/IpAddrControllerTest.java b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/controller/IpAddrControllerTest.java
index 4e075f026..8eef294f9 100644
--- a/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/controller/IpAddrControllerTest.java
+++ b/services/private_ip_manager/src/test/java/com/futurewei/alcor/privateipmanager/controller/IpAddrControllerTest.java
@@ -23,6 +23,7 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -36,9 +37,12 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
+
@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc
+@AutoConfigureRestDocs(outputDir = "target/generated-snippets")
public class IpAddrControllerTest {
@Autowired
private MockMvc mockMvc;
@@ -53,6 +57,7 @@ public void createIpAddrRangeTest() throws Exception {
.content(ipAddrRangeJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
+ .andDo(document("ips_range_post"))
.andDo(print());
}
@@ -60,6 +65,7 @@ public void createIpAddrRangeTest() throws Exception {
public void deleteIpAddrRange() throws Exception {
this.mockMvc.perform(delete("/ips/range/range1"))
.andDo(print())
+ .andDo(document("ips_range_delete"))
.andExpect(status().isOk());
}
@@ -67,6 +73,7 @@ public void deleteIpAddrRange() throws Exception {
public void getIpAddrRangeTest() throws Exception {
this.mockMvc.perform(get("/ips/range/range1"))
.andDo(print())
+ .andDo(document("ips_range_get"))
.andExpect(status().isOk());
}
@@ -74,6 +81,7 @@ public void getIpAddrRangeTest() throws Exception {
public void listIpAddrRangeTest() throws Exception {
this.mockMvc.perform(get("/ips/range/"))
.andDo(print())
+ .andDo(document("ips_range_list"))
.andExpect(status().isOk());
}
@@ -87,6 +95,7 @@ public void allocateIpAddrTest() throws Exception {
.content(ipAddrRequestJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
+ .andDo(document("ips_post"))
.andDo(print());
}
@@ -111,6 +120,7 @@ public void allocateIpAddrBulkTest() throws Exception {
.content(ipAddrRequestBulkJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
+ .andDo(document("ips_bulk_post"))
.andDo(print());
}
@@ -124,6 +134,7 @@ public void activateIpAddrStateTest() throws Exception {
.content(ipAddrRequestJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
+ .andDo(document("ips_activate"))
.andDo(print());
}
@@ -146,6 +157,7 @@ public void activateIpAddrStateBulkTest() throws Exception {
.content(ipAddrRequestBulkJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
+ .andDo(document("ips_bulk_activate"))
.andDo(print());
}
@@ -159,6 +171,7 @@ public void deactivateIpAddrStateTest() throws Exception {
.content(ipAddrRequestJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
+ .andDo(document("ips_deactivate"))
.andDo(print());
}
@@ -181,6 +194,7 @@ public void deactivateIpAddrStateBulkTest() throws Exception {
.content(ipAddrRequestBulkJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
+ .andDo(document("ips_bulk_deactivate"))
.andDo(print());
}
@@ -188,7 +202,8 @@ public void deactivateIpAddrStateBulkTest() throws Exception {
public void releaseIpAddrTest() throws Exception {
this.mockMvc.perform(delete("/ips/4/range1/11.11.11.1"))
.andDo(print())
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andDo(document("ips_delete"));
}
@Test
@@ -210,6 +225,7 @@ public void releaseIpAddrBulkTest() throws Exception {
.content(ipAddrRequestBulkJson)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
+ .andDo(document("ips_bulk_delete"))
.andDo(print());
}
@@ -217,13 +233,15 @@ public void releaseIpAddrBulkTest() throws Exception {
public void getIpAddrTest() throws Exception {
this.mockMvc.perform(get("/ips/4/range1/11.11.11.1"))
.andDo(print())
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andDo(document("ips_get"));
}
@Test
public void listIpAddrTest() throws Exception {
this.mockMvc.perform(get("/ips/4/range1"))
.andDo(print())
- .andExpect(status().isOk());
+ .andExpect(status().isOk())
+ .andDo(document("ips_list"));
}
}
diff --git a/services/route_manager/pom.xml b/services/route_manager/pom.xml
index b7eba4df4..c0af5b5e5 100644
--- a/services/route_manager/pom.xml
+++ b/services/route_manager/pom.xml
@@ -73,6 +73,11 @@
spring-boot-starter-test
test
+
+
+ org.springframework.restdocs
+ spring-restdocs-mockmvc
+
io.springfox
springfox-swagger2
diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/RouteControllerTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/RouteControllerTests.java
index 5a30a5de1..be69b0448 100644
--- a/services/route_manager/src/test/java/com/futurewei/alcor/route/RouteControllerTests.java
+++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/RouteControllerTests.java
@@ -24,11 +24,14 @@
import java.io.IOException;
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"httpbin=http://localhost:${wiremock.server.port}"})
@AutoConfigureMockMvc
+@AutoConfigureRestDocs(outputDir = "target/generated-snippets")
public class RouteControllerTests {
@Autowired
@@ -49,7 +52,8 @@ public void routeGetById_canFindRoute_pass () throws Exception {
this.mockMvc.perform(get(getByIdUri))
.andDo(print())
.andExpect(status().isOk())
- .andExpect(MockMvcResultMatchers.jsonPath("$.route.id").value(UnitTestConfig.routeId));
+ .andExpect(MockMvcResultMatchers.jsonPath("$.route.id").value(UnitTestConfig.routeId))
+ .andDo(document("route_get_byid"));
}
@Test
@@ -57,6 +61,7 @@ public void routeGetById_canNotFindRoute_notPass () throws Exception {
Mockito.when(routeDatabaseService.getByRouteId(UnitTestConfig.routeId)).thenReturn(null);
String response = this.mockMvc.perform(get(getByIdUri))
.andDo(print())
+ .andDo(document("route_get_byid_notpass"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
System.out.println("-----json returned = " + response);
@@ -69,7 +74,8 @@ public void createVpcRoute_create_pass () throws Exception {
.content(UnitTestConfig.vpcResource))
.andDo(print())
.andExpect(status().is(201))
- .andExpect(MockMvcResultMatchers.jsonPath("$.route.destination").value(UnitTestConfig.cidr));
+ .andExpect(MockMvcResultMatchers.jsonPath("$.route.destination").value(UnitTestConfig.cidr))
+ .andDo(document("vpc_route_post"));
}
@Test
@@ -78,6 +84,7 @@ public void createVpcRoute_parameterNullOrEmpty_notPass () throws Exception {
this.mockMvc.perform(post(createVpcUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.vpcResource))
.andDo(print())
+ .andDo(document("vpc_route_post_notpass"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.route.destination").value(UnitTestConfig.cidr));
} catch (Exception e) {
@@ -90,6 +97,7 @@ public void createSubnetRoute_create_pass () throws Exception {
this.mockMvc.perform(post(createSubnetUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_route_post"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.route.destination").value(UnitTestConfig.cidr));
}
@@ -100,6 +108,7 @@ public void createSubnetRoute_parameterNullOrEmpty_notPass () throws Exception {
this.mockMvc.perform(post(createSubnetUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_route_post_paramerror"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.route.destination").value(UnitTestConfig.cidr));
} catch (Exception e) {
@@ -113,6 +122,7 @@ public void deleteRuleById_deleteWhenIdExist_pass () throws Exception {
.thenReturn(new RouteState(){{setId(UnitTestConfig.routeId);}});
this.mockMvc.perform(delete(deleteUri))
.andDo(print())
+ .andDo(document("rule_delete"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.id").value(UnitTestConfig.routeId));
}
@@ -123,6 +133,7 @@ public void deleteRuleById_deleteWhenIdNotExist_notPass () throws Exception {
.thenReturn(null);
String response = this.mockMvc.perform(delete(deleteUri))
.andDo(print())
+ .andDo(document("rule_delete_notexist"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
assertEquals("{\"id\":null}", response);
diff --git a/services/subnet_manager/pom.xml b/services/subnet_manager/pom.xml
index ab0de2c9d..b8863a825 100644
--- a/services/subnet_manager/pom.xml
+++ b/services/subnet_manager/pom.xml
@@ -74,6 +74,12 @@
spring-boot-starter-test
test
+
+
+ org.springframework.restdocs
+ spring-restdocs-mockmvc
+ test
+
commons-net
commons-net
diff --git a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/SubnetControllerTests.java b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/SubnetControllerTests.java
index 811934454..edbab34d4 100644
--- a/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/SubnetControllerTests.java
+++ b/services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/SubnetControllerTests.java
@@ -31,11 +31,14 @@
import java.util.HashMap;
import java.util.Map;
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"httpbin=http://localhost:${wiremock.server.port}"})
@AutoConfigureMockMvc
+@AutoConfigureRestDocs(outputDir = "target/generated-snippets")
public class SubnetControllerTests {
@Autowired
@@ -62,6 +65,7 @@ public void subnetGetById_canFindSubnet_pass () throws Exception {
this.mockMvc.perform(get(getByIdUri))
.andDo(print())
.andExpect(status().isOk())
+ .andDo(document("subnet_get_pass"))
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.id").value(UnitTestConfig.subnetId));
}
@@ -71,6 +75,7 @@ public void subnetGetById_canNotFindSubnet_notPass () throws Exception {
String response = this.mockMvc.perform(get(getByIdUri))
.andDo(print())
.andExpect(status().isOk())
+ .andDo(document("subnet_get_nopass"))
.andReturn().getResponse().getContentAsString();
System.out.println("-----json returned = " + response);
assertEquals("{\"subnet\":null}", response);
@@ -104,6 +109,7 @@ public void createSubnetState_create_pass () throws Exception {
.content(UnitTestConfig.resource))
.andDo(print())
.andExpect(status().is(201))
+ .andDo(document("subnet_post_pass"))
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.id").value(UnitTestConfig.subnetId));
}
@@ -136,6 +142,7 @@ public void createSubnetState_canNotFindVpcState_notPass () throws Exception {
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_post_novpc"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.id").value(UnitTestConfig.subnetId));
}catch (Exception ex) {
@@ -173,6 +180,7 @@ public void createSubnetState_canNotFindRoute_notPass () throws Exception {
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_post_noroute"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.id").value(UnitTestConfig.subnetId));
}catch (Exception ex) {
@@ -210,6 +218,7 @@ public void createSubnetState_canNotFindMac_notPass () throws Exception {
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_get_nomac"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.id").value(UnitTestConfig.subnetId));
}catch (Exception ex) {
@@ -249,6 +258,7 @@ public void createSubnetState_canNotFindIP_notPass () throws Exception {
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_get_noip"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.id").value(UnitTestConfig.subnetId));
}catch (Exception ex) {
@@ -305,6 +315,7 @@ public void updateSubnetState_noUpdate_pass () throws Exception {
this.mockMvc.perform(put(putUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_put_noupdate"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.id").value(UnitTestConfig.subnetId));
}
@@ -321,6 +332,7 @@ public void updateSubnetState_update_pass () throws Exception {
this.mockMvc.perform(put(putUri).contentType(MediaType.APPLICATION_JSON)
.content(UnitTestConfig.updateResource))
.andDo(print())
+ .andDo(document("subnet_puts"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.subnet.name").value(UnitTestConfig.updateName));
}
@@ -332,6 +344,7 @@ public void updateSubnetState_canNotFindSubnet_notPass () throws Exception {
try {
this.mockMvc.perform(put(putUri).contentType(MediaType.APPLICATION_JSON).content(UnitTestConfig.resource))
.andDo(print())
+ .andDo(document("subnet_put_nosubnet"))
.andExpect(status().isOk());
}catch (Exception ex) {
//System.out.println(ex.getMessage());
@@ -349,7 +362,9 @@ public void getSubnetStatesByProjectIdAndVpcId_getMap_pass () throws Exception {
UnitTestConfig.name,UnitTestConfig.cidr);
subnetStates.put("SubnetState", subnetState);
Mockito.when(subnetDatabaseService.getAllSubnets()).thenReturn(subnetStates);
- this.mockMvc.perform(get(getByProjectIdAndVpcIdUri)).andDo(print())
+ this.mockMvc.perform(get(getByProjectIdAndVpcIdUri))
+ .andDo(print())
+ .andDo(document("subnet_get_project_vpc"))
.andExpect(status().isOk());
}
@@ -358,6 +373,7 @@ public void getSubnetStatesByProjectIdAndVpcId_getEmptyMap_pass () throws Except
Map subnetStates = new HashMap<>();
Mockito.when(subnetDatabaseService.getAllSubnets()).thenReturn(subnetStates);
this.mockMvc.perform(get(getByProjectIdAndVpcIdUri)).andDo(print())
+ .andDo(document("subnet_get_project_vpc_empty"))
.andExpect(status().isOk());
}
@@ -370,6 +386,7 @@ public void deleteSubnetState_deleteWhenIdExist_pass () throws Exception {
UnitTestConfig.name,UnitTestConfig.cidr));
this.mockMvc.perform(delete(deleteUri))
.andDo(print())
+ .andDo(document("subnet_delete"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.id").value(UnitTestConfig.subnetId));
}
@@ -380,6 +397,7 @@ public void deleteSubnetState_deleteWhenIdNotExist_pass () throws Exception {
.thenReturn(null);
String response = this.mockMvc.perform(delete(deleteUri))
.andDo(print())
+ .andDo(document("subnet_delete_noexist"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
System.out.println("-----json returned = " + response);
diff --git a/services/vpc_manager/pom.xml b/services/vpc_manager/pom.xml
index 386c54c76..0f359f55c 100644
--- a/services/vpc_manager/pom.xml
+++ b/services/vpc_manager/pom.xml
@@ -90,6 +90,12 @@
test
+
+ org.springframework.restdocs
+ spring-restdocs-mockmvc
+ test
+
+
com.futurewei.alcor.common
AlcorCommonLib
diff --git a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/VpcControllerTests.java b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/VpcControllerTests.java
index 8e64a08ab..a74a2c455 100644
--- a/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/VpcControllerTests.java
+++ b/services/vpc_manager/src/test/java/com/futurewei/alcor/vpcmanager/VpcControllerTests.java
@@ -34,10 +34,15 @@
import java.util.List;
import java.util.Map;
+
+import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
+import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
+
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"httpbin=http://localhost:${wiremock.server.port}"})
@AutoConfigureMockMvc
+@AutoConfigureRestDocs(outputDir = "target/generated-snippets")
public class VpcControllerTests {
@Autowired
@@ -63,6 +68,7 @@ public void vpcGetById_canFindVpc_pass () throws Exception {
UnitTestConfig.cidr, null));
this.mockMvc.perform(get(getByIdUri))
.andDo(print())
+ .andDo(document("vpc_get_byid"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.vpc.id").value(UnitTestConfig.vpcId));
}
@@ -72,6 +78,7 @@ public void vpcGetById_canNotFindVpc_notPass () throws Exception {
Mockito.when(vpcDatabaseService.getByVpcId(UnitTestConfig.vpcId)).thenReturn(null);
String response = this.mockMvc.perform(get(getByIdUri))
.andDo(print())
+ .andDo(document("vpc_get_nofind"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
System.out.println("-----json returned = " + response);
@@ -89,6 +96,7 @@ public void createVpcState_create_pass () throws Exception {
.thenReturn(routeWebJson);
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON).content(UnitTestConfig.vpcResource))
.andDo(print())
+ .andDo(document("vpcstate_post"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.vpc.id").value(UnitTestConfig.vpcId));
}
@@ -110,6 +118,7 @@ public void createVpcState_canNotFindRoute_notPass () throws Exception {
try {
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON).content(UnitTestConfig.vpcResource))
.andDo(print())
+ .andDo(document("vpcstate_post_noroute"))
.andExpect(status().is(201))
.andExpect(MockMvcResultMatchers.jsonPath("$.vpc.routes[0].destination").value(UnitTestConfig.cidr));
} catch (Exception e) {
@@ -125,6 +134,7 @@ public void updateVpcStateByVpcId_noUpdate_pass () throws Exception {
UnitTestConfig.cidr, null));
this.mockMvc.perform(put(updateUri).contentType(MediaType.APPLICATION_JSON).content(UnitTestConfig.vpcResource))
.andDo(print())
+ .andDo(document("vpcstate_update_no"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.vpc.id").value(UnitTestConfig.vpcId));
}
@@ -140,6 +150,7 @@ public void updateVpcStateByVpcId_update_pass () throws Exception {
UnitTestConfig.cidr, null));
this.mockMvc.perform(put(updateUri).contentType(MediaType.APPLICATION_JSON).content(UnitTestConfig.vpcResource))
.andDo(print())
+ .andDo(document("vpcstate_update"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.vpc.name").value(UnitTestConfig.updateName));
}
@@ -152,6 +163,7 @@ public void deleteVpcStateByVpcId_deleteWhenIdExist_pass () throws Exception {
UnitTestConfig.cidr, null));
this.mockMvc.perform(delete(deleteUri))
.andDo(print())
+ .andDo(document("vpcsate_delete"))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.id").value(UnitTestConfig.vpcId));
}
@@ -162,6 +174,7 @@ public void deleteVpcStateByVpcId_deleteWhenIdNotExist_pass () throws Exception
.thenReturn(null);
String response = this.mockMvc.perform(delete(deleteUri))
.andDo(print())
+ .andDo(document("vpcstate_delete_noexist"))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
System.out.println("-----json returned = " + response);
@@ -177,6 +190,7 @@ public void getVpcStatesByProjectId_getMap_pass () throws Exception {
vpcStates.put("VpcState", vpcState);
Mockito.when(vpcDatabaseService.getAllVpcs()).thenReturn(vpcStates);
this.mockMvc.perform(get(getByProjectIdUri)).andDo(print())
+ .andDo(document("vpcstate_get_by_projectid"))
.andExpect(status().isOk());
}
@@ -185,6 +199,7 @@ public void getVpcStatesByProjectId_getEmptyMap_pass () throws Exception {
Map vpcStates = new HashMap<>();
Mockito.when(vpcDatabaseService.getAllVpcs()).thenReturn(vpcStates);
this.mockMvc.perform(get(getByProjectIdUri)).andDo(print())
+ .andDo(document("vpcstate_get_by_projectid_empty"))
.andExpect(status().isOk());
}