final String endpoint = restMethod.getForwardedEndpoint() + request.getUri() + parameterUri;
@Test public void testProcess(){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); Mockito.when(methodRepository.save(Mockito.any(RestMethod.class))).thenReturn(restMethod); final CreateRestMethodInput input = CreateRestMethodInput.builder() .projectId(restProject.getId()) .applicationId(restApplication.getId()) .resourceId(restResource.getId()) .method(restMethod) .build(); final ServiceTask<CreateRestMethodInput> serviceTask = new ServiceTask<CreateRestMethodInput>(input); final ServiceResult<CreateRestMethodOutput> serviceResult = service.process(serviceTask); final CreateRestMethodOutput createRestApplicationOutput = serviceResult.getOutput(); final RestMethod returnedRestMethod = createRestApplicationOutput.getCreatedRestMethod(); Assert.assertEquals(restMethod.getName(), returnedRestMethod.getName()); Assert.assertEquals(restMethod.getHttpMethod(), returnedRestMethod.getHttpMethod()); Assert.assertEquals(restMethod.getDefaultBody(), returnedRestMethod.getDefaultBody()); Assert.assertEquals(restMethod.getForwardedEndpoint(), returnedRestMethod.getForwardedEndpoint()); Assert.assertEquals(restMethod.getStatus(), returnedRestMethod.getStatus()); Assert.assertEquals(restMethod.getMockResponses(), returnedRestMethod.getMockResponses()); Assert.assertEquals(restMethod.getResponseStrategy(), returnedRestMethod.getResponseStrategy()); }
@Test public void testProcessWithoutStatus(){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); restMethod.setStatus(null); Mockito.when(methodRepository.save(Mockito.any(RestMethod.class))).thenReturn(restMethod); final CreateRestMethodInput input = CreateRestMethodInput.builder() .projectId(restProject.getId()) .applicationId(restApplication.getId()) .resourceId(restResource.getId()) .method(restMethod) .build(); final ServiceTask<CreateRestMethodInput> serviceTask = new ServiceTask<CreateRestMethodInput>(input); final ServiceResult<CreateRestMethodOutput> serviceResult = service.process(serviceTask); final CreateRestMethodOutput createRestApplicationOutput = serviceResult.getOutput(); final RestMethod returnedRestMethod = createRestApplicationOutput.getCreatedRestMethod(); Assert.assertEquals(restMethod.getName(), returnedRestMethod.getName()); Assert.assertEquals(restMethod.getHttpMethod(), returnedRestMethod.getHttpMethod()); Assert.assertEquals(restMethod.getDefaultBody(), returnedRestMethod.getDefaultBody()); Assert.assertEquals(restMethod.getForwardedEndpoint(), returnedRestMethod.getForwardedEndpoint()); Assert.assertEquals(restMethod.getStatus(), RestMethodStatus.MOCKED); Assert.assertEquals(restMethod.getMockResponses(), returnedRestMethod.getMockResponses()); Assert.assertEquals(restMethod.getResponseStrategy(), returnedRestMethod.getResponseStrategy()); }
@Test public void testProcessWithoutResponseStrategy(){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); restMethod.setResponseStrategy(null); Mockito.when(methodRepository.save(Mockito.any(RestMethod.class))).thenReturn(restMethod); final CreateRestMethodInput input = CreateRestMethodInput.builder() .projectId(restProject.getId()) .applicationId(restApplication.getId()) .resourceId(restResource.getId()) .method(restMethod) .build(); final ServiceTask<CreateRestMethodInput> serviceTask = new ServiceTask<CreateRestMethodInput>(input); final ServiceResult<CreateRestMethodOutput> serviceResult = service.process(serviceTask); final CreateRestMethodOutput createRestApplicationOutput = serviceResult.getOutput(); final RestMethod returnedRestMethod = createRestApplicationOutput.getCreatedRestMethod(); Assert.assertEquals(restMethod.getName(), returnedRestMethod.getName()); Assert.assertEquals(restMethod.getHttpMethod(), returnedRestMethod.getHttpMethod()); Assert.assertEquals(restMethod.getDefaultBody(), returnedRestMethod.getDefaultBody()); Assert.assertEquals(restMethod.getForwardedEndpoint(), returnedRestMethod.getForwardedEndpoint()); Assert.assertEquals(restMethod.getStatus(), returnedRestMethod.getStatus()); Assert.assertEquals(restMethod.getMockResponses(), returnedRestMethod.getMockResponses()); Assert.assertEquals(restMethod.getResponseStrategy(), RestResponseStrategy.RANDOM); }
/** * The process message is responsible for processing an incoming serviceTask and generate * a response based on the incoming serviceTask input * @param serviceTask The serviceTask that will be processed by the service * @return A result based on the processed incoming serviceTask * @see ServiceTask * @see ServiceResult */ @Override public ServiceResult<UpdateRestMethodOutput> process(final ServiceTask<UpdateRestMethodInput> serviceTask) { final UpdateRestMethodInput input = serviceTask.getInput(); final RestMethod updatedRestMethod = input.getRestMethod(); final RestMethod existing = this.methodRepository.findOne(input.getRestMethodId()); existing.setName(updatedRestMethod.getName()); existing.setHttpMethod(updatedRestMethod.getHttpMethod()); existing.setResponseStrategy(updatedRestMethod.getResponseStrategy()); existing.setStatus(updatedRestMethod.getStatus()); existing.setForwardedEndpoint(updatedRestMethod.getForwardedEndpoint()); existing.setNetworkDelay(updatedRestMethod.getNetworkDelay()); existing.setSimulateNetworkDelay(updatedRestMethod.getSimulateNetworkDelay()); existing.setDefaultMockResponseId(updatedRestMethod.getDefaultMockResponseId()); this.methodRepository.update(input.getRestMethodId(), existing); return createServiceResult(UpdateRestMethodOutput.builder() .restMethod(updatedRestMethod) .build()); } }
Assert.assertEquals("http://castlemock.com/v1", getAllMockServicesMethod.getForwardedEndpoint()); Assert.assertEquals(HttpMethod.GET, getAllMockServicesMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, getAllMockServicesMethod.getStatus()); Assert.assertEquals("http://castlemock.com/v1", createMockMethod.getForwardedEndpoint()); Assert.assertEquals(HttpMethod.POST, createMockMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, createMockMethod.getStatus()); Assert.assertEquals("http://castlemock.com/v1", headMockMethod.getForwardedEndpoint()); Assert.assertEquals(HttpMethod.HEAD, headMockMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, headMockMethod.getStatus()); Assert.assertEquals("http://castlemock.com/v1", optionsMockMethod.getForwardedEndpoint()); Assert.assertEquals(HttpMethod.OPTIONS, optionsMockMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, optionsMockMethod.getStatus()); Assert.assertEquals("http://castlemock.com/v1", getMockByIdMethod.getForwardedEndpoint()); Assert.assertEquals(HttpMethod.GET, getMockByIdMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, getMockByIdMethod.getStatus()); Assert.assertEquals("http://castlemock.com/v1", updateMockMethod.getForwardedEndpoint()); Assert.assertEquals(HttpMethod.PUT, updateMockMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, updateMockMethod.getStatus()); Assert.assertEquals("http://castlemock.com/v1", deleteMockMethod.getForwardedEndpoint()); Assert.assertEquals(HttpMethod.DELETE, deleteMockMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, deleteMockMethod.getStatus());
Assert.assertNull(restMethod.getResourceId()); Assert.assertNull(restMethod.getInvokeAddress()); Assert.assertNull(restMethod.getForwardedEndpoint()); Assert.assertNull(restMethod.getDefaultBody());