Fix some things I broke 65/84965/2
authordglFromAtt <dgl@research.att.com>
Wed, 10 Apr 2019 22:48:26 +0000 (18:48 -0400)
committerdglFromAtt <dgl@research.att.com>
Wed, 10 Apr 2019 23:05:58 +0000 (19:05 -0400)
patchset2: use is2xx() in TopicResourceTest
Change-Id: Icb6711f290164c4a2c952d5250746f274a048a73
Signed-off-by: dglFromAtt <dgl@research.att.com>
Issue-ID: DMAAP-1095
Signed-off-by: dglFromAtt <dgl@research.att.com>
src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java
src/test/java/org/onap/dmaap/dbcapi/service/MirrorMakerServiceTest.java

index 2be1b33..688bbce 100644 (file)
@@ -49,6 +49,7 @@ public class MrProvConnection extends BaseLoggingClass{
     private String authMethod;
     private    String    user;
     private    String    encPwd;
+    private    String  unit_test;
     private boolean hostnameVerify;
     
     public MrProvConnection() {
@@ -60,6 +61,7 @@ public class MrProvConnection extends BaseLoggingClass{
         authMethod = p.getProperty("MR.authentication", "none");
         topicMgrCred =  getCred();
         hostnameVerify= "true".equalsIgnoreCase(p.getProperty("MR.hostnameVerify", "true"));
+        unit_test = p.getProperty( "UnitTest", "No" );
         
     }
     
@@ -199,11 +201,17 @@ public class MrProvConnection extends BaseLoggingClass{
                 err.setFields( uc.getURL().getHost());
                 return new String( "500: " + uhe.getMessage());
             }catch ( ConnectException ce ) {
-                errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, "HTTP Connection Exception"  );
-                err.setCode(500);
-                err.setMessage("HTTP Connection Exception");
-                err.setFields( uc.getURL().getHost());
+                       if ( unit_test.equals( "Yes" ) ) {
+                               err.setCode(200);
+                               err.setMessage( "simulated response");
+                               logger.info( "artificial 200 response from doPostMessage because unit_test =" + unit_test );
+               } else { 
+                       errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, "HTTP Connection Exception"  );
+                       err.setCode(500);
+                       err.setMessage("HTTP Connection Exception");
+                       err.setFields( uc.getURL().getHost());
                 return new String( "500: " + ce.getMessage());
+               }
             }
             rc = uc.getResponseCode();
             logger.info( "http response code:" + rc );
index 0a5f91a..b3f713f 100644 (file)
@@ -204,9 +204,9 @@ public class MrTopicConnection extends BaseLoggingClass  {
             
                } catch (Exception e) {
                if ( unit_test.equals( "Yes" ) ) {
-                               response.setCode(200);
+                               response.setCode(201);
                                response.setMessage( "simulated response");
-                               logger.info( "artificial 200 response from doPostMessage because unit_test =" + unit_test );
+                               logger.info( "artificial 201 response from doPostMessage because unit_test =" + unit_test );
                } else {
 
                                response.setCode(500);
index 88840fe..04c1bda 100644 (file)
@@ -54,6 +54,12 @@ public class TopicResourceTest extends JerseyTest {
 
        private static final String  fmt = "%24s: %s%n";
 
+       private boolean is2xx(int val ) {
+               if ( val >= 200 && val < 300 ) {
+                       return true;
+               }
+               return false;
+       }
 
        @Before
        public void preTest() throws Exception {
@@ -62,9 +68,10 @@ public class TopicResourceTest extends JerseyTest {
 
                        Dmaap dmaap = factory.genDmaap();
                        Entity<Dmaap> reqEntity = Entity.entity( dmaap, MediaType.APPLICATION_JSON );
-                       Response resp = target( "dmaap").request().put( reqEntity, Response.class );
-                       System.out.println( resp.getStatus() );
-                       assertTrue( resp.getStatus() == 200 );
+                       Response resp = target( "dmaap").request().post( reqEntity, Response.class );
+                       System.out.println( "POST dmaap resp=" + resp.getStatus() );
+                       assertTrue( is2xx( resp.getStatus()) );
+               
                }catch (Exception e ) {
                }
                try {
@@ -73,7 +80,7 @@ public class TopicResourceTest extends JerseyTest {
                        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 );
+                               assertTrue( is2xx( resp.getStatus())  );
                        }
                } catch (Exception e ) {
                }
@@ -83,7 +90,7 @@ public class TopicResourceTest extends JerseyTest {
                        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 );
+                               assertTrue( is2xx( resp.getStatus()) );
                        }       
                } catch (Exception e ) {
                        
index dcdfcdf..bfa4126 100644 (file)
@@ -97,7 +97,7 @@ public class MR_ClientServiceTest {
                if ( nTopic != null ) {
                        assertTrue( nTopic.getTopicName().equals( topic.getTopicName() ));
                }
-               String[] actions = { "pub", "view" };
+
                MR_Client c = factory.genPublisher( "edge",  topic.getFqtn() );
 
                c = cls.addMr_Client( c, topic, err );
@@ -114,7 +114,7 @@ public class MR_ClientServiceTest {
        }
 
        @Test
-       public void test5() {
+       public void AddSubscriberToTopic() {
                Topic topic = factory.genSimpleTopic( "test5" );
                ApiError err = new ApiError();
                Topic nTopic = ts.addTopic( topic, err, false );
@@ -124,11 +124,13 @@ public class MR_ClientServiceTest {
                MR_Client c = factory.genPublisher( "central", topic.getFqtn() );
 
                c = cls.addMr_Client( c, topic, err );
-               if ( c != null ) {
-                               c = factory.genSubscriber( "central", topic.getFqtn() );
-                               c = cls.updateMr_Client( c, err );
-                               assertTrue( err.getCode() == 200 );
-               }
-       }
+               assertTrue( c != null );
 
+               c = factory.genSubscriber( "central", topic.getFqtn() );
+               c = cls.addMr_Client( c, topic, err );
+               assertTrue( err.getCode() == 200 );
+
+               
+       }
+       
 }
index 787d232..f247bad 100644 (file)
@@ -42,6 +42,9 @@ public class MirrorMakerServiceTest {
        private MR_ClusterService mcs;
        private MR_ClientService cls;
        private DcaeLocationService dls;
+       
+       private Topic replicationTopic;
+
 
        DmaapService ds;
        String locname;
@@ -73,6 +76,24 @@ public class MirrorMakerServiceTest {
                mcs.addMr_Cluster( node, err);
                node = factory.genMR_Cluster("edge" );
                mcs.addMr_Cluster(node,  err);
+
+
+               String t = "org.onap.dmaap.bridgingTopic";
+               replicationTopic = factory.genSimpleTopic(t);
+               replicationTopic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
+
+               String c = "publisher";
+               String[] a = { "sub", "view" };
+               MR_Client sub = factory.genMR_Client("central",  replicationTopic.getFqtn(), c, a );
+               String[] b = { "pub", "view" };
+               MR_Client pub = factory.genMR_Client( "edge", replicationTopic.getFqtn(), c, b );
+               ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
+
+               clients.add( sub );
+               clients.add( pub );
+
+               replicationTopic.setClients( clients );
+
        }
 
        @After
@@ -101,23 +122,8 @@ public class MirrorMakerServiceTest {
        public void CreateMirrorMakerWithSingleTopic() {
                ApiError err = new ApiError();
 
-               String t = "org.onap.dmaap.bridgingTopic";
-               Topic topic = factory.genSimpleTopic(t);
-               topic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
-
-               String c = "publisher";
-               String[] a = { "sub", "view" };
-               MR_Client sub = factory.genMR_Client("central",  topic.getFqtn(), c, a );
-               String[] b = { "pub", "view" };
-               MR_Client pub = factory.genMR_Client( "edge", topic.getFqtn(), c, b );
-               ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
-
-               clients.add( sub );
-               clients.add( pub );
-
-               topic.setClients( clients );
 
-               Topic nTopic = ts.updateTopic( topic, err );
+               Topic nTopic = ts.addTopic(replicationTopic, err, true );
 
                assertTrue( err.getCode() == 200 );
                
@@ -127,6 +133,13 @@ public class MirrorMakerServiceTest {
        @Test
        public void DeleteMirrorMakerWithSingleTopic() {
 
+               ApiError err = new ApiError();
+               Topic nTopic = ts.addTopic(replicationTopic, err, true );
+               replicationTopic.setTopicDescription("modified topic");
+               nTopic = ts.updateTopic( replicationTopic, err );
+
+               assertTrue( err.getCode() == 200 );
+
                
                List<String> mma = mms.getAllMirrorMakers();
                
@@ -149,23 +162,11 @@ public class MirrorMakerServiceTest {
 
                ApiError err = new ApiError();
 
-               String t = "org.onap.dmaap.bridgingTopic";
-               Topic topic = factory.genSimpleTopic(t);
-               topic.setReplicationCase( ReplicationType.REPLICATION_EDGE_TO_CENTRAL );
-
-               String c = "publisher";
-               String[] a = { "sub", "view" };
-               MR_Client sub = factory.genMR_Client("central",  topic.getFqtn(), c, a );
-               String[] b = { "pub", "view" };
-               MR_Client pub = factory.genMR_Client( "edge", topic.getFqtn(), c, b );
-               ArrayList<MR_Client> clients = new ArrayList<MR_Client>();
-
-               clients.add( sub );
-               clients.add( pub );
 
-               topic.setClients( clients );
+               Topic nTopic = ts.addTopic( replicationTopic, err, true );
+               replicationTopic.setTopicDescription("modified topic");
+               nTopic = ts.updateTopic( replicationTopic, err );
 
-               Topic nTopic = ts.updateTopic( topic, err );
 
                assertTrue( err.getCode() == 200 );
                List<String> mma = mms.getAllMirrorMakers();