/** * The method will add a new {@link RestMethod} and update an already existing {@link RestMethod}. * @param newRestMethod The new {@link RestMethod} that might be added to the final list of {@link RestMethod} (resultRestApplication). * @param existingRestMethods A list of existing {@link RestMethod} * @param resultRestMethods A list of the result of {@link RestMethod}. These will be the new {@link RestMethod}. * @since 1.10 */ private void updateRestMethod(final RestMethod newRestMethod, final List<RestMethod> existingRestMethods, final List<RestMethod> resultRestMethods) { final RestMethod existingRestMethod = findRestMethod(existingRestMethods, newRestMethod.getName()); // The new REST method does not exists. Add it to the resource if (existingRestMethod == null) { resultRestMethods.add(newRestMethod); return; } // THe REST method already exists. Update it. existingRestMethod.setHttpMethod(newRestMethod.getHttpMethod()); resultRestMethods.add(existingRestMethod); }
restMethod.setHttpMethod(HttpMethod.valueOf(methodType)); restMethod.setStatus(RestMethodStatus.MOCKED); restMethod.setResponseStrategy(RestResponseStrategy.RANDOM);
public static RestMethod generateRestMethod(){ final RestMethod restMethod = new RestMethod(); restMethod.setId("REST METHOD"); restMethod.setName("REST method name"); restMethod.setForwardedEndpoint("Forward endpoint"); restMethod.setDefaultBody("Default body"); restMethod.setCurrentResponseSequenceIndex(1); restMethod.setStatus(RestMethodStatus.MOCKED); restMethod.setHttpMethod(HttpMethod.GET); restMethod.setMockResponses(new ArrayList<RestMockResponse>()); restMethod.setResponseStrategy(RestResponseStrategy.RANDOM); return restMethod; } }
restMethod.setStatus(RestMethodStatus.MOCKED); restMethod.setResponseStrategy(RestResponseStrategy.RANDOM); restMethod.setHttpMethod(httpMethod);
@Test(expected = IllegalArgumentException.class) public void testProcessResourceNotFound(){ RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.POST); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.GET); RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.PUT); restResource1.getMethods().add(restMethod1); restResource1.getMethods().add(restMethod2); restResource1.getMethods().add(restMethod3); Mockito.when(resourceRepository.findWithApplicationId("RestApplicationId")).thenReturn(Arrays.asList(restResource1)); Mockito.when(methodRepository.findWithResourceId(restResource1.getId())).thenReturn(Arrays.asList(restMethod1, restMethod2, restMethod3)); Mockito.when(mockResponseRepository.findWithMethodId(Mockito.anyString())).thenReturn(new ArrayList<>()); IdentifyRestMethodInput input1 = IdentifyRestMethodInput.builder() .restProjectId("RestProjectId") .restApplicationId("RestApplicationId") .restResourceUri("/random") .httpMethod(HttpMethod.GET) .build(); ServiceTask<IdentifyRestMethodInput> serviceTask1 = new ServiceTask<IdentifyRestMethodInput>(input1); service.process(serviceTask1); }
restMethod.setStatus(RestMethodStatus.MOCKED); restMethod.setResponseStrategy(RestResponseStrategy.RANDOM); restMethod.setHttpMethod(httpMethod);
restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.POST); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.GET); RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.PUT); restResource1.getMethods().add(restMethod1); restResource1.getMethods().add(restMethod2); restResource2.setUri("/user/resource"); RestMethod restMethod4 = RestMethodGenerator.generateRestMethod(); restMethod4.setHttpMethod(HttpMethod.POST); RestMethod restMethod5 = RestMethodGenerator.generateRestMethod(); restMethod5.setHttpMethod(HttpMethod.GET); restResource2.getMethods().add(restMethod4); restResource2.getMethods().add(restMethod5);
restMethod.setHttpMethod(httpMethod); restMethod.setName(methodName); restMethod.setStatus(RestMethodStatus.MOCKED);
restResource1.setUri("/user/{test}"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.GET); restResource2.setUri("/user/{test}/resource"); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.POST);
restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.POST); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.GET); RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.PUT); restResource1.getMethods().add(restMethod1); restResource1.getMethods().add(restMethod2); restResource2.setUri("/user/resource"); RestMethod restMethod4 = RestMethodGenerator.generateRestMethod(); restMethod4.setHttpMethod(HttpMethod.POST); RestMethod restMethod5 = RestMethodGenerator.generateRestMethod(); restMethod5.setHttpMethod(HttpMethod.GET); restResource2.getMethods().add(restMethod4); restResource2.getMethods().add(restMethod5);
restResource1.setUri("/user/{variable}.json"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.GET); restResource2.setUri("/user/id.{type}"); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.GET); restResource3.setUri("/resource/{id}...{type}"); RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.GET);
restMethod.setCurrentResponseSequenceIndex(0); restMethod.setForwardedEndpoint(FORWARD_ENDPOINT); restMethod.setHttpMethod(HttpMethod.GET); restMethod.setId(METHOD_ID); restMethod.setInvokeAddress("http://localhost:8080" + CONTEXT + SLASH + MOCK + SLASH + REST + SLASH +
/** * 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()); } }
restMethod.setName(methodV1.getName()); restMethod.setId(methodV1.getId()); restMethod.setHttpMethod(methodV1.getHttpMethod()); restMethod.setForwardedEndpoint(methodV1.getForwardedEndpoint()); restMethod.setDefaultBody(methodV1.getDefaultBody());
restMethod.setCurrentResponseSequenceIndex(0); restMethod.setForwardedEndpoint(FORWARD_ENDPOINT); restMethod.setHttpMethod(HttpMethod.GET); restMethod.setId(METHOD_ID); restMethod.setInvokeAddress("http://localhost:8080" + CONTEXT + SLASH + MOCK + SLASH + REST + SLASH +