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 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<ReadRestResourceQueryParametersOutput> process( final ServiceTask<ReadRestResourceQueryParametersInput> serviceTask) { final ReadRestResourceQueryParametersInput input = serviceTask.getInput(); final RestResource resource = super.resourceRepository.findOne(input.getResourceId()); final Set<String> pathParameters = UrlUtility.getPathParameters(resource.getUri()); final Set<RestParameterQuery> parameterQueries = pathParameters.stream() .map(pathParameter -> { RestParameterQuery query = new RestParameterQuery(); query.setQuery(pathParameter); return query; }) .collect(Collectors.toSet()); return createServiceResult(ReadRestResourceQueryParametersOutput.builder() .queries(parameterQueries) .build()); } }
@Test public void canValidateMatch(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("userId"); parameterQuery1.setQuery("123"); final RestParameterQuery parameterQuery2 = new RestParameterQuery(); parameterQuery2.setParameter("country"); parameterQuery2.setQuery("SE"); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1, parameterQuery2); final Map<String, String> pathParameters = ImmutableMap.of("userId", "123", "country", "SE"); final boolean result = RestParameterQueryValidator.validate(parameterQueries, pathParameters); assertTrue(result); }
@Test public void canValidateNoMatch(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("userId"); parameterQuery1.setQuery("345"); final RestParameterQuery parameterQuery2 = new RestParameterQuery(); parameterQuery2.setParameter("country"); parameterQuery2.setQuery("SE"); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1, parameterQuery2); final Map<String, String> pathParameters = ImmutableMap.of("userId", "123", "country", "SE"); final boolean result = RestParameterQueryValidator.validate(parameterQueries, pathParameters); assertFalse(result); }
@Test public void canValidateMissing(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("userId"); parameterQuery1.setQuery("123"); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1); final Map<String, String> pathParameters = ImmutableMap.of("userId", "123", "country", "SE"); final boolean result = RestParameterQueryValidator.validate(parameterQueries, pathParameters); assertFalse(result); }
@Test public void canValidateNotMatchCase(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("username"); parameterQuery1.setQuery("karl"); parameterQuery1.setMatchCase(false); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1); final Map<String, String> pathParameters = ImmutableMap.of("username", "kArL"); final boolean result = RestParameterQueryValidator.validate(parameterQueries, pathParameters); assertTrue(result); }
@Test public void canValidateMultiple(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("userId"); parameterQuery1.setQuery("123"); final RestParameterQuery parameterQuery2 = new RestParameterQuery(); parameterQuery2.setParameter("country"); parameterQuery2.setQuery("SE"); final RestParameterQuery parameterQuery3 = new RestParameterQuery(); parameterQuery3.setParameter("country"); parameterQuery3.setQuery("NO"); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1, parameterQuery2, parameterQuery3); final Map<String, String> pathParameters = ImmutableMap.of("userId", "123", "country", "SE"); final boolean result = RestParameterQueryValidator.validate(parameterQueries, pathParameters); assertTrue(result); }
@Test public void canValidateMatchCase(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("username"); parameterQuery1.setQuery("karl"); parameterQuery1.setMatchCase(true); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1); final Map<String, String> pathParameters = ImmutableMap.of("username", "kArL"); final boolean result = RestParameterQueryValidator.validate(parameterQueries, pathParameters); assertFalse(result); }
@Test public void canValidateMatchReqexCaseSensetive(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("username"); parameterQuery1.setQuery("a*b"); parameterQuery1.setMatchRegex(true); parameterQuery1.setMatchCase(true); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1); assertTrue(RestParameterQueryValidator.validate(parameterQueries, ImmutableMap.of("username", "aaaaab"))); assertFalse(RestParameterQueryValidator.validate(parameterQueries, ImmutableMap.of("username", "AAAAB"))); }
@Test public void canValidateMatchReqexIgnoreCase(){ final RestParameterQuery parameterQuery1 = new RestParameterQuery(); parameterQuery1.setParameter("username"); parameterQuery1.setQuery("a*b"); parameterQuery1.setMatchRegex(true); parameterQuery1.setMatchCase(false); final List<RestParameterQuery> parameterQueries = ImmutableList.of(parameterQuery1); assertTrue(RestParameterQueryValidator.validate(parameterQueries, ImmutableMap.of("username", "aaaaab"))); assertTrue(RestParameterQueryValidator.validate(parameterQueries, ImmutableMap.of("username", "AAAAB"))); }
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; } }
parameterQuery.setQuery("Value"); parameterQuery.setMatchAny(false); parameterQuery.setMatchCase(false);