Search in sources :

Example 1 with TestSuiteGlobalConf

use of ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf in project X-Road by nordic-institute.

the class RestMetadataServiceHandlerTest method init.

/**
 * Init data for tests
 */
@Before
public void init() {
    GlobalConf.reload(new TestSuiteGlobalConf());
    KeyConf.reload(new TestSuiteKeyConf());
    ServerConf.reload(new TestSuiteServerConf() {

        @Override
        public DescriptionType getDescriptionType(ServiceId service) {
            return DescriptionType.OPENAPI3;
        }

        @Override
        public String getServiceDescriptionURL(ServiceId service) {
            if (SUBSYSTEM_FOR_JSON_FILE.equals(service.getSubsystemCode())) {
                return "http://localhost:9858/petstore.json";
            } else if (SUBSYSTEM_FOR_UNSUPPORTED_YAML_FILE.equals(service.getSubsystemCode())) {
                return "http://localhost:9858/openapi_incompatible_version.yaml";
            } else {
                return "http://localhost:9858/petstore.yaml";
            }
        }
    });
    httpClientMock = mock(HttpClient.class);
    mockRequest = mock(HttpServletRequest.class);
    mockResponse = mock(HttpServletResponse.class);
    mockProxyMessage = mock(ProxyMessage.class);
    mockServer = new WireMockServer(options().port(MOCK_SERVER_PORT));
    mockServer.stubFor(WireMock.any(urlPathEqualTo("/petstore.json")).willReturn(aResponse().withBodyFile("petstore.json")));
    mockServer.stubFor(WireMock.any(urlPathEqualTo("/petstore.yaml")).willReturn(aResponse().withBodyFile("petstore.yaml")));
    mockServer.start();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ProxyMessage(ee.ria.xroad.proxy.protocol.ProxyMessage) TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) DescriptionType(ee.ria.xroad.common.conf.serverconf.model.DescriptionType) TestSuiteKeyConf(ee.ria.xroad.proxy.testsuite.TestSuiteKeyConf) TestSuiteServerConf(ee.ria.xroad.proxy.testsuite.TestSuiteServerConf) HttpClient(org.apache.http.client.HttpClient) HttpServletResponse(javax.servlet.http.HttpServletResponse) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) ServiceId(ee.ria.xroad.common.identifier.ServiceId) Before(org.junit.Before)

Example 2 with TestSuiteGlobalConf

use of ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf in project X-Road by nordic-institute.

the class GetListClientsMessage method startUp.

@Override
protected void startUp() throws Exception {
    super.startUp();
    GlobalConf.reload(new TestSuiteGlobalConf() {

        @Override
        public List<MemberInfo> getMembers(String... instanceIdentifier) {
            String[] instances = instanceIdentifier;
            assertThat("Wrong Xroad instance in query", instances, arrayContaining(EXPECTED_XR_INSTANCE));
            return expectedMembers;
        }
    });
}
Also used : TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) List(java.util.List)

Example 3 with TestSuiteGlobalConf

use of ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf in project X-Road by nordic-institute.

the class MetadataClientRequestProcessorTest method shouldProcessListClients.

@Test
public void shouldProcessListClients() throws Exception {
    final List<MemberInfo> expectedMembers = Arrays.asList(createMember("producer", null), createMember("producer", "subsystem"), createMember("anothermemeber", null), createMember("anothermemeber", "somesub"), createMember("thirdmember", null));
    GlobalConf.reload(new TestSuiteGlobalConf() {

        @Override
        public List<MemberInfo> getMembers(String... instanceIdentifier) {
            String[] instances = instanceIdentifier;
            assertThat("Wrong Xroad instance in query", instances, arrayContaining(EXPECTED_XR_INSTANCE));
            return expectedMembers;
        }
    });
    MetadataClientRequestProcessor processorToTest = new MetadataClientRequestProcessor(LIST_CLIENTS, mockRequest, mockResponse);
    processorToTest.process();
    assertContentTypeIsIn(xmlUtf8ContentTypes());
    List<MemberInfo> members = unmarshaller.unmarshal(mockServletOutputStream.getResponseSource(), ClientListType.class).getValue().getMember().stream().map(clientType -> new MemberInfo(clientType.getId(), clientType.getName())).collect(Collectors.toList());
    assertThat("Wrong amount of clients", members.size(), is(expectedMembers.size()));
    assertThat("Wrong members", members, containsInAnyOrder(expectedMembers.toArray()));
}
Also used : Matchers.arrayContaining(org.hamcrest.Matchers.arrayContaining) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) MetaserviceTestUtil.xmlUtf8ContentTypes(ee.ria.xroad.proxy.util.MetaserviceTestUtil.xmlUtf8ContentTypes) CentralServiceId(ee.ria.xroad.common.identifier.CentralServiceId) Enumeration(java.util.Enumeration) CentralServiceId.create(ee.ria.xroad.common.identifier.CentralServiceId.create) ObjectFactory(ee.ria.xroad.common.metadata.ObjectFactory) MetaserviceTestUtil(ee.ria.xroad.proxy.util.MetaserviceTestUtil) GlobalConf(ee.ria.xroad.common.conf.globalconf.GlobalConf) Assert.assertThat(org.junit.Assert.assertThat) HttpServletRequest(javax.servlet.http.HttpServletRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) Is.is(org.hamcrest.core.Is.is) ExpectedException(org.junit.rules.ExpectedException) Matchers.isIn(org.hamcrest.Matchers.isIn) JAXBContext(javax.xml.bind.JAXBContext) Before(org.junit.Before) Unmarshaller(javax.xml.bind.Unmarshaller) HttpServletResponse(javax.servlet.http.HttpServletResponse) LIST_CENTRAL_SERVICES(ee.ria.xroad.common.metadata.MetadataRequests.LIST_CENTRAL_SERVICES) ClientListType(ee.ria.xroad.common.metadata.ClientListType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) KeyConf(ee.ria.xroad.proxy.conf.KeyConf) List(java.util.List) Rule(org.junit.Rule) MemberInfo(ee.ria.xroad.common.conf.globalconf.MemberInfo) CentralServiceListType(ee.ria.xroad.common.metadata.CentralServiceListType) TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) LIST_CLIENTS(ee.ria.xroad.common.metadata.MetadataRequests.LIST_CLIENTS) ClientId(ee.ria.xroad.common.identifier.ClientId) TestSuiteKeyConf(ee.ria.xroad.proxy.testsuite.TestSuiteKeyConf) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) MemberInfo(ee.ria.xroad.common.conf.globalconf.MemberInfo) ClientListType(ee.ria.xroad.common.metadata.ClientListType) List(java.util.List) Test(org.junit.Test)

Example 4 with TestSuiteGlobalConf

use of ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf in project X-Road by nordic-institute.

the class MetadataHandlerTest method init.

/**
 * Init common data for tests
 */
@Before
public void init() {
    GlobalConf.reload(new TestSuiteGlobalConf());
    KeyConf.reload(new TestSuiteKeyConf());
    httpClientMock = mock(HttpClient.class);
    mockRequest = mock(HttpServletRequest.class);
    mockResponse = mock(HttpServletResponse.class);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) TestSuiteKeyConf(ee.ria.xroad.proxy.testsuite.TestSuiteKeyConf) HttpClient(org.apache.http.client.HttpClient) HttpServletResponse(javax.servlet.http.HttpServletResponse) Before(org.junit.Before)

Example 5 with TestSuiteGlobalConf

use of ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf in project X-Road by nordic-institute.

the class ProxyMonitorServiceHandlerTest method init.

/**
 * Init data for tests
 */
@Before
public void init() throws IOException {
    GlobalConf.reload(new TestSuiteGlobalConf() {

        @Override
        public String getInstanceIdentifier() {
            return EXPECTED_XR_INSTANCE;
        }
    });
    KeyConf.reload(new TestSuiteKeyConf());
    ServerConf.reload(new TestSuiteServerConf() {

        @Override
        public SecurityServerId getIdentifier() {
            return DEFAULT_OWNER_SERVER;
        }
    });
    mockRequest = mock(HttpServletRequest.class);
    mockProxyMessage = mock(ProxyMessage.class);
    when(mockProxyMessage.getSoapContentType()).thenReturn(MimeTypes.TEXT_XML_UTF8);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ProxyMessage(ee.ria.xroad.proxy.protocol.ProxyMessage) TestSuiteGlobalConf(ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf) TestSuiteKeyConf(ee.ria.xroad.proxy.testsuite.TestSuiteKeyConf) TestSuiteServerConf(ee.ria.xroad.proxy.testsuite.TestSuiteServerConf) SecurityServerId(ee.ria.xroad.common.identifier.SecurityServerId) Matchers.containsString(org.hamcrest.Matchers.containsString) Before(org.junit.Before)

Aggregations

TestSuiteGlobalConf (ee.ria.xroad.proxy.testsuite.TestSuiteGlobalConf)17 TestSuiteKeyConf (ee.ria.xroad.proxy.testsuite.TestSuiteKeyConf)8 TestSuiteServerConf (ee.ria.xroad.proxy.testsuite.TestSuiteServerConf)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Before (org.junit.Before)7 ClientId (ee.ria.xroad.common.identifier.ClientId)5 List (java.util.List)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 SecurityServerId (ee.ria.xroad.common.identifier.SecurityServerId)4 ProxyMessage (ee.ria.xroad.proxy.protocol.ProxyMessage)4 MetaserviceTestUtil (ee.ria.xroad.proxy.util.MetaserviceTestUtil)3 X509Certificate (java.security.cert.X509Certificate)3 HttpClient (org.apache.http.client.HttpClient)3 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)2 MemberInfo (ee.ria.xroad.common.conf.globalconf.MemberInfo)2 CentralServiceId (ee.ria.xroad.common.identifier.CentralServiceId)2 Collection (java.util.Collection)2 Test (org.junit.Test)2 GlobalConf (ee.ria.xroad.common.conf.globalconf.GlobalConf)1 DescriptionType (ee.ria.xroad.common.conf.serverconf.model.DescriptionType)1