diff options
author | Smokowski, Steve (ss835w) <ss835w@us.att.com> | 2018-08-30 19:06:46 -0400 |
---|---|---|
committer | Smokowski, Steve (ss835w) <ss835w@us.att.com> | 2018-08-31 10:35:31 -0400 |
commit | b92b1f86492d1fb0e546ef5124116abdf2d07dc9 (patch) | |
tree | f57ba276175711fd1a180ee7978d5ab464220711 /adapters/mso-requests-db-adapter/src/test/java | |
parent | 138f17fce465cdabb928525983323319162f20d2 (diff) |
Update Logging
Add CXF interceptor for SOAP based logging
Clean up extra logging statements
Add UT to ensure MDC properly populated
Change package name on Jax-RS Filter to be more accurate
Issue-ID: SO-947
Change-Id: I3a2afc58de3bf370675658ce3d19cf899b90def7
Change-Id: I3a2afc58de3bf370675658ce3d19cf899b90def7
Signed-off-by: Smokowski, Steve (ss835w) <ss835w@us.att.com>
Diffstat (limited to 'adapters/mso-requests-db-adapter/src/test/java')
3 files changed, 124 insertions, 21 deletions
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java index 58eb0085ad..11f8ff0c36 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/InfraActiveRequestsRepositoryCustomControllerTest.java @@ -8,6 +8,7 @@ import org.junit.runner.RunWith; import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -39,6 +40,9 @@ public class InfraActiveRequestsRepositoryCustomControllerTest { @LocalServerPort private int port; + + @Value("${mso.adapters.requestDb.auth}") + private String msoAdaptersAuth; private String createURLWithPort(String uri) { return "http://localhost:" + port + uri; @@ -82,6 +86,7 @@ public class InfraActiveRequestsRepositoryCustomControllerTest { headers.set("Accept", MediaType.APPLICATION_JSON); headers.set("Content-Type", MediaType.APPLICATION_JSON); + headers.set("Authorization", msoAdaptersAuth); infraActiveRequests = new InfraActiveRequests(); @@ -181,12 +186,13 @@ public class InfraActiveRequestsRepositoryCustomControllerTest { @Test public void checkVnfIdStatusTest() { - HttpEntity<List<String>> entityList = new HttpEntity("", headers); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/infraActiveRequests" + "/checkVnfIdStatus/" + infraActiveRequests.getOperationalEnvId())); + HttpEntity<String> entity = new HttpEntity(HttpEntity.EMPTY, headers); ResponseEntity<InfraActiveRequests> response = restTemplate.exchange( builder.toUriString(), - HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class); + HttpMethod.GET,entity , InfraActiveRequests.class); infraActiveRequestsResponse = response.getBody(); diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java index 4d00421e6c..9ac0cce841 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java @@ -23,15 +23,20 @@ package org.onap.so.adapters.requestsdb.adapters; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.List; - +import java.util.Map; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import org.onap.so.adapters.requestsdb.application.TestAppender; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.adapters.requestsdb.MsoRequestsDbAdapter; import org.onap.so.adapters.requestsdb.RequestStatusType; import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; @@ -41,12 +46,17 @@ import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.beans.ResourceOperationStatus; import org.onap.so.db.request.data.repository.OperationStatusRepository; import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; +import org.onap.so.logger.MsoLogger; import org.onap.so.requestsdb.RequestsDbConstant; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import ch.qos.logback.classic.spi.ILoggingEvent; @RunWith(SpringRunner.class) @SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -55,8 +65,7 @@ public class MSORequestDBImplTest { @LocalServerPort private int port; - - @Autowired + private MsoRequestsDbAdapter dbAdapter; @Autowired @@ -71,6 +80,16 @@ public class MSORequestDBImplTest { public InfraActiveRequests setupTestEntities() { return buildTestRequest(); } + + @Before + public void before(){ + JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean(); + jaxWsProxyFactory.setServiceClass(MsoRequestsDbAdapter.class); + jaxWsProxyFactory.setAddress("http://localhost:" + port + "/services/RequestsDbAdapter"); + jaxWsProxyFactory.setUsername("bpel"); + jaxWsProxyFactory.setPassword("password1$"); + dbAdapter = (MsoRequestsDbAdapter) jaxWsProxyFactory.create(); + } private InfraActiveRequests buildTestRequest() { InfraActiveRequests testRequest= new InfraActiveRequests(); @@ -94,11 +113,9 @@ public class MSORequestDBImplTest { return testRequest; } - - - @Test public void getByRequestId() throws MsoRequestsDbException { + InfraActiveRequests testRequest = setupTestEntities(); // Given String requestId = "00032ab7-3fb3-42e5-965d-8ea592502017"; @@ -121,10 +138,8 @@ public class MSORequestDBImplTest { try { dbAdapter.getInfraRequest(requestId); fail("Expected MsoRequestsDbException to be thrown"); - } catch (MsoRequestsDbException e) { - assertEquals(e.getMessage(),"Error retrieving MSO Infra Requests DB for Request ID invalidRequestId"); } catch (Exception e) { - fail("Expected MsoRequestsDbException to be thrown, unknown exception thrown"); + assertEquals(e.getMessage(),"Error retrieving MSO Infra Requests DB for Request ID invalidRequestId"); } } @@ -230,11 +245,9 @@ public class MSORequestDBImplTest { null, null, null); - fail("Expected MsoRequestsDbException to be thrown"); - } catch (MsoRequestsDbException e) { - assertEquals(e.getMessage(),"Error retrieving MSO Infra Requests DB for Request ID invalidRequestId"); + fail("Expected MsoRequestsDbException to be thrown"); } catch (Exception e) { - fail("Expected MsoRequestsDbException to be thrown, unknown exception thrown"); + assertEquals(e.getMessage(),"Error retrieving MSO Infra Requests DB for Request ID invalidRequestId"); } } @@ -328,6 +341,7 @@ public class MSORequestDBImplTest { @Test public void updateServiceOperation_Not_Found() throws MsoRequestsDbException{ + TestAppender.events.clear(); String serviceId = "badserviceId"; String operationId = "operationid"; String operation = "newOperationType"; @@ -349,12 +363,35 @@ public class MSORequestDBImplTest { updatedOperationStatus.setProgress(progress); updatedOperationStatus.setReason(reason); updatedOperationStatus.setOperationContent(operationContent); - - thrown.expect(MsoRequestsDbException.class); - thrown.expectMessage("Unable to retrieve OperationStatus Object ServiceId: " + serviceId + " operationId: " + operationId); - - dbAdapter.updateServiceOperationStatus(serviceId, operationId, operation, userId, - result, operationContent, progress, reason); + + try { + dbAdapter.updateServiceOperationStatus(serviceId, operationId, operation, userId, + result, operationContent, progress, reason); + fail("Expected MsoRequestsDbException to be thrown"); + } catch (Exception e) { + assertEquals("Entity not found. Unable to retrieve OperationStatus Object ServiceId: " + serviceId + " operationId: " + operationId,e.getMessage()); + for(ILoggingEvent logEvent : TestAppender.events) + if(logEvent.getLoggerName().equals("org.onap.so.logging.cxf.interceptor.SOAPLoggingInInterceptor") && + logEvent.getMarker().getName().equals("ENTRY") + ){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); + assertNotNull(mdc.get(MsoLogger.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals("",mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + assertEquals("/services/RequestsDbAdapter",mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME)); + assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + }else if(logEvent.getLoggerName().equals("org.onap.so.logging.cxf.interceptor.SOAPLoggingOutInterceptor") && + logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("EXIT")){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals("500",mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); + assertEquals("",mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + assertEquals("/services/RequestsDbAdapter",mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME)); + assertEquals("ERROR",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + } + } } @@ -423,6 +460,7 @@ public class MSORequestDBImplTest { @Test public void updateResourceOperationStatus() throws MsoRequestsDbException{ + TestAppender.events.clear(); String resourceTemplateUUID = "template1"; String serviceId = "serviceId"; String operationId = "operationId"; @@ -454,6 +492,28 @@ public class MSORequestDBImplTest { ResourceOperationStatus actualResource = dbAdapter.getResourceOperationStatus(serviceId, operationId,"template1"); assertThat(actualResource, sameBeanAs(expectedResource)); + + for(ILoggingEvent logEvent : TestAppender.events) + if(logEvent.getLoggerName().equals("org.onap.so.logging.cxf.interceptor.SOAPLoggingInInterceptor") && + logEvent.getMarker().getName().equals("ENTRY") + ){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); + assertNotNull(mdc.get(MsoLogger.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals("",mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + assertEquals("/services/RequestsDbAdapter",mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME)); + assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + }else if(logEvent.getLoggerName().equals("org.onap.so.logging.cxf.interceptor.SOAPLoggingOutInterceptor") && + logEvent.getMarker().getName().equals("EXIT")){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals(null,mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); + assertEquals("",mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + assertEquals("/services/RequestsDbAdapter",mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME)); + assertEquals("COMPLETED",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + } } diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/TestAppender.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/TestAppender.java new file mode 100644 index 0000000000..0da1fd7565 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/TestAppender.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.requestsdb.application; + +import java.util.ArrayList; +import java.util.List; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; + + + +public class TestAppender extends AppenderBase<ILoggingEvent> { + public static List<ILoggingEvent> events = new ArrayList<>(); + + @Override + public void append(ILoggingEvent loggingEvent) { + events.add(loggingEvent); + } +} |