use of javax.ws.rs.core.HttpHeaders in project graylog2-server by Graylog2.
the class RestToolsTest method buildEndpointUriReturnsHeaderValueIfHeaderIsPresent.
@Test
public void buildEndpointUriReturnsHeaderValueIfHeaderIsPresent() throws Exception {
final HttpHeaders httpHeaders = mock(javax.ws.rs.core.HttpHeaders.class);
when(httpHeaders.getRequestHeader(anyString())).thenReturn(ImmutableList.of("http://header.example.com"));
final URI endpointUri = URI.create("http://graylog.example.com");
assertThat(RestTools.buildEndpointUri(httpHeaders, endpointUri)).isEqualTo("http://header.example.com");
}
use of javax.ws.rs.core.HttpHeaders in project graylog2-server by Graylog2.
the class RestToolsTest method buildEndpointUriReturnsDefaultUriIfHeaderIsMissing.
@Test
public void buildEndpointUriReturnsDefaultUriIfHeaderIsMissing() throws Exception {
final HttpHeaders httpHeaders = mock(HttpHeaders.class);
when(httpHeaders.getRequestHeader(anyString())).thenReturn(ImmutableList.of());
final URI endpointUri = URI.create("http://graylog.example.com");
assertThat(RestTools.buildEndpointUri(httpHeaders, endpointUri)).isEqualTo(endpointUri.toString());
}
use of javax.ws.rs.core.HttpHeaders in project graylog2-server by Graylog2.
the class RestToolsTest method buildEndpointUriReturnsDefaultUriIfHeaderIsEmpty.
@Test
public void buildEndpointUriReturnsDefaultUriIfHeaderIsEmpty() throws Exception {
final HttpHeaders httpHeaders = mock(HttpHeaders.class);
when(httpHeaders.getRequestHeader(anyString())).thenReturn(ImmutableList.of(""));
final URI endpointUri = URI.create("http://graylog.example.com");
assertThat(RestTools.buildEndpointUri(httpHeaders, endpointUri)).isEqualTo(endpointUri.toString());
}
use of javax.ws.rs.core.HttpHeaders in project OpenAM by OpenRock.
the class RestAuthCallbackHandlerManagerTest method shouldHandleCallbacksIntoJsonIfAtLeastOneCannotBeDoneInternally.
@Test
public void shouldHandleCallbacksIntoJsonIfAtLeastOneCannotBeDoneInternally() 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);
JsonValue jsonCallback1 = new JsonValue(new LinkedHashMap<String, String>());
jsonCallback1.put("KEY1", "VALUE1");
JsonValue jsonCallback2 = new JsonValue(new LinkedHashMap<String, String>());
jsonCallback2.put("KEY2", "VALUE2");
given(restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(Matchers.<Class<? extends Callback>>anyObject())).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2);
given(restAuthCallbackHandler1.updateCallbackFromRequest(request, response, callback1)).willReturn(true);
given(restAuthCallbackHandler2.updateCallbackFromRequest(request, response, callback2)).willReturn(false);
given(restAuthCallbackHandler1.convertToJson(callback1, 1)).willReturn(jsonCallback1);
given(restAuthCallbackHandler2.convertToJson(callback2, 2)).willReturn(jsonCallback2);
//When
JsonValue jsonCallbacks = restAuthCallbackHandlerManager.handleCallbacks(request, response, callbacks);
//Then
verify(restAuthCallbackHandler1).updateCallbackFromRequest(request, response, callback1);
verify(restAuthCallbackHandler2).updateCallbackFromRequest(request, response, callback2);
verify(restAuthCallbackHandler1).convertToJson(callback1, 1);
verify(restAuthCallbackHandler2).convertToJson(callback2, 2);
assertEquals(jsonCallbacks.size(), 2);
assertEquals(jsonCallbacks.get(0).get("KEY1").asString(), "VALUE1");
assertEquals(jsonCallbacks.get(1).get("KEY2").asString(), "VALUE2");
}
use of javax.ws.rs.core.HttpHeaders in project ddf by codice.
the class TestRestEndpoint method assertExceptionThrown.
protected void assertExceptionThrown(Class<? extends Throwable> klass) throws IngestException, SourceUnavailableException, URISyntaxException {
CatalogFramework framework = mock(CatalogFramework.class);
when(framework.create(isA(CreateRequest.class))).thenThrow(klass);
when(framework.create(isA(CreateStorageRequest.class))).thenThrow(klass);
HttpHeaders headers = createHeaders(Arrays.asList(MediaType.APPLICATION_JSON));
RESTEndpoint rest = new RESTEndpoint(framework);
addMatchingService(rest, Arrays.asList(getSimpleTransformer()));
UriInfo info = givenUriInfo(SAMPLE_ID);
try {
rest.addDocument(headers, info, mock(HttpServletRequest.class), mock(MultipartBody.class), null, new ByteArrayInputStream("".getBytes()));
fail();
} catch (ServerErrorException e) {
if (klass.getName().equals(SourceUnavailableException.class.getName())) {
assertThat(e.getResponse().getStatus(), equalTo(INTERNAL_SERVER_ERROR));
} else if (klass.getName().equals(IngestException.class.getName())) {
assertThat(e.getResponse().getStatus(), equalTo(BAD_REQUEST));
}
}
}
Aggregations