Search in sources :

Example 1 with ServiceId

use of ee.ria.xroad.common.identifier.ServiceId in project X-Road by nordic-institute.

the class MetadataServiceHandlerTest method shouldHandleGetWsdl.

@Test
public void shouldHandleGetWsdl() throws Exception {
    final ServiceId serviceId = ServiceId.create(DEFAULT_CLIENT, GET_WSDL);
    TestMetadataServiceHandlerImpl handlerToTest = prepareTestConstructsForWsdl(serviceId);
    handlerToTest.setTestFilter(OverwriteAttributeFilter.createOverwriteSoapAddressFilter("expected-location"));
    // execution
    handlerToTest.startHandling(mockRequest, mockProxyMessage, httpClientMock, mock(OpMonitoringData.class));
    // verification
    final List<String> expectedWSDLServiceNames = Arrays.asList("getRandom", "helloService");
    final List<String> expectedEndpointUrls = Arrays.asList("expected-location");
    assertThat("Content type does not match", handlerToTest.getResponseContentType(), containsString("multipart/related; type=\"text/xml\"; charset=UTF-8;"));
    TestMimeContentHandler handler = parseWsdlResponse(handlerToTest.getResponseContent(), // this response content type and the headless parsing is some super funky business
    handlerToTest.getResponseContentType());
    SoapHeader xrHeader = handler.getXrHeader();
    assertThat("Response client does not match", xrHeader.getService(), is(serviceId));
    final List<String> operationNames = handler.getOperationNames();
    assertThat("Expected to find certain operations", operationNames, containsInAnyOrder(expectedWSDLServiceNames.toArray()));
    List<String> endpointUrls = handler.getEndpointUrls();
    assertThat("Expected to find overwritten endpoint urls", endpointUrls, containsInAnyOrder(expectedEndpointUrls.toArray()));
}
Also used : OpMonitoringData(ee.ria.xroad.common.opmonitoring.OpMonitoringData) SoapHeader(ee.ria.xroad.common.message.SoapHeader) Matchers.containsString(org.hamcrest.Matchers.containsString) ServiceId(ee.ria.xroad.common.identifier.ServiceId) Test(org.junit.Test)

Example 2 with ServiceId

use of ee.ria.xroad.common.identifier.ServiceId 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));
}
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 3 with ServiceId

use of ee.ria.xroad.common.identifier.ServiceId 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 4 with ServiceId

use of ee.ria.xroad.common.identifier.ServiceId 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 5 with ServiceId

use of ee.ria.xroad.common.identifier.ServiceId 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)

Aggregations

ServiceId (ee.ria.xroad.common.identifier.ServiceId)76 Test (org.junit.Test)58 ClientId (ee.ria.xroad.common.identifier.ClientId)32 OpMonitoringData (ee.ria.xroad.common.opmonitoring.OpMonitoringData)18 TestUtil.createTestServiceId (ee.ria.xroad.proxy.conf.TestUtil.createTestServiceId)18 TestSuiteServerConf (ee.ria.xroad.proxy.testsuite.TestSuiteServerConf)14 CodedException (ee.ria.xroad.common.CodedException)13 DescriptionType (ee.ria.xroad.common.conf.serverconf.model.DescriptionType)13 ServiceDescriptionType (ee.ria.xroad.common.conf.serverconf.model.ServiceDescriptionType)12 ServiceType (ee.ria.xroad.common.conf.serverconf.model.ServiceType)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 List (java.util.List)12 HttpClient (org.apache.http.client.HttpClient)12 ClientType (ee.ria.xroad.common.conf.serverconf.model.ClientType)11 SoapHeader (ee.ria.xroad.common.message.SoapHeader)11 IOException (java.io.IOException)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)10 ServerConfType (ee.ria.xroad.common.conf.serverconf.model.ServerConfType)10 WireMock (com.github.tomakehurst.wiremock.client.WireMock)9