Java Code Examples for org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder#param()

The following examples show how to use org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder#param() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportControllerIT.java    From find with MIT License 6 votes vote down vote up
@Test
public void exportAsCsv() throws Exception {
    final String json = "{\"queryRestrictions\": {" +
            "\"text\": \"*\", \"indexes\": " + mvcIntegrationTestUtils.getDatabasesAsJson() +
            "}," +
            "\"max_results\": 5," +
            "\"summary\": \"off\"}";

    final MockHttpServletRequestBuilder requestBuilder = post(ExportController.EXPORT_PATH + ExportController.CSV_PATH).with(authentication(biAuth()));
    requestBuilder.param(ExportController.QUERY_REQUEST_PARAM, json);
    final String selectedField1 = "dateCreated";
    requestBuilder.param(ExportController.SELECTED_EXPORT_FIELDS_PARAM, selectedField1);
    final String selectedField2 = "WEIGHT";
    requestBuilder.param(ExportController.SELECTED_EXPORT_FIELDS_PARAM, selectedField2);

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(ExportFormat.CSV.getMimeType()))
            .andExpect(content().string(notNullValue()));
}
 
Example 2
Source File: StoreControllerTest.java    From ssm-demo with Apache License 2.0 6 votes vote down vote up
@Test
public void testList() throws Exception {
    //创建书架创建的请求
    //请求方式为post
    MockHttpServletRequestBuilder mockHttpServletRequestBuilder = MockMvcRequestBuilders.post("/store/list.do");
    //有些参数我注释掉了,你可以自行添加相关参数,得到不同的测试结果
    //status为0的记录
    //mockHttpServletRequestBuilder.param("status", "0");
    //书架编号为dd的记录
    //mockHttpServletRequestBuilder.param("number", "dd");
    //第一页
    mockHttpServletRequestBuilder.param("page", "1");
    //每页10条记录
    mockHttpServletRequestBuilder.param("rows", "10");
    mockMvc.perform(mockHttpServletRequestBuilder).andExpect(status().isOk())
            .andDo(print());

    //控制台会打印如下结果:
    //MockHttpServletResponse:
    //Status = 200 即为后端成功相应
    //返回数据
}
 
Example 3
Source File: ContentVersioningControllerIntegrationTest.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ResultActions listLatestVersions(UserDetails user, Map<String,String> params) throws Exception {
    String accessToken = mockOAuthInterceptor(user);

    final MockHttpServletRequestBuilder requestBuilder = get("/plugins/versioning/contents/")
            .sessionAttr("user", user)
            .header("Authorization", "Bearer " + accessToken);

    for (String key : Optional.ofNullable(params).orElse(new HashMap<>()).keySet()) {
        requestBuilder.param(key, params.get(key));
    }

    return mockMvc.perform(requestBuilder)
            .andDo(print());
}
 
Example 4
Source File: ExportControllerIT.java    From find with MIT License 5 votes vote down vote up
@Test
public void exportSunburstToPptx() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = post(ExportController.EXPORT_PATH + ExportController.PPTX_PATH + ExportController.SUNBURST_PATH).with(authentication(biAuth()));
    requestBuilder.param(ExportController.DATA_PARAM, getData(SUNBURST_DATA));

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(ExportFormat.PPTX.getMimeType()))
            .andExpect(content().string(notNullValue()));
}
 
Example 5
Source File: ExportControllerIT.java    From find with MIT License 5 votes vote down vote up
@Test
public void exportTopicMapToPptx() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = post(ExportController.EXPORT_PATH + ExportController.PPTX_PATH + ExportController.TOPIC_MAP_PATH).with(authentication(biAuth()));
    requestBuilder.param(ExportController.DATA_PARAM, getData(TOPIC_MAP_DATA));

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(ExportFormat.PPTX.getMimeType()))
            .andExpect(content().string(notNullValue()));
}
 
Example 6
Source File: MvcIntegrationTestUtils.java    From find with MIT License 5 votes vote down vote up
public String[] getFields(final MockMvc mockMvc, final String subPath, final String... fieldTypes) throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = get(FieldsController.FIELDS_PATH + subPath)
            .with(authentication(userAuth()));
    requestBuilder.param(FieldsController.FIELD_TYPES_PARAM, fieldTypes);
    addFieldRequestParams(requestBuilder);

    final MvcResult mvcResult = mockMvc.perform(requestBuilder)
            .andReturn();
    final Collection<Map<String, String>> tagNames = JsonPath.compile("$").read(mvcResult.getResponse().getContentAsString());
    return tagNames.stream().map(tagName -> tagName.get("id")).toArray(String[]::new);
}
 
Example 7
Source File: ResourceVersioningControllerIntegrationTest.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ResultActions listTrashedResources(UserDetails user, Map<String,String> params) throws Exception {
    String accessToken = mockOAuthInterceptor(user);

    final MockHttpServletRequestBuilder requestBuilder = get("/plugins/versioning/resources")
            .sessionAttr("user", user)
            .header("Authorization", "Bearer " + accessToken);

    for (String key : Optional.ofNullable(params).orElse(new HashMap<>()).keySet()) {
        requestBuilder.param(key, params.get(key));
    }

    return mockMvc.perform(requestBuilder)
            .andDo(print());
}
 
Example 8
Source File: ExportControllerIT.java    From find with MIT License 5 votes vote down vote up
@Test
public void exportReportToPptxMultiPage() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = post(ExportController.EXPORT_PATH + ExportController.PPTX_PATH + ExportController.REPORT_PATH).with(authentication(biAuth()));
    requestBuilder.param(ExportController.DATA_PARAM, getData(REPORT_DATA));
    requestBuilder.param(ExportController.MULTI_PAGE_PARAM, "true");

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(ExportFormat.PPTX.getMimeType()))
            .andExpect(content().string(notNullValue()));
}
 
Example 9
Source File: ControllerBaseTest.java    From Dolphin with Apache License 2.0 5 votes vote down vote up
private MockHttpServletResponse service(Map<String, String> params, MockHttpServletRequestBuilder httpServletRequestBuilder) throws Exception {
    if (params != null) {
        for (String name : params.keySet()) {
            httpServletRequestBuilder.param(name, params.get(name));
        }
    }

    return mockMvc.perform(httpServletRequestBuilder).andExpect(status().isOk()).andReturn().getResponse();
}
 
Example 10
Source File: FieldsControllerIT.java    From find with MIT License 5 votes vote down vote up
@Test
public void getParametricFields() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = get(FieldsController.FIELDS_PATH + FieldsController.GET_PARAMETRIC_FIELDS_PATH).with(authentication(userAuth()));
    requestBuilder.param(FieldsController.FIELD_TYPES_PARAM, FieldTypeParam.Parametric.name(), FieldTypeParam.Numeric.name(), FieldTypeParam.NumericDate.name());
    addParams(requestBuilder);

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$", not(empty())));
}
 
Example 11
Source File: ExportControllerIT.java    From find with MIT License 5 votes vote down vote up
@Test
public void exportMapToPptx() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = post(ExportController.EXPORT_PATH + ExportController.PPTX_PATH + ExportController.MAP_PATH).with(authentication(biAuth()));
    requestBuilder.param(ExportController.DATA_PARAM, getData(MAP_DATA));
    requestBuilder.param(ExportController.TITLE_PARAM, "Test");

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(ExportFormat.PPTX.getMimeType()))
            .andExpect(content().string(notNullValue()));
}
 
Example 12
Source File: ElectronicTaxReceiptMobileControllerTest.java    From nfscan with MIT License 5 votes vote down vote up
private ResultResponse donateRequest(String accessKey, double total) throws Exception {
    MockHttpServletRequestBuilder builder = post("/fe/electronictaxreceipts/donate.action");
    builder.contentType(MediaType.APPLICATION_FORM_URLENCODED);
    builder.param("accessKey", accessKey);
    builder.param("total", String.valueOf(total));

    Gson gson = new Gson();
    return gson.fromJson(
            mockMvc.perform(builder).andExpect(status().isOk()).andReturn().getResponse().getContentAsString(),
            ResultResponse.class
    );
}
 
Example 13
Source File: TaxReceiptMobileControllerTest.java    From nfscan with MIT License 5 votes vote down vote up
private ResultResponse manualDonate(TaxReceipt taxReceipt) throws Exception {
    MockHttpServletRequestBuilder builder = post("/fe/taxreceipts/manual/donate.action");
    builder.contentType(MediaType.APPLICATION_FORM_URLENCODED);
    builder.param("cnpj", taxReceipt.getCnpj());
    builder.param("date", new SimpleDateFormat(DATE_FORMAT).format(taxReceipt.getDate()));
    builder.param("coo", taxReceipt.getCoo());
    builder.param("total", String.valueOf(taxReceipt.getTotal()));

    Gson gson = new Gson();
    return gson.fromJson(
            mockMvc.perform(builder).andExpect(status().isOk()).andReturn().getResponse().getContentAsString(),
            ResultResponse.class
    );
}
 
Example 14
Source File: ExportControllerIT.java    From find with MIT License 5 votes vote down vote up
@Test
public void exportListToPptx() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = post(ExportController.EXPORT_PATH + ExportController.PPTX_PATH + ExportController.LIST_PATH).with(authentication(biAuth()));
    requestBuilder.param(ExportController.DATA_PARAM, getData(LIST_DATA));
    requestBuilder.param(ExportController.RESULTS_PARAM, "");
    requestBuilder.param(ExportController.SORT_BY_PARAM, "");

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(ExportFormat.PPTX.getMimeType()))
            .andExpect(content().string(notNullValue()));
}
 
Example 15
Source File: ExportControllerIT.java    From find with MIT License 5 votes vote down vote up
@Test
public void exportReportToPptx() throws Exception {
    final MockHttpServletRequestBuilder requestBuilder = post(ExportController.EXPORT_PATH + ExportController.PPTX_PATH + ExportController.REPORT_PATH).with(authentication(biAuth()));
    requestBuilder.param(ExportController.DATA_PARAM, getData(REPORT_DATA));
    requestBuilder.param(ExportController.MULTI_PAGE_PARAM, "false");

    mockMvc.perform(requestBuilder)
            .andExpect(status().isOk())
            .andExpect(content().contentType(ExportFormat.PPTX.getMimeType()))
            .andExpect(content().string(notNullValue()));
}
 
Example 16
Source File: LocalServerSecurityWithUsersFileTests.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Test
public void testEndpointAuthentication() throws Exception {

	logger.info(String.format(
			"Using parameters - httpMethod: %s, " + "URL: %s, URL parameters: %s, user credentials: %s",
			this.httpMethod, this.url, this.urlParameters, userCredentials));

	final MockHttpServletRequestBuilder rb;

	switch (httpMethod) {
	case GET:
		rb = get(url);
		break;
	case POST:
		rb = post(url);
		break;
	case PUT:
		rb = put(url);
		break;
	case DELETE:
		rb = delete(url);
		break;
	default:
		throw new IllegalArgumentException("Unsupported Method: " + httpMethod);
	}

	if (this.userCredentials != null) {
		rb.header("Authorization",
				basicAuthorizationHeader(this.userCredentials.getUsername(), this.userCredentials.getPassword()));
	}

	if (!CollectionUtils.isEmpty(urlParameters)) {
		for (Map.Entry<String, String> mapEntry : urlParameters.entrySet()) {
			rb.param(mapEntry.getKey(), mapEntry.getValue());
		}
	}

	final ResultMatcher statusResultMatcher;

	switch (expectedHttpStatus) {
	case UNAUTHORIZED:
		statusResultMatcher = status().isUnauthorized();
		break;
	case FORBIDDEN:
		statusResultMatcher = status().isForbidden();
		break;
	case FOUND:
		statusResultMatcher = status().isFound();
		break;
	case NOT_FOUND:
		statusResultMatcher = status().isNotFound();
		break;
	case OK:
		statusResultMatcher = status().isOk();
		break;
	case CREATED:
		statusResultMatcher = status().isCreated();
		break;
	case BAD_REQUEST:
		statusResultMatcher = status().isBadRequest();
		break;
	case INTERNAL_SERVER_ERROR:
		statusResultMatcher = status().isInternalServerError();
		break;
	default:
		throw new IllegalArgumentException("Unsupported Status: " + expectedHttpStatus);
	}

	try {
		localDataflowResource.getMockMvc().perform(rb).andDo(print()).andExpect(statusResultMatcher);
	}
	catch (AssertionError e) {
		throw new AssertionError(String.format(
				"Assertion failed for parameters - httpMethod: %s, "
						+ "URL: %s, URL parameters: %s, user credentials: %s",
				this.httpMethod, this.url, this.urlParameters, this.userCredentials), e);
	}
}
 
Example 17
Source File: GatewayApiControllerTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteApi() throws Exception {
    String path = "/gateway/api/delete.json";

    // Add one entity into memory repository for delete
    ApiDefinitionEntity addEntity = new ApiDefinitionEntity();
    addEntity.setApp(TEST_APP);
    addEntity.setIp(TEST_IP);
    addEntity.setPort(TEST_PORT);
    addEntity.setApiName("ccc");
    Date date = new Date();
    addEntity.setGmtCreate(date);
    addEntity.setGmtModified(date);
    Set<ApiPredicateItemEntity> addRedicateItemEntities = new HashSet<>();
    addEntity.setPredicateItems(addRedicateItemEntities);
    ApiPredicateItemEntity addPredicateItemEntity = new ApiPredicateItemEntity();
    addPredicateItemEntity.setMatchStrategy(URL_MATCH_STRATEGY_EXACT);
    addPredicateItemEntity.setPattern("/user/add");
    addEntity = repository.save(addEntity);

    given(sentinelApiClient.modifyApis(eq(TEST_APP), eq(TEST_IP), eq(TEST_PORT), any())).willReturn(true);

    MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post(path);
    requestBuilder.param("id", String.valueOf(addEntity.getId()));

    // Do controller logic
    MvcResult mvcResult = mockMvc.perform(requestBuilder)
            .andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print()).andReturn();

    // Verify the modifyApis method has been called
    verify(sentinelApiClient).modifyApis(eq(TEST_APP), eq(TEST_IP), eq(TEST_PORT), any());

    // Verify the result
    Result<Long> result = JSONObject.parseObject(mvcResult.getResponse().getContentAsString(), new TypeReference<Result<Long>>() {});
    assertTrue(result.isSuccess());

    assertEquals(addEntity.getId(), result.getData());

    // Now no entities in memory
    List<ApiDefinitionEntity> entitiesInMem = repository.findAllByApp(TEST_APP);
    assertEquals(0, entitiesInMem.size());
}
 
Example 18
Source File: GatewayApiControllerTest.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryApis() throws Exception {
    String path = "/gateway/api/list.json";

    List<ApiDefinitionEntity> entities = new ArrayList<>();

    // Mock two entities
    ApiDefinitionEntity entity = new ApiDefinitionEntity();
    entity.setId(1L);
    entity.setApp(TEST_APP);
    entity.setIp(TEST_IP);
    entity.setPort(TEST_PORT);
    entity.setApiName("foo");
    Date date = new Date();
    entity.setGmtCreate(date);
    entity.setGmtModified(date);

    Set<ApiPredicateItemEntity> itemEntities = new LinkedHashSet<>();
    entity.setPredicateItems(itemEntities);
    ApiPredicateItemEntity itemEntity = new ApiPredicateItemEntity();
    itemEntity.setPattern("/aaa");
    itemEntity.setMatchStrategy(URL_MATCH_STRATEGY_EXACT);

    itemEntities.add(itemEntity);
    entities.add(entity);

    ApiDefinitionEntity entity2 = new ApiDefinitionEntity();
    entity2.setId(2L);
    entity2.setApp(TEST_APP);
    entity2.setIp(TEST_IP);
    entity2.setPort(TEST_PORT);
    entity2.setApiName("biz");
    entity.setGmtCreate(date);
    entity.setGmtModified(date);

    Set<ApiPredicateItemEntity> itemEntities2 = new LinkedHashSet<>();
    entity2.setPredicateItems(itemEntities2);
    ApiPredicateItemEntity itemEntity2 = new ApiPredicateItemEntity();
    itemEntity2.setPattern("/bbb");
    itemEntity2.setMatchStrategy(URL_MATCH_STRATEGY_PREFIX);

    itemEntities2.add(itemEntity2);
    entities.add(entity2);

    CompletableFuture<List<ApiDefinitionEntity>> completableFuture = mock(CompletableFuture.class);
    given(completableFuture.get()).willReturn(entities);
    given(sentinelApiClient.fetchApis(TEST_APP, TEST_IP, TEST_PORT)).willReturn(completableFuture);

    MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get(path);
    requestBuilder.param("app", TEST_APP);
    requestBuilder.param("ip", TEST_IP);
    requestBuilder.param("port", String.valueOf(TEST_PORT));

    // Do controller logic
    MvcResult mvcResult = mockMvc.perform(requestBuilder)
            .andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print()).andReturn();

    // Verify the fetchApis method has been called
    verify(sentinelApiClient).fetchApis(TEST_APP, TEST_IP, TEST_PORT);

    // Verify if two same entities are got
    Result<List<ApiDefinitionEntity>> result = JSONObject.parseObject(mvcResult.getResponse().getContentAsString(), new TypeReference<Result<List<ApiDefinitionEntity>>>(){});
    assertTrue(result.isSuccess());

    List<ApiDefinitionEntity> data = result.getData();
    assertEquals(2, data.size());
    assertEquals(entities, data);

    // Verify the entities are add into memory repository
    List<ApiDefinitionEntity> entitiesInMem = repository.findAllByApp(TEST_APP);
    assertEquals(2, entitiesInMem.size());
    assertEquals(entities, entitiesInMem);
}
 
Example 19
Source File: GatewayApiControllerTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteApi() throws Exception {
    String path = "/gateway/api/delete.json";

    // Add one entity into memory repository for delete
    ApiDefinitionEntity addEntity = new ApiDefinitionEntity();
    addEntity.setApp(TEST_APP);
    addEntity.setIp(TEST_IP);
    addEntity.setPort(TEST_PORT);
    addEntity.setApiName("ccc");
    Date date = new Date();
    addEntity.setGmtCreate(date);
    addEntity.setGmtModified(date);
    Set<ApiPredicateItemEntity> addRedicateItemEntities = new HashSet<>();
    addEntity.setPredicateItems(addRedicateItemEntities);
    ApiPredicateItemEntity addPredicateItemEntity = new ApiPredicateItemEntity();
    addPredicateItemEntity.setMatchStrategy(URL_MATCH_STRATEGY_EXACT);
    addPredicateItemEntity.setPattern("/user/add");
    addEntity = repository.save(addEntity);

    given(sentinelApiClient.modifyApis(eq(TEST_APP), eq(TEST_IP), eq(TEST_PORT), any())).willReturn(true);

    MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post(path);
    requestBuilder.param("id", String.valueOf(addEntity.getId()));

    // Do controller logic
    MvcResult mvcResult = mockMvc.perform(requestBuilder)
            .andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print()).andReturn();

    // Verify the modifyApis method has been called
    verify(sentinelApiClient).modifyApis(eq(TEST_APP), eq(TEST_IP), eq(TEST_PORT), any());

    // Verify the result
    Result<Long> result = JSONObject.parseObject(mvcResult.getResponse().getContentAsString(), new TypeReference<Result<Long>>() {});
    assertTrue(result.isSuccess());

    assertEquals(addEntity.getId(), result.getData());

    // Now no entities in memory
    List<ApiDefinitionEntity> entitiesInMem = repository.findAllByApp(TEST_APP);
    assertEquals(0, entitiesInMem.size());
}
 
Example 20
Source File: GatewayApiControllerTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryApis() throws Exception {
    String path = "/gateway/api/list.json";

    List<ApiDefinitionEntity> entities = new ArrayList<>();

    // Mock two entities
    ApiDefinitionEntity entity = new ApiDefinitionEntity();
    entity.setId(1L);
    entity.setApp(TEST_APP);
    entity.setIp(TEST_IP);
    entity.setPort(TEST_PORT);
    entity.setApiName("foo");
    Date date = new Date();
    entity.setGmtCreate(date);
    entity.setGmtModified(date);

    Set<ApiPredicateItemEntity> itemEntities = new LinkedHashSet<>();
    entity.setPredicateItems(itemEntities);
    ApiPredicateItemEntity itemEntity = new ApiPredicateItemEntity();
    itemEntity.setPattern("/aaa");
    itemEntity.setMatchStrategy(URL_MATCH_STRATEGY_EXACT);

    itemEntities.add(itemEntity);
    entities.add(entity);

    ApiDefinitionEntity entity2 = new ApiDefinitionEntity();
    entity2.setId(2L);
    entity2.setApp(TEST_APP);
    entity2.setIp(TEST_IP);
    entity2.setPort(TEST_PORT);
    entity2.setApiName("biz");
    entity.setGmtCreate(date);
    entity.setGmtModified(date);

    Set<ApiPredicateItemEntity> itemEntities2 = new LinkedHashSet<>();
    entity2.setPredicateItems(itemEntities2);
    ApiPredicateItemEntity itemEntity2 = new ApiPredicateItemEntity();
    itemEntity2.setPattern("/bbb");
    itemEntity2.setMatchStrategy(URL_MATCH_STRATEGY_PREFIX);

    itemEntities2.add(itemEntity2);
    entities.add(entity2);

    CompletableFuture<List<ApiDefinitionEntity>> completableFuture = mock(CompletableFuture.class);
    given(completableFuture.get()).willReturn(entities);
    given(sentinelApiClient.fetchApis(TEST_APP, TEST_IP, TEST_PORT)).willReturn(completableFuture);

    MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get(path);
    requestBuilder.param("app", TEST_APP);
    requestBuilder.param("ip", TEST_IP);
    requestBuilder.param("port", String.valueOf(TEST_PORT));

    // Do controller logic
    MvcResult mvcResult = mockMvc.perform(requestBuilder)
            .andExpect(MockMvcResultMatchers.status().isOk()).andDo(MockMvcResultHandlers.print()).andReturn();

    // Verify the fetchApis method has been called
    verify(sentinelApiClient).fetchApis(TEST_APP, TEST_IP, TEST_PORT);

    // Verify if two same entities are got
    Result<List<ApiDefinitionEntity>> result = JSONObject.parseObject(mvcResult.getResponse().getContentAsString(), new TypeReference<Result<List<ApiDefinitionEntity>>>(){});
    assertTrue(result.isSuccess());

    List<ApiDefinitionEntity> data = result.getData();
    assertEquals(2, data.size());
    assertEquals(entities, data);

    // Verify the entities are add into memory repository
    List<ApiDefinitionEntity> entitiesInMem = repository.findAllByApp(TEST_APP);
    assertEquals(2, entitiesInMem.size());
    assertEquals(entities, entitiesInMem);
}