public static RestResource generateRestResource(){ final RestResource restResource = new RestResource(); restResource.setId("REST Resource"); restResource.setName("Rest resource name"); restResource.setMethods(new ArrayList<RestMethod>()); restResource.setUri("URI"); return restResource; }
@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); }
@Test(expected = IllegalArgumentException.class) public void testProcessMethodNotFound(){ RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restResource2.setId("Resource2"); restResource2.setUri("/user/resource"); RestMethod restMethod4 = RestMethodGenerator.generateRestMethod();
@Test public void testVariableProcess1(){ RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user/{test}"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restResource2.setId("Resource2"); restResource2.setUri("/user/{test}/resource"); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod();
@Test public void testVariableProcess2(){ RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user/{variable}.json"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restResource2.setId("Resource2"); restResource2.setUri("/user/id.{type}"); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restResource3.setId("Resource3"); restResource3.setUri("/resource/{id}...{type}"); RestMethod restMethod3 = RestMethodGenerator.generateRestMethod();
@Test public void testProcess(){ RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restResource2.setId("Resource2"); restResource2.setUri("/user/resource"); RestMethod restMethod4 = RestMethodGenerator.generateRestMethod();
resource.setUri(restResourceV1.getUri()); resource.setName(restResourceV1.getName()); resource.setId(restResourceV1.getId()); resource.setApplicationId(application.getId()); application.getResources().add(resource);