diff options
13 files changed, 210 insertions, 120 deletions
@@ -1,2 +1,7 @@ /target/ /bin/ +logs +debug-logs +.idea +.project +msgrtr.iml
\ No newline at end of file @@ -33,7 +33,7 @@ <parent> <groupId>org.onap.oparent</groupId> <artifactId>oparent</artifactId> - <version>2.1.0</version> + <version>3.2.0</version> </parent> <properties> @@ -42,8 +42,8 @@ <cxf.version>3.0.4</cxf.version> <jstl.version>1.2</jstl.version> <log4j.version>2.13.3</log4j.version> - <maven.compiler.target>1.7</maven.compiler.target> - <maven.compiler.source>1.7</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> + <maven.compiler.source>11</maven.compiler.source> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <onap.nexus.url>https://nexus.onap.org</onap.nexus.url> <sonar.language>java</sonar.language> @@ -102,12 +102,12 @@ <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> - <version>1.2.0</version> + <version>1.2.3</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> - <version>1.2.0</version> + <version>1.2.3</version> </dependency> <dependency> <groupId>org.grails</groupId> @@ -194,7 +194,7 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.11</version> + <version>4.12</version> <scope>test</scope> </dependency> <dependency> @@ -213,7 +213,7 @@ <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> - <version>1.7.6</version> + <version>1.7.28</version> </dependency> <!-- Log4j2 logger --> <dependency> @@ -252,22 +252,22 @@ <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> - <version>4.3.18.RELEASE</version> + <version>5.2.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> - <version>5.2.3.RELEASE</version> + <version>5.2.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> - <version>4.3.18.RELEASE</version> + <version>5.2.10.RELEASE</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> - <version>3.0.1</version> + <version>4.0.1</version> <scope>provided</scope> </dependency> @@ -282,7 +282,7 @@ <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> - <version>20131018</version> + <version>20160810</version> </dependency> <!-- Apache Kafka --> @@ -299,14 +299,27 @@ <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - <version>23.6.1-jre</version> + <version>30.1.1-jre</version> </dependency> <dependency> <groupId>com.att.eelf</groupId> <artifactId>eelf-core</artifactId> - <version>0.0.1</version> - <scope>compile</scope> + <version>1.0.0</version> + <exclusions> + <exclusion> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </exclusion> + <exclusion> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + </exclusion> + <exclusion> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + </exclusion> + </exclusions> </dependency> <!-- our NSA server library --> @@ -350,6 +363,18 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>1.3.2</version> + </dependency> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>2.3.1</version> + </dependency> + <!-- sun.security.acl? --> + <!-- our base client library, for its command line tools --> <dependency> @@ -411,45 +436,54 @@ <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> - <version>2.8.11</version> + <version>2.12.2</version> <scope>test</scope> </dependency> - <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> - <version>2.11.2</version> + <version>2.12.2</version> </dependency> - <dependency> <groupId>org.powermock</groupId> - <artifactId>powermock-api-mockito</artifactId> - <version>1.6.4</version> + <artifactId>powermock-module-junit4</artifactId> + <version>2.0.7</version> <scope>test</scope> </dependency> - <dependency> <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <version>1.6.4</version> + <artifactId>powermock-core</artifactId> + <version>2.0.7</version> <scope>test</scope> </dependency> - <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4-rule</artifactId> - <version>1.6.4</version> + <version>2.0.7</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>1.10.19</version> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-support</artifactId> + <version>2.0.7</version> <scope>test</scope> </dependency> - + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito2</artifactId> + <version>2.0.7</version> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.8.1</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + </dependency> </dependencies> - <build> <finalName>DMaaP</finalName> <resources> @@ -464,12 +498,12 @@ <plugins> <plugin> <artifactId>maven-checkstyle-plugin</artifactId> - <version>2.17</version> + <version>3.1.2</version> <dependencies> <dependency> <groupId>org.onap.oparent</groupId> <artifactId>checkstyle</artifactId> - <version>2.0.0</version> + <version>3.0.0</version> </dependency> </dependencies> <executions> @@ -484,11 +518,11 @@ <includeResources>false</includeResources> <includeTestSourceDirectory>true</includeTestSourceDirectory> <includeTestResources>false</includeTestResources> - <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <sourceDirectories>${project.build.sourceDirectory}</sourceDirectories> <excludes> </excludes> <consoleOutput>true</consoleOutput> - <failsOnViolation>false</failsOnViolation> + <failOnViolation>false</failOnViolation> </configuration> </execution> <execution> @@ -503,14 +537,14 @@ with minor changes --> <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> - <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <sourceDirectories>${project.build.sourceDirectory}</sourceDirectories> <includeResources>true</includeResources> <includeTestSourceDirectory>true</includeTestSourceDirectory> <includeTestResources>true</includeTestResources> <excludes> </excludes> <consoleOutput>true</consoleOutput> - <failsOnViolation>false</failsOnViolation> + <failOnViolation>false</failOnViolation> </configuration> </execution> </executions> @@ -559,12 +593,23 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <version>2.12.4</version> + <version>3.0.0-M5</version> <configuration> <excludes> <!-- exclude until junits updated <exclude>**/DME2*.java</exclude> --> </excludes> - <!-- <skipTests>true</skipTests> --> + <argLine> + --illegal-access=permit + </argLine> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <configuration> + <argLine> + --illegal-access=permit + </argLine> </configuration> </plugin> <plugin> diff --git a/src/test/java/org/onap/dmaap/dmf/mr/service/impl/EventsServiceImplTest.java b/src/test/java/org/onap/dmaap/dmf/mr/service/impl/EventsServiceImplTest.java index f9178e1..09361db 100644 --- a/src/test/java/org/onap/dmaap/dmf/mr/service/impl/EventsServiceImplTest.java +++ b/src/test/java/org/onap/dmaap/dmf/mr/service/impl/EventsServiceImplTest.java @@ -24,11 +24,11 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -62,7 +62,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.dmaap.dmf.mr.CambriaApiException; import org.onap.dmaap.dmf.mr.backends.Consumer; import org.onap.dmaap.dmf.mr.backends.ConsumerFactory; @@ -81,7 +81,7 @@ import org.onap.dmaap.dmf.mr.utils.ConfigurationReader; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.Silent.class) public class EventsServiceImplTest { private InputStream iStream = null; @@ -118,6 +118,7 @@ public class EventsServiceImplTest { private MockHttpServletRequest request; + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); @@ -187,7 +188,7 @@ public class EventsServiceImplTest { when(configurationReader.getfConsumerFactory()).thenReturn(factory); when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey); doThrow(new UnavailableException("Could not acquire consumer lock")).when(factory) - .getConsumerFor(eq(topicName), eq(consumerGroup), eq(clientId), anyInt(), anyString()); + .getConsumerFor(eq(topicName), eq(consumerGroup), eq(clientId), anyInt(), anyString()); thrown.expect(CambriaApiException.class); thrown.expectMessage(containsString(String.valueOf(HttpStatus.SC_SERVICE_UNAVAILABLE))); @@ -252,8 +253,8 @@ public class EventsServiceImplTest { String consumerGroup = "CG5"; String clientId = "7"; givenConfiguredWithMocks(metricsTopicName); - when(factory.getConsumerFor(eq(metricsTopicName), eq(consumerGroup), eq(clientId), anyInt(), anyString())) - .thenReturn(consumer); + when(factory.getConsumerFor(eq(metricsTopicName), eq(consumerGroup), eq(clientId), anyInt(), any())) + .thenReturn(consumer); doNothing().when(eventsService).respondOkWithStream(eq(dMaapContext), any(CambriaOutboundEventStream.class)); //when @@ -267,7 +268,7 @@ public class EventsServiceImplTest { @Test public void getEvents_shouldNotAuthorizeClient_whenTopicNoteEnforcedWithAaf_andTopicHasNoOwnerSet() - throws Exception { + throws Exception { //given String topicName = "someSimpleTopicName"; String consumerGroup = "CG5"; @@ -276,8 +277,8 @@ public class EventsServiceImplTest { when(permittedRequest.getHeaders(anyString())).thenReturn(Collections.<String>emptyEnumeration()); dMaapContext.setRequest(permittedRequest); givenConfiguredWithMocks(topicName); - when(factory.getConsumerFor(eq(topicName), eq(consumerGroup), eq(clientId), anyInt(), anyString())) - .thenReturn(consumer); + when(factory.getConsumerFor(eq(topicName), eq(consumerGroup), eq(clientId), anyInt(), any())) + .thenReturn(consumer); doNothing().when(eventsService).respondOkWithStream(eq(dMaapContext), any(CambriaOutboundEventStream.class)); when(createdTopic.getOwner()).thenReturn(Strings.EMPTY); @@ -292,7 +293,7 @@ public class EventsServiceImplTest { @Test public void getEvents_shouldFailDmaapAuthorization_whenTopicOwnerIsSet_andUserHasNoReadPermissionToTopic() - throws Exception { + throws Exception { //given String topicName = "someSimpleTopicName"; String consumerGroup = "CG5"; @@ -302,7 +303,7 @@ public class EventsServiceImplTest { dMaapContext.setRequest(permittedRequest); givenConfiguredWithMocks(topicName); when(factory.getConsumerFor(eq(topicName), eq(consumerGroup), eq(clientId), anyInt(), anyString())) - .thenReturn(consumer); + .thenReturn(consumer); doNothing().when(eventsService).respondOkWithStream(eq(dMaapContext), any(CambriaOutboundEventStream.class)); when(createdTopic.getOwner()).thenReturn("SimpleTopicOwner"); when(dmaaPAuthenticator.authenticate(dMaapContext)).thenReturn(nsaSimpleApiKey); @@ -335,7 +336,7 @@ public class EventsServiceImplTest { givenConfiguredWithMocks(topicName); givenConfiguredWithProperties(messageLimit, timeout, meta, pretty, cacheEnabled); when(factory.getConsumerFor(eq(topicName), eq(consumerGroup), eq(clientId), anyInt(), anyString())) - .thenReturn(consumer); + .thenReturn(consumer); givenUserAuthorizedWithAAF(request, topicName, "sub"); //when @@ -355,7 +356,7 @@ public class EventsServiceImplTest { } private void givenConfiguredWithProperties(String messageLimit, String timeout, String meta, String pretty, - String cacheEnabled) { + String cacheEnabled) { when(eventsService.getPropertyFromAJSCmap("meta")).thenReturn(meta); when(eventsService.getPropertyFromAJSCmap("pretty")).thenReturn(pretty); when(eventsService.getPropertyFromAJSCmap(ConsumerFactory.kSetting_EnableCache)).thenReturn(cacheEnabled); @@ -373,7 +374,7 @@ public class EventsServiceImplTest { } private void verifyInvocationOrderForSuccessCase(String topicName, String consumerGroup, String clientId, - ArgumentCaptor<CambriaOutboundEventStream> osWriter) throws Exception { + ArgumentCaptor<CambriaOutboundEventStream> osWriter) throws Exception { InOrder inOrder = Mockito.inOrder(configurationReader, factory, metrics, limiter, consumer, eventsService); inOrder.verify(configurationReader).getfMetrics(); @@ -402,11 +403,11 @@ public class EventsServiceImplTest { } - + @Test public void pushEvents_shouldFailDmaapAuthorization_whenTopicOwnerIsSet_andUserHasNoWritePermissionToTopic() - throws Exception { + throws Exception { //given String topicName = "someSimpleTopicName"; @@ -431,7 +432,7 @@ public class EventsServiceImplTest { @Test public void pushEvents_shouldFailOnAafAuthorization_whenCadiIsEnabled_topicNameEnforced_andUserHasNoPermission() - throws Exception { + throws Exception { //given String topicPrefix = "org.onap.aaf.enforced"; String topicName = topicPrefix + ".topicName"; @@ -479,7 +480,7 @@ public class EventsServiceImplTest { String topicName = "topicWithoutTransaction"; givenConfiguredWithMocks(topicName); doThrow(new IOException()).when(publisher) - .sendBatchMessageNew(eq(topicName), Mockito.<ArrayList<ProducerRecord<String, String>>>any()); + .sendBatchMessageNew(eq(topicName), Mockito.<ArrayList<ProducerRecord<String, String>>>any()); thrown.expect(CambriaApiException.class); thrown.expectMessage(containsString(String.valueOf(HttpStatus.SC_NOT_FOUND))); @@ -527,7 +528,7 @@ public class EventsServiceImplTest { doNothing().when(eventsService).respondOk(eq(dMaapContext), any(JSONObject.class)); request.addUserRole("org.onap.dmaap.mr.topic|:topic." + topicName + "|pub"); doThrow(new IOException()).when(publisher) - .sendBatchMessageNew(eq(topicName), Mockito.<ArrayList<ProducerRecord<String, String>>>any()); + .sendBatchMessageNew(eq(topicName), Mockito.<ArrayList<ProducerRecord<String, String>>>any()); thrown.expect(CambriaApiException.class); thrown.expectMessage(containsString(String.valueOf(HttpStatus.SC_NOT_FOUND))); @@ -556,7 +557,7 @@ public class EventsServiceImplTest { //then ArgumentCaptor<JSONObject> captor = ArgumentCaptor.forClass(JSONObject.class); verify(publisher) - .sendBatchMessageNew(eq(metricsTopicName), Mockito.<ArrayList<ProducerRecord<String, String>>>any()); + .sendBatchMessageNew(eq(metricsTopicName), Mockito.<ArrayList<ProducerRecord<String, String>>>any()); verify(eventsService).respondOk(eq(dMaapContext), captor.capture()); verify(permittedRequest, never()).isUserInRole(anyString()); verify(createdTopic, never()).checkUserWrite(any(NsaSimpleApiKey.class)); diff --git a/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java b/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java index f287e8c..da5be91 100644 --- a/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java +++ b/src/test/java/org/onap/dmaap/dmf/mr/service/impl/TopicServiceImplTest.java @@ -23,12 +23,12 @@ package org.onap.dmaap.dmf.mr.service.impl; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.contains; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; @@ -36,11 +36,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import com.att.ajsc.filemonitor.AJSCPropertiesMap; import com.att.nsa.configs.ConfigDbException; import com.att.nsa.security.NsaAcl; import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException; import com.att.nsa.security.db.simple.NsaSimpleApiKey; import java.io.IOException; +import java.nio.file.attribute.UserPrincipal; import java.util.Arrays; import java.util.HashSet; import javax.servlet.ServletOutputStream; @@ -56,7 +58,10 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.MockitoRule; +import org.mockito.quality.Strictness; import org.onap.dmaap.dmf.mr.CambriaApiException; import org.onap.dmaap.dmf.mr.beans.DMaaPContext; import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker; @@ -68,10 +73,13 @@ import org.onap.dmaap.dmf.mr.metabroker.Broker1; import org.onap.dmaap.dmf.mr.metabroker.Topic; import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator; import org.onap.dmaap.dmf.mr.utils.ConfigurationReader; -import sun.security.acl.PrincipalImpl; +import java.security.Principal; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.Silent.class) public class TopicServiceImplTest { @@ -130,9 +138,9 @@ public class TopicServiceImplTest { doNothing().when(topicService).respondOk(any(DMaaPContext.class),anyString()); doNothing().when(topicService).respondOk(any(DMaaPContext.class),any(JSONObject.class)); when(topicService.getPropertyFromAJSCbean("enforced.topic.name.AAF")) - .thenReturn("org.onap.dmaap.mr"); + .thenReturn("org.onap.dmaap.mr"); when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")) - .thenReturn("org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:"); + .thenReturn("org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:"); } private void givenTopicBean(String topicName) { @@ -145,17 +153,18 @@ public class TopicServiceImplTest { public void createTopic_shouldSkipAAFAuthorization_whenCadiIsEnabled_andTopicNameNotEnforced() throws Exception { //given String topicName = "UNAUTHENTICATED.PRH.REGISTRATION"; - givenTopicBean(topicName); - when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean())) - .thenReturn(createdTopic); + when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean())) + .thenReturn(createdTopic); + + givenTopicBean(topicName); //when topicService.createTopic(dmaapContext, topicBean); //then - verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), - anyBoolean()); + verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), + anyBoolean()); verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class)); verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM); } @@ -166,15 +175,15 @@ public class TopicServiceImplTest { String topicName = "org.onap.dmaap.mr.topic-2"; givenTopicBean(topicName); - when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean())) - .thenReturn(createdTopic); + when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean())) + .thenReturn(createdTopic); //when topicService.createTopic(dmaapContext, topicBean); //then - verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), - anyBoolean()); + verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), + anyBoolean()); verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class)); verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM); } @@ -186,15 +195,15 @@ public class TopicServiceImplTest { givenTopicBean(topicName); doReturn(null).when(topicService).getDmaapAuthenticatedUser(dmaapContext); - when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean())) - .thenReturn(createdTopic); + when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean())) + .thenReturn(createdTopic); //when topicService.createTopic(dmaapContext, topicBean); //then - verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), - anyBoolean()); + verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), + anyBoolean()); verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class)); } @@ -204,18 +213,24 @@ public class TopicServiceImplTest { String topicName = "org.onap.dmaap.mr.topic-4"; givenTopicBean(topicName); + Principal user = new UserPrincipal(){ + @Override + public String getName(){ + return "user"; + } + }; when(topicService.isCadiEnabled()).thenReturn(true); when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(true); - when(httpServReq.getUserPrincipal()).thenReturn(new PrincipalImpl("user")); - when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), eq("user"), anyInt(), anyInt(), anyBoolean())) - .thenReturn(createdTopic); + when(httpServReq.getUserPrincipal()).thenReturn(user); + when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), eq("user"), anyInt(), anyInt(), anyBoolean())) + .thenReturn(createdTopic); //when topicService.createTopic(dmaapContext, topicBean); //then verify(httpServReq).isUserInRole(TOPIC_CREATE_PEM); - verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), eq("user"), anyInt(), anyInt(), anyBoolean()); + verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), eq("user"), anyInt(), anyInt(), anyBoolean()); verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class)); verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext); } @@ -228,12 +243,18 @@ public class TopicServiceImplTest { String topicName = "org.onap.dmaap.mr.topic-5"; givenTopicBean(topicName); + Principal user = new Principal(){ + @Override + public String getName(){ + return "user"; + } + }; when(topicService.isCadiEnabled()).thenReturn(true); when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(false); - when(httpServReq.getUserPrincipal()).thenReturn(new PrincipalImpl("user")); + when(httpServReq.getUserPrincipal()).thenReturn(user); when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), eq("user"), anyInt(), anyInt(), anyBoolean())) - .thenReturn(createdTopic); + .thenReturn(createdTopic); //when topicService.createTopic(dmaapContext, topicBean); @@ -253,8 +274,8 @@ public class TopicServiceImplTest { String topicName = "org.onap.dmaap.mr.topic-6"; givenTopicBean(topicName); - when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean())) - .thenThrow(new ConfigDbException("fail")); + when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), any(), anyInt(), anyInt(), anyBoolean())) + .thenThrow(new ConfigDbException("fail")); //when topicService.createTopic(dmaapContext, topicBean); @@ -269,8 +290,8 @@ public class TopicServiceImplTest { String topicName = "org.onap.dmaap.mr.topic-7"; givenTopicBean(topicName); - when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean())) - .thenThrow(new Broker1.TopicExistsException("enfTopicNamePlusExtra")); + when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean())) + .thenThrow(new Broker1.TopicExistsException("enfTopicNamePlusExtra")); //when topicService.createTopic(dmaapContext, topicBean); @@ -351,7 +372,7 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException { + TopicExistsException, JSONException, ConfigDbException { Assert.assertNotNull(topicService); //PowerMockito.mockStatic(DMaaPResponseBuilder.class); @@ -368,7 +389,7 @@ public class TopicServiceImplTest { @Test public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException { + TopicExistsException, JSONException, ConfigDbException { Assert.assertNotNull(topicService); //PowerMockito.mockStatic(DMaaPResponseBuilder.class); @@ -395,7 +416,7 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException, - IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -414,7 +435,7 @@ public class TopicServiceImplTest { @Test public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException, - IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -432,7 +453,7 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException, - IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -451,7 +472,7 @@ public class TopicServiceImplTest { @Test public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException, - IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -471,7 +492,7 @@ public class TopicServiceImplTest { @Test public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -496,7 +517,7 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -601,7 +622,7 @@ public class TopicServiceImplTest { @Test public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -626,8 +647,8 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testPermitConsumerForTopic_nulltopic() - throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + throws DMaaPAccessDeniedException, CambriaApiException, IOException, + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -652,7 +673,7 @@ public class TopicServiceImplTest { @Test public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -677,8 +698,8 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testdenyConsumerForTopic_nulltopic() - throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + throws DMaaPAccessDeniedException, CambriaApiException, IOException, + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -704,7 +725,7 @@ public class TopicServiceImplTest { @Test public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -729,8 +750,8 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testPermitPublisherForTopic_nulltopic() - throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + throws DMaaPAccessDeniedException, CambriaApiException, IOException, + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -755,7 +776,7 @@ public class TopicServiceImplTest { @Test public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -782,8 +803,8 @@ public class TopicServiceImplTest { @Test(expected = TopicExistsException.class) public void testDenyPublisherForTopic_nulltopic() - throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + throws DMaaPAccessDeniedException, CambriaApiException, IOException, + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -809,7 +830,7 @@ public class TopicServiceImplTest { @Test public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -834,7 +855,7 @@ public class TopicServiceImplTest { @Test public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException, - TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { + TopicExistsException, JSONException, ConfigDbException, AccessDeniedException { Assert.assertNotNull(topicService); @@ -859,3 +880,4 @@ public class TopicServiceImplTest { } + diff --git a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/Kafka011ConsumerTest.java b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/Kafka011ConsumerTest.java index 88d703e..3b9fbb3 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/Kafka011ConsumerTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/Kafka011ConsumerTest.java @@ -35,11 +35,13 @@ import org.onap.dmaap.dmf.mr.backends.kafka.Kafka011Consumer; import org.onap.dmaap.dmf.mr.backends.kafka.KafkaLiveLockAvoider2; import org.onap.dmaap.dmf.mr.constants.CambriaConstants; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.att.ajsc.filemonitor.AJSCPropertiesMap; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ AJSCPropertiesMap.class }) public class Kafka011ConsumerTest { diff --git a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaConsumerCacheTest.java b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaConsumerCacheTest.java index ced6fc4..de70a92 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaConsumerCacheTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaConsumerCacheTest.java @@ -32,6 +32,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -44,6 +45,7 @@ import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache.KafkaConsumerCach import org.onap.dmaap.dmf.mr.constants.CambriaConstants; import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ AJSCPropertiesMap.class }) public class KafkaConsumerCacheTest { diff --git a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaLiveLockAvoider2Test.java b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaLiveLockAvoider2Test.java index 71d50e8..7f81641 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaLiveLockAvoider2Test.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaLiveLockAvoider2Test.java @@ -40,9 +40,10 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.dmaap.dmf.mr.backends.kafka.KafkaLiveLockAvoider2; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; - +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) public class KafkaLiveLockAvoider2Test { diff --git a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaPublisherTest.java b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaPublisherTest.java index 8292c2c..e72b9d3 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaPublisherTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/backends/kafka/KafkaPublisherTest.java @@ -39,12 +39,14 @@ import org.onap.dmaap.dmf.mr.beans.LogDetails; import org.onap.dmaap.dmf.mr.constants.CambriaConstants; import org.onap.dmaap.dmf.mr.utils.Utils; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import com.att.ajsc.filemonitor.AJSCPropertiesMap; import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ Utils.class }) public class KafkaPublisherTest { diff --git a/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPKafkaMetaBrokerTest.java b/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPKafkaMetaBrokerTest.java index 0f4702a..a992104 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPKafkaMetaBrokerTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPKafkaMetaBrokerTest.java @@ -34,6 +34,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -49,6 +50,7 @@ import com.att.nsa.configs.ConfigDb; import com.att.nsa.configs.ConfigDbException; import com.att.nsa.configs.ConfigPath; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ AdminClient.class }) public class DMaaPKafkaMetaBrokerTest { diff --git a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/AdminServiceImplemTest.java b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/AdminServiceImplemTest.java index 1895ac6..3ef23f5 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/AdminServiceImplemTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/AdminServiceImplemTest.java @@ -44,9 +44,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class }) public class AdminServiceImplemTest { diff --git a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/ApiKeysServiceImplTest.java b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/ApiKeysServiceImplTest.java index a0ad709..322cf2a 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/ApiKeysServiceImplTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/ApiKeysServiceImplTest.java @@ -52,9 +52,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class }) public class ApiKeysServiceImplTest { diff --git a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/MMServiceImplTest.java b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/MMServiceImplTest.java index 20a8cad..5d1394f 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/MMServiceImplTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/MMServiceImplTest.java @@ -63,11 +63,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class, PropertiesMapBean.class, AJSCPropertiesMap.class }) diff --git a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/UIServiceImplTest.java b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/UIServiceImplTest.java index 2fbbec1..fe65b1b 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/service/impl/UIServiceImplTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/service/impl/UIServiceImplTest.java @@ -52,9 +52,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @RunWith(PowerMockRunner.class) @PrepareForTest({ DMaaPAuthenticatorImpl.class, DMaaPResponseBuilder.class }) public class UIServiceImplTest { |