Fix some things I broke
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>
diff --git a/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
index 2be1b33..688bbce 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
@@ -49,6 +49,7 @@
private String authMethod;
private String user;
private String encPwd;
+ private String unit_test;
private boolean hostnameVerify;
public MrProvConnection() {
@@ -60,6 +61,7 @@
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 @@
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 );
diff --git a/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java b/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
index 0a5f91a..b3f713f 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
@@ -204,9 +204,9 @@
} 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);
diff --git a/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
index 88840fe..04c1bda 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/resources/TopicResourceTest.java
@@ -54,6 +54,12 @@
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 @@
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 @@
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 @@
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 ) {
diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java
index dcdfcdf..bfa4126 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java
@@ -97,7 +97,7 @@
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 @@
}
@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 @@
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 );
+
+
+ }
+
}
diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/MirrorMakerServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/MirrorMakerServiceTest.java
index 787d232..f247bad 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/service/MirrorMakerServiceTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/service/MirrorMakerServiceTest.java
@@ -42,6 +42,9 @@
private MR_ClusterService mcs;
private MR_ClientService cls;
private DcaeLocationService dls;
+
+ private Topic replicationTopic;
+
DmaapService ds;
String locname;
@@ -73,6 +76,24 @@
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 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 @@
@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 @@
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>();
+ Topic nTopic = ts.addTopic( replicationTopic, err, true );
+ replicationTopic.setTopicDescription("modified topic");
+ nTopic = ts.updateTopic( replicationTopic, err );
- clients.add( sub );
- clients.add( pub );
-
- topic.setClients( clients );
-
- Topic nTopic = ts.updateTopic( topic, err );
assertTrue( err.getCode() == 200 );
List<String> mma = mms.getAllMirrorMakers();