Search in sources :

Example 1 with GET_WSDL

use of ee.ria.xroad.common.metadata.MetadataRequests.GET_WSDL in project X-Road by nordic-institute.

the class MetadataServiceHandlerTest method shouldThrowUnknownServiceWhenWsdlUrlNotFound.

@Test
public void shouldThrowUnknownServiceWhenWsdlUrlNotFound() throws Exception {
    final ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, GET_WSDL);
    final ServiceId requestingWsdlForService = ServiceId.create(DEFAULT_CLIENT, "someServiceWithoutWsdl");
    MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
    WsdlRequestData wsdlRequestData = new WsdlRequestData();
    wsdlRequestData.setServiceCode(requestingWsdlForService.getServiceCode());
    InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> marshaller.marshal(wsdlRequestData, soapBody)).buildAsInputStream();
    when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
    handlerToTest.canHandle(serviceId, mockProxyMessage);
    thrown.expect(CodedException.class);
    thrown.expect(faultCodeEquals(X_UNKNOWN_SERVICE));
    thrown.expectMessage(containsString("Could not find wsdl URL for service"));
    // execution, should throw..
    handlerToTest.startHandling(mockRequest, mockProxyMessage, httpClientMock, mock(OpMonitoringData.class));
}
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) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WsdlRequestData(ee.ria.xroad.proxy.common.WsdlRequestData) TestSoapBuilder(ee.ria.xroad.proxy.util.MetaserviceTestUtil.TestSoapBuilder) ServiceId(ee.ria.xroad.common.identifier.ServiceId) Test(org.junit.Test)

Example 2 with GET_WSDL

use of ee.ria.xroad.common.metadata.MetadataRequests.GET_WSDL in project X-Road by nordic-institute.

the class MetadataServiceHandlerTest method shouldThrowWhenMissingServiceCodeInWsdlRequestBody.

@Test
public void shouldThrowWhenMissingServiceCodeInWsdlRequestBody() throws Exception {
    final ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, GET_WSDL);
    MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
    InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> soapBody.addChildElement(GET_WSDL_REQUEST).addChildElement(REQUEST)).buildAsInputStream();
    when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
    handlerToTest.canHandle(serviceId, mockProxyMessage);
    thrown.expect(CodedException.class);
    thrown.expect(faultCodeEquals(ErrorCodes.X_INVALID_REQUEST));
    thrown.expectMessage(containsString("Missing serviceCode in message body"));
    // execution, should throw..
    handlerToTest.startHandling(mockRequest, mockProxyMessage, httpClientMock, mock(OpMonitoringData.class));
}
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) 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 3 with GET_WSDL

use of ee.ria.xroad.common.metadata.MetadataRequests.GET_WSDL in project X-Road by nordic-institute.

the class MetadataServiceHandlerTest method shouldBeAbleToHandleGetWsdl.

@Test
public void shouldBeAbleToHandleGetWsdl() throws Exception {
    // setup
    MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
    ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, GET_WSDL);
    InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> soapBody.addChildElement(GET_WSDL_REQUEST).addChildElement(REQUEST)).buildAsInputStream();
    when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
    // execution & verification
    assertTrue("Wasn't able to handle get wsdl", 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 4 with GET_WSDL

use of ee.ria.xroad.common.metadata.MetadataRequests.GET_WSDL in project X-Road by nordic-institute.

the class MetadataServiceHandlerTest method shouldThrowRuntimeExWhenWsdlUrlNotOk200.

@Test
public void shouldThrowRuntimeExWhenWsdlUrlNotOk200() throws Exception {
    final ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, GET_WSDL);
    final ServiceId requestingWsdlForService = ServiceId.create(DEFAULT_CLIENT, "someServiceWithWsdl122");
    MetadataServiceHandlerImpl handlerToTest = new MetadataServiceHandlerImpl();
    WsdlRequestData wsdlRequestData = new WsdlRequestData();
    wsdlRequestData.setServiceCode(requestingWsdlForService.getServiceCode());
    InputStream soapContentInputStream = new TestSoapBuilder().withClient(DEFAULT_CLIENT).withService(serviceId).withModifiedBody(soapBody -> marshaller.marshal(wsdlRequestData, soapBody)).buildAsInputStream();
    when(mockProxyMessage.getSoapContent()).thenReturn(soapContentInputStream);
    setUpDatabase(requestingWsdlForService);
    mockServer.stubFor(WireMock.any(urlPathEqualTo(EXPECTED_WSDL_QUERY_PATH)).willReturn(aResponse().withStatus(HttpServletResponse.SC_FORBIDDEN)));
    mockServer.start();
    handlerToTest.canHandle(serviceId, mockProxyMessage);
    thrown.expect(RuntimeException.class);
    thrown.expectMessage(containsString("Received HTTP error: 403 - Forbidden"));
    // execution, should throw..
    handlerToTest.startHandling(mockRequest, mockProxyMessage, httpClientMock, mock(OpMonitoringData.class));
}
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) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WsdlRequestData(ee.ria.xroad.proxy.common.WsdlRequestData) TestSoapBuilder(ee.ria.xroad.proxy.util.MetaserviceTestUtil.TestSoapBuilder) ServiceId(ee.ria.xroad.common.identifier.ServiceId) Test(org.junit.Test)

Aggregations

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