use of ee.ria.xroad.proxy.util.MetaserviceTestUtil.LIST_METHODS_REQUEST in project X-Road by nordic-institute.
the class MetadataServiceHandlerTest method shouldBeAbleToHandleListMethods.
@Test
public void shouldBeAbleToHandleListMethods() throws Exception {
// setup
MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, LIST_METHODS);
InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> soapBody.addChildElement(LIST_METHODS_REQUEST).addChildElement(REQUEST)).buildAsInputStream();
when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
// execution & verification
assertTrue("Wasn't able to handle list methods", handlerToTest.canHandle(serviceId, mockProxyMessage));
}
use of ee.ria.xroad.proxy.util.MetaserviceTestUtil.LIST_METHODS_REQUEST in project X-Road by nordic-institute.
the class MetadataServiceHandlerTest method shouldHandleListMethods.
@Test
public void shouldHandleListMethods() throws Exception {
// setup
List<ServiceId> expectedServices = Arrays.asList(ServiceId.create(DEFAULT_CLIENT, "getNumber"), ServiceId.create(DEFAULT_CLIENT, "helloThere"), ServiceId.create(DEFAULT_CLIENT, "putThings"));
final ClientId expectedClient = DEFAULT_CLIENT;
final ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, LIST_METHODS);
ServerConf.reload(new TestSuiteServerConf() {
@Override
public List<ServiceId> getServicesByDescriptionType(ClientId serviceProvider, DescriptionType descriptionType) {
assertThat("Client id does not match expected", serviceProvider, is(expectedClient));
return expectedServices;
}
});
MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> soapBody.addChildElement(LIST_METHODS_REQUEST).addChildElement(REQUEST)).buildAsInputStream();
when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
handlerToTest.canHandle(serviceId, mockProxyMessage);
// execution
handlerToTest.startHandling(mockRequest, mockProxyMessage, httpClientMock, mock(OpMonitoringData.class));
// verification
assertThat("Content type does not match", handlerToTest.getResponseContentType(), is(TEXT_XML_UTF8));
final SOAPMessage message = messageFactory.createMessage(null, handlerToTest.getResponseContent());
final SoapHeader xrHeader = unmarshaller.unmarshal(message.getSOAPHeader(), SoapHeader.class).getValue();
List<ServiceId> resultServices = verifyAndGetSingleBodyElementOfType(message.getSOAPBody(), MethodListType.class).getService();
assertThat("Response client does not match", xrHeader.getClient(), is(expectedClient));
assertThat("Response client does not match", xrHeader.getService(), is(serviceId));
assertThat("Wrong amount of services", resultServices.size(), is(expectedServices.size()));
assertThat("Wrong services", resultServices, containsInAnyOrder(expectedServices.toArray()));
}
Aggregations