org.springframework.test.web.client.ExpectedCount Java Examples

The following examples show how to use org.springframework.test.web.client.ExpectedCount. 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: DataServiceControllerTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockRetrieveEntityWithRequestParamServer() {
    this.server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/system_design?filter=id,0001_0000000001", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"key_name\": \"EDP\",\n" +
                    "            \"business_group\": 105,\n" +
                    "            \"code\": \"EDP\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"r_guid\": \"0001_0000000001\",\n" +
                    "            \"name\": \"Deposit Micro Core System\",\n" +
                    "            \"description\": \"Deposit Micro Core System\",\n" +
                    "            \"id\": \"0001_0000000001\",\n" +
                    "            \"state\": 34,\n" +
                    "            \"fixed_date\": \"2019-07-24 17:28:15\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #2
Source File: DataServiceControllerTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockUpdateEntityServer() {
    // mockFwdNodeExpression
    this.server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/system_design/update", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"key_name\": \"updated_system_design_code\",\n" +
                    "            \"business_group\": 105,\n" +
                    "            \"code\": \"updated_system_design_code\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"r_guid\": \"0001_0000000022\",\n" +
                    "            \"name\": \"create_test_again\",\n" +
                    "            \"description\": \"This is a create test\",\n" +
                    "            \"id\": \"0001_0000000022\",\n" +
                    "            \"state\": 34,\n" +
                    "            \"fixed_date\": \"\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #3
Source File: RestTemplateResponseErrorHandlerIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test(expected = NotFoundException.class)
public void givenRemoteApiCall_when404Error_thenThrowNotFound() {
    Assert.assertNotNull(this.builder);
    Assert.assertNotNull(this.server);

    RestTemplate restTemplate = this.builder
      .errorHandler(new RestTemplateResponseErrorHandler())
      .build();

    this.server
      .expect(ExpectedCount.once(), requestTo("/bars/4242"))
      .andExpect(method(HttpMethod.GET))
      .andRespond(withStatus(HttpStatus.NOT_FOUND));

    Bar response = restTemplate.getForObject("/bars/4242", Bar.class);
    this.server.verify();
}
 
Example #4
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockCreateUserServer(MockRestServiceServer server) {
    String createUserJsonString = String.format("{\"password\":\"%s\",\"username\":\"%s\"}", MOCK_PASSWORD, MOCK_USERNAME);
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/users", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andExpect(content().json(createUserJsonString))
            .andRespond(withSuccess(String.format("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": {\n" +
                    "    \"createdBy\": null,\n" +
                    "    \"updatedBy\": null,\n" +
                    "    \"createdTime\": \"2019-12-04T06:34:06.110+0000\",\n" +
                    "    \"updatedTime\": null,\n" +
                    "    \"id\": 1,\n" +
                    "    \"username\": \"%s\",\n" +
                    "    \"password\": \"%s\",\n" +
                    "    \"active\": true,\n" +
                    "    \"blocked\": null\n" +
                    "  }\n" +
                    "}", MOCK_USERNAME, AS_RETURN_PASSWORD), MediaType.APPLICATION_JSON));

}
 
Example #5
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockRetrieveUserServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/users", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess(String.format("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": [\n" +
                    "    {\n" +
                    "      \"createdBy\": null,\n" +
                    "      \"updatedBy\": null,\n" +
                    "      \"createdTime\": \"2019-12-04T06:34:06.000+0000\",\n" +
                    "      \"updatedTime\": null,\n" +
                    "      \"id\": 1,\n" +
                    "      \"username\": \"%s\",\n" +
                    "      \"password\": \"%s\",\n" +
                    "      \"active\": true,\n" +
                    "      \"blocked\": null\n" +
                    "    }\n" +
                    "  ]\n" +
                    "}", USERNAME, AS_RETURN_PASSWORD), MediaType.APPLICATION_JSON));

}
 
Example #6
Source File: ConfigServerValues.java    From rabbitmq-mock with Apache License 2.0 6 votes vote down vote up
private void configure(MockRestServiceServer mockConfigServer) {
    String config = "{\n"
        + "  name: 'config-server-env'\n"
        + "  propertySources: [{\n"
        + "    name: 'config-server-test-source'\n"
        + "    source: {\n"
        + sourceAsHjson()
        + "    }\n"
        + "  }]\n"
        + "}";
    mockConfigServer.reset();
    mockConfigServer.expect(ExpectedCount.manyTimes(), requestTo(CoreMatchers.endsWith("/application/default")))
        .andRespond(withSuccess(
            readHjson(config).toString(Stringify.FORMATTED),
            MediaType.APPLICATION_JSON_UTF8
        ));
}
 
Example #7
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockRegisterRoleServer(MockRestServiceServer server) {
    String createRoleJsonString = String.format("{\"displayName\":\"%s\",\"name\":\"%s\",\"email\":\"%s\"}", ROLE_DISPLAY_NAME, ROLE_NAME, ROLE_EMAIL);
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andExpect(content().json(createRoleJsonString))
            .andRespond(withSuccess(String.format("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": {\n" +
                    "    \"createdBy\": null,\n" +
                    "    \"updatedBy\": null,\n" +
                    "    \"createdTime\": \"2019-12-04T06:37:39.805+0000\",\n" +
                    "    \"updatedTime\": null,\n" +
                    "    \"id\": \"1\",\n" +
                    "    \"name\": \"%s\",\n" +
                    "    \"displayName\": \"%s\",\n" +
                    "    \"email\": \"%s\"\n" +
                    "  }\n" +
                    "}", ROLE_NAME, ROLE_DISPLAY_NAME, ROLE_EMAIL), MediaType.APPLICATION_JSON));
}
 
Example #8
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockRetrieveRoleByIdServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s", this.gatewayUrl, ROLE_ID)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess(String.format("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\":\n" +
                    "    {\n" +
                    "      \"createdBy\": null,\n" +
                    "      \"updatedBy\": null,\n" +
                    "      \"createdTime\": \"2019-12-04T06:37:40.000+0000\",\n" +
                    "      \"updatedTime\": null,\n" +
                    "      \"id\": \"1\",\n" +
                    "      \"name\": \"%s\",\n" +
                    "      \"displayName\": \"%s\",\n" +
                    "      \"email\": \"%s\"\n" +
                    "    }\n" +
                    "}", ROLE_NAME, ROLE_DISPLAY_NAME, ROLE_EMAIL), MediaType.APPLICATION_JSON));

}
 
Example #9
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockRetrieveRoleServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess(String.format("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": [\n" +
                    "    {\n" +
                    "      \"createdBy\": null,\n" +
                    "      \"updatedBy\": null,\n" +
                    "      \"createdTime\": \"2019-12-04T06:37:40.000+0000\",\n" +
                    "      \"updatedTime\": null,\n" +
                    "      \"id\": \"1\",\n" +
                    "      \"name\": \"%s\",\n" +
                    "      \"displayName\": \"%s\",\n" +
                    "      \"email\": \"%s\"\n" +
                    "    }\n" +
                    "  ]\n" +
                    "}", ROLE_NAME, ROLE_DISPLAY_NAME, ROLE_EMAIL), MediaType.APPLICATION_JSON));

}
 
Example #10
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockGetRolesFromUserServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/users/%s/roles", this.gatewayUrl, USERNAME)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess(String.format("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": [\n" +
                    "    {\n" +
                    "      \"createdBy\": null,\n" +
                    "      \"updatedBy\": null,\n" +
                    "      \"createdTime\": \"2019-12-04T06:56:39.000+0000\",\n" +
                    "      \"updatedTime\": null,\n" +
                    "      \"id\": \"1\",\n" +
                    "      \"name\": \"%s\",\n" +
                    "      \"displayName\": \"%s\",\n" +
                    "      \"email\": \"%s\"\n" +
                    "    }\n" +
                    "  ]\n" +
                    "}", ROLE_NAME, ROLE_DISPLAY_NAME, ROLE_EMAIL), MediaType.APPLICATION_JSON));

}
 
Example #11
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockGetUsersFromRoleServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/users", this.gatewayUrl, ROLE_ID)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess(String.format("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": [\n" +
                    "    {\n" +
                    "      \"createdBy\": null,\n" +
                    "      \"updatedBy\": null,\n" +
                    "      \"createdTime\": \"2019-12-04T06:56:18.000+0000\",\n" +
                    "      \"updatedTime\": null,\n" +
                    "      \"id\": 1,\n" +
                    "      \"username\": \"%s\",\n" +
                    "      \"password\": \"%s\",\n" +
                    "      \"active\": true,\n" +
                    "      \"blocked\": null\n" +
                    "    }\n" +
                    "  ]\n" +
                    "}", USERNAME, AS_RETURN_PASSWORD), MediaType.APPLICATION_JSON));

}
 
Example #12
Source File: DataServiceControllerTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockCreateEntityServer() {
    this.server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/system_design/create", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"key_name\": \"create_test_again\",\n" +
                    "            \"business_group\": 105,\n" +
                    "            \"code\": \"create_test_again\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"r_guid\": \"0001_0000000022\",\n" +
                    "            \"name\": \"create_test_again\",\n" +
                    "            \"description\": \"This is a create test\",\n" +
                    "            \"id\": \"0001_0000000022\",\n" +
                    "            \"state\": 34,\n" +
                    "            \"fixed_date\": \"\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #13
Source File: RoleMenuServiceTest.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
private void mockRetrieveRoleWithPackageMenusServer() {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s", this.gatewayUrl, ROLE_ONE)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": {\n" +
                    "        \"id\": 1,\n" +
                    "        \"name\": \"1\",\n" +
                    "        \"displayName\": \"1_display_name\"\n" +
                    "    }\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/authorities", this.gatewayUrl, ROLE_ONE)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #14
Source File: StandardEntityOperationServiceTestsMockers.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public void mockSingleLinkNodeWithFilterExpressionServer(MockRestServiceServer server) {
    // mockFwdNodeExpression
    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/we-cmdb/entities/system_design/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"key_name\": \"EDP\",\n" + "            \"business_group\": 105,\n"
                    + "            \"code\": \"EDP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"r_guid\": \"0001_0000000001\",\n"
                    + "            \"name\": \"Deposit Micro Core System\",\n"
                    + "            \"description\": \"Deposit Micro Core System\",\n"
                    + "            \"displayName\": \"Deposit Micro Core System\",\n"
                    + "            \"id\": \"0001_0000000001\",\n" + "            \"state\": 34,\n"
                    + "            \"fixed_date\": \"2019-07-24 17:28:15\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/we-cmdb/entities/unit/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"code\": \"APP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"package\": \"\",\n" + "            \"r_guid\": \"0008_0000000003\",\n"
                    + "            \"description\": \"\",\n" + "            \"displayName\": \"\",\n"
                    + "            \"resource_set\": \"0020_0000000001\",\n"
                    + "            \"key_name\": \"EDP-CORE_PRD-APP\",\n" + "            \"instance_num\": 1,\n"
                    + "            \"subsys\": \"0007_0000000003\",\n"
                    + "            \"id\": \"0008_0000000003\",\n" + "            \"state\": 37,\n"
                    + "            \"fixed_date\": \"2019-07-24 16:30:37\",\n"
                    + "            \"unit_design\": \"0003_0000000002\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));
}
 
Example #15
Source File: RoleMenuServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockRetrieveRoleWithSystemMenusServer() {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s", this.gatewayUrl, ROLE_ONE)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": {\n" +
                    "        \"id\": 1,\n" +
                    "        \"name\": \"1\",\n" +
                    "        \"displayName\": \"1_display_name\"\n" +
                    "    }\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/authorities/revoke", this.gatewayUrl, ROLE_ONE)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/authorities", this.gatewayUrl, ROLE_ONE)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #16
Source File: StandardEntityOperationServiceTestsMockers.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public void mockPackageNameWithDashAndFwdNodeExpressionServer(MockRestServiceServer server) {
    // mockFwdNodeExpression
    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/we-cmdb/entities/system_design/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"key_name\": \"EDP\",\n" + "            \"business_group\": 105,\n"
                    + "            \"code\": \"EDP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"r_guid\": \"0001_0000000001\",\n"
                    + "            \"name\": \"Deposit Micro Core System\",\n"
                    + "            \"description\": \"Deposit Micro Core System\",\n"
                    + "            \"displayName\": \"Deposit Micro Core System\",\n"
                    + "            \"id\": \"0001_0000000001\",\n" + "            \"state\": 34,\n"
                    + "            \"fixed_date\": \"2019-07-24 17:28:15\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/we-cmdb/entities/unit/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"code\": \"APP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"package\": \"\",\n" + "            \"r_guid\": \"0008_0000000003\",\n"
                    + "            \"description\": \"\",\n" + "            \"displayName\": \"\",\n"
                    + "            \"resource_set\": \"0020_0000000001\",\n"
                    + "            \"key_name\": \"EDP-CORE_PRD-APP\",\n" + "            \"instance_num\": 1,\n"
                    + "            \"subsys\": \"0007_0000000003\",\n"
                    + "            \"id\": \"0008_0000000003\",\n" + "            \"state\": 37,\n"
                    + "            \"fixed_date\": \"2019-07-24 16:30:37\",\n"
                    + "            \"unit_design\": \"0003_0000000002\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));
}
 
Example #17
Source File: StandardEntityOperationServiceTestsMockers.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public void mockFwdNodeExpressionServer(MockRestServiceServer server) {
    // mockFwdNodeExpression
    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/wecmdb/entities/system_design/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"key_name\": \"EDP\",\n" + "            \"business_group\": 105,\n"
                    + "            \"code\": \"EDP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"r_guid\": \"0001_0000000001\",\n"
                    + "            \"name\": \"Deposit Micro Core System\",\n"
                    + "            \"description\": \"Deposit Micro Core System\",\n"
                    + "            \"displayName\": \"Deposit Micro Core System\",\n"
                    + "            \"id\": \"0001_0000000001\",\n" + "            \"state\": 34,\n"
                    + "            \"fixed_date\": \"2019-07-24 17:28:15\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/wecmdb/entities/unit/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"code\": \"APP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"package\": \"\",\n" + "            \"r_guid\": \"0008_0000000003\",\n"
                    + "            \"description\": \"\",\n" + "            \"displayName\": \"\",\n"
                    + "            \"resource_set\": \"0020_0000000001\",\n"
                    + "            \"key_name\": \"EDP-CORE_PRD-APP\",\n" + "            \"instance_num\": 1,\n"
                    + "            \"subsys\": \"0007_0000000003\",\n"
                    + "            \"id\": \"0008_0000000003\",\n" + "            \"state\": 37,\n"
                    + "            \"fixed_date\": \"2019-07-24 16:30:37\",\n"
                    + "            \"unit_design\": \"0003_0000000002\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));
}
 
Example #18
Source File: StandardEntityOperationServiceTestsMockers.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public void mockOneLinkWithOpToOnlyExpressionServer(MockRestServiceServer server) {
    // mockOneLinkWithOpToOnlyExpression
    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/wecmdb/entities/subsys_design/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"business_group\": 105,\n" + "            \"code\": \"ADMBATCH\",\n"
                    + "            \"orchestration\": null,\n" + "            \"r_guid\": \"0002_0000000006\",\n"
                    + "            \"description\": \"ADM Batch Subsystem\",\n"
                    + "            \"displayName\": \"ADM Batch Subsystem\",\n"
                    + "            \"dcn_design_type\": 132,\n" + "            \"key_name\": \"EDP-ADMBATCH\",\n"
                    + "            \"name\": \"ADM Batch Subsystem\",\n"
                    + "            \"id\": \"0002_0000000006\",\n" + "            \"state\": 34,\n"
                    + "            \"fixed_date\": \"2019-07-24 16:28:25\",\n"
                    + "            \"system_design\": \"0001_0000000001\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/wecmdb/entities/system_design/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"key_name\": \"EDP\",\n" + "            \"business_group\": 105,\n"
                    + "            \"code\": \"EDP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"r_guid\": \"0001_0000000001\",\n"
                    + "            \"name\": \"Deposit Micro Core System\",\n"
                    + "            \"description\": \"Deposit Micro Core System\",\n"
                    + "            \"displayName\": \"Deposit Micro Core System\",\n"
                    + "            \"id\": \"0001_0000000001\",\n" + "            \"state\": 34,\n"
                    + "            \"fixed_date\": \"2019-07-24 17:28:15\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));
}
 
Example #19
Source File: StandardEntityOperationServiceTestsMockers.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
public void mockFwdNodeExpressionWriteBackServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/wecmdb/entities/system_design/query", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"key_name\": \"EDP\",\n" + "            \"business_group\": 105,\n"
                    + "            \"code\": \"EDP\",\n" + "            \"orchestration\": null,\n"
                    + "            \"r_guid\": \"0001_0000000001\",\n"
                    + "            \"name\": \"Deposit Micro Core System\",\n"
                    + "            \"description\": \"Deposit Micro Core System\",\n"
                    + "            \"displayName\": \"Deposit Micro Core System\",\n"
                    + "            \"id\": \"0001_0000000001\",\n" + "            \"state\": 34,\n"
                    + "            \"fixed_date\": \"2019-07-24 17:28:15\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(),
            requestTo(String.format("http://%s/wecmdb/entities/system_design/update", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\n" + "    \"status\": \"OK\",\n" + "    \"message\": \"Success\",\n"
                    + "    \"data\": [\n" + "        {\n" + "            \"biz_key\": null,\n"
                    + "            \"key_name\": \"EDP\",\n" + "            \"business_group\": 105,\n"
                    + "            \"code\": \"Test\",\n" + "            \"orchestration\": null,\n"
                    + "            \"r_guid\": \"0001_0000000001\",\n"
                    + "            \"name\": \"Deposit Micro Core System\",\n"
                    + "            \"description\": \"Deposit Micro Core System\",\n"
                    + "            \"displayName\": \"Deposit Micro Core System\",\n"
                    + "            \"id\": \"0001_0000000001\",\n" + "            \"state\": 34,\n"
                    + "            \"fixed_date\": \"2019-07-24 17:28:15\"\n" + "        }\n" + "    ]\n" + "}",
                    MediaType.APPLICATION_JSON));
}
 
Example #20
Source File: CustomerClientRestServiceServerTest.java    From bootiful-testing-online-training with Apache License 2.0 5 votes vote down vote up
@Test
public void customerByIdShouldReturnACustomer() {

	this.mockRestServiceServer
		.expect(ExpectedCount.manyTimes(), requestTo("http://localhost:8080/customers/1"))
		.andExpect(method(HttpMethod.GET))
		.andRespond(withSuccess(this.customerById, MediaType.APPLICATION_JSON_UTF8));

	Customer customer = client.getCustomerById(1L);
	BDDAssertions.then(customer.getFirstName()).isEqualToIgnoringCase("first");
	BDDAssertions.then(customer.getLastName()).isEqualToIgnoringCase("last");
	BDDAssertions.then(customer.getEmail()).isEqualToIgnoringCase("email");
	BDDAssertions.then(customer.getId()).isEqualTo(1L);
	this.mockRestServiceServer.verify();
}
 
Example #21
Source File: EmployeeServiceMockRestServiceServerUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMockingIsDoneByMockRestServiceServer_whenGetIsCalled_shouldReturnMockedObject() throws Exception {
    Employee emp = new Employee("E001", "Eric Simmons");

    mockServer.expect(ExpectedCount.once(),
      requestTo(new URI("http://localhost:8080/employee/E001")))
        .andExpect(method(HttpMethod.GET))
        .andRespond(withStatus(HttpStatus.OK)
          .contentType(MediaType.APPLICATION_JSON)
          .body(mapper.writeValueAsString(emp)));

    Employee employee = empService.getEmployee("E001");
    mockServer.verify();
    Assert.assertEquals(emp, employee);
}
 
Example #22
Source File: RoleMenuServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockRetrieveRoleWithMixedTypeMenusServer() {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s", this.gatewayUrl, ROLE_TWO)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": {\n" +
                    "        \"id\": 2,\n" +
                    "        \"name\": \"2\",\n" +
                    "        \"displayName\": \"2_display_name\"\n" +
                    "    }\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/authorities/revoke", this.gatewayUrl, ROLE_TWO)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/authorities", this.gatewayUrl, ROLE_TWO)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #23
Source File: RoleMenuServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockRetrieveMenuByRoleIdServer() {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s", this.gatewayUrl, ROLE_ONE)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": {\n" +
                    "        \"id\": 1,\n" +
                    "        \"name\": \"1\",\n" +
                    "        \"displayName\": \"1_display_name\"\n" +
                    "    }\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s", this.gatewayUrl, ROLE_TWO)))
            .andExpect(method(HttpMethod.GET))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": {\n" +
                    "        \"id\": 2,\n" +
                    "        \"name\": \"2\",\n" +
                    "        \"displayName\": \"2_display_name\"\n" +
                    "    }\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #24
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockRevokeRoleFromUsers(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/users/revoke", this.gatewayUrl, GRANT_ROLE_ID)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #25
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockGrantRoleToUsersServer(MockRestServiceServer server) {

        server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/%s/users", this.gatewayUrl, GRANT_ROLE_ID)))
                .andExpect(method(HttpMethod.POST))
                .andExpect(header("Authorization", TOKEN))
                .andRespond(withSuccess("{\n" +
                        "  \"status\": \"OK\",\n" +
                        "  \"message\": \"success\",\n" +
                        "  \"data\": null\n" +
                        "}", MediaType.APPLICATION_JSON));

    }
 
Example #26
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockDeleteRoleServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/roles/1", this.gatewayUrl)))
            .andExpect(method(HttpMethod.DELETE))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));

}
 
Example #27
Source File: UserManagementServiceTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockDeleteUserServer(MockRestServiceServer server) {
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/auth/v1/users/%s", this.gatewayUrl, USER_ID)))
            .andExpect(method(HttpMethod.DELETE))
            .andExpect(header("Authorization", TOKEN))
            .andRespond(withSuccess("{\n" +
                    "  \"status\": \"OK\",\n" +
                    "  \"message\": \"success\",\n" +
                    "  \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #28
Source File: DataServiceControllerTest.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
private void mockDeleteEntityServer() {
    // mockFwdNodeExpression
    this.server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/system_design/delete", this.gatewayUrl)))
            .andExpect(method(HttpMethod.POST))
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": null\n" +
                    "}", MediaType.APPLICATION_JSON));
}
 
Example #29
Source File: RootlessExpressionServiceTest.java    From wecube-platform with Apache License 2.0 4 votes vote down vote up
private void mockOneLinkWithOpByOnlyExpressionServer(MockRestServiceServer server) {
    // mockOneLinkWithOpByOnlyExpression

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/subsys", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"subsys_design\": \"0002_0000000010\",\n" +
                    "            \"key_name\": \"ECIF-CORE_PRD\",\n" +
                    "            \"code\": \"CORE\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"manager\": \"nertonsong\",\n" +
                    "            \"r_guid\": \"0007_0000000001\",\n" +
                    "            \"description\": \"ECIF-CORE PRD\",\n" +
                    "            \"id\": \"0007_0000000001\",\n" +
                    "            \"state\": 37,\n" +
                    "            \"env\": 111,\n" +
                    "            \"fixed_date\": \"2019-07-24 16:30:17\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/unit?filter=subsys,0007_0000000001", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"code\": \"APP\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"package\": \"\",\n" +
                    "            \"r_guid\": \"0008_0000000001\",\n" +
                    "            \"description\": \"\",\n" +
                    "            \"resource_set\": \"0020_0000000001\",\n" +
                    "            \"key_name\": \"ECIF-CORE_PRD-APP\",\n" +
                    "            \"instance_num\": 1,\n" +
                    "            \"subsys\": \"0007_0000000001\",\n" +
                    "            \"id\": \"0008_0000000001\",\n" +
                    "            \"state\": 37,\n" +
                    "            \"fixed_date\": \"2019-07-24 16:30:35\",\n" +
                    "            \"unit_design\": \"0003_0000000006\"\n" +
                    "        },\n" +
                    "        {\n" +
                    "            \"biz_key\": \"\",\n" +
                    "            \"code\": \"DB\",\n" +
                    "            \"orchestration\": 231,\n" +
                    "            \"package\": \"0011_0000000010\",\n" +
                    "            \"r_guid\": \"0008_0000000007\",\n" +
                    "            \"description\": \"aa\",\n" +
                    "            \"resource_set\": \"0020_0000000001\",\n" +
                    "            \"key_name\": \"ECIF-CORE_PRD-DB\",\n" +
                    "            \"instance_num\": 1,\n" +
                    "            \"subsys\": \"0007_0000000001\",\n" +
                    "            \"id\": \"0008_0000000007\",\n" +
                    "            \"state\": 37,\n" +
                    "            \"fixed_date\": \"\",\n" +
                    "            \"unit_design\": \"0003_0000000007\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));

}
 
Example #30
Source File: RootlessExpressionServiceTest.java    From wecube-platform with Apache License 2.0 4 votes vote down vote up
private void mockMultipleLinksWithOpToOnlyExpressionServer(MockRestServiceServer server) {
    // first expression
    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/subsys", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"subsys_design\": \"0002_0000000010\",\n" +
                    "            \"key_name\": \"ECIF-CORE_PRD\",\n" +
                    "            \"code\": \"CORE\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"manager\": \"nertonsong\",\n" +
                    "            \"r_guid\": \"0007_0000000001\",\n" +
                    "            \"description\": \"ECIF-CORE PRD\",\n" +
                    "            \"id\": \"0007_0000000001\",\n" +
                    "            \"state\": 37,\n" +
                    "            \"env\": 111,\n" +
                    "            \"fixed_date\": \"2019-07-24 16:30:17\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/subsys_design?filter=id,0002_0000000010", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"business_group\": 105,\n" +
                    "            \"code\": \"CORE\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"r_guid\": \"0002_0000000010\",\n" +
                    "            \"description\": \"CRM Core Subsystem\",\n" +
                    "            \"dcn_design_type\": 135,\n" +
                    "            \"key_name\": \"ECIF-CORE\",\n" +
                    "            \"name\": \"CRM Core Subsystem\",\n" +
                    "            \"id\": \"0002_0000000010\",\n" +
                    "            \"state\": 34,\n" +
                    "            \"fixed_date\": \"2019-07-24 16:28:27\",\n" +
                    "            \"system_design\": \"0001_0000000003\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));

    server.expect(ExpectedCount.manyTimes(), requestTo(String.format("http://%s/wecmdb/entities/system_design?filter=id,0001_0000000003", this.gatewayUrl)))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess("{\n" +
                    "    \"status\": \"OK\",\n" +
                    "    \"message\": \"Success\",\n" +
                    "    \"data\": [\n" +
                    "        {\n" +
                    "            \"biz_key\": null,\n" +
                    "            \"key_name\": \"ECIF\",\n" +
                    "            \"business_group\": 105,\n" +
                    "            \"code\": \"ECIF\",\n" +
                    "            \"orchestration\": null,\n" +
                    "            \"r_guid\": \"0001_0000000003\",\n" +
                    "            \"name\": \"CRM System\",\n" +
                    "            \"description\": \"CRM System\",\n" +
                    "            \"id\": \"0001_0000000003\",\n" +
                    "            \"state\": 34,\n" +
                    "            \"fixed_date\": \"2019-07-24 17:28:17\"\n" +
                    "        }\n" +
                    "    ]\n" +
                    "}", MediaType.APPLICATION_JSON));
}