use of ee.ria.xroad.common.metadata.MetadataRequests.ALLOWED_METHODS in project X-Road by nordic-institute.
the class MetadataServiceHandlerTest method shouldBeAbleToHandleAllowedMethodsMethods.
@Test
public void shouldBeAbleToHandleAllowedMethodsMethods() throws Exception {
// setup
MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, ALLOWED_METHODS);
InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> soapBody.addChildElement(ALLOWED_METHODS_REQUEST).addChildElement(REQUEST)).buildAsInputStream();
when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
// execution & verification
assertTrue("Wasn't able to handle allowed methods", handlerToTest.canHandle(serviceId, mockProxyMessage));
}
use of ee.ria.xroad.common.metadata.MetadataRequests.ALLOWED_METHODS in project X-Road by nordic-institute.
the class MetadataServiceHandlerTest method shouldHandleAllowedMethods.
@Test
public void shouldHandleAllowedMethods() 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, ALLOWED_METHODS);
ServerConf.reload(new TestSuiteServerConf() {
@Override
public List<ServiceId> getAllowedServicesByDescriptionType(ClientId serviceProvider, ClientId client, DescriptionType descriptionType) {
assertThat("Wrong client in query", client, is(expectedClient));
assertThat("Wrong service provider in query", serviceProvider, is(serviceId.getClientId()));
return expectedServices;
}
});
MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> soapBody.addChildElement(ALLOWED_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