Search in sources :

Example 1 with ALLOWED_METHODS

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));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) XMLUnit(org.custommonkey.xmlunit.XMLUnit) Arrays(java.util.Arrays) ServiceDescriptionType(ee.ria.xroad.common.conf.serverconf.model.ServiceDescriptionType) MetaserviceTestUtil(ee.ria.xroad.proxy.util.MetaserviceTestUtil) SOAPException(javax.xml.soap.SOAPException) URISyntaxException(java.net.URISyntaxException) MethodListType(ee.ria.xroad.common.metadata.MethodListType) MimeException(org.apache.james.mime4j.MimeException) ServiceType(ee.ria.xroad.common.conf.serverconf.model.ServiceType) GET_WSDL_REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.GET_WSDL_REQUEST) DescriptionType(ee.ria.xroad.common.conf.serverconf.model.DescriptionType) ServiceId(ee.ria.xroad.common.identifier.ServiceId) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Assert.assertThat(org.junit.Assert.assertThat) ByteArrayInputStream(java.io.ByteArrayInputStream) ALLOWED_METHODS(ee.ria.xroad.common.metadata.MetadataRequests.ALLOWED_METHODS) AbstractContentHandler(org.apache.james.mime4j.parser.AbstractContentHandler) After(org.junit.After) LIST_METHODS(ee.ria.xroad.common.metadata.MetadataRequests.LIST_METHODS) ClientType(ee.ria.xroad.common.conf.serverconf.model.ClientType) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) MimeStreamParser(org.apache.james.mime4j.parser.MimeStreamParser) CodedExceptionMatcher.faultCodeEquals(ee.ria.xroad.proxy.util.MetaserviceTestUtil.CodedExceptionMatcher.faultCodeEquals) Field(org.apache.james.mime4j.stream.Field) ProxyMessage(ee.ria.xroad.proxy.protocol.ProxyMessage) JAXBException(javax.xml.bind.JAXBException) TestSoapBuilder(ee.ria.xroad.proxy.util.MetaserviceTestUtil.TestSoapBuilder) StandardCharsets(java.nio.charset.StandardCharsets) SystemProperties(ee.ria.xroad.common.SystemProperties) KeyConf(ee.ria.xroad.proxy.conf.KeyConf) IOUtils(org.apache.commons.io.IOUtils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) X_UNKNOWN_SERVICE(ee.ria.xroad.common.ErrorCodes.X_UNKNOWN_SERVICE) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ProvideSystemProperty(org.junit.contrib.java.lang.system.ProvideSystemProperty) ServerConfDatabaseCtx.doInTransaction(ee.ria.xroad.common.conf.serverconf.ServerConfDatabaseCtx.doInTransaction) Matchers.containsString(org.hamcrest.Matchers.containsString) TestSuiteServerConf(ee.ria.xroad.proxy.testsuite.TestSuiteServerConf) ServerConfType(ee.ria.xroad.common.conf.serverconf.model.ServerConfType) Mockito.mock(org.mockito.Mockito.mock) ALLOWED_METHODS_REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.ALLOWED_METHODS_REQUEST) Getter(lombok.Getter) BeforeClass(org.junit.BeforeClass) ObjectFactory(ee.ria.xroad.common.metadata.ObjectFactory) WSDLReader(javax.wsdl.xml.WSDLReader) Marshaller(javax.xml.bind.Marshaller) MimeConfig(org.apache.james.mime4j.stream.MimeConfig) MetaserviceTestUtil.parseOperationNamesFromWSDLDefinition(ee.ria.xroad.proxy.util.MetaserviceTestUtil.parseOperationNamesFromWSDLDefinition) GlobalConf(ee.ria.xroad.common.conf.globalconf.GlobalConf) WireMock(com.github.tomakehurst.wiremock.client.WireMock) HttpServletRequest(javax.servlet.http.HttpServletRequest) WSDLFactory(javax.wsdl.factory.WSDLFactory) MessageFactory(javax.xml.soap.MessageFactory) HttpClient(org.apache.http.client.HttpClient) SoapHeader(ee.ria.xroad.common.message.SoapHeader) BodyDescriptor(org.apache.james.mime4j.stream.BodyDescriptor) ExpectedException(org.junit.rules.ExpectedException) JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) InputSource(org.xml.sax.InputSource) Unmarshaller(javax.xml.bind.Unmarshaller) X_INVALID_SERVICE_TYPE(ee.ria.xroad.common.ErrorCodes.X_INVALID_SERVICE_TYPE) Definition(javax.wsdl.Definition) TEXT_XML_UTF8(ee.ria.xroad.common.util.MimeTypes.TEXT_XML_UTF8) Files(java.nio.file.Files) REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.REQUEST) WsdlRequestData(ee.ria.xroad.proxy.common.WsdlRequestData) MetaserviceTestUtil.verifyAndGetSingleBodyElementOfType(ee.ria.xroad.proxy.util.MetaserviceTestUtil.verifyAndGetSingleBodyElementOfType) HttpServletResponse(javax.servlet.http.HttpServletResponse) WireMockConfiguration.options(com.github.tomakehurst.wiremock.core.WireMockConfiguration.options) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) LIST_METHODS_REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.LIST_METHODS_REQUEST) OpMonitoringData(ee.ria.xroad.common.opmonitoring.OpMonitoringData) WSDLException(javax.wsdl.WSDLException) CodedException(ee.ria.xroad.common.CodedException) MimeTypes(ee.ria.xroad.common.util.MimeTypes) Rule(org.junit.Rule) Paths(java.nio.file.Paths) ErrorCodes(ee.ria.xroad.common.ErrorCodes) GET_WSDL(ee.ria.xroad.common.metadata.MetadataRequests.GET_WSDL) HEADER_CONTENT_TYPE(ee.ria.xroad.common.util.MimeUtils.HEADER_CONTENT_TYPE) SOAPMessage(javax.xml.soap.SOAPMessage) ServerConf(ee.ria.xroad.common.conf.serverconf.ServerConf) ClientId(ee.ria.xroad.common.identifier.ClientId) TestSuiteKeyConf(ee.ria.xroad.proxy.testsuite.TestSuiteKeyConf) MetaserviceTestUtil.parseEndpointUrlsFromWSDLDefinition(ee.ria.xroad.proxy.util.MetaserviceTestUtil.parseEndpointUrlsFromWSDLDefinition) Diff(org.custommonkey.xmlunit.Diff) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestSoapBuilder(ee.ria.xroad.proxy.util.MetaserviceTestUtil.TestSoapBuilder) ServiceId(ee.ria.xroad.common.identifier.ServiceId) Test(org.junit.Test)

Example 2 with ALLOWED_METHODS

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()));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) XMLUnit(org.custommonkey.xmlunit.XMLUnit) Arrays(java.util.Arrays) ServiceDescriptionType(ee.ria.xroad.common.conf.serverconf.model.ServiceDescriptionType) MetaserviceTestUtil(ee.ria.xroad.proxy.util.MetaserviceTestUtil) SOAPException(javax.xml.soap.SOAPException) URISyntaxException(java.net.URISyntaxException) MethodListType(ee.ria.xroad.common.metadata.MethodListType) MimeException(org.apache.james.mime4j.MimeException) ServiceType(ee.ria.xroad.common.conf.serverconf.model.ServiceType) GET_WSDL_REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.GET_WSDL_REQUEST) DescriptionType(ee.ria.xroad.common.conf.serverconf.model.DescriptionType) ServiceId(ee.ria.xroad.common.identifier.ServiceId) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Assert.assertThat(org.junit.Assert.assertThat) ByteArrayInputStream(java.io.ByteArrayInputStream) ALLOWED_METHODS(ee.ria.xroad.common.metadata.MetadataRequests.ALLOWED_METHODS) AbstractContentHandler(org.apache.james.mime4j.parser.AbstractContentHandler) After(org.junit.After) LIST_METHODS(ee.ria.xroad.common.metadata.MetadataRequests.LIST_METHODS) ClientType(ee.ria.xroad.common.conf.serverconf.model.ClientType) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) MimeStreamParser(org.apache.james.mime4j.parser.MimeStreamParser) CodedExceptionMatcher.faultCodeEquals(ee.ria.xroad.proxy.util.MetaserviceTestUtil.CodedExceptionMatcher.faultCodeEquals) Field(org.apache.james.mime4j.stream.Field) ProxyMessage(ee.ria.xroad.proxy.protocol.ProxyMessage) JAXBException(javax.xml.bind.JAXBException) TestSoapBuilder(ee.ria.xroad.proxy.util.MetaserviceTestUtil.TestSoapBuilder) StandardCharsets(java.nio.charset.StandardCharsets) SystemProperties(ee.ria.xroad.common.SystemProperties) KeyConf(ee.ria.xroad.proxy.conf.KeyConf) IOUtils(org.apache.commons.io.IOUtils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) X_UNKNOWN_SERVICE(ee.ria.xroad.common.ErrorCodes.X_UNKNOWN_SERVICE) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ProvideSystemProperty(org.junit.contrib.java.lang.system.ProvideSystemProperty) ServerConfDatabaseCtx.doInTransaction(ee.ria.xroad.common.conf.serverconf.ServerConfDatabaseCtx.doInTransaction) Matchers.containsString(org.hamcrest.Matchers.containsString) TestSuiteServerConf(ee.ria.xroad.proxy.testsuite.TestSuiteServerConf) ServerConfType(ee.ria.xroad.common.conf.serverconf.model.ServerConfType) Mockito.mock(org.mockito.Mockito.mock) ALLOWED_METHODS_REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.ALLOWED_METHODS_REQUEST) Getter(lombok.Getter) BeforeClass(org.junit.BeforeClass) ObjectFactory(ee.ria.xroad.common.metadata.ObjectFactory) WSDLReader(javax.wsdl.xml.WSDLReader) Marshaller(javax.xml.bind.Marshaller) MimeConfig(org.apache.james.mime4j.stream.MimeConfig) MetaserviceTestUtil.parseOperationNamesFromWSDLDefinition(ee.ria.xroad.proxy.util.MetaserviceTestUtil.parseOperationNamesFromWSDLDefinition) GlobalConf(ee.ria.xroad.common.conf.globalconf.GlobalConf) WireMock(com.github.tomakehurst.wiremock.client.WireMock) HttpServletRequest(javax.servlet.http.HttpServletRequest) WSDLFactory(javax.wsdl.factory.WSDLFactory) MessageFactory(javax.xml.soap.MessageFactory) HttpClient(org.apache.http.client.HttpClient) SoapHeader(ee.ria.xroad.common.message.SoapHeader) BodyDescriptor(org.apache.james.mime4j.stream.BodyDescriptor) ExpectedException(org.junit.rules.ExpectedException) JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) InputSource(org.xml.sax.InputSource) Unmarshaller(javax.xml.bind.Unmarshaller) X_INVALID_SERVICE_TYPE(ee.ria.xroad.common.ErrorCodes.X_INVALID_SERVICE_TYPE) Definition(javax.wsdl.Definition) TEXT_XML_UTF8(ee.ria.xroad.common.util.MimeTypes.TEXT_XML_UTF8) Files(java.nio.file.Files) REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.REQUEST) WsdlRequestData(ee.ria.xroad.proxy.common.WsdlRequestData) MetaserviceTestUtil.verifyAndGetSingleBodyElementOfType(ee.ria.xroad.proxy.util.MetaserviceTestUtil.verifyAndGetSingleBodyElementOfType) HttpServletResponse(javax.servlet.http.HttpServletResponse) WireMockConfiguration.options(com.github.tomakehurst.wiremock.core.WireMockConfiguration.options) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) LIST_METHODS_REQUEST(ee.ria.xroad.proxy.util.MetaserviceTestUtil.LIST_METHODS_REQUEST) OpMonitoringData(ee.ria.xroad.common.opmonitoring.OpMonitoringData) WSDLException(javax.wsdl.WSDLException) CodedException(ee.ria.xroad.common.CodedException) MimeTypes(ee.ria.xroad.common.util.MimeTypes) Rule(org.junit.Rule) Paths(java.nio.file.Paths) ErrorCodes(ee.ria.xroad.common.ErrorCodes) GET_WSDL(ee.ria.xroad.common.metadata.MetadataRequests.GET_WSDL) HEADER_CONTENT_TYPE(ee.ria.xroad.common.util.MimeUtils.HEADER_CONTENT_TYPE) SOAPMessage(javax.xml.soap.SOAPMessage) ServerConf(ee.ria.xroad.common.conf.serverconf.ServerConf) ClientId(ee.ria.xroad.common.identifier.ClientId) TestSuiteKeyConf(ee.ria.xroad.proxy.testsuite.TestSuiteKeyConf) MetaserviceTestUtil.parseEndpointUrlsFromWSDLDefinition(ee.ria.xroad.proxy.util.MetaserviceTestUtil.parseEndpointUrlsFromWSDLDefinition) Diff(org.custommonkey.xmlunit.Diff) InputStream(java.io.InputStream) OpMonitoringData(ee.ria.xroad.common.opmonitoring.OpMonitoringData) ServiceDescriptionType(ee.ria.xroad.common.conf.serverconf.model.ServiceDescriptionType) DescriptionType(ee.ria.xroad.common.conf.serverconf.model.DescriptionType) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestSuiteServerConf(ee.ria.xroad.proxy.testsuite.TestSuiteServerConf) MethodListType(ee.ria.xroad.common.metadata.MethodListType) SOAPMessage(javax.xml.soap.SOAPMessage) ServiceId(ee.ria.xroad.common.identifier.ServiceId) TestSoapBuilder(ee.ria.xroad.proxy.util.MetaserviceTestUtil.TestSoapBuilder) ClientId(ee.ria.xroad.common.identifier.ClientId) SoapHeader(ee.ria.xroad.common.message.SoapHeader) List(java.util.List) Test(org.junit.Test)

Aggregations

WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)2 WireMock.urlPathEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo)2 WireMockConfiguration.options (com.github.tomakehurst.wiremock.core.WireMockConfiguration.options)2 CodedException (ee.ria.xroad.common.CodedException)2 ErrorCodes (ee.ria.xroad.common.ErrorCodes)2 X_INVALID_SERVICE_TYPE (ee.ria.xroad.common.ErrorCodes.X_INVALID_SERVICE_TYPE)2 X_UNKNOWN_SERVICE (ee.ria.xroad.common.ErrorCodes.X_UNKNOWN_SERVICE)2 SystemProperties (ee.ria.xroad.common.SystemProperties)2 GlobalConf (ee.ria.xroad.common.conf.globalconf.GlobalConf)2 ServerConf (ee.ria.xroad.common.conf.serverconf.ServerConf)2 ServerConfDatabaseCtx.doInTransaction (ee.ria.xroad.common.conf.serverconf.ServerConfDatabaseCtx.doInTransaction)2 ClientType (ee.ria.xroad.common.conf.serverconf.model.ClientType)2 DescriptionType (ee.ria.xroad.common.conf.serverconf.model.DescriptionType)2 ServerConfType (ee.ria.xroad.common.conf.serverconf.model.ServerConfType)2 ServiceDescriptionType (ee.ria.xroad.common.conf.serverconf.model.ServiceDescriptionType)2 ServiceType (ee.ria.xroad.common.conf.serverconf.model.ServiceType)2 ClientId (ee.ria.xroad.common.identifier.ClientId)2 ServiceId (ee.ria.xroad.common.identifier.ServiceId)2