use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.
the class RestMetadataServiceHandlerTest method shouldHandleListMethods.
@Test
public void shouldHandleListMethods() throws Exception {
RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, LIST_METHODS);
RestRequest mockRestRequest = mock(RestRequest.class);
when(mockRestRequest.getServiceId()).thenReturn(serviceId);
when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
when(mockRestRequest.getClientId()).thenReturn(DEFAULT_CLIENT);
when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
RestResponse restResponse = handlerToTest.getRestResponse();
assertEquals(HttpStatus.SC_OK, restResponse.getResponseCode());
assertEquals("OK", restResponse.getReason());
CachingStream restResponseBody = handlerToTest.getRestResponseBody();
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RestServiceDetailsListType restServiceDetailsList = MAPPER.readValue(restResponseBody.getCachedContents(), RestServiceDetailsListType.class);
assertEquals(3, restServiceDetailsList.getService().size());
assertEquals(1, restServiceDetailsList.getService().get(0).getEndpointList().size());
}
use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.
the class RestMetadataServiceHandlerTest method shouldDetectUnsupportedOpenapiVersion.
@Test(expected = CodedException.class)
public void shouldDetectUnsupportedOpenapiVersion() throws Exception {
RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
// Test for petstore.yaml parsing
ServiceId serviceId = ServiceId.create(CLIENT_WITH_UNSUPPORTED_OPENAPI, GET_OPENAPI);
RestRequest mockRestRequest = mock(RestRequest.class);
when(mockRestRequest.getQuery()).thenReturn("serviceCode=yaml");
when(mockRestRequest.getServiceId()).thenReturn(serviceId);
when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
when(mockRestRequest.getClientId()).thenReturn(CLIENT_WITH_UNSUPPORTED_OPENAPI);
when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
}
use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.
the class RestMetadataServiceHandlerTest method shouldHandleAllowedMethods.
@Test
public void shouldHandleAllowedMethods() throws Exception {
RestMetadataServiceHandlerImpl handlerToTest = new RestMetadataServiceHandlerImpl();
ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, ALLOWED_METHODS);
RestRequest mockRestRequest = mock(RestRequest.class);
when(mockRestRequest.getServiceId()).thenReturn(serviceId);
when(mockRestRequest.getVerb()).thenReturn(RestRequest.Verb.GET);
when(mockRestRequest.getClientId()).thenReturn(DEFAULT_CLIENT);
when(mockRestRequest.getHash()).thenReturn(REQUEST_HASH);
when(mockProxyMessage.getRest()).thenReturn(mockRestRequest);
ProxyMessageDecoder mockDecoder = mock(ProxyMessageDecoder.class);
ProxyMessageEncoder mockEncoder = mock(ProxyMessageEncoder.class);
handlerToTest.startHandling(mockRequest, mockProxyMessage, mockDecoder, mockEncoder, httpClientMock, httpClientMock, mock(OpMonitoringData.class));
RestResponse restResponse = handlerToTest.getRestResponse();
assertEquals(HttpStatus.SC_OK, restResponse.getResponseCode());
assertEquals("OK", restResponse.getReason());
CachingStream restResponseBody = handlerToTest.getRestResponseBody();
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RestServiceDetailsListType restServiceDetailsList = MAPPER.readValue(restResponseBody.getCachedContents(), RestServiceDetailsListType.class);
assertEquals(3, restServiceDetailsList.getService().size());
assertEquals(1, restServiceDetailsList.getService().get(0).getEndpointList().size());
}
use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.
the class ServerMessageProcessor method preprocess.
@Override
protected void preprocess() throws Exception {
encoder = new ProxyMessageEncoder(servletResponse.getOutputStream(), SoapUtils.getHashAlgoId());
servletResponse.setContentType(encoder.getContentType());
servletResponse.addHeader(HEADER_HASH_ALGO_ID, SoapUtils.getHashAlgoId());
}
use of ee.ria.xroad.proxy.protocol.ProxyMessageEncoder in project X-Road by nordic-institute.
the class ServerRestMessageProcessor method preprocess.
@Override
protected void preprocess() throws Exception {
encoder = new ProxyMessageEncoder(servletResponse.getOutputStream(), CryptoUtils.DEFAULT_DIGEST_ALGORITHM_ID);
servletResponse.setContentType(encoder.getContentType());
servletResponse.addHeader(HEADER_HASH_ALGO_ID, SoapUtils.getHashAlgoId());
}
Aggregations