public static RestParameterQuery generateRestParameterQuery(){ final RestParameterQuery parameterQuery = new RestParameterQuery(); parameterQuery.setParameter("Parameter"); parameterQuery.setQuery("Query"); parameterQuery.setMatchAny(false); parameterQuery.setMatchCase(false); parameterQuery.setMatchRegex(false); return parameterQuery; } }
/** * The method generates a default response. * @return The newly generated {@link RestMockResponse}. */ protected RestMockResponse generateResponse(){ RestMockResponse restMockResponse = new RestMockResponse(); restMockResponse.setName(AUTO_GENERATED_MOCK_RESPONSE_DEFAULT_NAME); restMockResponse.setHttpStatusCode(DEFAULT_RESPONSE_CODE); restMockResponse.setStatus(RestMockResponseStatus.ENABLED); restMockResponse.setUsingExpressions(true); return restMockResponse; }
/** * The method provides the functionality to convert an instance (parent) to an instance of a subclass to the * provided parent. * @param parent The parent that will be converted into a subtype of the provided parent * @return A new instance of the parent, but as a subtype of the parent */ @Override public RestProject convertType(Project parent) { return new RestProject(parent); }
final HttpMethod httpMethod, final boolean generatedResponse){ Assert.assertEquals(applicationName, restApplication.getName()); Assert.assertNull(restApplication.getId()); Assert.assertNull(restApplication.getProjectId()); Assert.assertEquals(1, restApplication.getResources().size()); RestResource restResource = restApplication.getResources().get(0); Assert.assertEquals(resourceName, restResource.getName()); Assert.assertEquals(resourceUri, restResource.getUri()); Assert.assertNull(restResource.getId()); Assert.assertNull(restResource.getApplicationId()); Assert.assertNull(restResource.getInvokeAddress()); Assert.assertEquals(1, restResource.getMethods().size()); RestMethod restMethod = restResource.getMethods().get(0); Assert.assertEquals(methodName, restMethod.getName()); Assert.assertEquals(httpMethod, restMethod.getHttpMethod()); Assert.assertEquals(RestMethodStatus.MOCKED, restMethod.getStatus()); Assert.assertEquals(RestResponseStrategy.RANDOM, restMethod.getResponseStrategy()); Assert.assertEquals(0, restMethod.getNetworkDelay()); Assert.assertFalse(restMethod.getSimulateNetworkDelay()); Assert.assertNull(restMethod.getId()); Assert.assertNull(restMethod.getResourceId()); Assert.assertNull(restMethod.getInvokeAddress()); Assert.assertNull(restMethod.getForwardedEndpoint()); Assert.assertNull(restMethod.getDefaultBody());
public static RestMockResponse generateRestMockResponse(){ final RestParameterQuery parameterQuery = new RestParameterQuery(); parameterQuery.setParameter("Parameter"); parameterQuery.setQuery("Query"); parameterQuery.setMatchAny(false); parameterQuery.setMatchCase(false); parameterQuery.setMatchRegex(false); final RestMockResponse restMockResponse = new RestMockResponse(); restMockResponse.setName("Rest mock response name"); restMockResponse.setBody("Rest mock response body"); restMockResponse.setId("REST MOCK RESPONSE"); restMockResponse.setStatus(RestMockResponseStatus.ENABLED); restMockResponse.setHttpStatusCode(200); restMockResponse.setParameterQueries(ImmutableList.of(parameterQuery)); return restMockResponse; } }
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; }
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; } }
public static RestProject generateRestProject(){ 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>()); return project; }
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; }
RestResource createRestResource(String applicationId, String uri) { RestResource restResource = new RestResource(); restResource.setApplicationId(applicationId); restResource.setUri(uri); return restResource; } }
public static RestApplication generateRestApplication(){ final RestApplication restApplication = new RestApplication(); restApplication.setId("REST APPLICATION"); restApplication.setName("Rest application name"); restApplication.setResources(new ArrayList<RestResource>()); return restApplication; }
private RestMockResponse createrestMockResponse(String name) { RestMockResponse dto = new RestMockResponse(); dto.setName(name); return dto; } }
private RestProject createRestProject(String name) { RestProject restProject = new RestProject(); restProject.setName(name); return restProject; } }
/** * Count the method statuses for {@link RestApplication} * @param restApplication The application which statuses will be counted * @return The result of the status count */ protected Map<RestMethodStatus, Integer> getRestMethodStatusCount(final RestApplication restApplication){ Preconditions.checkNotNull(restApplication, "The REST application cannot be null"); final Map<RestMethodStatus, Integer> statuses = new HashMap<RestMethodStatus, Integer>(); for(RestMethodStatus restMethodStatus : RestMethodStatus.values()){ statuses.put(restMethodStatus, 0); } final List<String> resourceIds = this.resourceRepository.findIdsWithApplicationId(restApplication.getId()); for(String resourceId : resourceIds){ final List<RestMethod> methods = this.methodRepository.findWithResourceId(resourceId); for(RestMethod restMethod : methods){ RestMethodStatus restMethodStatus = restMethod.getStatus(); statuses.put(restMethodStatus, statuses.get(restMethodStatus)+1); } } return statuses; }
private Optional<RestMockResponse> getDefaultMockResponse(final RestMethod restMethod, final List<RestMockResponse> mockResponses){ final String defaultResponseId = restMethod.getDefaultMockResponseId(); if(defaultResponseId != null && !defaultResponseId.isEmpty()){ LOGGER.info("Use the default response"); for (RestMockResponse tmpMockResponse : mockResponses) { if(defaultResponseId.equals(tmpMockResponse.getId())){ return Optional.of(tmpMockResponse); } } LOGGER.error("Unable to find the default response"); } return Optional.empty(); }
/** * Find a REST resource with a specific name for a REST application * @param name The name of the REST resource * @return A REST resource that matches the search criteria. Null otherwise. */ public RestResource findRestResource(List<RestResource> restResources, String name){ for(RestResource restResource : restResources){ if(restResource.getName().equals(name)){ return restResource; } } return null; }
/** * Find a REST application with a specific name for a rest project * @param name The name of the REST application * @return A REST application that matches the search criteria. Null otherwise. */ public RestApplication findRestApplication(List<RestApplication> restApplications, String name){ for(RestApplication restApplication : restApplications){ if(restApplication.getName().equals(name)){ return restApplication; } } return null; }
/** * Find a REST method with a specific name for a REST resource * @param name The name of the REST method * @return A REST method that matches the search criteria. Null otherwise. */ public RestMethod findRestMethod(List<RestMethod> restMethods, String name){ for(RestMethod restMethod : restMethods){ if(restMethod.getName().equals(name)){ return restMethod; } } return null; }
/** * Find a REST resource with a project id, application id and a set of resource parts * @param restProjectId The id of the project that the resource belongs to * @param restApplicationId The id of the application that the resource belongs to * @param otherRestResourceUriParts The set of resources that will be used to identify the REST resource * @return A REST resource that matches the search criteria. Null otherwise */ protected RestResource findRestResource(final String restProjectId, final String restApplicationId, final String[] otherRestResourceUriParts) { final List<RestResource> resources = this.resourceRepository.findWithApplicationId(restApplicationId); for(RestResource restResource : resources){ if(UrlUtility.compareUri(restResource.getUri(), otherRestResourceUriParts)){ return restResource; } } return null; }