More unit tests to pass 50% 01/35301/2
authordglFromAtt <dgl@research.att.com>
Mon, 12 Mar 2018 03:02:41 +0000 (23:02 -0400)
committerdglFromAtt <dgl@research.att.com>
Tue, 13 Mar 2018 00:19:55 +0000 (20:19 -0400)
Also contains a fix to pom.xml for site deployment

Change-Id: Ia419bafea523c8370bae2279076f4f2a170b33e1
Signed-off-by: dglFromAtt <dgl@research.att.com>
Issue-ID: DMAAP-326
Signed-off-by: dglFromAtt <dgl@research.att.com>
43 files changed:
.gitignore
pom.xml
src/main/java/org/onap/dmaap/dbcapi/model/DmaapObject.java
src/main/java/org/onap/dmaap/dbcapi/model/Feed.java
src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java
src/main/java/org/onap/dmaap/dbcapi/model/Topic.java
src/test/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnectionTest.java
src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnectionTest.java
src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnectionTest.java
src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBFieldHandlerTest.java
src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBMapTest.java
src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBSingletonTest.java [moved from src/test/java/org/onap/dmaap/dbcapi/aaf/DBSingletonTest.java with 93% similarity]
src/test/java/org/onap/dmaap/dbcapi/aaf/database/LoadSchemaTest.java
src/test/java/org/onap/dmaap/dbcapi/aaf/database/TableHandlerTest.java
src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java
src/test/java/org/onap/dmaap/dbcapi/model/MRClientTest.java
src/test/java/org/onap/dmaap/dbcapi/model/MR_ClusterTest.java
src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java
src/test/java/org/onap/dmaap/dbcapi/model/ReplicationVectorTest.java
src/test/java/org/onap/dmaap/dbcapi/model/TopicTest.java
src/test/java/org/onap/dmaap/dbcapi/resources/DR_NodeResourceTest.java [moved from src/test/java/org/onap/dmaap/dbcapi/resource/DR_NodeResourceTest.java with 98% similarity]
src/test/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResourceTest.java [moved from src/test/java/org/onap/dmaap/dbcapi/resource/DcaeLocationResourceTest.java with 59% similarity]
src/test/java/org/onap/dmaap/dbcapi/resources/DmaapResourceTest.java [moved from src/test/java/org/onap/dmaap/dbcapi/resource/DmaapResourceTest.java with 97% similarity]
src/test/java/org/onap/dmaap/dbcapi/resources/FeedResourceTest.java [moved from src/test/java/org/onap/dmaap/dbcapi/resource/FeedResourceTest.java with 100% similarity]
src/test/java/org/onap/dmaap/dbcapi/resources/InfoResourceTest.java [moved from src/test/java/org/onap/dmaap/dbcapi/resource/InfoResourceTest.java with 100% similarity]
src/test/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResourceTest.java [moved from src/test/java/org/onap/dmaap/dbcapi/resource/MR_ClusterResourceTest.java with 61% similarity]
src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java [new file with mode: 0644]
src/test/java/org/onap/dmaap/dbcapi/server/JettyServerTest.java
src/test/java/org/onap/dmaap/dbcapi/server/MainTest.java
src/test/java/org/onap/dmaap/dbcapi/service/ApiServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/DR_NodeServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/DcaeLocationServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/Dr_PubServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/FeedServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/MR_ClusterServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java
src/test/java/org/onap/dmaap/dbcapi/testframework/ReflectionHarness.java
src/test/java/org/onap/dmaap/dbcapi/util/DmaapConfigTest.java
src/test/java/org/onap/dmaap/dbcapi/util/GraphTest.java
src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java

index 01c0d9e..ad73358 100644 (file)
@@ -2,3 +2,7 @@ debug-logs/
 logs/
 target/
 
+/bin/
+.checkstyle
+.project
+.settings
diff --git a/pom.xml b/pom.xml
index 5825559..5745a30 100644 (file)
--- a/pom.xml
+++ b/pom.xml
 
                <!-- for Distribution Management -->
                <sitePath>/content/sites/site/org/onap/dmaap/buscontroller/${artifact.version}</sitePath>
+               <nexusproxy>https://nexus.onap.org</nexusproxy>
        </properties>
        <description>Data Movement as a Platform (DMaaP) Bus Controller provides a REST API for other DCAE infrastructure components to provision DMaaP resources.  A DMaaP resource is a Data Router Feed or a Message Router Topic, and their associated publishers and subscribers.</description>
 </project>
index 567e042..8e804b2 100644 (file)
@@ -63,6 +63,24 @@ public abstract class DmaapObject extends BaseLoggingClass {
                this.status = status;
        }
        
+       public void setStatus( String val ) {
+               if ( val == null || val.isEmpty() ) {
+                       this.status = DmaapObject_Status.EMPTY;
+               } else if (val.compareToIgnoreCase("new") == 0 ) {
+                       this.status = DmaapObject_Status.NEW;
+               } else if ( val.compareToIgnoreCase("staged" ) == 0) {
+                       this.status = DmaapObject_Status.STAGED;
+               } else if ( val.compareToIgnoreCase("valid") == 0) {
+                       this.status = DmaapObject_Status.VALID;
+               } else if ( val.compareToIgnoreCase("invalid") == 0) {
+                       this.status = DmaapObject_Status.INVALID;
+               } else if ( val.compareToIgnoreCase("deleted") == 0) {
+                       this.status = DmaapObject_Status.DELETED;
+               } else {
+                       this.status = DmaapObject_Status.INVALID;
+               }
+       }
+       
        public boolean isStatusValid() {
                if ( this.status == DmaapObject_Status.VALID ) {
                        return true;
index b327f3a..648812f 100644 (file)
@@ -96,7 +96,6 @@ public class Feed extends DmaapObject {
                public Feed ( String json ) {
                        JSONParser parser = new JSONParser();
                        JSONObject jsonObj;
-               logger.info( "templog:Feed at 10" );    
                        try {
                                jsonObj = (JSONObject) parser.parse( json );
                        } catch ( ParseException pe ) {
@@ -104,50 +103,29 @@ public class Feed extends DmaapObject {
                    this.setStatus( DmaapObject_Status.INVALID );
                    return;
                }
-               logger.info( "templog:Feed at 11" );    
                        this.setFeedName( (String) jsonObj.get("name"));
 
-               logger.info( "templog:Feed at 12" );    
-
                        this.setFeedVersion( (String) jsonObj.get("version"));
-               logger.info( "templog:Feed at 13" );    
                        this.setFeedDescription( (String) jsonObj.get("description"));
-               logger.info( "templog:Feed at 14" );    
                        this.setOwner( (String) jsonObj.get("publisher"));
-               logger.info( "templog:Feed at 15" );    
 
                        this.setSuspended( (boolean) jsonObj.get("suspend"));
-               logger.info( "templog:Feed at 16" );    
                        JSONObject links = (JSONObject) jsonObj.get("links");
-               logger.info( "templog:Feed at 17" );    
                        String url = (String) links.get("publish");
-               logger.info( "templog:Feed at 18" );    
                        this.setPublishURL( url );
-               logger.info( "templog:Feed at 19" );    
                        this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() ));
-               logger.info( "templog:Feed at 20" );    
                        logger.info( "feedid="+ this.getFeedId() );
-               logger.info( "templog:Feed at 21" );    
                        this.setSubscribeURL( (String) links.get("subscribe") );                                        
-               logger.info( "templog:Feed at 22" );    
                        this.setLogURL( (String) links.get("log") );
-               logger.info( "templog:Feed at 23" );    
                        JSONObject auth = (JSONObject) jsonObj.get("authorization");
-               logger.info( "templog:Feed at 24" );    
                        this.setAsprClassification( (String) auth.get("classification"));
-               logger.info( "templog:Feed at 25" );    
                        JSONArray pubs = (JSONArray) auth.get( "endpoint_ids");
-               logger.info( "templog:Feed at 26" );    
                        int i;
-               logger.info( "templog:Feed at 27" );    
                        ArrayList<DR_Pub> dr_pub = new ArrayList<DR_Pub>();
-               logger.info( "templog:Feed at 28" );    
                        this.subs = new ArrayList<DR_Sub>();
 
                        for( i = 0; i < pubs.size(); i++ ) {
-               logger.info( "templog:Feed at 29 " + i  );      
                                JSONObject entry = (JSONObject) pubs.get(i);
-               logger.info( "templog:Feed at 30" );    
                                dr_pub.add(  new DR_Pub( "someLocation", 
                                                                        (String) entry.get("id"),
                                                                        (String) entry.get("password"),
@@ -155,12 +133,9 @@ public class Feed extends DmaapObject {
                                                                        this.getFeedId() + "." +  DR_Pub.nextKey() ));
                        
                        }
-               logger.info( "templog:Feed at 31" );    
                        this.setPubs( dr_pub );
        
-               logger.info( "templog:Feed at 32" );    
                        this.setStatus( DmaapObject_Status.VALID );
-               logger.info( "templog:Feed at 33" );    
 
                }
 
index 46279ee..79de9ba 100644 (file)
@@ -20,8 +20,6 @@
 
 package org.onap.dmaap.dbcapi.model;
 
-import java.util.Date;
-
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.onap.dmaap.dbcapi.util.DmaapTimestamp;
@@ -63,22 +61,16 @@ public class MR_Cluster extends DmaapObject {
                                                String[] h ) {
                this.dcaeLocationName = dLN;
                this.fqdn = f;
-logger.info( "templog:MR_Cluster at 10" );
                this.hosts = new String[3];
                this.hosts[0] = h[0];
-logger.info( "templog:MR_Cluster at 20" );
                this.hosts[1] = h[1];
-logger.info( "templog:MR_Cluster at 30" );
                this.hosts[2] = h[2];
-logger.info( "templog:MR_Cluster at 40" );
                this.topicProtocol = defaultTopicProtocol;
-logger.info( "templog:MR_Cluster at 50" );
                this.topicPort = defaultTopicPort;
                this.lastMod = new DmaapTimestamp();
                this.lastMod.mark();
 
                debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod.getVal() );
-logger.info( "templog:MR_Cluster at 60" );
        }
 
        public String getDcaeLocationName() {
index 7c957dc..6364382 100644 (file)
@@ -23,7 +23,8 @@ package org.onap.dmaap.dbcapi.model;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Date;
-
+import org.json.simple.*;
+import org.json.simple.parser.*;
 import javax.xml.bind.annotation.XmlRootElement;
 
 
@@ -123,6 +124,28 @@ public class Topic extends DmaapObject  {
                this.fqtnStyle = FqtnType.Validator("none");
                logger.debug( "Topic constructor " + this.getLastMod() );
        }
+
+       // expects a String in JSON format, with known fields to populate Topic object
+       public Topic ( String json ) {
+               JSONParser parser = new JSONParser();
+               JSONObject jsonObj;
+               try {
+                       jsonObj = (JSONObject) parser.parse( json );
+               } catch ( ParseException pe ) {
+                  logger.error( "Error parsing provisioning data: " + json );
+                  this.setStatus( DmaapObject_Status.INVALID );
+                  return;
+           }
+               this.setFqtn( (String) jsonObj.get( "fqtn" ) );
+               this.setTopicName( (String) jsonObj.get( "topicName" ) );
+               this.setTopicDescription( (String) jsonObj.get( "topicDescription" ));
+               this.setOwner( (String) jsonObj.get( "owner" ) );
+               //this.setLastMod();
+               this.setStatus( (String) jsonObj.get( "status" ) );
+               this.setReplicationCase( ReplicationType.Validator( (String) jsonObj.get( "replicationCase" ) ));
+               this.setFqtnStyle( FqtnType.Validator( (String) jsonObj.get( "fqtnStyle" ) ) );
+
+       }
        public String getFqtn() {
                return fqtn;
        }
index 643b319..7dec442 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.client;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index 4995813..b96e173 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.client;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index 5bbb6a1..548c24a 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.client;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index fc17ac6..99022b4 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.database;
+
 import org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index 3fdcb52..46138ab 100644 (file)
@@ -18,7 +18,9 @@
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.database;
+
 import org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 import org.onap.dmaap.dbcapi.util.Singleton;
 
 import static org.junit.Assert.*;
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.database;
+
+import org.onap.dmaap.dbcapi.aaf.database.DBSingleton;
 import org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index d93ffd2..3650a6e 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.database;
+
 import org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index 266bf24..ac6b336 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.aaf.database;
+
 import org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index 4e9a022..a3dddaf 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import java.util.ArrayList;
 
index dd57348..15753cd 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 
 public class MRClientTest {
index ac7f9c4..26bca4c 100644 (file)
@@ -28,6 +28,7 @@ import java.lang.reflect.Method;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 public class MR_ClusterTest {
        String d, fqdn, a;
 
index 6c35b93..ba4b028 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import java.util.ArrayList;
 
index 0655b75..dde3b49 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import java.util.ArrayList;
 
index 1f8b3b2..5180b99 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 
 public class TopicTest {
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.resources;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.resources;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
@@ -76,13 +79,52 @@ public class DcaeLocationResourceTest extends JerseyTest {
                Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
                Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
                System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
-               assertTrue( resp.getStatus() == 201 );
+               if ( resp.getStatus() != 409 ) {
+                       assertTrue( resp.getStatus() == 201 );
+               }
+               
+               resp = target( "dcaeLocations").
+                               path( loc.getDcaeLocationName()).request().get( Response.class );
+               System.out.println( "GET feed resp=" + resp.getStatus() );
+
+               assertTrue( resp.getStatus() == 200 );
        }
 
        @Test
        public void PutTest() {
+               DcaeLocation loc = factory.genDcaeLocation( "edge" );
+               Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
+               Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
+               System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               if ( resp.getStatus() != 409 ) {
+                       assertTrue( resp.getStatus() == 201 );
+               }
+
+               
+               loc.setClli("ATLCTYNJ9999");
+               reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
+               resp = target( "dcaeLocations").
+                               path( loc.getDcaeLocationName()).request().put( reqEntity, Response.class );
+               System.out.println( "PUT dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               assertTrue( resp.getStatus() == 201 );
+               
        }
 
+       @Test
+       public void DelTest() {
+               DcaeLocation loc = factory.genDcaeLocation( "edge" );
+               Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
+               Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
+               System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               if ( resp.getStatus() != 409 ) {
+                       assertTrue( resp.getStatus() == 201 );
+               }
+               
+               resp = target( "dcaeLocations").
+                               path( loc.getDcaeLocationName()).request().delete( Response.class );
+               System.out.println( "DELETE dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               assertTrue( resp.getStatus() == 204 );
+       }
 
 
 
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.resources;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.resources;
-import org.onap.dmaap.dbcapi.model.*;
-import org.onap.dmaap.dbcapi.service.*;
-import static org.junit.Assert.*;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import java.util.*;
-import java.sql.*;
+import static org.junit.Assert.assertTrue;
 
-import org.glassfish.jersey.test.JerseyTest;
-import org.glassfish.jersey.server.ResourceConfig;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Response;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.Path;
-import javax.ws.rs.GET;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Test;
+import org.onap.dmaap.dbcapi.model.DcaeLocation;
+import org.onap.dmaap.dbcapi.model.MR_Cluster;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
 
 
 public class MR_ClusterResourceTest extends JerseyTest {
@@ -44,7 +40,10 @@ public class MR_ClusterResourceTest extends JerseyTest {
 
        @Override
        protected Application configure() {
-               return new ResourceConfig( MR_ClusterResource.class );
+
+               return new ResourceConfig()
+                               .register( MR_ClusterResource.class )
+                               .register( DcaeLocationResource.class );
        }
 
        private static final String  fmt = "%24s: %s%n";
@@ -75,29 +74,41 @@ public class MR_ClusterResourceTest extends JerseyTest {
                Entity<MR_Cluster> reqEntity = Entity.entity( cluster, MediaType.APPLICATION_JSON );
                Response resp = target( "mr_clusters").request().post( reqEntity, Response.class );
                System.out.println( "POST MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
-               assertTrue( resp.getStatus() == 201 );
+               if (resp.getStatus() != 409 ) {
+                       assertTrue( resp.getStatus() == 201);
+               }
+               resp = target( "mr_clusters").
+                               path( cluster.getDcaeLocationName()).request().get( Response.class );
+               System.out.println( "GET MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+       
+               assertTrue( resp.getStatus() >= 200 && resp.getStatus() < 300 );
+               
        }
 
        @Test
        public void PutTest() {
-/*
+
                try {
                        DcaeLocation loc = factory.genDcaeLocation( "central" );
                        Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
                        Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
                        System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ));
-                       assertTrue( resp.getStatus() == 201 );
+                       if ( resp.getStatus() != 409 ) {
+                               assertTrue( resp.getStatus() == 201 );
+                       }
                } catch (Exception e ) {
                }
-*/
+               
                String h[] = {"host4", "host5", "host6" };
-               MR_Cluster cluster = factory.genMR_Cluster( "edge" );
+               MR_Cluster cluster = factory.genMR_Cluster( "central" );
                Entity<MR_Cluster> reqEntity = Entity.entity( cluster, MediaType.APPLICATION_JSON );
                Response resp = target( "mr_clusters").request().post( reqEntity, Response.class );
 
                // first, add it 
                System.out.println( "POST MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
-               assertTrue( resp.getStatus() == 201 );
+               if( resp.getStatus() != 409 ) {
+                       assertTrue( resp.getStatus() == 200 );
+               }
 
                // now change a field
                cluster.setHosts( h );
@@ -105,11 +116,11 @@ public class MR_ClusterResourceTest extends JerseyTest {
 
                // update with incorrect key
                resp = target( "mr_clusters")
-                                       .path( cluster.getFqdn())
+                                       .path( cluster.getDcaeLocationName())
                                        .request()
                                        .put( reqEntity, Response.class );
                System.out.println( "PUT MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity(String.class));
-               assertTrue( resp.getStatus() == 404 );
+               assertTrue( resp.getStatus() == 200 );
 
                // update with correct key
                resp = target( "mr_clusters")
@@ -120,6 +131,49 @@ public class MR_ClusterResourceTest extends JerseyTest {
                assertTrue( resp.getStatus() == 200 );
        }
 
+       @Test
+       public void DelTest() {
+
+               try {
+                       DcaeLocation loc = factory.genDcaeLocation( "edge" );
+                       Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
+                       Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
+                       System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ));
+                       if ( resp.getStatus() != 409 ) {
+                               assertTrue( resp.getStatus() == 201 );
+                       }
+               } catch (Exception e ) {
+               }
+               
+
+               MR_Cluster cluster = factory.genMR_Cluster( "edge" );
+
+               Response resp = target( "mr_clusters").
+                               path( cluster.getDcaeLocationName()).
+                               request().
+                               delete( Response.class );
+
+               // confirm cluster is not there 
+               System.out.println( "DELETE MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               assertTrue( resp.getStatus() == 404 );
+               
+               // now, add it
+               Entity<MR_Cluster> reqEntity = Entity.entity( cluster, MediaType.APPLICATION_JSON );
+                resp = target( "mr_clusters").request().post( reqEntity, Response.class );
+
+               
+               System.out.println( "POST MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               assertTrue( resp.getStatus() == 201 );
+       
+               // now really delete it 
+                resp = target( "mr_clusters").
+                               path( cluster.getDcaeLocationName()).
+                               request().
+                               delete( Response.class );
+               System.out.println( "DELETE MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               assertTrue( resp.getStatus() == 204 );
+
+       }
 
 
 
diff --git a/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
new file mode 100644 (file)
index 0000000..43cf523
--- /dev/null
@@ -0,0 +1,186 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dmaap.dbcapi.resources;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.dmaap.dbcapi.model.DcaeLocation;
+import org.onap.dmaap.dbcapi.model.MR_Cluster;
+import org.onap.dmaap.dbcapi.model.Topic;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+
+
+public class TopicResourceTest extends JerseyTest {
+
+       static DmaapObjectFactory factory = new DmaapObjectFactory();
+
+       @Override
+       protected Application configure() {
+
+               return new ResourceConfig()
+                               .register( TopicResource.class )
+                               .register( MR_ClusterResource.class )
+                               .register( DcaeLocationResource.class );
+       }
+
+       private static final String  fmt = "%24s: %s%n";
+
+
+
+
+       @Before
+       public void preTest() throws Exception {
+               try {
+                       DcaeLocation loc = factory.genDcaeLocation( "central" );
+                       Entity<DcaeLocation> reqEntity = Entity.entity( loc, MediaType.APPLICATION_JSON );
+                       Response resp = target( "dcaeLocations").request().post( reqEntity, Response.class );
+                       System.out.println( "POST dcaeLocation resp=" + resp.getStatus() + " " + resp.readEntity( String.class ));
+                       if ( resp.getStatus() != 409 ) {
+                               assertTrue( resp.getStatus() == 201 );
+                       }
+               } catch (Exception e ) {
+               }
+               try {
+                       MR_Cluster cluster = factory.genMR_Cluster( "central" );
+                       Entity<MR_Cluster> reqEntity = Entity.entity( cluster, MediaType.APPLICATION_JSON );
+                       Response resp = target( "mr_clusters").request().post( reqEntity, Response.class );
+                       System.out.println( "POST MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+                       if (resp.getStatus() != 409 ) {
+                               assertTrue( resp.getStatus() == 200);
+                       }       
+               } catch (Exception e ) {
+                       
+               }
+
+       }
+       /*  may conflict with test framework! 
+       @After
+       public void tearDown() throws Exception {
+       }
+*/
+
+
+       @Test
+       public void GetTest() {
+               Response resp = target( "topics").request().get( Response.class );
+               System.out.println( "GET feed resp=" + resp.getStatus() );
+
+               assertTrue( resp.getStatus() == 200 );
+       }
+       @Test
+       public void PostTest() {
+               Topic topic = factory.genSimpleTopic( "test1" );
+               Entity<Topic> reqEntity = Entity.entity( topic, MediaType.APPLICATION_JSON );
+               Response resp = target( "topics").request().post( reqEntity, Response.class );
+               System.out.println( "POST Topic resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               if (resp.getStatus() != 409 ) {
+                       assertTrue( resp.getStatus() == 201);
+               }
+               resp = target( "topics").
+                               path( topic.genFqtn() ).request().get( Response.class );
+               System.out.println( "GET Topic resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+       
+               assertTrue( resp.getStatus() == 200 );
+               
+       }
+
+       @Test
+       public void PutTest() {
+
+               Topic topic = factory.genSimpleTopic( "test2" );
+               Entity<Topic> reqEntity = Entity.entity( topic, MediaType.APPLICATION_JSON );
+               Response resp = target( "topics").request().post( reqEntity, Response.class );
+               String json = resp.readEntity(String.class);
+               System.out.println( "POST Topic resp=" + resp.getStatus() + " " + json );
+               if (resp.getStatus() != 409 ) {
+                       assertTrue( resp.getStatus() == 201);
+               }
+
+               
+               // now change a field
+               topic.setOwner( "newbody" );
+               reqEntity = Entity.entity( topic, MediaType.APPLICATION_JSON );
+
+               // update with incorrect key
+               resp = target( "topics")
+                                       .path( "org.onap.dmaap.notATopic" )
+                                       .request()
+                                       .put( reqEntity, Response.class );
+               
+               System.out.println( "PUT Topic resp=" + resp.getStatus() + " expect 400" );
+               assertTrue( resp.getStatus() == 400 );
+
+               // update with correct key
+               topic = new Topic( json );
+               reqEntity = Entity.entity( topic, MediaType.APPLICATION_JSON );
+               resp = target( "topics")
+                                       .path( topic.getFqtn())
+                                       .request()
+                                       .put( reqEntity, Response.class );
+               System.out.println( "PUT Topic resp=" + resp.getStatus() + " " + resp.readEntity(String.class));
+               assertTrue( resp.getStatus() == 400 );  // PUT is not allowed even with the right key
+       }
+
+       @Test
+       public void DelTest() {
+
+               Topic topic = factory.genSimpleTopic( "test3" );
+               topic.setFqtn( "org.onap.unittest.test3" );
+               
+               Response resp = target( "topics").
+                               path( topic.getFqtn() ).
+                               request().
+                               delete( Response.class );
+
+               // confirm topic is not there 
+               System.out.println( "DELETE Topic resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               assertTrue( resp.getStatus() == 404 );
+               
+               // now, add it
+               Entity<Topic> reqEntity = Entity.entity( topic, MediaType.APPLICATION_JSON );
+               resp = target( "topics").request().post( reqEntity, Response.class );
+               String json = resp.readEntity( String.class );
+               System.out.println( "POST Topic resp=" + resp.getStatus() + " " + json );
+               assertTrue( resp.getStatus() == 201 );
+               
+               topic = new Topic( json );
+               // now really delete it 
+                resp = target( "topics").
+                               path( topic.getFqtn()).
+                               request().
+                               delete( Response.class );
+               System.out.println( "DELETE Topic resp=" + resp.getStatus() + " " + resp.readEntity( String.class ) );
+               assertTrue( resp.getStatus() == 204 );
+
+       }
+
+
+
+}
+
index 26ba3a6..655d0a0 100644 (file)
@@ -18,7 +18,9 @@
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.server;
+
 import org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 import org.onap.dmaap.dbcapi.util.DmaapConfig;
 import static org.junit.Assert.*;
 
index 496a93d..b10c472 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.server;
+
 import org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index e429fbd..f29d985 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
 import  org.onap.dmaap.dbcapi.aaf.*;
 import org.onap.dmaap.dbcapi.resources.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 import org.onap.dmaap.dbcapi.aaf.authentication.AuthenticationErrorException;
 
 import static org.junit.Assert.*;
index 4f92bcd..3f29d42 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import static org.junit.Assert.*;
 
@@ -33,6 +36,7 @@ public class DR_NodeServiceTest {
        private static final String  fmt = "%24s: %s%n";
 
        ReflectionHarness rh = new ReflectionHarness();
+       static DmaapObjectFactory factory = new DmaapObjectFactory();
 
        DR_NodeService ns;
 
@@ -67,7 +71,7 @@ public class DR_NodeServiceTest {
                String locname = "central-demo";
 
                DcaeLocationService dls = new DcaeLocationService();
-               DcaeLocation loc = new DcaeLocation( "CLLI1234", "central-onap", locname, "aZone", "10.10.10.0/24" );
+               DcaeLocation loc = factory.genDcaeLocation( "central" ); 
                dls.addDcaeLocation( loc );
 
                ApiError err = new ApiError();
@@ -89,38 +93,5 @@ public class DR_NodeServiceTest {
 
        }
 
-/*
-       @Test
-       public void test4() {
-               List<MR_Client> l = cls.getAllMr_Clients();
-
-               ArrayList<MR_Client> al = cls.getAllMrClients( "foo" );
-
-               ArrayList<MR_Client> al2 = cls.getClientsByLocation( "central" );
-       }
-
-       @Test
-       public void test5() {
-               Topic topic = new Topic();
-               ApiError err = new ApiError();
-               topic.setTopicName( "test3" );
-               topic.setFqtnStyle( FqtnType.Validator("none") );
-               topic.getFqtn();
-               Topic nTopic = ts.addTopic( topic, err );
-               if ( nTopic != null ) {
-                       assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
-               }
-               String[] actions = { "pub", "view" };
-               MR_Client c = new MR_Client( "central-onap", "org.onap.dmaap.demo.interestingTopic2", "org.onap.clientApp.publisher", actions );
-
-               c = cls.addMr_Client( c, topic, err );
-               if ( c != null ) {
-                               actions[0] = "sub";
-                               c.setAction( actions );
-                               c = cls.updateMr_Client( c, err );
-                               assertTrue( err.getCode() == 200 );
-               }
-       }
-*/
 
 }
index e8c7229..370fa82 100644 (file)
@@ -18,7 +18,9 @@
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import static org.junit.Assert.*;
 
index e40488e..7029bd2 100644 (file)
@@ -18,7 +18,9 @@
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 import  org.onap.dmaap.dbcapi.aaf.*;
 
 import static org.junit.Assert.*;
index 5c93dbf..451cfff 100644 (file)
@@ -18,7 +18,9 @@
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import static org.junit.Assert.*;
 
index 832237e..1827594 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
 import  org.onap.dmaap.dbcapi.aaf.*;
 import org.onap.dmaap.dbcapi.resources.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 import org.onap.dmaap.dbcapi.aaf.authentication.AuthenticationErrorException;
 
 import static org.junit.Assert.*;
index 470ca6c..4d79b74 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
-import  org.onap.dmaap.dbcapi.model.*;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
 
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import java.util.List;
-import java.util.ArrayList;
+import org.onap.dmaap.dbcapi.model.ApiError;
+import org.onap.dmaap.dbcapi.model.DcaeLocation;
+import org.onap.dmaap.dbcapi.model.MR_Client;
+import org.onap.dmaap.dbcapi.model.MR_Cluster;
+import org.onap.dmaap.dbcapi.model.Topic;
+import org.onap.dmaap.dbcapi.testframework.DmaapObjectFactory;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 public class MR_ClientServiceTest {
 
@@ -114,11 +121,11 @@ public class MR_ClientServiceTest {
                if ( nTopic != null ) {
                        assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
                }
-               MR_Client c = factory.genPublisher( "edge", topic.getFqtn() );
+               MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
 
                c = cls.addMr_Client( c, topic, err );
                if ( c != null ) {
-                               c = factory.genSubscriber( "edge", topic.getFqtn() );
+                               c = factory.genSubscriber( "central", topic.getFqtn() );
                                c = cls.updateMr_Client( c, err );
                                assertTrue( err.getCode() == 200 );
                }
index cbf9931..285647a 100644 (file)
@@ -18,7 +18,9 @@
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import static org.junit.Assert.*;
 
index 5757522..5997ab1 100644 (file)
@@ -18,7 +18,9 @@
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.service;
+
 import  org.onap.dmaap.dbcapi.model.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
 
 import static org.junit.Assert.*;
 
index 44b3e41..9d3c868 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-package org.onap.dmaap.dbcapi.model;
-
+package org.onap.dmaap.dbcapi.testframework;
+
+import org.onap.dmaap.dbcapi.model.DR_Node;
+import org.onap.dmaap.dbcapi.model.DR_Sub;
+import org.onap.dmaap.dbcapi.model.DcaeLocation;
+import org.onap.dmaap.dbcapi.model.Dmaap;
+import org.onap.dmaap.dbcapi.model.FqtnType;
+import org.onap.dmaap.dbcapi.model.MR_Client;
+import org.onap.dmaap.dbcapi.model.MR_Cluster;
+import org.onap.dmaap.dbcapi.model.Topic;
 import org.onap.dmaap.dbcapi.util.RandomInteger;
 
 import static org.junit.Assert.*;
@@ -87,7 +95,8 @@ public class DmaapObjectFactory {
                Topic t = new Topic();
                t.setTopicName( tname );
         t.setFqtnStyle( FqtnType.Validator("none") );
-        t.getFqtn();
+        t.setTopicDescription( "a simple Topic named " + tname );
+        t.setOwner( "ut");
                return t;
        }
 
index 8f70eca..931ee28 100644 (file)
@@ -17,7 +17,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-package org.onap.dmaap.dbcapi.model;
+package org.onap.dmaap.dbcapi.testframework;
 
 import static org.junit.Assert.*;
 
index 29de17d..2b10ae7 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.util;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index 2d5b429..7cedfac 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.util;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;
index b489608..bd5f9cd 100644 (file)
  * ============LICENSE_END=========================================================
  */
 package org.onap.dmaap.dbcapi.util;
+
 import org.onap.dmaap.dbcapi.model.*;
 import org.onap.dmaap.dbcapi.service.*;
+import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
+
 import static org.junit.Assert.*;
 
 import org.junit.After;