restResource.getMethods().add(restMethod);
/** * The method will add a new {@link RestResource} and update an already existing {@link RestResource}. * @param newRestResource The new {@link RestResource} that might be added to the final list of {@link RestResource} (resultRestApplication). * @param existingRestResources A list of existing {@link RestResource} * @param resultRestResources A list of the result of {@link RestResource}. These will be the new {@link RestResource}. * @since 1.10 */ private void updateRestResource(final RestResource newRestResource, final List<RestResource> existingRestResources, final List<RestResource> resultRestResources){ // Check if the new REST resource already exists final RestResource existingRestResource = findRestResource(existingRestResources, newRestResource.getName()); // It doesn't exists. Simply add it to the existing application if (existingRestResource == null) { resultRestResources.add(newRestResource); return; } // Update resource existingRestResource.setUri(newRestResource.getUri()); final List<RestMethod> existingRestMethods = this.methodRepository.findWithResourceId(existingRestResource.getId()); final List<RestMethod> resultRestMethods = new ArrayList<RestMethod>(); for(RestMethod newRestMethod : newRestResource.getMethods()){ updateRestMethod(newRestMethod, existingRestMethods, resultRestMethods); } resultRestResources.add(existingRestResource); newRestResource.setMethods(resultRestMethods); }
public static RestProject generateFullRestProject(){ final RestProject project = new RestProject(); project.setId("REST PROJECT"); project.setName("Project name"); project.setDescription("Project description"); project.setCreated(new Date()); project.setUpdated(new Date()); project.setApplications(new ArrayList<RestApplication>()); for(int applicationIndex = 0; applicationIndex < 3; applicationIndex++){ final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); restApplication.setResources(new ArrayList<RestResource>()); project.getApplications().add(restApplication); for(int resourceIndex = 0; resourceIndex < 3; resourceIndex++){ final RestResource restResource = RestResourceGenerator.generateRestResource(); restResource.setMethods(new ArrayList<RestMethod>()); restApplication.getResources().add(restResource); for(int methodIndex = 0; methodIndex < 3; methodIndex++){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); restMethod.setMockResponses(new ArrayList<RestMockResponse>()); restResource.getMethods().add(restMethod); for(int responseIndex = 0; responseIndex < 3; responseIndex++){ final RestMockResponse restMockResponse = RestMockResponseGenerator.generateRestMockResponse(); restMethod.getMockResponses().add(restMockResponse); } } } } return project; }
Operation operation = resourcePath.getGet(); RestMethod restMethod = createRestMethod(operation, definitions, HttpMethod.GET, forwardAddress, generateResponse); restResource.getMethods().add(restMethod); restResource.getMethods().add(restMethod); restResource.getMethods().add(restMethod); restResource.getMethods().add(restMethod); restResource.getMethods().add(restMethod); restResource.getMethods().add(restMethod);
restResource.getMethods().add(restMethod);
@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); }
restResource.getMethods().add(restMethod);
RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.PUT); restResource1.getMethods().add(restMethod1); restResource1.getMethods().add(restMethod2); restResource1.getMethods().add(restMethod3); RestMethod restMethod5 = RestMethodGenerator.generateRestMethod(); restMethod5.setHttpMethod(HttpMethod.GET); restResource2.getMethods().add(restMethod4); restResource2.getMethods().add(restMethod5);
for (RestMethod method : resource.getMethods()) { if(this.methodRepository.exists(method.getId())){ throw new IllegalArgumentException("A method with the following key already exists: " + method.getId());
RestResource savedResource = this.resourceRepository.save(restResource); for(RestMethod method : restResource.getMethods()){ method.setResourceId(savedResource.getId());
RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.PUT); restResource1.getMethods().add(restMethod1); restResource1.getMethods().add(restMethod2); restResource1.getMethods().add(restMethod3); RestMethod restMethod5 = RestMethodGenerator.generateRestMethod(); restMethod5.setHttpMethod(HttpMethod.GET); restResource2.getMethods().add(restMethod4); restResource2.getMethods().add(restMethod5);
restMethod.setCurrentResponseSequenceIndex(methodV1.getCurrentResponseSequenceIndex()); restMethod.setResourceId(resource.getId()); resource.getMethods().add(restMethod);
Assert.assertEquals(1, restResource.getMethods().size()); RestMethod restMethod = restResource.getMethods().get(0); Assert.assertEquals(methodName, restMethod.getName()); Assert.assertEquals(httpMethod, restMethod.getHttpMethod());
RestMethod getAllMockServicesMethod = mockResource.getMethods().stream() .filter(method -> method.getName().equals("getAllMockServices")) .findFirst() RestMethod createMockMethod = mockResource.getMethods().stream() .filter(method -> method.getName().equals("createMock")) .findFirst() RestMethod headMockMethod = mockResource.getMethods().stream() .filter(method -> method.getName().equals("headMock")) .findFirst() RestMethod optionsMockMethod = mockResource.getMethods().stream() .filter(method -> method.getName().equals("optionsMock")) .findFirst() RestMethod getMockByIdMethod = mockWithParameterResource.getMethods().stream() .filter(method -> method.getName().equals("Get mock by mock id")) .findFirst() RestMethod updateMockMethod = mockWithParameterResource.getMethods().stream() .filter(method -> method.getName().equals("updateMock")) .findFirst() RestMethod deleteMockMethod = mockWithParameterResource.getMethods().stream() .filter(method -> method.getName().equals("deleteMock")) .findFirst()