diff options
Diffstat (limited to 'common/src/test')
4 files changed, 98 insertions, 9 deletions
diff --git a/common/src/test/java/org/onap/so/client/HttpClientTest.java b/common/src/test/java/org/onap/so/client/HttpClientTest.java index b12ed5956a..a01e2bb812 100644 --- a/common/src/test/java/org/onap/so/client/HttpClientTest.java +++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java @@ -32,7 +32,7 @@ import java.net.MalformedURLException; import java.net.URL; import org.junit.Rule; import org.junit.Test; -import org.onap.so.utils.TargetEntity; +import org.onap.logging.filter.base.ONAPComponents; import com.github.tomakehurst.wiremock.junit.WireMockRule; public class HttpClientTest { @@ -49,7 +49,7 @@ public class HttpClientTest { .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(""))); URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); - HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN); + HttpClient client = httpClientFactory.newJsonClient(url, ONAPComponents.BPMN); client.addBasicAuthHeader( "97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF", @@ -68,7 +68,7 @@ public class HttpClientTest { .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(""))); URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); - HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN); + HttpClient client = httpClientFactory.newJsonClient(url, ONAPComponents.BPMN); client.addAdditionalHeader("Accept", "application/json"); client.addAdditionalHeader("id", null); @@ -86,7 +86,7 @@ public class HttpClientTest { .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(""))); URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post"); - HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN); + HttpClient client = httpClientFactory.newJsonClient(url, ONAPComponents.BPMN); client.addBasicAuthHeader("", "12345"); client.addAdditionalHeader("Accept", "application/json"); diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java index 745dee23e8..cd00a9e4de 100644 --- a/common/src/test/java/org/onap/so/client/RestClientTest.java +++ b/common/src/test/java/org/onap/so/client/RestClientTest.java @@ -39,7 +39,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.utils.TargetEntity; +import org.onap.logging.filter.base.ONAPComponents; @RunWith(MockitoJUnitRunner.class) public class RestClientTest { @@ -82,7 +82,7 @@ public class RestClientTest { private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException { RestClient client = httpClientFactory.newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), - TargetEntity.BPMN); + ONAPComponents.BPMN); return spy(client); } diff --git a/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java b/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java index bc600310b3..5075da3b7a 100644 --- a/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java +++ b/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java @@ -34,7 +34,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.so.client.policy.JettisonStyleMapperProvider; import org.onap.so.utils.CryptoUtils; -import org.onap.so.utils.TargetEntity; +import org.onap.logging.filter.base.ONAPComponents; public class AdapterRestClientTest { @@ -88,9 +88,9 @@ public class AdapterRestClientTest { } @Test - public void getTargetEntity_success() throws URISyntaxException { + public void getONAPComponents_success() throws URISyntaxException { AdapterRestClient testedObject = new AdapterRestClient(adapterRestPropertiesMock, new URI("")); - assertThat(testedObject.getTargetEntity()).isEqualTo(TargetEntity.OPENSTACK_ADAPTER); + assertThat(testedObject.getTargetEntity()).isEqualTo(ONAPComponents.OPENSTACK_ADAPTER); } @Test diff --git a/common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java b/common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java new file mode 100644 index 0000000000..5e2a51a56f --- /dev/null +++ b/common/src/test/java/org/onap/so/externaltasks/logging/AuditMDCSetupTest.java @@ -0,0 +1,89 @@ +package org.onap.so.externaltasks.logging; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.doReturn; +import org.camunda.bpm.client.task.ExternalTask; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.logger.MdcConstants; +import org.slf4j.MDC; + +@RunWith(MockitoJUnitRunner.class) +public class AuditMDCSetupTest { + + @Mock + private ExternalTask externalTask; + + @Spy + @InjectMocks + private AuditMDCSetup mdcSetup; + + private String requestId = "9bb86b8d-a02f-4a0b-81a9-2eb963850009"; + private String serviceName = "testServiceName"; + + @After + public void tearDown() { + MDC.clear(); + } + + @Test + public void setupMDCTest() { + doReturn(requestId).when(externalTask).getVariable("mso-request-id"); + doReturn(serviceName).when(externalTask).getTopicName(); + + mdcSetup.setupMDC(externalTask); + + assertNotNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); + assertEquals(requestId, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertEquals(serviceName, MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME)); + assertEquals("SO.OPENSTACK_ADAPTER", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + assertEquals(ONAPLogConstants.ResponseStatus.INPROGRESS.toString(), + MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + } + + @Test + public void setElapsedTimeTest() { + MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-06-18T02:09:06.024Z"); + + mdcSetup.setElapsedTime(); + + assertNotNull(MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME)); + } + + @Test + public void setResponseCodeTest() { + mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.INPROGRESS.toString()); + + assertEquals(ONAPLogConstants.ResponseStatus.INPROGRESS.toString(), + MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + assertEquals(ONAPLogConstants.ResponseStatus.INPROGRESS.toString(), + MDC.get(MdcConstants.OPENSTACK_STATUS_CODE)); + } + + @Test + public void clearClientMDCsTest() { + MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString()); + MDC.put(MdcConstants.OPENSTACK_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString()); + MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-06-18T02:09:06.024Z"); + MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, "318"); + MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, "SO.OPENSTACK_ADAPTER"); + + mdcSetup.clearClientMDCs(); + + assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + assertNull(MDC.get(MdcConstants.OPENSTACK_STATUS_CODE)); + assertNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); + assertNull(MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME)); + assertNull(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + + } + +} |