use of javax.ws.rs.core.HttpHeaders in project OpenAM by OpenRock.
the class RestAuthCallbackHandlerManagerTest method shouldHandleCallbacksInternally.
@Test
public void shouldHandleCallbacksInternally() throws RestAuthResponseException, RestAuthException {
//Given
HttpHeaders headers = mock(HttpHeaders.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
Callback callback1 = mock(Callback.class);
Callback callback2 = mock(Callback.class);
Callback[] callbacks = new Callback[] { callback1, callback2 };
RestAuthCallbackHandler restAuthCallbackHandler1 = mock(RestAuthCallbackHandler.class);
RestAuthCallbackHandler restAuthCallbackHandler2 = mock(RestAuthCallbackHandler.class);
given(restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(Matchers.<Class<? extends Callback>>anyObject())).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2);
given(restAuthCallbackHandler1.updateCallbackFromRequest(request, response, callback1)).willReturn(true);
given(restAuthCallbackHandler2.updateCallbackFromRequest(request, response, callback2)).willReturn(true);
//When
JsonValue jsonCallbacks = restAuthCallbackHandlerManager.handleCallbacks(request, response, callbacks);
//Then
verify(restAuthCallbackHandler1).updateCallbackFromRequest(request, response, callback1);
verify(restAuthCallbackHandler2).updateCallbackFromRequest(request, response, callback2);
verify(restAuthCallbackHandler1, never()).convertToJson(callback1, 1);
verify(restAuthCallbackHandler2, never()).convertToJson(callback2, 2);
assertEquals(jsonCallbacks.size(), 0);
}
use of javax.ws.rs.core.HttpHeaders in project ddf by codice.
the class TestRestEndpoint method testAddDocumentWithMetadataPositiveCase.
@Test
public void testAddDocumentWithMetadataPositiveCase() throws IOException, CatalogTransformerException, IngestException, SourceUnavailableException, URISyntaxException, InvalidSyntaxException, MimeTypeResolutionException {
CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
HttpHeaders headers = createHeaders(Arrays.asList(MediaType.APPLICATION_JSON));
BundleContext bundleContext = mock(BundleContext.class);
Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>();
ServiceReference serviceReference = mock(ServiceReference.class);
InputTransformer inputTransformer = mock(InputTransformer.class);
when(inputTransformer.transform(any())).thenReturn(new MetacardImpl());
when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer);
serviceReferences.add(serviceReference);
when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences);
RESTEndpoint rest = new RESTEndpoint(framework) {
@Override
BundleContext getBundleContext() {
return bundleContext;
}
};
UuidGenerator uuidGenerator = mock(UuidGenerator.class);
when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
rest.setUuidGenerator(uuidGenerator);
rest.setMetacardTypes(Collections.singletonList(BasicTypes.BASIC_METACARD));
MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
when(mimeTypeMapper.getMimeTypeForFileExtension("txt")).thenReturn("text/plain");
when(mimeTypeMapper.getMimeTypeForFileExtension("xml")).thenReturn("text/xml");
rest.setMimeTypeMapper(mimeTypeMapper);
addMatchingService(rest, Arrays.asList(getSimpleTransformer()));
UriInfo info = givenUriInfo(SAMPLE_ID);
List<Attachment> attachments = new ArrayList<>();
ContentDisposition contentDisposition = new ContentDisposition("form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt");
Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()), contentDisposition);
attachments.add(attachment);
ContentDisposition contentDisposition1 = new ContentDisposition("form-data; name=parse.metadata; filename=C:\\DDF\\metacard.xml");
Attachment attachment1 = new Attachment("parse.metadata", new ByteArrayInputStream("Some Text Again".getBytes()), contentDisposition1);
attachments.add(attachment1);
ContentDisposition contentDisposition2 = new ContentDisposition("form-data; name=metadata; filename=C:\\DDF\\metacard.xml");
Attachment attachment2 = new Attachment("metadata", new ByteArrayInputStream("<meta>beta</meta>".getBytes()), contentDisposition2);
attachments.add(attachment2);
MultipartBody multipartBody = new MultipartBody(attachments);
Response response = rest.addDocument(headers, info, mock(HttpServletRequest.class), multipartBody, null, new ByteArrayInputStream("".getBytes()));
LOGGER.debug(ToStringBuilder.reflectionToString(response));
assertThat(response.getStatus(), equalTo(201));
assertThat(response.getMetadata(), notNullValue());
assertThat(response.getMetadata().get(Metacard.ID).get(0).toString(), equalTo(SAMPLE_ID));
}
use of javax.ws.rs.core.HttpHeaders in project ddf by codice.
the class TestRestEndpoint method testAddDocumentPositiveCase.
@Test
public void testAddDocumentPositiveCase() throws IOException, CatalogTransformerException, IngestException, SourceUnavailableException, URISyntaxException {
CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
HttpHeaders headers = createHeaders(Arrays.asList(MediaType.APPLICATION_JSON));
RESTEndpoint rest = new RESTEndpoint(framework);
addMatchingService(rest, Arrays.asList(getSimpleTransformer()));
UriInfo info = givenUriInfo(SAMPLE_ID);
Response response = rest.addDocument(headers, info, mock(HttpServletRequest.class), mock(MultipartBody.class), null, new ByteArrayInputStream("".getBytes()));
LOGGER.debug(ToStringBuilder.reflectionToString(response));
assertThat(response.getStatus(), equalTo(201));
assertThat(response.getMetadata(), notNullValue());
assertThat(response.getMetadata().get(Metacard.ID).get(0).toString(), equalTo(SAMPLE_ID));
}
use of javax.ws.rs.core.HttpHeaders in project microservice_framework by CJSCommonPlatform.
the class RestAdapterGenerator_GETMethodBodyTest method shouldPassHttpHeadersToRestProcessor.
@SuppressWarnings("unchecked")
@Test
public void shouldPassHttpHeadersToRestProcessor() throws Exception {
generator.run(restRamlWithQueryApiDefaults().with(resource("/path").with(httpActionWithDefaultMapping(GET).withDefaultResponseType())).build(), configurationWithBasePackage(BASE_PACKAGE, outputFolder, new CommonGeneratorProperties()));
final Class<?> resourceClass = compiler.compiledClassOf(BASE_PACKAGE, "resource", "DefaultQueryApiPathResource");
final Object resourceObject = getInstanceOf(resourceClass);
final HttpHeaders headers = new ThreadLocalHttpHeaders();
setField(resourceObject, "headers", headers);
final Method method = firstMethodOf(resourceClass).get();
method.invoke(resourceObject);
verify(restProcessor).process(anyString(), any(Function.class), anyString(), eq(headers), any(Collection.class));
}
use of javax.ws.rs.core.HttpHeaders in project microservice_framework by CJSCommonPlatform.
the class DefaultRestProcessor method process.
private Response process(final String responseStrategyName, final Function<InterceptorContext, Optional<JsonEnvelope>> interceptorChain, final String action, final Optional<JsonObject> initialPayload, final HttpHeaders headers, final Collection<Parameter> params, final Optional<List<FileInputDetails>> fileInputDetails) {
traceLogger.trace(logger, () -> format("Processing REST message: %s", httpTraceLoggerHelper.toHttpHeaderTrace(headers)));
final JsonEnvelope envelope = envelopeBuilderFactory.builder().withInitialPayload(initialPayload).withAction(action).withHeaders(headers).withParams(params).build();
traceLogger.trace(logger, () -> format("REST message converted to envelope: %s", envelope));
final InterceptorContext interceptorContext = fileInputDetails.map(value -> fileBasedInterceptorContextFactory.create(value, envelope)).orElseGet(() -> interceptorContextWithInput(envelope));
final Optional<JsonEnvelope> result = interceptorChain.apply(interceptorContext);
traceLogger.trace(logger, () -> format("REST message processed: %s", envelope));
return responseStrategyCache.responseStrategyOf(responseStrategyName).responseFor(action, result);
}
Aggregations