changes for code coverage 61/33461/1
authorSunil Unnava <su622b@att.com>
Wed, 28 Feb 2018 19:21:40 +0000 (14:21 -0500)
committerSunil Unnava <su622b@att.com>
Wed, 28 Feb 2018 19:26:14 +0000 (14:26 -0500)
Issue-ID: DMAAP-271
Change-Id: Ib8fd245fdbe9ef3457e8303c5379977b237ec09a
Signed-off-by: Sunil Unnava <su622b@att.com>
pom.xml
src/main/java/com/att/nsa/dmaap/service/EventsRestService.java
src/main/java/com/att/nsa/dmaap/service/MMRestService.java
src/main/java/com/att/nsa/dmaap/service/TopicRestService.java
src/main/java/com/att/nsa/dmaap/service/TransactionRestService.java
src/test/java/com/att/nsa/dmaap/service/EventsRestServiceTest.java
src/test/java/com/att/nsa/dmaap/service/MMRestServiceTest.java
src/test/java/com/att/nsa/dmaap/service/TopicRestServiceTest.java
src/test/java/com/att/nsa/dmaap/service/TransactionRestServiceTest.java

diff --git a/pom.xml b/pom.xml
index ce24164..6be8e51 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -1,24 +1,14 @@
-<!--
-     ============LICENSE_START=======================================================
-     org.onap.dmaap
-     ================================================================================
-     Copyright © 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=========================================================
-   
-     ECOMP is a trademark and service mark of AT&T Intellectual Property.
-     
- -->
+<!-- ============LICENSE_START======================================================= 
+       org.onap.dmaap ================================================================================ 
+       Copyright © 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========================================================= 
+       ECOMP is a trademark and service mark of AT&T Intellectual Property. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
                <artifactId>oparent</artifactId>
                <version>0.1.1</version>
        </parent>
-       
+
        <groupId>org.onap.dmaap.messagerouter.messageservice</groupId>
        <artifactId>dmaapMR1</artifactId>
        <version>1.1.3-SNAPSHOT</version>
        <name>dmaap-messagerouter-messageservice</name>
        <description>Message Router - Restful interface built for kafka</description>
-        <licenses>
-         <license>
-           <name>Apache License Version 2.0</name>
-         </license>
+       <licenses>
+               <license>
+                       <name>Apache License Version 2.0</name>
+               </license>
        </licenses>
 
        <developers>
-          <developer>
-            <name>Rajashree</name>
-            <email></email>
-            <organization>ATT</organization>
-            <organizationUrl>www.att.com</organizationUrl>
-          </developer>
-          <developer>
-            <name>Ramkumar</name>
-            <email></email>
-            <organization>ATT</organization>
-            <organizationUrl>www.att.com</organizationUrl>
-          </developer>
-        </developers>
-       
+               <developer>
+                       <name>Rajashree</name>
+                       <email></email>
+                       <organization>ATT</organization>
+                       <organizationUrl>www.att.com</organizationUrl>
+               </developer>
+               <developer>
+                       <name>Ramkumar</name>
+                       <email></email>
+                       <organization>ATT</organization>
+                       <organizationUrl>www.att.com</organizationUrl>
+               </developer>
+       </developers>
+
        <build>
                <plugins>
-               <plugin>
+                       <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-site-plugin</artifactId>
                                <version>3.6</version>
                                        </dependency>
                                </dependencies>
                        </plugin>
-                       
-                               <plugin>
-                                               <groupId>org.apache.maven.plugins</groupId>
-                                               <artifactId>maven-jar-plugin</artifactId>
-                                               <version>3.0.2</version>
-                               </plugin>
-                                       
-               <!--    <plugin>
+
+                       <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-javadoc-plugin</artifactId>
-                               <version>2.10.4</version>
-                               <configuration>
-                                       <additionalparam>-Xdoclint:none</additionalparam>
-                               </configuration>
-                               <executions>
-                                       <execution>
-                                               <id>attach-javadocs</id>
-                                               <goals>
-                                                       <goal>jar</goal>
-                                               </goals>
-                                       </execution>
-                               </executions>
-                       </plugin> -->
+                               <artifactId>maven-jar-plugin</artifactId>
+                               <version>3.0.2</version>
+                       </plugin>
+
+                       <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> 
+                               <version>2.10.4</version> <configuration> <additionalparam>-Xdoclint:none</additionalparam> 
+                               </configuration> <executions> <execution> <id>attach-javadocs</id> <goals> 
+                               <goal>jar</goal> </goals> </execution> </executions> </plugin> -->
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-source-plugin</artifactId>
                                                </goals>
                                        </execution>
                                </executions>
-                       </plugin>               
+                       </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-release-plugin</artifactId>
                                <version>1.0.0</version>
                                <configuration>
                                        <imageName>onap/dmaap/dmaap-mr</imageName>
-                                       <dockerDirectory>${dockerLocation}</dockerDirectory> 
+                                       <dockerDirectory>${dockerLocation}</dockerDirectory>
                                        <serverId>docker-hub</serverId>
                                        <imageTags>
                                                <imageTag>${dmaapImg}</imageTag>
                                                <imageTag>latest</imageTag>
                                        </imageTags>
                                        <forceTags>true</forceTags>
-                               <resources>
-                                       <resource>
-                                         <targetPath>/</targetPath>
-                                         <directory>${dockerLocation}</directory>
-                                         <include>${project.build.finalName}.jar</include>
-                                       </resource>
-                                       <resource>
-                                         <targetPath>/</targetPath>
-                                         <directory>${project.build.directory}</directory>
-                                         <include>**/**</include>
-                                       </resource>
-                                 </resources>
-                                </configuration>
+                                       <resources>
+                                               <resource>
+                                                       <targetPath>/</targetPath>
+                                                       <directory>${dockerLocation}</directory>
+                                                       <include>${project.build.finalName}.jar</include>
+                                               </resource>
+                                               <resource>
+                                                       <targetPath>/</targetPath>
+                                                       <directory>${project.build.directory}</directory>
+                                                       <include>**/**</include>
+                                               </resource>
+                                       </resources>
+                               </configuration>
                                <executions>
-                          <execution>
-                                       <id>build-image</id>
-                                       <phase>package</phase>
-                                       <goals>
-                                         <goal>build</goal>
-                                       </goals>
-                                       <configuration>
-                                         <skipDockerBuild>${skip.docker.build}</skipDockerBuild>
-                                       </configuration>
-                                 </execution> 
+                                       <execution>
+                                               <id>build-image</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>build</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <skipDockerBuild>${skip.docker.build}</skipDockerBuild>
+                                               </configuration>
+                                       </execution>
 
-                                 <execution>
-                                       <id>tag-image-project-version</id>
-                                       <phase>package</phase>
-                                       <goals>
-                                         <goal>tag</goal>
-                                       </goals>
-                                       <configuration>
-                                         <image>onap/dmaap/dmaap-mr</image>
-                                         <newName>${docker.push.registry}/onap/dmaap/dmaap-mr:${project.version}</newName>
-                                         <skipDockerTag>${skip.docker.push}</skipDockerTag>
-                                       </configuration>
-                                 </execution>
-                                 
-                                 <execution>
-                                       <id>tag-image-latest</id>
-                                       <phase>package</phase>
-                                       <goals>
-                                         <goal>tag</goal>
-                                       </goals>
-                                       <configuration>
-                                         <image>onap/dmaap/dmaap-mr</image>
-                                         <newName>${docker.push.registry}/onap/dmaap/dmaap-mr:latest</newName>
-                                         <skipDockerTag>${skip.docker.push}</skipDockerTag>
-                                       </configuration>
-                                 </execution>
-                                 
-                                <execution>
-                                       <id>push-image-latest</id>
-                                       <phase>deploy</phase>
-                                       <goals>
-                                         <goal>push</goal>
-                                       </goals>
-                                       <configuration>
-                                         <imageName>${docker.push.registry}/onap/dmaap/dmaap-mr:${project.version}</imageName>
-                                         <skipDockerPush>${skip.docker.push}</skipDockerPush>
-                                       </configuration>
-                                 </execution>
-                                 
-                                 <execution>
-                                       <id>push-image</id>
-                                       <phase>deploy</phase>
-                                       <goals>
-                                         <goal>push</goal>
-                                       </goals>
-                                       <configuration>
-                                         <imageName>${docker.push.registry}/onap/dmaap/dmaap-mr:latest</imageName>
-                                         <skipDockerPush>${skip.docker.push}</skipDockerPush>
-                                       </configuration>
-                                 </execution>
+                                       <execution>
+                                               <id>tag-image-project-version</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>tag</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <image>onap/dmaap/dmaap-mr</image>
+                                                       <newName>${docker.push.registry}/onap/dmaap/dmaap-mr:${project.version}</newName>
+                                                       <skipDockerTag>${skip.docker.push}</skipDockerTag>
+                                               </configuration>
+                                       </execution>
+
+                                       <execution>
+                                               <id>tag-image-latest</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>tag</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <image>onap/dmaap/dmaap-mr</image>
+                                                       <newName>${docker.push.registry}/onap/dmaap/dmaap-mr:latest</newName>
+                                                       <skipDockerTag>${skip.docker.push}</skipDockerTag>
+                                               </configuration>
+                                       </execution>
+
+                                       <execution>
+                                               <id>push-image-latest</id>
+                                               <phase>deploy</phase>
+                                               <goals>
+                                                       <goal>push</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <imageName>${docker.push.registry}/onap/dmaap/dmaap-mr:${project.version}</imageName>
+                                                       <skipDockerPush>${skip.docker.push}</skipDockerPush>
+                                               </configuration>
+                                       </execution>
+
+                                       <execution>
+                                               <id>push-image</id>
+                                               <phase>deploy</phase>
+                                               <goals>
+                                                       <goal>push</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <imageName>${docker.push.registry}/onap/dmaap/dmaap-mr:latest</imageName>
+                                                       <skipDockerPush>${skip.docker.push}</skipDockerPush>
+                                               </configuration>
+                                       </execution>
                                </executions>
-                       </plugin>                                                                                                                                                                                                                                                                                                        
+                       </plugin>
                        <plugin>
                                <groupId>com.blackducksoftware.integration</groupId>
                                <artifactId>hub-maven-plugin</artifactId>
                                        </execution>
                                </executions>
                        </plugin>
-                       
+
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>2.8.0-01</version>
                                <extensions>true</extensions>
                        </plugin>
-                                       
+
                </plugins>
        </build>
 
                        8080 -->
                <serverPort>3904</serverPort>
                <sslport>3905</sslport>
-       
+
                <testRouteOffer>workstation</testRouteOffer>
                <testEnv>DEV</testEnv>
                <dmaapImg>${project.version}</dmaapImg>
                <camel.version>2.15.5</camel.version>
                <sitePath>/content/sites/site/org/onap/dmaap/messagerouter/messageservice/${project.artifactId}/${project.version}</sitePath>
                <skip.docker.build>true</skip.docker.build>
-        <skip.docker.push>true</skip.docker.push>
+               <skip.docker.push>true</skip.docker.push>
                <nexusproxy>https://nexus.onap.org</nexusproxy>
                <docker.push.registry>nexus3.onap.org:10003</docker.push.registry>
        </properties>
 
                <!-- cmn-CommonDataModel dependency added to resolve build issue not finding 
                        version 100.0.64 -->
-               
-               <!-- <dependency>
-                       <groupId>csi-schemas-source</groupId>
-                       <artifactId>cmn-CommonDataModel</artifactId>
-                       <version>112.0.50</version>
-               </dependency> -->
-       <!-- TODO: add open source version here -->
+
+               <!-- <dependency> <groupId>csi-schemas-source</groupId> <artifactId>cmn-CommonDataModel</artifactId> 
+                       <version>112.0.50</version> </dependency> -->
+               <!-- TODO: add open source version here -->
                <dependency>
                        <groupId>com.att.cadi</groupId>
                        <artifactId>cadi-core</artifactId>
                        <version>1.3.0</version>
                </dependency>
+               <dependency>
+                       <groupId>com.att.aft</groupId>
+                       <artifactId>dme2</artifactId>
+                       <version>3.1.200-oss</version>
+               </dependency>
                <dependency>
                        <groupId>commons-io</groupId>
                        <artifactId>commons-io</artifactId>
                        <version>1.3.2</version>
                </dependency>
                <dependency>
-                           <groupId>org.onap.dmaap.messagerouter.msgrtr</groupId>
-                               <artifactId>msgrtr</artifactId>
-                               <version>1.0.0</version>
+                       <groupId>org.onap.dmaap.messagerouter.msgrtr</groupId>
+                       <artifactId>msgrtr</artifactId>
+                       <version>1.1.1</version>
                        <exclusions>
                                <exclusion>
                                        <groupId>org.slf4j</groupId>
 
                        </exclusions>
                </dependency>
-
+               <dependency>
+                       <groupId>org.mockito</groupId>
+                       <artifactId>mockito-core</artifactId>
+                       <version>1.10.19</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.powermock</groupId>
+                       <artifactId>powermock-module-junit4</artifactId>
+                       <version>1.6.4</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.powermock</groupId>
+                       <artifactId>powermock-api-mockito</artifactId>
+                       <version>1.6.4</version>
+                       <scope>test</scope>
+               </dependency>
                <dependency>
                        <groupId>org.codehaus.jackson</groupId>
                        <artifactId>jackson-jaxrs</artifactId>
                        <version>1.9.13</version>
                </dependency>
-               
+
                <dependency>
                        <groupId>org.codehaus.jackson</groupId>
                        <artifactId>jackson-mapper-asl</artifactId>
                        <artifactId>jackson-core-asl</artifactId>
                        <version>1.9.13</version>
                </dependency>
-               
+
                <dependency>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-core</artifactId>
                        <version>2.4.3</version>
                </dependency>
-               
+
                <dependency>
-                   <groupId>com.fasterxml.jackson.core</groupId>
-                   <artifactId>jackson-databind</artifactId>
-                   <version>2.3.3</version>
+                       <groupId>com.fasterxml.jackson.core</groupId>
+                       <artifactId>jackson-databind</artifactId>
+                       <version>2.3.3</version>
                </dependency>
-               
+
                <dependency>
-               <groupId>junit</groupId>
-               <artifactId>junit</artifactId>
-               <version>4.11</version>
-               <scope>test</scope>
-      </dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.11</version>
+                       <scope>test</scope>
+               </dependency>
 
                <dependency>
                        <groupId>org.json</groupId>
                        <!-- <scope>provided</scope> -->
                </dependency>
                <dependency>
-                 <groupId>com.att.ajsc</groupId>
-                 <artifactId>ajsc-archetype-parent</artifactId>
-                 <version>1.0.0</version>
-                 <type>pom</type>
-               </dependency>           
-               
-               <dependency>
+                       <groupId>com.att.ajsc</groupId>
+                       <artifactId>ajsc-archetype-parent</artifactId>
+                       <version>1.0.0</version>
+                       <type>pom</type>
+               </dependency>
+
+               <dependency>
                        <groupId>com.att.cadi</groupId>
                        <artifactId>cadi-aaf</artifactId>
                        <version>1.3.0</version>
-               </dependency>   
-               
-               <dependency>
+               </dependency>
+
+               <dependency>
                        <groupId>com.att.inno</groupId>
                        <artifactId>rosetta</artifactId>
                        <version>1.2.11</version>
-               </dependency>   
-               <dependency>
+               </dependency>
+               <dependency>
                        <groupId>com.att.inno</groupId>
                        <artifactId>env</artifactId>
                        <version>1.2.11</version>
-               </dependency>           
-               <dependency>
+               </dependency>
+               <dependency>
                        <groupId>com.att.inno</groupId>
                        <artifactId>xgen</artifactId>
                        <version>1.2.11</version>
-               </dependency>                           
-               <dependency>
+               </dependency>
+               <dependency>
                        <groupId>com.att.inno</groupId>
                        <artifactId>rosetta</artifactId>
                        <version>1.2.11</version>
-               </dependency>                   
+               </dependency>
                <dependency>
                        <groupId>backport-util-concurrent</groupId>
                        <artifactId>backport-util-concurrent</artifactId>
                        <version>3.1</version>
                </dependency>
                <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-core</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-quartz</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-spring</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-restlet</artifactId>
-                               <version>${camel.version}</version>
-                               <exclusions>
-                                       <exclusion>
-                                               <artifactId>org.restlet</artifactId>
-                                               <groupId>org.restlet.jse</groupId>
-                                       </exclusion>
-                               </exclusions>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-servlet</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-http4</artifactId>
-                               <version>${camel.version}</version>
-                               <exclusions>
-                                       <exclusion>
-                                               <groupId>org.apache.geronimo.specs</groupId>
-                                               <artifactId>geronimo-servlet_2.5_spec</artifactId>
-                                       </exclusion>
-                               </exclusions>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-groovy</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-twitter</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-mail</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-smpp</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-jms</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-script</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-xmpp</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>org.apache.camel</groupId>
-                               <artifactId>camel-velocity</artifactId>
-                               <version>${camel.version}</version>
-                       </dependency>
-                       <dependency>
-                               <groupId>com.att.ajsc</groupId>
-                               <artifactId>ajsc-runner</artifactId>
-                               <version>1.0.0</version>
-                               <scope>runtime</scope>
-                       </dependency>
-                       <dependency>
-                               <groupId>com.att.ajsc</groupId>
-                               <artifactId>ajsc-core</artifactId>
-                               <version>1.0.0</version>
-                               <scope>provided</scope>
-                       </dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-core</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-quartz</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-spring</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-restlet</artifactId>
+                       <version>${camel.version}</version>
+                       <exclusions>
+                               <exclusion>
+                                       <artifactId>org.restlet</artifactId>
+                                       <groupId>org.restlet.jse</groupId>
+                               </exclusion>
+                       </exclusions>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-servlet</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-http4</artifactId>
+                       <version>${camel.version}</version>
+                       <exclusions>
+                               <exclusion>
+                                       <groupId>org.apache.geronimo.specs</groupId>
+                                       <artifactId>geronimo-servlet_2.5_spec</artifactId>
+                               </exclusion>
+                       </exclusions>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-groovy</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-twitter</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-mail</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-smpp</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-jms</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-script</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-xmpp</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.camel</groupId>
+                       <artifactId>camel-velocity</artifactId>
+                       <version>${camel.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.att.ajsc</groupId>
+                       <artifactId>ajsc-runner</artifactId>
+                       <version>1.0.0</version>
+                       <scope>runtime</scope>
+               </dependency>
+               <dependency>
+                       <groupId>com.att.ajsc</groupId>
+                       <artifactId>ajsc-core</artifactId>
+                       <version>1.0.0</version>
+                       <scope>provided</scope>
+               </dependency>
        </dependencies>
        <!-- <build> <resources> <resource> <directory>${basedir}/ajsc-shared-config/etc</directory> 
                </resource> </resources> </build> -->
                <!-- Use this profile to run the AJSC locally. This profile can be successfully 
                        shutdown WITHIN eclipse even in a Windows environment. Debugging is also 
                        available with this profile. -->
-       <profile>
-      <id>docker</id>
-      <properties>
-        
-        <skip.docker.build>false</skip.docker.build>
-        <skip.docker.tag>false</skip.docker.tag>
-        <skip.docker.push>false</skip.docker.push>
-      </properties>
-    </profile>
-    
-    <profile>
+               <profile>
+                       <id>docker</id>
+                       <properties>
+
+                               <skip.docker.build>false</skip.docker.build>
+                               <skip.docker.tag>false</skip.docker.tag>
+                               <skip.docker.push>false</skip.docker.push>
+                       </properties>
+               </profile>
+
+               <profile>
                        <id>runLocal</id>
                        <build>
                                <defaultGoal>initialize</defaultGoal>
                                </plugins>
                        </build>
                </profile>
-       
+
                <profile>
                        <id>runAjsc</id>
                        <build>
                                                <version>2.8.0-01</version>
                                                <extensions>true</extensions>
                                        </plugin>
-                                       
+
                                        <plugin>
                                                <groupId>org.codehaus.mojo</groupId>
                                                <artifactId>exec-maven-plugin</artifactId>
                                                                        </resources>
                                                                </configuration>
                                                        </execution>
-                                       <execution>
-                                               <id>copy-docker-file</id>
-                                               <phase>prepare-package</phase>
-                                               <goals>
-                                                       <goal>copy-resources</goal>
-                                               </goals>
-                                               <configuration>
-                                                       <outputDirectory>${dockerLocation}</outputDirectory>
-                                                       <overwrite>true</overwrite>
-                                                       <resources>
-                                                               <resource>
-                                                                       <directory>${basedir}/src/main/resources/docker</directory>
-                                                                       <filtering>true</filtering>
-                                                                       <includes>
-                                                                               <include>**/*</include>
-                                                                       </includes>
-                                                               </resource>
-                                                       </resources>
-                                               </configuration>
-                                       </execution>
+                                                       <execution>
+                                                               <id>copy-docker-file</id>
+                                                               <phase>prepare-package</phase>
+                                                               <goals>
+                                                                       <goal>copy-resources</goal>
+                                                               </goals>
+                                                               <configuration>
+                                                                       <outputDirectory>${dockerLocation}</outputDirectory>
+                                                                       <overwrite>true</overwrite>
+                                                                       <resources>
+                                                                               <resource>
+                                                                                       <directory>${basedir}/src/main/resources/docker</directory>
+                                                                                       <filtering>true</filtering>
+                                                                                       <includes>
+                                                                                               <include>**/*</include>
+                                                                                       </includes>
+                                                                               </resource>
+                                                                       </resources>
+                                                               </configuration>
+                                                       </execution>
 
                                                </executions>
                                        </plugin>
                        </build>
                </profile>
        </profiles>
-       
+
 </project>
index cda431c..6fbfd01 100644 (file)
@@ -56,9 +56,10 @@ import com.att.nsa.configs.ConfigDbException;
 import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
 import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
+
 /**
- * This class is a CXF REST service which acts 
- * as gateway for MR Event Service.
+ * This class is a CXF REST service which acts as gateway for MR Event Service.
+ * 
  * @author author
  *
  */
@@ -69,7 +70,8 @@ public class EventsRestService {
        /**
         * Logger obj
         */
-       //private Logger log = Logger.getLogger(EventsRestService.class.toString());
+       // private Logger log =
+       // Logger.getLogger(EventsRestService.class.toString());
        private static final EELFLogger log = EELFManager.getInstance().getLogger(EventsRestService.class);
        /**
         * HttpServletRequest obj
@@ -83,7 +85,6 @@ public class EventsRestService {
        @Context
        private HttpServletResponse response;
 
-
        /**
         * Config Reader
         */
@@ -97,6 +98,8 @@ public class EventsRestService {
        @Autowired
        private DMaaPErrorMessages errorMessages;
 
+       private DMaaPContext dmaapContext = new DMaaPContext();
+
        /**
         * This method is used to consume messages.Taking three parameter
         * topic,consumerGroup and consumerId .Consumer decide to which topic they
@@ -118,50 +121,44 @@ public class EventsRestService {
         */
        @GET
        @Path("/{topic}/{consumergroup}/{consumerid}")
-       public void getEvents(@PathParam("topic") String topic, @PathParam("consumergroup") 
-       String consumergroup,
+       public void getEvents(@PathParam("topic") String topic, @PathParam("consumergroup") String consumergroup,
                        @PathParam("consumerid") String consumerid) throws CambriaApiException {
                // log.info("Consuming message from topic " + topic );
-               DMaaPContext dMaaPContext = getDmaapContext();
-               dMaaPContext.setConsumerRequestTime(Utils.getFormattedDate(new Date()));
+               dmaapContext = getDmaapContext();
+               dmaapContext.setConsumerRequestTime(Utils.getFormattedDate(new Date()));
 
                try {
 
-                       eventsService.getEvents(dMaaPContext, topic, consumergroup, consumerid);
-               } 
-               catch (TopicExistsException  e) {
+                       eventsService.getEvents(dmaapContext, topic, consumergroup, consumerid);
+               } catch (TopicExistsException e) {
                        log.error("Error while reading data from topic [" + topic + "].", e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
-                                       DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(), errorMessages.getConsumeMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic, null, null, 
-                                                       consumerid,
-                                       request.getRemoteHost());
+                                       DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getConsumeMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, null, null, consumerid, request.getRemoteHost());
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
 
-               }
-               catch (DMaaPAccessDeniedException | AccessDeniedException  e) {
+               } catch (DMaaPAccessDeniedException | AccessDeniedException e) {
                        log.error("Error while reading data from topic [" + topic + "].", e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
-                                       DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(), errorMessages.getConsumeMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic, null, null, 
-                                                       consumerid,
-                                       request.getRemoteHost());
+                                       DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getConsumeMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, null, null, consumerid, request.getRemoteHost());
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
 
                }
-               
+
                catch (ConfigDbException | UnavailableException | IOException e) {
                        log.error("Error while reading data from topic [" + topic + "].", e);
-               
+
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
-                                       DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(), errorMessages.getConsumeMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic, null, null, 
-                                                       consumerid,
-                                       request.getRemoteHost());
+                                       DMaaPResponseCode.CONSUME_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getConsumeMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, null, null, consumerid, request.getRemoteHost());
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
 
@@ -192,36 +189,33 @@ public class EventsRestService {
 
                try {
                        eventsService.pushEvents(getDmaapContext(), topic, msg, partitionKey, null);
-               } 
-               catch ( TopicExistsException  e) {
+               } catch (TopicExistsException e) {
                        log.error("Error while publishing to topic [" + topic + "].", e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
-                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
-                                       Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-               }
-               catch ( DMaaPAccessDeniedException | AccessDeniedException  e) {
+               } catch (DMaaPAccessDeniedException | AccessDeniedException e) {
                        log.error("Error while publishing to topic [" + topic + "].", e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
-                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
-                                       Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
                }
-               
-               
-               catch (ConfigDbException |   IOException | missingReqdSetting e) {
+
+               catch (ConfigDbException | IOException | missingReqdSetting e) {
                        log.error("Error while publishing to topic [" + topic + "].", e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
-                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
-                                       Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
                }
@@ -250,40 +244,37 @@ public class EventsRestService {
                // );
 
                try {
-                       eventsService.pushEvents(getDmaapContext(), topic, request.getInputStream(), 
-                                       partitionKey,
+                       eventsService.pushEvents(getDmaapContext(), topic, request.getInputStream(), partitionKey,
                                        Utils.getFormattedDate(new Date()));
-               } 
-               
-               catch ( TopicExistsException  e) {
+               }
+
+               catch (TopicExistsException e) {
                        log.error("Error while publishing to topic [" + topic + "].", e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
-                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
-                                       Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-               }
-               catch ( DMaaPAccessDeniedException| AccessDeniedException  e) {
+               } catch (DMaaPAccessDeniedException | AccessDeniedException e) {
                        log.error("Error while publishing to topic [" + topic + "].", e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
-                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), errorMessages.getPublishMsgError()
-                                                       + e.getMessage(), null, Utils.getFormattedDate(new Date()), topic,
-                                       Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
+                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+                                       errorMessages.getPublishMsgError() + e.getMessage(), null, Utils.getFormattedDate(new Date()),
+                                       topic, Utils.getUserApiKey(request), request.getRemoteHost(), null, null);
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
                }
-               
-               catch (ConfigDbException  | IOException | missingReqdSetting  e) {
+
+               catch (ConfigDbException | IOException | missingReqdSetting e) {
                        log.error("Error while publishing to topic : " + topic, e);
 
                        ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
-                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(), "Transaction-"
-                                                       + errorMessages.getPublishMsgError() + e.getMessage(), null,
-                                       Utils.getFormattedDate(new Date()), topic, Utils.getUserApiKey(request), 
-                                       request.getRemoteHost(),
+                                       DMaaPResponseCode.PUBLISH_MSG_ERROR.getResponseCode(),
+                                       "Transaction-" + errorMessages.getPublishMsgError() + e.getMessage(), null,
+                                       Utils.getFormattedDate(new Date()), topic, Utils.getUserApiKey(request), request.getRemoteHost(),
                                        null, null);
                        log.info(errRes.toString());
                        throw new CambriaApiException(errRes);
@@ -302,7 +293,6 @@ public class EventsRestService {
         */
        private DMaaPContext getDmaapContext() {
 
-               DMaaPContext dmaapContext = new DMaaPContext();
                dmaapContext.setRequest(request);
                dmaapContext.setResponse(response);
                dmaapContext.setConfigReader(configReader);
index ab457e5..a715e1f 100644 (file)
@@ -27,7 +27,6 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.POST;
@@ -115,6 +114,8 @@ public class MMRestService {
        @Autowired
        private DMaaPErrorMessages errorMessages;
 
+       private DMaaPAAFAuthenticator dmaapAAFauthenticator = new DMaaPAAFAuthenticatorImpl();
+
        /**
         * This method is used for taking Configuration Object,HttpServletRequest
         * Object,HttpServletRequest HttpServletResponse Object,HttpServletSession
@@ -178,7 +179,7 @@ public class MMRestService {
                                                || createMirrorMaker.getCreateMirrorMaker().getStatus() != null) {
                                        sendErrResponse(ctx, "This is not a CreateMirrorMaker request. Please try again.");
                                }
-                               
+
                                // if empty, blank name is entered
                                else if (StringUtils.isBlank(name)) {
                                        sendErrResponse(ctx, "Name can not be empty or blank.");
@@ -253,8 +254,8 @@ public class MMRestService {
 
                                // Check if request has listAllMirrorMaker and
                                // listAllMirrorMaker is empty
-                               if ((jsonOb != null) && (jsonOb.has("listAllMirrorMaker") &&
-                                    jsonOb.getJSONObject("listAllMirrorMaker").length() == 0)) {
+                               if ((jsonOb != null) && (jsonOb.has("listAllMirrorMaker")
+                                               && jsonOb.getJSONObject("listAllMirrorMaker").length() == 0)) {
                                        jsonOb.put("messageID", randomStr);
                                        InputStream inStream = null;
 
@@ -329,7 +330,7 @@ public class MMRestService {
                                                || updateMirrorMaker.getUpdateMirrorMaker().getStatus() != null) {
                                        sendErrResponse(ctx, "This is not a UpdateMirrorMaker request. Please try again.");
                                }
-                               
+
                                // if empty, blank name is entered
                                else if (StringUtils.isBlank(name)) {
                                        sendErrResponse(ctx, "Name can not be empty or blank.");
@@ -405,11 +406,11 @@ public class MMRestService {
                                // Check if request has DeleteMirrorMaker and
                                // DeleteMirrorMaker has MirrorMaker object with name variable
                                // and check if the name contain only alpha numeric
-                               if ((jsonOb != null) && (jsonOb.has("deleteMirrorMaker") 
-                                               && jsonOb.getJSONObject("deleteMirrorMaker").length() == 1
-                                               && jsonOb.getJSONObject("deleteMirrorMaker").has("name") 
-                                               && !StringUtils.isBlank(jsonOb.getJSONObject("deleteMirrorMaker").getString("name"))
-                                               && isAlphaNumeric(jsonOb.getJSONObject("deleteMirrorMaker").getString("name")))) {
+                               if ((jsonOb != null)
+                                               && (jsonOb.has("deleteMirrorMaker") && jsonOb.getJSONObject("deleteMirrorMaker").length() == 1
+                                                               && jsonOb.getJSONObject("deleteMirrorMaker").has("name")
+                                                               && !StringUtils.isBlank(jsonOb.getJSONObject("deleteMirrorMaker").getString("name"))
+                                                               && isAlphaNumeric(jsonOb.getJSONObject("deleteMirrorMaker").getString("name")))) {
 
                                        jsonOb.put("messageID", randomStr);
                                        InputStream inStream = null;
@@ -451,7 +452,7 @@ public class MMRestService {
 
                        for (int i = 0; i < jArray.length(); i++) {
                                jObj = jArray.getJSONObject(i);
-                               
+
                                JSONObject obj = new JSONObject();
                                if (jObj.has(MESSAGE)) {
                                        obj = jObj.getJSONObject(MESSAGE);
@@ -526,9 +527,7 @@ public class MMRestService {
 
                boolean hasPermission = false;
 
-               DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-
-               if (aaf.aafAuthentication(ctx.getRequest(), permission)) {
+               if (dmaapAAFauthenticator.aafAuthentication(ctx.getRequest(), permission)) {
                        hasPermission = true;
                }
                return hasPermission;
@@ -556,7 +555,7 @@ public class MMRestService {
 
                                for (int i = 0; i < jsonArray.length(); i++) {
                                        jsonObj = jsonArray.getJSONObject(i);
-                                       
+
                                        JSONObject obj = new JSONObject();
                                        if (jsonObj.has(MESSAGE)) {
                                                obj = jsonObj.getJSONObject(MESSAGE);
@@ -577,7 +576,7 @@ public class MMRestService {
                        }
 
                } catch (Exception e) {
-                       LOGGER.error("Exception: ", e);                 
+                       LOGGER.error("Exception: ", e);
                }
        }
 
@@ -630,11 +629,9 @@ public class MMRestService {
                                // numeric
                                // and check if the request has namespace and namespace contains
                                // only alpha numeric
-                               if (jsonOb != null 
-                                               && jsonOb.length() == 2 && jsonOb.has("name")
-                                               && !StringUtils.isBlank(jsonOb.getString("name"))
-                                               && isAlphaNumeric(jsonOb.getString("name")) && jsonOb.has(NAMESPACE)
-                                               && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))) {
+                               if (jsonOb != null && jsonOb.length() == 2 && jsonOb.has("name")
+                                               && !StringUtils.isBlank(jsonOb.getString("name")) && isAlphaNumeric(jsonOb.getString("name"))
+                                               && jsonOb.has(NAMESPACE) && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))) {
 
                                        String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
                                                        "msgRtr.mirrormakeruser.aaf.create") + jsonOb.getString(NAMESPACE) + "|create";
@@ -681,7 +678,7 @@ public class MMRestService {
 
                                                if (msgFrmSubscribe != null && msgFrmSubscribe.length() > 0
                                                                && isListMirrorMaker(msgFrmSubscribe, randomStr)) {
-                                                       
+
                                                        JSONArray listMirrorMaker;
                                                        listMirrorMaker = getListMirrorMaker(msgFrmSubscribe, randomStr);
 
@@ -784,16 +781,18 @@ public class MMRestService {
                                        LOGGER.error("JSONException: ", ex);
                                }
 
-                               // Check if the request has name and name contains only alpha numeric,
+                               // Check if the request has name and name contains only alpha
+                               // numeric,
                                // check if the request has namespace and
                                // check if the request has whitelistTopicName
                                // check if the topic name contains only alpha numeric
                                if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name")
-                                               && !StringUtils.isBlank(jsonOb.getString("name")) 
-                                               && isAlphaNumeric(jsonOb.getString("name")) 
+                                               && !StringUtils.isBlank(jsonOb.getString("name")) && isAlphaNumeric(jsonOb.getString("name"))
                                                && jsonOb.has(NAMESPACE) && !StringUtils.isBlank(jsonOb.getString(NAMESPACE))
-                                               && jsonOb.has("whitelistTopicName") && !StringUtils.isBlank(jsonOb.getString("whitelistTopicName"))
-                                               && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(jsonOb.getString("whitelistTopicName").lastIndexOf(".")+1, 
+                                               && jsonOb.has("whitelistTopicName")
+                                               && !StringUtils.isBlank(jsonOb.getString("whitelistTopicName"))
+                                               && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(
+                                                               jsonOb.getString("whitelistTopicName").lastIndexOf(".") + 1,
                                                                jsonOb.getString("whitelistTopicName").length()))) {
 
                                        String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
@@ -843,7 +842,7 @@ public class MMRestService {
 
                                                if (msgFrmSubscribe != null && msgFrmSubscribe.length() > 0
                                                                && isListMirrorMaker(msgFrmSubscribe, randomStr)) {
-                                                       
+
                                                        listMirrorMaker = getListMirrorMaker(msgFrmSubscribe, randomStr);
                                                        String whitelist = null;
 
@@ -967,12 +966,15 @@ public class MMRestService {
                                        LOGGER.error("JSONException: ", ex);
                                }
 
-                               // Check if the request has name and name contains only alpha numeric,
+                               // Check if the request has name and name contains only alpha
+                               // numeric,
                                // check if the request has namespace and
                                // check if the request has whitelistTopicName
-                               if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name") && isAlphaNumeric(jsonOb.getString("name"))
-                                               && jsonOb.has(NAMESPACE) && jsonOb.has("whitelistTopicName") 
-                                               && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(jsonOb.getString("whitelistTopicName").lastIndexOf(".")+1, 
+                               if (jsonOb != null && jsonOb.length() == 3 && jsonOb.has("name")
+                                               && isAlphaNumeric(jsonOb.getString("name")) && jsonOb.has(NAMESPACE)
+                                               && jsonOb.has("whitelistTopicName")
+                                               && isAlphaNumeric(jsonOb.getString("whitelistTopicName").substring(
+                                                               jsonOb.getString("whitelistTopicName").lastIndexOf(".") + 1,
                                                                jsonOb.getString("whitelistTopicName").length()))) {
 
                                        String permission = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,
@@ -1029,12 +1031,13 @@ public class MMRestService {
 
                                                        for (int i = 0; i < jsonArray.length(); i++) {
                                                                jsonObj = jsonArray.getJSONObject(i);
-                                                               
+
                                                                JSONObject obj = new JSONObject();
                                                                if (jsonObj.has(MESSAGE)) {
                                                                        obj = jsonObj.getJSONObject(MESSAGE);
                                                                }
-                                                               if (obj.has("messageID") && obj.get("messageID").equals(randomStr) && obj.has(LISTMIRRORMAKER)) {
+                                                               if (obj.has("messageID") && obj.get("messageID").equals(randomStr)
+                                                                               && obj.has(LISTMIRRORMAKER)) {
                                                                        listMirrorMaker = obj.getJSONArray(LISTMIRRORMAKER);
                                                                        break;
                                                                }
@@ -1068,22 +1071,21 @@ public class MMRestService {
                                                                sendErrResponse(ctx, "The topic does not exist.");
                                                        }
 
-
                                                        if (removeTopic) {
                                                                UpdateWhiteList updateWhiteList = new UpdateWhiteList();
                                                                MirrorMaker mirrorMaker = new MirrorMaker();
-                                                               
+
                                                                mirrorMaker.setName(jsonOb.getString("name"));
                                                                mirrorMaker.setWhitelist(removeTopic(whitelist, topicToRemove));
-                                                       
+
                                                                String newRandom = getRandomNum();
-                                                               
+
                                                                updateWhiteList.setMessageID(newRandom);
                                                                updateWhiteList.setUpdateWhiteList(mirrorMaker);
-                                                               
+
                                                                Gson g = new Gson();
                                                                g.toJson(updateWhiteList);
-                                                               
+
                                                                InputStream inputStream;
                                                                inputStream = IOUtils.toInputStream(g.toJson(updateWhiteList), UTF_8);
                                                                callPubSubForWhitelist(newRandom, ctx, inputStream, getNamespace(topicToRemove));
@@ -1132,7 +1134,7 @@ public class MMRestService {
                }
 
                if (topicList.contains(topicToRemove)) {
-                       for (String topic: topicList) {
+                       for (String topic : topicList) {
                                if (!topic.equals(topicToRemove)) {
                                        newTopicList.add(topic);
                                }
@@ -1145,7 +1147,7 @@ public class MMRestService {
        }
 
        private void callPubSubForWhitelist(String randomStr, DMaaPContext ctx, InputStream inStream, String namespace) {
-               
+
                try {
                        mirrorService.pushEvents(ctx, topic, inStream, null, null);
                        long startTime = System.currentTimeMillis();
@@ -1167,7 +1169,7 @@ public class MMRestService {
 
                                for (int i = 0; i < jsonArray.length(); i++) {
                                        jsonObj = jsonArray.getJSONObject(i);
-                                       
+
                                        JSONObject obj = new JSONObject();
                                        if (jsonObj.has(MESSAGE)) {
                                                obj = jsonObj.getJSONObject(MESSAGE);
@@ -1231,18 +1233,18 @@ public class MMRestService {
 
                return whitelist;
        }
-       
+
        private JSONArray getListMirrorMaker(String msgFrmSubscribe, String randomStr) {
                JSONObject jsonObj;
                JSONArray jsonArray;
                JSONArray listMirrorMaker = new JSONArray();
-               
+
                msgFrmSubscribe = removeExtraChar(msgFrmSubscribe);
                jsonArray = new JSONArray(msgFrmSubscribe);
 
                for (int i = 0; i < jsonArray.length(); i++) {
                        jsonObj = jsonArray.getJSONObject(i);
-                       
+
                        JSONObject obj = new JSONObject();
                        if (jsonObj.has(MESSAGE)) {
                                obj = jsonObj.getJSONObject(MESSAGE);
@@ -1252,6 +1254,6 @@ public class MMRestService {
                                break;
                        }
                }
-               return listMirrorMaker;         
+               return listMirrorMaker;
        }
 }
index 6742cd5..50bd069 100644 (file)
@@ -62,8 +62,8 @@ import com.att.nsa.configs.ConfigDbException;
 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
 
 /**
- * This class is a CXF REST service which acts 
- * as gateway for MR Topic Service.
+ * This class is a CXF REST service which acts as gateway for MR Topic Service.
+ * 
  * @author author
  *
  */
@@ -75,7 +75,8 @@ public class TopicRestService {
        /**
         * Logger obj
         */
-       //private static final Logger LOGGER = Logger           .getLogger(TopicRestService.class);
+       // private static final Logger LOGGER = Logger
+       // .getLogger(TopicRestService.class);
        private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(TopicRestService.class);
        /**
         * Config Reader
@@ -100,76 +101,72 @@ public class TopicRestService {
         * TopicService obj
         */
        @Autowired
-       private TopicService topicService;
-       
+       private TopicService tService;
+
        /**
         * DMaaPErrorMessages obj
         */
        @Autowired
        private DMaaPErrorMessages errorMessages;
-       
+
+       private DMaaPContext dmaapContext = new DMaaPContext();
+
        /**
         * mrNamespace
         */
-       //@Value("${msgRtr.namespace.aaf}")
-//     private String mrNamespace;
-       
+       // @Value("${msgRtr.namespace.aaf}")
+       // private String mrNamespace;
 
        /**
         * Fetches a list of topics from the current kafka instance and converted
         * into json object.
         * 
         * @return list of the topics in json format
-        * @throws AccessDeniedException 
-        * @throws CambriaApiException 
+        * @throws AccessDeniedException
+        * @throws CambriaApiException
         * @throws IOException
         * @throws JSONException
-        * */
+        */
        @GET
-       //@Produces(MediaType.TEXT_PLAIN)
+       // @Produces(MediaType.TEXT_PLAIN)
        public void getTopics() throws CambriaApiException {
                try {
-                                               
+
                        LOGGER.info("Authenticating the user before fetching the topics");
-                       //String permission = "com.att.dmaap.mr.topic|*|view";
-                       String mrNameS= com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,"msgRtr.namespace.aaf");
-                       String permission =mrNameS+"|"+"*"+"|"+"view";
+                       // String permission = "com.att.dmaap.mr.topic|*|view";
+                       String mrNameS = com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,
+                                       "msgRtr.namespace.aaf");
+                       String permission = mrNameS + "|" + "*" + "|" + "view";
                        DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-                       //Check if client is using AAF CADI Basic Authorization
-                       //If yes then check for AAF role authentication else display all topics 
-                       if(null!=getDmaapContext().getRequest().getHeader("Authorization"))
-                       {
-                               if(!aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
-                               {
-                               
-                                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-                                                       DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(), 
-                                                       errorMessages.getNotPermitted1()+" read "+errorMessages.getNotPermitted2());
+                       // Check if client is using AAF CADI Basic Authorization
+                       // If yes then check for AAF role authentication else display all
+                       // topics
+                       if (null != getDmaapContext().getRequest().getHeader("Authorization")) {
+                               if (!aaf.aafAuthentication(getDmaapContext().getRequest(), permission)) {
+
+                                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                                                       DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+                                                       errorMessages.getNotPermitted1() + " read " + errorMessages.getNotPermitted2());
                                        LOGGER.info(errRes.toString());
                                        throw new DMaaPAccessDeniedException(errRes);
-                                       
-                               
+
                                }
-                       }       
-                       
-                               LOGGER.info("Fetching all Topics");
-                               
-                               topicService.getTopics(getDmaapContext());
-       
-                               LOGGER.info("Returning List of all Topics");
-                       
-                       
+                       }
+
+                       LOGGER.info("Fetching all Topics");
+
+                       tService.getTopics(getDmaapContext());
+
+                       LOGGER.info("Returning List of all Topics");
+
                } catch (JSONException | ConfigDbException | IOException excp) {
-                       LOGGER.error(
-                                       "Failed to retrieve list of all topics: "
-                                                       + excp.getMessage(), excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND, 
-                                       DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(), 
-                                       errorMessages.getTopicsfailure()+ excp.getMessage());
+                       LOGGER.error("Failed to retrieve list of all topics: " + excp.getMessage(), excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(),
+                                       errorMessages.getTopicsfailure() + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
 
                }
        }
@@ -179,62 +176,56 @@ public class TopicRestService {
         * into json object.
         * 
         * @return list of the topics in json format
-        * @throws AccessDeniedException 
-        * @throws CambriaApiException 
+        * @throws AccessDeniedException
+        * @throws CambriaApiException
         * @throws IOException
         * @throws JSONException
-        * */
+        */
        @GET
        @Path("/listAll")
-       //@Produces(MediaType.TEXT_PLAIN)
+       // @Produces(MediaType.TEXT_PLAIN)
        public void getAllTopics() throws CambriaApiException {
                try {
-                                               
+
                        LOGGER.info("Authenticating the user before fetching the topics");
-                       //String permission = "com.att.dmaap.mr.topic|*|view";
-                       String mrNameS= com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,"msgRtr.namespace.aaf");
-                       String permission =mrNameS+"|"+"*"+"|"+"view";
+                       // String permission = "com.att.dmaap.mr.topic|*|view";
+                       String mrNameS = com.att.ajsc.beans.PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop,
+                                       "msgRtr.namespace.aaf");
+                       String permission = mrNameS + "|" + "*" + "|" + "view";
                        DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-                       //Check if client is using AAF CADI Basic Authorization
-                       //If yes then check for AAF role authentication else display all topics 
-                       if(null!=getDmaapContext().getRequest().getHeader("Authorization"))
-                       {
-                               if(!aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
-                               {
-                               
-                                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-                                                       DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(), 
-                                                       errorMessages.getNotPermitted1()+" read "+errorMessages.getNotPermitted2());
+                       // Check if client is using AAF CADI Basic Authorization
+                       // If yes then check for AAF role authentication else display all
+                       // topics
+                       if (null != getDmaapContext().getRequest().getHeader("Authorization")) {
+                               if (!aaf.aafAuthentication(getDmaapContext().getRequest(), permission)) {
+
+                                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                                                       DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+                                                       errorMessages.getNotPermitted1() + " read " + errorMessages.getNotPermitted2());
                                        LOGGER.info(errRes.toString());
                                        throw new DMaaPAccessDeniedException(errRes);
-                                       
-                               
+
                                }
-                       }       
-                       
-                               LOGGER.info("Fetching all Topics");
-                               
-                               topicService.getAllTopics(getDmaapContext());
-       
-                               LOGGER.info("Returning List of all Topics");
-                       
-                       
+                       }
+
+                       LOGGER.info("Fetching all Topics");
+
+                       tService.getAllTopics(getDmaapContext());
+
+                       LOGGER.info("Returning List of all Topics");
+
                } catch (JSONException | ConfigDbException | IOException excp) {
-                       LOGGER.error(
-                                       "Failed to retrieve list of all topics: "
-                                                       + excp.getMessage(), excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND, 
-                                       DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(), 
-                                       errorMessages.getTopicsfailure()+ excp.getMessage());
+                       LOGGER.error("Failed to retrieve list of all topics: " + excp.getMessage(), excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       DMaaPResponseCode.GET_TOPICS_FAIL.getResponseCode(),
+                                       errorMessages.getTopicsfailure() + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
 
                }
        }
 
-       
        /**
         * Returns details of the topic whose name is passed as a parameter
         * 
@@ -242,59 +233,55 @@ public class TopicRestService {
         *            - name of the topic
         * @return details of a topic whose name is mentioned in the request in json
         *         format.
-        * @throws AccessDeniedException 
-        * @throws DMaaPAccessDeniedException 
+        * @throws AccessDeniedException
+        * @throws DMaaPAccessDeniedException
         * @throws IOException
-        * */
+        */
        @GET
        @Path("/{topicName}")
-       //@Produces(MediaType.TEXT_PLAIN)
+       // @Produces(MediaType.TEXT_PLAIN)
        public void getTopic(@PathParam("topicName") String topicName) throws CambriaApiException {
                try {
-                       
-                       LOGGER.info("Authenticating the user before fetching the details about topic = "+ topicName);
+
+                       LOGGER.info("Authenticating the user before fetching the details about topic = " + topicName);
                        DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-                       
-                       //String permission= "com.att.ecomp_test.crm.mr.topic|:topic.com.att.ecomp_test.crm.preDemo|view";
-                       
-                       //Check if client is using AAF CADI Basic Authorization
-                       //If yes then check for AAF role authentication else display all topics 
-                       if(null!=getDmaapContext().getRequest().getHeader("Authorization"))
-                       {
+
+                       // String permission=
+                       // "com.att.ecomp_test.crm.mr.topic|:topic.com.att.ecomp_test.crm.preDemo|view";
+
+                       // Check if client is using AAF CADI Basic Authorization
+                       // If yes then check for AAF role authentication else display all
+                       // topics
+                       if (null != getDmaapContext().getRequest().getHeader("Authorization")) {
                                String permission = aaf.aafPermissionString(topicName, "view");
-                               if(!aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
-                               {
-                                               
-                                               ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-                                                               DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(), 
-                                                               errorMessages.getNotPermitted1()+" read "+errorMessages.getNotPermitted2());
-                                               LOGGER.info(errRes.toString());
-                                               throw new DMaaPAccessDeniedException(errRes);
-                                       }
-                       } 
-                       
-                               LOGGER.info("Fetching Topic: " + topicName);
-                               
-                               topicService.getTopic(getDmaapContext(), topicName);
-
-                               LOGGER.info("Fetched details of topic: " + topicName);
-               
+                               if (!aaf.aafAuthentication(getDmaapContext().getRequest(), permission)) {
+
+                                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                                                       DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+                                                       errorMessages.getNotPermitted1() + " read " + errorMessages.getNotPermitted2());
+                                       LOGGER.info(errRes.toString());
+                                       throw new DMaaPAccessDeniedException(errRes);
+                               }
+                       }
+
+                       LOGGER.info("Fetching Topic: " + topicName);
+
+                       tService.getTopic(getDmaapContext(), topicName);
+
+                       LOGGER.info("Fetched details of topic: " + topicName);
+
                } catch (ConfigDbException | IOException | TopicExistsException excp) {
-                       LOGGER.error("Failed to retrieve details of topic: " + topicName,
-                                       excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND, 
-                                       DMaaPResponseCode.GET_TOPICS_DETAILS_FAIL.getResponseCode(), 
-                                       errorMessages.getTopicDetailsFail()+topicName+ excp.getMessage());
+                       LOGGER.error("Failed to retrieve details of topic: " + topicName, excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       DMaaPResponseCode.GET_TOPICS_DETAILS_FAIL.getResponseCode(),
+                                       errorMessages.getTopicDetailsFail() + topicName + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
-                       
+
                }
        }
 
-       
-       
        /**
         * This method is still not working. Need to check on post call and how to
         * accept parameters for post call
@@ -303,57 +290,50 @@ public class TopicRestService {
         *            it will have the bean object
         * @throws TopicExistsException
         * @throws CambriaApiException
-        * @throws JSONException 
+        * @throws JSONException
         * @throws IOException
         * @throws AccessDeniedException
         * 
-        * */
+        */
        @POST
        @Path("/create")
        @Consumes({ MediaType.APPLICATION_JSON })
-       //@Produces(MediaType.TEXT_PLAIN)
+       // @Produces(MediaType.TEXT_PLAIN)
        public void createTopic(TopicBean topicBean) throws CambriaApiException, JSONException {
-       try {
-                       LOGGER.info("Creating Topic."+topicBean.getTopicName());
-               
-                       topicService.createTopic(getDmaapContext(), topicBean);
+               try {
+                       LOGGER.info("Creating Topic." + topicBean.getTopicName());
+
+                       tService.createTopic(getDmaapContext(), topicBean);
 
                        LOGGER.info("Topic created Successfully.");
-               } 
-       catch (TopicExistsException ex){
-               
-               LOGGER.error("Error while creating a topic: " + ex.getMessage(),
-                               ex);
-               
-               ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT, 
-                               DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(), 
-                               errorMessages.getCreateTopicFail()+ ex.getMessage());
-               LOGGER.info(errRes.toString());
-               throw new CambriaApiException(errRes);
-               
-               
-       
-       
-               }catch (AccessDeniedException | DMaaPAccessDeniedException excp) {
-                       LOGGER.error("Error while creating a topic: " + excp.getMessage(),
-                                       excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, 
-                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(), 
-                                       errorMessages.getCreateTopicFail()+ excp.getMessage());
+               } catch (TopicExistsException ex) {
+
+                       LOGGER.error("Error while creating a topic: " + ex.getMessage(), ex);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_CONFLICT,
+                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getCreateTopicFail() + ex.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
-               }catch (CambriaApiException |  IOException                       excp) {
-                       LOGGER.error("Error while creating a topic: " + excp.getMessage(),
-                                       excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND, 
-                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(), 
-                                       errorMessages.getCreateTopicFail()+ excp.getMessage());
+
+               } catch (AccessDeniedException | DMaaPAccessDeniedException excp) {
+                       LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getCreateTopicFail() + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
+
+               } catch (CambriaApiException | IOException excp) {
+                       LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getCreateTopicFail() + excp.getMessage());
+                       LOGGER.info(errRes.toString());
+                       throw new CambriaApiException(errRes);
+
                }
        }
 
@@ -362,45 +342,42 @@ public class TopicRestService {
         * 
         * @param topicName
         *            topic
-        * @throws CambriaApiException 
+        * @throws CambriaApiException
         * @throws IOException
-        * */
+        */
        @DELETE
        @Path("/{topicName}")
-       //@Produces(MediaType.TEXT_PLAIN)
+       // @Produces(MediaType.TEXT_PLAIN)
        public void deleteTopic(@PathParam("topicName") String topicName) throws CambriaApiException {
                try {
                        LOGGER.info("Deleting Topic: " + topicName);
 
-                       topicService.deleteTopic(getDmaapContext(), topicName);
+                       tService.deleteTopic(getDmaapContext(), topicName);
 
                        LOGGER.info("Topic [" + topicName + "] deleted successfully.");
-               } catch (DMaaPAccessDeniedException| AccessDeniedException excp) {
-                       LOGGER.error("Error while creating a topic: " + excp.getMessage(),
-                                       excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, 
-                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(), 
-                                       errorMessages.getCreateTopicFail()+ excp.getMessage());
+               } catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
+                       LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getCreateTopicFail() + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
-       }catch (IOException | ConfigDbException
-                               | CambriaApiException | TopicExistsException excp) {
+
+               } catch (IOException | ConfigDbException | CambriaApiException | TopicExistsException excp) {
                        LOGGER.error("Error while deleting topic: " + topicName, excp);
-               
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND, 
-                                       DMaaPResponseCode.DELETE_TOPIC_FAIL.getResponseCode(), 
-                                       errorMessages.getDeleteTopicFail()+ topicName + excp.getMessage());
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       DMaaPResponseCode.DELETE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getDeleteTopicFail() + topicName + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
+
                }
        }
 
        private DMaaPContext getDmaapContext() {
 
-               DMaaPContext dmaapContext = new DMaaPContext();
                dmaapContext.setRequest(request);
                dmaapContext.setResponse(response);
                dmaapContext.setConfigReader(configReader);
@@ -413,49 +390,48 @@ public class TopicRestService {
         * This method will fetch the details of publisher by giving topic name
         * 
         * @param topicName
-        * @throws CambriaApiException 
-        * @throws AccessDeniedException 
+        * @throws CambriaApiException
+        * @throws AccessDeniedException
         */
        @GET
        @Path("/{topicName}/producers")
-       //@Produces(MediaType.TEXT_PLAIN)
-       public void getPublishersByTopicName(
-                       @PathParam("topicName") String topicName) throws CambriaApiException {
+       // @Produces(MediaType.TEXT_PLAIN)
+       public void getPublishersByTopicName(@PathParam("topicName") String topicName) throws CambriaApiException {
                try {
-                       
-//                     String permission = "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"manage";
-//                     DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-//                     String permission = aaf.aafPermissionString(topicName, "view");
-//                     if(aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
-//                     {
-                               LOGGER.info("Fetching list of all the publishers for topic "
-                                               + topicName);
-
-                               topicService.getPublishersByTopicName(getDmaapContext(), topicName);
-
-                               LOGGER.info("Returning list of all the publishers for topic "
-                                               + topicName);
-//                     }else{
-//                             LOGGER.error("Error while fetching list of publishers for topic "+ topicName);
-//                             
-//                             ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-//                                             DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(), 
-//                                             errorMessages.getNotPermitted1()+" fetch list of publishers "+errorMessages.getNotPermitted2());
-//                             LOGGER.info(errRes);
-//                             throw new DMaaPAccessDeniedException(errRes);
-//                             
-//                     }
-                       
+
+                       // String permission =
+                       // "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"manage";
+                       // DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
+                       // String permission = aaf.aafPermissionString(topicName, "view");
+                       // if(aaf.aafAuthentication(getDmaapContext().getRequest(),
+                       // permission))
+                       // {
+                       LOGGER.info("Fetching list of all the publishers for topic " + topicName);
+
+                       tService.getPublishersByTopicName(getDmaapContext(), topicName);
+
+                       LOGGER.info("Returning list of all the publishers for topic " + topicName);
+                       // }else{
+                       // LOGGER.error("Error while fetching list of publishers for topic
+                       // "+ topicName);
+                       //
+                       // ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                       // DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+                       // errorMessages.getNotPermitted1()+" fetch list of publishers
+                       // "+errorMessages.getNotPermitted2());
+                       // LOGGER.info(errRes);
+                       // throw new DMaaPAccessDeniedException(errRes);
+                       //
+                       // }
+
                } catch (IOException | ConfigDbException | TopicExistsException excp) {
-                       LOGGER.error("Error while fetching list of publishers for topic "
-                                       + topicName, excp);
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND, 
-                                       DMaaPResponseCode.GET_PUBLISHERS_BY_TOPIC.getResponseCode(), 
-                                       "Error while fetching list of publishers for topic: "
-                                                       + topicName + excp.getMessage());
+                       LOGGER.error("Error while fetching list of publishers for topic " + topicName, excp);
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       DMaaPResponseCode.GET_PUBLISHERS_BY_TOPIC.getResponseCode(),
+                                       "Error while fetching list of publishers for topic: " + topicName + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
+
                }
        }
 
@@ -464,44 +440,38 @@ public class TopicRestService {
         * 
         * @param topicName
         * @param producerId
-        * @throws CambriaApiException 
+        * @throws CambriaApiException
         */
        @PUT
        @Path("/{topicName}/producers/{producerId}")
-       public void permitPublisherForTopic(
-                       @PathParam("topicName") String topicName,
+       public void permitPublisherForTopic(@PathParam("topicName") String topicName,
                        @PathParam("producerId") String producerId) throws CambriaApiException {
                try {
-                       LOGGER.info("Granting write access to producer [" + producerId
-                                       + "] for topic " + topicName);
+                       LOGGER.info("Granting write access to producer [" + producerId + "] for topic " + topicName);
 
-                       topicService.permitPublisherForTopic(getDmaapContext(), topicName,
-                                       producerId);
+                       tService.permitPublisherForTopic(getDmaapContext(), topicName, producerId);
 
-                       LOGGER.info("Write access has been granted to producer ["
-                                       + producerId + "] for topic " + topicName);
+                       LOGGER.info("Write access has been granted to producer [" + producerId + "] for topic " + topicName);
                } catch (AccessDeniedException | DMaaPAccessDeniedException excp) {
-                       LOGGER.error("Error while creating a topic: " + excp.getMessage(),
-                                       excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, 
-                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(), 
-                                       errorMessages.getCreateTopicFail()+ excp.getMessage());
+                       LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getCreateTopicFail() + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
-         }catch ( ConfigDbException | IOException
-                               | TopicExistsException excp) {
-                       LOGGER.error("Error while granting write access to producer ["
-                                       + producerId + "] for topic " + topicName, excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND, 
-                                       DMaaPResponseCode.PERMIT_PUBLISHER_FOR_TOPIC.getResponseCode(), 
-                                       "Error while granting write access to producer ["
-                                                       + producerId + "] for topic " + topicName + excp.getMessage());
+
+               } catch (ConfigDbException | IOException | TopicExistsException excp) {
+                       LOGGER.error("Error while granting write access to producer [" + producerId + "] for topic " + topicName,
+                                       excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
+                                       DMaaPResponseCode.PERMIT_PUBLISHER_FOR_TOPIC.getResponseCode(),
+                                       "Error while granting write access to producer [" + producerId + "] for topic " + topicName
+                                                       + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
+
                }
        }
 
@@ -510,39 +480,34 @@ public class TopicRestService {
         * 
         * @param topicName
         * @param producerId
-        * @throws CambriaApiException 
+        * @throws CambriaApiException
         */
        @DELETE
        @Path("/{topicName}/producers/{producerId}")
        public void denyPublisherForTopic(@PathParam("topicName") String topicName,
                        @PathParam("producerId") String producerId) throws CambriaApiException {
                try {
-                       LOGGER.info("Revoking write access to producer [" + producerId
-                                       + "] for topic " + topicName);
+                       LOGGER.info("Revoking write access to producer [" + producerId + "] for topic " + topicName);
 
-                       topicService.denyPublisherForTopic(getDmaapContext(), topicName,
-                                       producerId);
+                       tService.denyPublisherForTopic(getDmaapContext(), topicName, producerId);
 
-                       LOGGER.info("Write access revoked for producer [" + producerId
-                                       + "] for topic " + topicName);
+                       LOGGER.info("Write access revoked for producer [" + producerId + "] for topic " + topicName);
                } catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
-                       LOGGER.error("Error while creating a topic: " + excp.getMessage(),
-                                       excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, 
-                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(), 
-                                       errorMessages.getCreateTopicFail()+ excp.getMessage());
+                       LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getCreateTopicFail() + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
-       }catch ( ConfigDbException | IOException
-                               | TopicExistsException excp) {
-                       LOGGER.error("Error while revoking write access for producer ["
-                                       + producerId + "] for topic " + topicName, excp);
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-                                       DMaaPResponseCode.REVOKE_PUBLISHER_FOR_TOPIC.getResponseCode(), 
-                                       "Error while revoking write access to producer ["
-                                                       + producerId + "] for topic " + topicName + excp.getMessage());
+
+               } catch (ConfigDbException | IOException | TopicExistsException excp) {
+                       LOGGER.error("Error while revoking write access for producer [" + producerId + "] for topic " + topicName,
+                                       excp);
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                                       DMaaPResponseCode.REVOKE_PUBLISHER_FOR_TOPIC.getResponseCode(),
+                                       "Error while revoking write access to producer [" + producerId + "] for topic " + topicName
+                                                       + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
                }
@@ -552,55 +517,51 @@ public class TopicRestService {
         * Get the consumer details by the topic name
         * 
         * @param topicName
-        * @throws AccessDeniedException 
-        * @throws CambriaApiException 
+        * @throws AccessDeniedException
+        * @throws CambriaApiException
         */
        @GET
        @Path("/{topicName}/consumers")
-       //@Produces(MediaType.TEXT_PLAIN)
-       public void getConsumersByTopicName(@PathParam("topicName") String topicName) throws AccessDeniedException, 
-       CambriaApiException {
+       // @Produces(MediaType.TEXT_PLAIN)
+       public void getConsumersByTopicName(@PathParam("topicName") String topicName)
+                       throws AccessDeniedException, CambriaApiException {
                try {
-                       
-                       
-//                     String permission = "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"view";
-//                     DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
-//                     String permission = aaf.aafPermissionString(topicName, "view");
-//                     if(aaf.aafAuthentication(getDmaapContext().getRequest(), permission))
-//                     {
-                               LOGGER.info("Fetching list of all consumers for topic " + topicName);
-
-                               topicService.getConsumersByTopicName(getDmaapContext(), topicName);
-
-                               LOGGER.info("Returning list of all consumers for topic "
-                                               + topicName);
-                               
-//                     }else{
-//                             LOGGER.error(
-//                                             "Error while fetching list of all consumers for topic "
-//                                                             + topicName);
-//                             ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-//                                             DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(), 
-//                                             errorMessages.getNotPermitted1()+" fetch list of consumers "+errorMessages.getNotPermitted2());
-//                             LOGGER.info(errRes);
-//                             throw new DMaaPAccessDeniedException(errRes);
-//                             
-//                             
-//                     }
-                       
-                       
-                       
+
+                       // String permission =
+                       // "com.att.dmaap.mr.topic"+"|"+topicName+"|"+"view";
+                       // DMaaPAAFAuthenticator aaf = new DMaaPAAFAuthenticatorImpl();
+                       // String permission = aaf.aafPermissionString(topicName, "view");
+                       // if(aaf.aafAuthentication(getDmaapContext().getRequest(),
+                       // permission))
+                       // {
+                       LOGGER.info("Fetching list of all consumers for topic " + topicName);
+
+                       tService.getConsumersByTopicName(getDmaapContext(), topicName);
+
+                       LOGGER.info("Returning list of all consumers for topic " + topicName);
+
+                       // }else{
+                       // LOGGER.error(
+                       // "Error while fetching list of all consumers for topic "
+                       // + topicName);
+                       // ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                       // DMaaPResponseCode.ACCESS_NOT_PERMITTED.getResponseCode(),
+                       // errorMessages.getNotPermitted1()+" fetch list of consumers
+                       // "+errorMessages.getNotPermitted2());
+                       // LOGGER.info(errRes);
+                       // throw new DMaaPAccessDeniedException(errRes);
+                       //
+                       //
+                       // }
+
                } catch (IOException | ConfigDbException | TopicExistsException excp) {
-                       LOGGER.error(
-                                       "Error while fetching list of all consumers for topic "
-                                                       + topicName, excp);
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-                                       DMaaPResponseCode.GET_CONSUMERS_BY_TOPIC.getResponseCode(), 
-                                       "Error while fetching list of all consumers for topic: "
-                                                       + topicName+ excp.getMessage());
+                       LOGGER.error("Error while fetching list of all consumers for topic " + topicName, excp);
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                                       DMaaPResponseCode.GET_CONSUMERS_BY_TOPIC.getResponseCode(),
+                                       "Error while fetching list of all consumers for topic: " + topicName + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
+
                }
        }
 
@@ -609,33 +570,28 @@ public class TopicRestService {
         * 
         * @param topicName
         * @param consumerId
-        * @throws CambriaApiException 
+        * @throws CambriaApiException
         */
        @PUT
        @Path("/{topicName}/consumers/{consumerId}")
-       public void permitConsumerForTopic(
-                       @PathParam("topicName") String topicName,
+       public void permitConsumerForTopic(@PathParam("topicName") String topicName,
                        @PathParam("consumerId") String consumerId) throws CambriaApiException {
                try {
-                       LOGGER.info("Granting read access to consumer [" + consumerId
-                                       + "] for topic " + topicName);
-
-                       topicService.permitConsumerForTopic(getDmaapContext(), topicName,
-                                       consumerId);
-
-                       LOGGER.info("Read access granted to consumer [" + consumerId
-                                       + "] for topic " + topicName);
-               } catch (AccessDeniedException | ConfigDbException | IOException
-                               | TopicExistsException excp) {
-                       LOGGER.error("Error while granting read access to consumer ["
-                                       + consumerId + "] for topic " + topicName, excp);
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-                                       DMaaPResponseCode.PERMIT_CONSUMER_FOR_TOPIC.getResponseCode(), 
-                                       "Error while granting read access to consumer ["
-                                                       + consumerId + "] for topic " + topicName+ excp.getMessage());
+                       LOGGER.info("Granting read access to consumer [" + consumerId + "] for topic " + topicName);
+
+                       tService.permitConsumerForTopic(getDmaapContext(), topicName, consumerId);
+
+                       LOGGER.info("Read access granted to consumer [" + consumerId + "] for topic " + topicName);
+               } catch (AccessDeniedException | ConfigDbException | IOException | TopicExistsException excp) {
+                       LOGGER.error("Error while granting read access to consumer [" + consumerId + "] for topic " + topicName,
+                                       excp);
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                                       DMaaPResponseCode.PERMIT_CONSUMER_FOR_TOPIC.getResponseCode(),
+                                       "Error while granting read access to consumer [" + consumerId + "] for topic " + topicName
+                                                       + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
+
                }
        }
 
@@ -644,45 +600,37 @@ public class TopicRestService {
         * 
         * @param topicName
         * @param consumerId
-        * @throws CambriaApiException 
+        * @throws CambriaApiException
         */
        @DELETE
        @Path("/{topicName}/consumers/{consumerId}")
        public void denyConsumerForTopic(@PathParam("topicName") String topicName,
                        @PathParam("consumerId") String consumerId) throws CambriaApiException {
                try {
-                       LOGGER.info("Revoking read access to consumer [" + consumerId
-                                       + "] for topic " + topicName);
-
-                       topicService.denyConsumerForTopic(getDmaapContext(), topicName,
-                                       consumerId);
-
-                       LOGGER.info("Read access revoked to consumer [" + consumerId
-                                       + "] for topic " + topicName);
-               } catch ( ConfigDbException | IOException
-                               | TopicExistsException excp) {
-                       LOGGER.error("Error while revoking read access to consumer ["
-                                       + consumerId + "] for topic " + topicName, excp);
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN, 
-                                       DMaaPResponseCode.REVOKE_CONSUMER_FOR_TOPIC.getResponseCode(), 
-                                       "Error while revoking read access to consumer ["
-                                                       + consumerId + "] for topic " + topicName+ excp.getMessage());
-                       LOGGER.info(errRes.toString());
-                       throw new CambriaApiException(errRes);
-               }catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
-                       LOGGER.error("Error while creating a topic: " + excp.getMessage(),
+                       LOGGER.info("Revoking read access to consumer [" + consumerId + "] for topic " + topicName);
+
+                       tService.denyConsumerForTopic(getDmaapContext(), topicName, consumerId);
+
+                       LOGGER.info("Read access revoked to consumer [" + consumerId + "] for topic " + topicName);
+               } catch (ConfigDbException | IOException | TopicExistsException excp) {
+                       LOGGER.error("Error while revoking read access to consumer [" + consumerId + "] for topic " + topicName,
                                        excp);
-                       
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, 
-                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(), 
-                                       errorMessages.getCreateTopicFail()+ excp.getMessage());
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
+                                       DMaaPResponseCode.REVOKE_CONSUMER_FOR_TOPIC.getResponseCode(),
+                                       "Error while revoking read access to consumer [" + consumerId + "] for topic " + topicName
+                                                       + excp.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
-                       
-       }
-       }
+               } catch (DMaaPAccessDeniedException | AccessDeniedException excp) {
+                       LOGGER.error("Error while creating a topic: " + excp.getMessage(), excp);
 
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_UNAUTHORIZED,
+                                       DMaaPResponseCode.CREATE_TOPIC_FAIL.getResponseCode(),
+                                       errorMessages.getCreateTopicFail() + excp.getMessage());
+                       LOGGER.info(errRes.toString());
+                       throw new CambriaApiException(errRes);
 
-       
+               }
+       }
 
 }
index a44c2ad..1a870a1 100644 (file)
@@ -47,9 +47,9 @@ import com.att.nsa.cambria.utils.ConfigurationReader;
 import com.att.nsa.configs.ConfigDbException;
 
 /**
- * This class is a CXF REST service 
- * which acts as gateway for DMaaP
- * Transaction Ids.
+ * This class is a CXF REST service which acts as gateway for DMaaP Transaction
+ * Ids.
+ * 
  * @author author
  *
  */
@@ -84,10 +84,13 @@ public class TransactionRestService {
        @Autowired
        private TransactionService transactionService;
 
+       private DMaaPContext dmaapContext = new DMaaPContext();
+
        /**
         * 
         * Returns a list of all the existing Transaction Ids
-        * @throws CambriaApiException 
+        * 
+        * @throws CambriaApiException
         * 
         * @throws IOException
         * @exception ConfigDbException
@@ -104,11 +107,10 @@ public class TransactionRestService {
 
                        LOGGER.info("Returning list of all transactions.");
                } catch (ConfigDbException | IOException e) {
-                       LOGGER.error("Error while retrieving list of all transactions: "
-                                       + e.getMessage(), e);
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED, 
-                                       DMaaPResponseCode.RETRIEVE_TRANSACTIONS.getResponseCode(), 
-                                       "Error while retrieving list of all transactions:"+e.getMessage());
+                       LOGGER.error("Error while retrieving list of all transactions: " + e.getMessage(), e);
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
+                                       DMaaPResponseCode.RETRIEVE_TRANSACTIONS.getResponseCode(),
+                                       "Error while retrieving list of all transactions:" + e.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
                }
@@ -121,7 +123,7 @@ public class TransactionRestService {
         * 
         * @param transactionId
         *            - id of transaction
-        * @throws CambriaApiException 
+        * @throws CambriaApiException
         * @throws IOException
         * @exception ConfigDbException
         * @exception IOException
@@ -131,22 +133,18 @@ public class TransactionRestService {
         */
        @GET
        @Path("/{transactionId}")
-       public void getTransactionObj(
-                       @PathParam("transactionId") String transactionId) throws CambriaApiException {
+       public void getTransactionObj(@PathParam("transactionId") String transactionId) throws CambriaApiException {
 
                LOGGER.info("Fetching details of Transaction ID : " + transactionId);
 
                try {
-                       transactionService.getTransactionObj(getDmaapContext(),
-                                       transactionId);
+                       transactionService.getTransactionObj(getDmaapContext(), transactionId);
                } catch (ConfigDbException | JSONException | IOException e) {
-                       LOGGER.error("Error while retrieving transaction details for id: "
-                                       + transactionId, e);
-               
-                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED, 
-                                       DMaaPResponseCode.RETRIEVE_TRANSACTIONS_DETAILS.getResponseCode(), 
-                                       "Error while retrieving transaction details for id: ["
-                                                       + transactionId + "]: " + e.getMessage());
+                       LOGGER.error("Error while retrieving transaction details for id: " + transactionId, e);
+
+                       ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_EXPECTATION_FAILED,
+                                       DMaaPResponseCode.RETRIEVE_TRANSACTIONS_DETAILS.getResponseCode(),
+                                       "Error while retrieving transaction details for id: [" + transactionId + "]: " + e.getMessage());
                        LOGGER.info(errRes.toString());
                        throw new CambriaApiException(errRes);
 
@@ -165,8 +163,7 @@ public class TransactionRestService {
         *         Object,HttpServlet Object
         * 
         */
-       private DMaaPContext getDmaapContext() {
-               DMaaPContext dmaapContext = new DMaaPContext();
+       public DMaaPContext getDmaapContext() {
                dmaapContext.setConfigReader(configReader);
                dmaapContext.setRequest(request);
                dmaapContext.setResponse(response);
index ff90bd7..05d39ba 100644 (file)
@@ -19,6 +19,8 @@
  */\r
 package com.att.nsa.dmaap.service;\r
 \r
+import java.util.Date;\r
+\r
 import org.junit.After;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
@@ -28,20 +30,26 @@ import org.mockito.InjectMocks;
 import org.mockito.Mock;\r
 import org.mockito.Mockito;\r
 import org.mockito.MockitoAnnotations;\r
+import static org.mockito.Mockito.when;\r
 import org.powermock.core.classloader.annotations.PrepareForTest;\r
 import org.powermock.modules.junit4.PowerMockRunner;\r
+import org.powermock.api.mockito.PowerMockito;\r
 \r
 import com.att.ajsc.beans.PropertiesMapBean;\r
 import com.att.nsa.cambria.CambriaApiException;\r
 import com.att.nsa.cambria.backends.ConsumerFactory.UnavailableException;\r
+import com.att.nsa.cambria.exception.DMaaPErrorMessages;\r
 import com.att.nsa.cambria.service.EventsService;\r
 import com.att.nsa.configs.ConfigDbException;\r
+import com.att.nsa.cambria.utils.Utils;\r
+import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;\r
 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
 \r
-import static org.mockito.Mockito.when;\r
+import static org.junit.Assert.assertTrue;\r
 \r
 import java.io.IOException;\r
 import java.io.InputStream;\r
+import java.util.Date;\r
 \r
 import javax.servlet.ServletInputStream;\r
 import javax.servlet.ServletOutputStream;\r
@@ -61,10 +69,10 @@ public class EventsRestServiceTest {
 \r
        @Mock\r
        private EventsService eventsService;\r
-       \r
+\r
        @Mock\r
        ErrorResponse errorResponse;\r
-       \r
+\r
        @Mock\r
        DMaaPContext dmaapContext;\r
 \r
@@ -75,7 +83,10 @@ public class EventsRestServiceTest {
        ServletInputStream servletInputStream;\r
 \r
        @Mock\r
-       HttpServletRequest httpServReq;\r
+       HttpServletRequest request;\r
+\r
+       @Mock\r
+       private DMaaPErrorMessages errorMessages;\r
 \r
        @Before\r
        public void setUp() throws Exception {\r
@@ -93,6 +104,59 @@ public class EventsRestServiceTest {
 \r
        }\r
 \r
+       @Test\r
+       public void testGetEvents_error() {\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(eventsService).getEvents(dmaapContext, "topicName",\r
+                                       "consumergroup", "consumerid");\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | UnavailableException | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).getEvents(dmaapContext, "topicName",\r
+                                       "consumergroup", "consumerid");\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | UnavailableException | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).getEvents(dmaapContext,\r
+                                       "topicName", "consumergroup", "consumerid");\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | UnavailableException | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.getEvents("topicName", "consumergroup", "consumerid");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+       }\r
+\r
        @Test(expected = TopicExistsException.class)\r
        public void testGetEvents_TopicExistException() throws CambriaApiException, ConfigDbException, TopicExistsException,\r
                        UnavailableException, IOException, AccessDeniedException {\r
@@ -103,10 +167,10 @@ public class EventsRestServiceTest {
                eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
 \r
        }\r
-       \r
+\r
        @Test(expected = DMaaPAccessDeniedException.class)\r
-       public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,\r
-                       UnavailableException, IOException, AccessDeniedException {\r
+       public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException,\r
+                       TopicExistsException, UnavailableException, IOException, AccessDeniedException {\r
 \r
                Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,\r
                                "topicName", "consumergroup", "consumerid");\r
@@ -114,17 +178,22 @@ public class EventsRestServiceTest {
                eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
 \r
        }\r
-       \r
-       /*@Test(expected = DMaaPAccessDeniedException.class)\r
-       public void testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException, ConfigDbException, TopicExistsException,\r
-                       UnavailableException, IOException, AccessDeniedException {\r
 \r
-               Mockito.doThrow(new DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(dmaapContext,\r
-                               "topicName", "consumergroup", "consumerid");\r
-\r
-               eventsService.getEvents(dmaapContext, "topicName", "consumergroup", "consumerid");\r
-\r
-       }*/\r
+       /*\r
+        * @Test(expected = DMaaPAccessDeniedException.class) public void\r
+        * testGetEvents_DMaaPAccessDeniedException() throws CambriaApiException,\r
+        * ConfigDbException, TopicExistsException, UnavailableException,\r
+        * IOException, AccessDeniedException {\r
+        * \r
+        * Mockito.doThrow(new\r
+        * DMaaPAccessDeniedException(errorResponse)).when(eventsService).getEvents(\r
+        * dmaapContext, "topicName", "consumergroup", "consumerid");\r
+        * \r
+        * eventsService.getEvents(dmaapContext, "topicName", "consumergroup",\r
+        * "consumerid");\r
+        * \r
+        * }\r
+        */\r
 \r
        @Test\r
        public void testPushEvents() throws CambriaApiException {\r
@@ -132,7 +201,59 @@ public class EventsRestServiceTest {
                eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
 \r
        }\r
-       \r
+\r
+       @Test\r
+       public void testPushEvents_error() {\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(dmaapContext, "topicName", iStream,\r
+                                       "partitionKey", null);\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | missingReqdSetting | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(dmaapContext, "topicName",\r
+                                       iStream, "partitionKey", null);\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | missingReqdSetting | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(dmaapContext,\r
+                                       "topicName", iStream, "partitionKey", null);\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | missingReqdSetting | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.pushEvents("topicName", iStream, "partitionKey");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+       }\r
 \r
        @Test\r
        public void testPushEvents_TopicExistException() throws CambriaApiException {\r
@@ -143,11 +264,64 @@ public class EventsRestServiceTest {
 \r
        @Test\r
        public void tesTPushEventsWithTransaction() throws CambriaApiException, IOException {\r
-               // when(dmaapContext.getRequest()).th\r
-               // thenReturn(httpServReq);\r
-               when(httpServReq.getInputStream()).thenReturn(servletInputStream);\r
+               when(request.getInputStream()).thenReturn(servletInputStream);\r
                eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
 \r
        }\r
 \r
+       @Test\r
+       public void tesTPushEventsWithTransaction_error() throws IOException {\r
+               when(request.getInputStream()).thenReturn(servletInputStream);\r
+               ServletInputStream stream = request.getInputStream();\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new TopicExistsException("error")).when(eventsService).pushEvents(dmaapContext,\r
+                                       "topicName", stream, "partitionKey", Utils.getFormattedDate(new Date()));\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | missingReqdSetting | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(eventsService).pushEvents(dmaapContext, "topicName",\r
+                                       stream, "partitionKey", Utils.getFormattedDate(new Date()));\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | missingReqdSetting | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(eventsService).pushEvents(dmaapContext, "topicName", stream,\r
+                                       "partitionKey", Utils.getFormattedDate(new Date()));\r
+               } catch (TopicExistsException | DMaaPAccessDeniedException | AccessDeniedException | ConfigDbException\r
+                               | missingReqdSetting | IOException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       eventsRestRestService.pushEventsWithTransaction("topicName", "partitionKey");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+       }\r
+\r
 }\r
index 6fa5592..d85ef9b 100644 (file)
@@ -163,19 +163,23 @@ public class MMRestServiceTest {
        public void testCallCreateMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
                        TopicExistsException, JSONException, ConfigDbException {\r
                prepareForTestCommon();\r
-               \r
-               String sampleJson = "{\"test\":\"test\"}";\r
+\r
+               // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {\r
+               // name:\"test\", consumer:\"test\", producer:\"test\",\r
+               // whitelist:\"test\",status:\"test\" }}";\r
+               String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";\r
                InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());\r
-               mmRestService.callCreateMirrorMaker(iStream);\r
+               mmRestService.callCreateMirrorMaker(inputSteam);\r
                assertTrue(true);\r
+\r
        }\r
 \r
        @Test\r
        public void testCallListAllMirrorMaker() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
                        TopicExistsException, JSONException, ConfigDbException {\r
                prepareForTestCommon();\r
-               \r
-               String sampleJson = "{\"test\":\"test\"}";\r
+\r
+               String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";\r
                InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());\r
                mmRestService.callListAllMirrorMaker(inputSteam);\r
                assertTrue(true);\r
@@ -184,24 +188,28 @@ public class MMRestServiceTest {
        @Test\r
        public void testCallUpdateMirrorMaker() throws ConfigDbException, CambriaApiException {\r
                prepareForTestCommon();\r
-               \r
-               \r
-               mmRestService.callUpdateMirrorMaker(iStream);\r
+\r
+               String sampleJson = "{ messageID:\"test\", updateMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";\r
+               InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());\r
+               mmRestService.callUpdateMirrorMaker(inputSteam);\r
                assertTrue(true);\r
        }\r
 \r
        @Test\r
        public void testCallDeleteMirrorMaker() throws ConfigDbException, CambriaApiException {\r
                prepareForTestCommon();\r
-               mmRestService.callDeleteMirrorMaker(iStream);\r
+\r
+               String sampleJson = "{ messageID:\"test\", deleteMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";\r
+               InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());\r
+               mmRestService.callDeleteMirrorMaker(inputSteam);\r
                assertTrue(true);\r
        }\r
 \r
        @Test\r
        public void testListWhiteList() throws ConfigDbException {\r
                prepareForTestCommon();\r
-               \r
-               String sampleJson = "{\"test\":\"test\"}";\r
+\r
+               String sampleJson = "{ name:\"test\", namespace:\"test\"}}";\r
                InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());\r
                mmRestService.listWhiteList(inputSteam);\r
                assertTrue(true);\r
@@ -210,9 +218,9 @@ public class MMRestServiceTest {
        @Test\r
        public void testCreateWhiteList() throws ConfigDbException {\r
                prepareForTestCommon();\r
-               String sampleJson = "{\"test\":\"test\"}";\r
+               String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";\r
                InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());\r
-               \r
+\r
                mmRestService.createWhiteList(inputSteam);\r
                assertTrue(true);\r
        }\r
@@ -220,13 +228,13 @@ public class MMRestServiceTest {
        @Test\r
        public void testDeleteWhiteList() throws ConfigDbException {\r
                prepareForTestCommon();\r
-               \r
-               String sampleJson = "{\"test\":\"test\"}";\r
+\r
+               String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";\r
                InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());\r
                mmRestService.deleteWhiteList(inputSteam);\r
                assertTrue(true);\r
        }\r
-       \r
+\r
        private void prepareForTestCommon() throws ConfigDbException {\r
                Assert.assertNotNull(mmRestService);\r
                PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
@@ -239,6 +247,9 @@ public class MMRestServiceTest {
 \r
                PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))\r
                                .thenReturn("admin");\r
+               PowerMockito\r
+                               .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))\r
+                               .thenReturn("aafcreate");\r
 \r
                PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))\r
                                .thenReturn("admin");\r
@@ -265,6 +276,8 @@ public class MMRestServiceTest {
                PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
                PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
                PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);\r
+               PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "aafcreatetest|create"))\r
+                               .thenReturn(true);\r
 \r
                PowerMockito.when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);\r
 \r
index abaac0f..8778602 100644 (file)
@@ -185,6 +185,40 @@ public class TopicRestServiceTest {
                topicService.getTopics();\r
        }\r
 \r
+       @Test\r
+       public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               PowerMockito.mockStatic(PropertiesMapBean.class);\r
+\r
+               assertTrue(true);\r
+               when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))\r
+                               .thenReturn("namespace");\r
+\r
+               PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(httpServReq.getHeader("Authorization")).thenReturn(null);\r
+\r
+               when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
+               String perms = "namespace" + "|" + "*" + "|" + "view";\r
+               when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);\r
+\r
+               when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).getTopics(dmaapContext);\r
+               } catch (JSONException | ConfigDbException | IOException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.getTopics();\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test(expected = DMaaPAccessDeniedException.class)\r
        public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
                        TopicExistsException, JSONException, ConfigDbException {\r
@@ -228,6 +262,36 @@ public class TopicRestServiceTest {
                topicService.getAllTopics();\r
        }\r
 \r
+       @Test\r
+       public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+               PowerMockito.mockStatic(PropertiesMapBean.class);\r
+\r
+               assertTrue(true);\r
+               when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))\r
+                               .thenReturn("namespace");\r
+\r
+               PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(httpServReq.getHeader("Authorization")).thenReturn(null);\r
+\r
+               when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).getAllTopics(dmaapContext);\r
+               } catch (JSONException | ConfigDbException | IOException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.getAllTopics();\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test(expected = DMaaPAccessDeniedException.class)\r
        public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
                        TopicExistsException, JSONException, ConfigDbException {\r
@@ -272,6 +336,37 @@ public class TopicRestServiceTest {
                topicService.getTopic("topicName");\r
        }\r
 \r
+       @Test\r
+       public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               PowerMockito.mockStatic(PropertiesMapBean.class);\r
+\r
+               assertTrue(true);\r
+               when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))\r
+                               .thenReturn("enfTopicName");\r
+\r
+               PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(httpServReq.getHeader("Authorization")).thenReturn(null);\r
+\r
+               when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).getTopic(dmaapContext, "topicName");\r
+               } catch (TopicExistsException | ConfigDbException | IOException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.getTopic("topicName");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testCreateTopic()\r
                        throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
@@ -289,6 +384,62 @@ public class TopicRestServiceTest {
                topicService.createTopic(topicBean);\r
        }\r
 \r
+       @Test\r
+       public void testCreateTopic_error() {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).createTopic(dmaapContext, topicBean);\r
+               } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.createTopic(topicBean);\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new TopicExistsException("error")).when(tService).createTopic(dmaapContext, topicBean);\r
+               } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.createTopic(topicBean);\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(tService).createTopic(dmaapContext, topicBean);\r
+               } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.createTopic(topicBean);\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testDeleteTopic()\r
                        throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
@@ -306,6 +457,48 @@ public class TopicRestServiceTest {
                topicService.deleteTopic("enfTopicNamePlusExtra");\r
        }\r
 \r
+       @Test\r
+       public void testDeleteTopic_error()\r
+                       throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).deleteTopic(dmaapContext, "enfTopicNamePlusExtra");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.deleteTopic("enfTopicNamePlusExtra");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(tService).deleteTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.deleteTopic("enfTopicNamePlusExtra");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testGetPublishersByTopicName()\r
                        throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
@@ -323,6 +516,33 @@ public class TopicRestServiceTest {
                topicService.getPublishersByTopicName("enfTopicNamePlusExtra");\r
        }\r
 \r
+       @Test\r
+       public void testGetPublishersByTopicName_error() {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).getPublishersByTopicName(dmaapContext,\r
+                                       "enfTopicNamePlusExtra");\r
+               } catch (TopicExistsException | ConfigDbException | IOException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.getPublishersByTopicName("enfTopicNamePlusExtra");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testPermitPublisherForTopic()\r
                        throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
@@ -340,6 +560,49 @@ public class TopicRestServiceTest {
                topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
        }\r
 \r
+       @Test\r
+       public void testPermitPublisherForTopic_error()\r
+                       throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).permitPublisherForTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra", "producerID");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(tService).permitPublisherForTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra", "producerID");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testDenyPublisherForTopic()\r
                        throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
@@ -357,6 +620,50 @@ public class TopicRestServiceTest {
                topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
        }\r
 \r
+       @Test\r
+       public void testDenyPublisherForTopic_error()\r
+                       throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).denyPublisherForTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra", "producerID");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(tService).denyPublisherForTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra", "producerID");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+       }\r
+\r
        @Test\r
        public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
                        TopicExistsException, AccessDeniedException {\r
@@ -374,6 +681,34 @@ public class TopicRestServiceTest {
                topicService.getConsumersByTopicName("enfTopicNamePlusExtra");\r
        }\r
 \r
+       @Test\r
+       public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
+                       TopicExistsException, AccessDeniedException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).getConsumersByTopicName(dmaapContext,\r
+                                       "enfTopicNamePlusExtra");\r
+               } catch (TopicExistsException | ConfigDbException | IOException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.getConsumersByTopicName("enfTopicNamePlusExtra");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
                        TopicExistsException, AccessDeniedException {\r
@@ -390,9 +725,9 @@ public class TopicRestServiceTest {
 \r
                topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
        }\r
-       \r
+\r
        @Test\r
-       public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
+       public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
                        TopicExistsException, AccessDeniedException {\r
 \r
                Assert.assertNotNull(topicService);\r
@@ -405,6 +740,35 @@ public class TopicRestServiceTest {
                TopicBean topicBean = new TopicBean();\r
                topicBean.setTopicName("enfTopicNamePlusExtra");\r
 \r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).permitConsumerForTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra", "consumerID");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,\r
+                       IOException, TopicExistsException, AccessDeniedException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
                topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
        }\r
 \r
@@ -425,4 +789,47 @@ public class TopicRestServiceTest {
                topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
        }\r
 \r
+       @Test\r
+       public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
+                       TopicExistsException, AccessDeniedException {\r
+\r
+               Assert.assertNotNull(topicService);\r
+\r
+               when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
+               when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
+               when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
+               when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
+\r
+               TopicBean topicBean = new TopicBean();\r
+               topicBean.setTopicName("enfTopicNamePlusExtra");\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(tService).denyConsumerForTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra", "consumerID");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new AccessDeniedException()).when(tService).denyConsumerForTopic(dmaapContext,\r
+                                       "enfTopicNamePlusExtra", "consumerID");\r
+               } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException\r
+                               | DMaaPAccessDeniedException excp) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");\r
+               } catch (CambriaApiException excp) {\r
+                       assertTrue(true);\r
+               }\r
+       }\r
+\r
 }\r
index 701cb3c..0952c25 100644 (file)
@@ -22,6 +22,7 @@ package com.att.nsa.dmaap.service;
 \r
 import static org.junit.Assert.*;\r
 \r
+import java.io.IOException;\r
 import java.lang.reflect.InvocationTargetException;\r
 import java.lang.reflect.Method;\r
 \r
@@ -42,6 +43,8 @@ import com.att.nsa.cambria.service.EventsService;
 import com.att.nsa.cambria.service.TransactionService;\r
 import com.att.nsa.configs.ConfigDbException;\r
 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
+import com.att.aft.dme2.internal.jettison.json.JSONException;\r
+import org.powermock.api.mockito.PowerMockito;\r
 \r
 @RunWith(PowerMockRunner.class)\r
 @PrepareForTest({ PropertiesMapBean.class })\r
@@ -70,6 +73,7 @@ public class TransactionRestServiceTest {
        public void testGetAllTransactionObjs() throws CambriaApiException {\r
 \r
                transactionRestService.getAllTransactionObjs();\r
+               assertTrue(true);\r
 \r
        }\r
 \r
@@ -77,6 +81,42 @@ public class TransactionRestServiceTest {
        public void testGetTransactionObj() throws CambriaApiException {\r
 \r
                transactionRestService.getTransactionObj("transactionId");\r
+               assertTrue(true);\r
+\r
+       }\r
+\r
+       @Test\r
+       public void testGetAllTransactionObjsError() throws CambriaApiException {\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(transactionService).getAllTransactionObjs(dmaapContext);\r
+               } catch (ConfigDbException | IOException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       transactionRestService.getAllTransactionObjs();\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
+\r
+       }\r
+\r
+       @Test\r
+       public void testGetTransactionObjError() {\r
+\r
+               try {\r
+                       PowerMockito.doThrow(new IOException()).when(transactionService).getTransactionObj(dmaapContext,\r
+                                       "transactionId");\r
+               } catch (ConfigDbException | JSONException | IOException e) {\r
+                       assertTrue(false);\r
+               }\r
+\r
+               try {\r
+                       transactionRestService.getTransactionObj("transactionId");\r
+               } catch (CambriaApiException e) {\r
+                       assertTrue(true);\r
+               }\r
 \r
        }\r
 \r