-
Notifications
You must be signed in to change notification settings - Fork 34
Restii #177
base: master
Are you sure you want to change the base?
Restii #177
Changes from all commits
3596692
d40d5c4
834eae0
cc2893a
abcc3bb
d68f198
332d373
dd70438
6ea6c79
bfd02e9
3965e06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,18 +26,35 @@ | |
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.*; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
properties = {"httpbin=http://localhost:${wiremock.server.port}"}) | ||
@AutoConfigureWireMock(port = 0) | ||
@AutoConfigureRestDocs(outputDir = "target/generated-snippets") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If most of the 126 files on the other PR could be found in the target/generated-snippets directory, that would be great. This means that we could safely remove those files in the /docs/apis/ directory as we could always find the latest by running "mvn test". right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick question: are we able to find the html files like alcor/docs/apis/mac-manager/swagger/html/index.html in the target/generated-snippets directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! How can we access the /swagger-ui.html if the microservice is not started? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found some ways to generate swagger html files during mvn test, I am now verifying |
||
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") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we use "mac_range_post"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
@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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just merged new UTs to VPC and Route Controllers. Could you please add the docs accordingly. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok let me add it
Now there is a problem, most microservices mvn test need to connect to the database, I currently deploy the database can be executed, but it is best to be able to leave the database
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to have a flag which could switch off DB access when generating the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The document is generated after the unit test is completed. As long as the unit test does not depend on the database during execution, the document can be generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Please work with @chenpiaoping to see if we can support DB-related UTs by Ignite mock.