Raise unit test coverage over 50%
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / service / DR_SubService.java
index c3f8c9c..d6012a7 100644 (file)
@@ -26,8 +26,8 @@ import java.util.Map;
 
 import javax.ws.rs.core.Response.Status;
 
-import org.onap.dmaap.dbcapi.aaf.client.DrProvConnection;
-import org.onap.dmaap.dbcapi.aaf.database.DatabaseClass;
+import org.onap.dmaap.dbcapi.client.DrProvConnection;
+import org.onap.dmaap.dbcapi.database.DatabaseClass;
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
 import org.onap.dmaap.dbcapi.model.ApiError;
@@ -96,6 +96,7 @@ public class DR_SubService extends BaseLoggingClass {
                String resp = prov.doPostDr_Sub( sub, apiError );
                if ( unit_test.equals( "Yes" ) ) {
                        resp = simulateResp( sub, "POST" );
+                       apiError.setCode(200);
                }
                logger.debug( "addDr_Sub resp=" + resp );
 
@@ -147,6 +148,10 @@ public class DR_SubService extends BaseLoggingClass {
                DrProvConnection prov = new DrProvConnection();
                prov.makeSubPutConnection( obj.getSubId() );
                String resp = prov.doPutDr_Sub( obj, apiError );
+               if ( unit_test.equals( "Yes" ) ) {
+                       resp = simulateResp( obj, "PUT" );
+                       apiError.setCode(200);
+               }
                logger.debug( "resp=" + resp );
 
                DR_Sub snew = null;
@@ -167,14 +172,21 @@ public class DR_SubService extends BaseLoggingClass {
                
        public void removeDr_Sub( String key, ApiError apiError ) {
                logger.debug( "enter removeDR_Subs()");
+               
                DR_Sub sub = dr_subs.get( key );
                if ( sub == null ) {
                        apiError.setCode(Status.NOT_FOUND.getStatusCode());
                        apiError.setFields( "subId");
                        apiError.setMessage("subId " + key + " not found");
                } else {        
-                       dr_subs.remove(key);
-                       apiError.setCode(200);
+                       DrProvConnection prov = new DrProvConnection();
+                       prov.makeSubPutConnection( key );
+                       String resp = prov.doDeleteDr_Sub( sub, apiError );
+                       logger.debug( "resp=" + resp );
+                       
+                       if ( apiError.is2xx() || unit_test.equals( "Yes" ) ) {
+                               dr_subs.remove(key);
+                       }
                }
 
                return;
@@ -191,8 +203,14 @@ public class DR_SubService extends BaseLoggingClass {
                } else {
                        subid = "99";
                }
-               String ret = String.format("{\"delivery\": {\"url\": \"https://%s/delivery/%s\", \"user\": \"joe\", \"password\": \"secret\", \"use100\":  true}, \"metadataOnly\": false, \"groupid\": \"0\" , \"follow_redirect\": true }", 
-                       server, subid );
+               String ret = String.format("{\"suspend\": false, \"delivery\": {\"url\": \"https://%s/delivery/%s\", \"user\": \"%s\", \"password\": \"%s\", \"use100\":  true}, \"metadataOnly\": false, \"groupid\": \"0\" , \"follow_redirect\": true, ", 
+                       server, subid, sub.getUsername(), sub.getUserpwd());
+               String links = String.format( "\"links\": {\"feed\": \"https://dr-prov/feedlog/%s\", \"self\": \"https://dr-prov/sub/%s\", \"log\": \"https://dr-prov/sublog/%s\" }", 
+                               sub.getFeedId(),
+                               sub.getSubId(),
+                               sub.getSubId() );
+               ret += links + "}";
+               logger.info( "DR_SubService:simulateResp=" + ret);
 
                return ret;
        }