-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
723fdbf
commit 4d06787
Showing
8 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/test/java/com/cowave/commons/client/http/MockMultiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.cowave.commons.client.http; | ||
|
||
import com.cowave.commons.client.http.multipart.MultiClientController; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* | ||
* @author shanhuiming | ||
* | ||
*/ | ||
@ContextConfiguration(classes = Application.class) | ||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(webEnvironment = DEFINED_PORT) | ||
public class MockMultiTest { | ||
|
||
@Autowired | ||
private MultiClientController multiClientController; | ||
|
||
private MockMvc mockMvc; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
mockMvc = MockMvcBuilders.standaloneSetup(multiClientController).build(); | ||
} | ||
|
||
@Test | ||
public void multi1() throws Exception { | ||
this.mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/client/multi1") | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.data.id").value(1)) | ||
.andExpect(jsonPath("$.data.name").value("xxx")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/test/java/com/cowave/commons/client/http/multipart/HttpUrlMultiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.cowave.commons.client.http.multipart; | ||
|
||
import com.cowave.commons.client.http.annotation.HttpClient; | ||
import com.cowave.commons.client.http.annotation.HttpLine; | ||
import com.cowave.commons.client.http.annotation.HttpMultiForm; | ||
import com.cowave.commons.client.http.response.HttpResponse; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author shanhuiming | ||
* | ||
*/ | ||
@HttpClient(url = "http://127.0.0.1:8080") | ||
public interface HttpUrlMultiService { | ||
|
||
@HttpLine("POST /api/v1/service/submit") | ||
HttpResponse<Object> submit(@HttpMultiForm Map<String, Object> multiBody); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/com/cowave/commons/client/http/multipart/MultiBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.cowave.commons.client.http.multipart; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* | ||
* @author shanhuiming | ||
* | ||
*/ | ||
@Data | ||
public class MultiBody { | ||
|
||
private Integer id; | ||
|
||
private String name; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/cowave/commons/client/http/multipart/MultiClientController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.cowave.commons.client.http.multipart; | ||
|
||
import com.cowave.commons.client.http.response.HttpResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author shanhuiming | ||
* | ||
*/ | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/client") | ||
public class MultiClientController { | ||
|
||
private final HttpUrlMultiService httpUrlMultiService; | ||
|
||
@GetMapping("/multi1") | ||
public HttpResponse<Object> multi1() { | ||
Map<String, Object> bodyMap = new HashMap<>(); | ||
bodyMap.put("id", 1); | ||
bodyMap.put("name", "xxx"); | ||
return httpUrlMultiService.submit(bodyMap); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/com/cowave/commons/client/http/multipart/MultiServiceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.cowave.commons.client.http.multipart; | ||
|
||
import com.cowave.commons.client.http.post.PostBody; | ||
import com.cowave.commons.client.http.response.Response; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* | ||
* @author shanhuiming | ||
* | ||
*/ | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/service") | ||
public class MultiServiceController { | ||
|
||
@PostMapping("/submit") | ||
public Response<MultiBody> create(MultiBody multiBody){ | ||
return Response.success(multiBody); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters