Allow POST dr_sub using FeedName
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / service / DR_SubService.java
index 138ff57..9d233a5 100644 (file)
@@ -3,6 +3,8 @@
  * org.onap.dmaap
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2019 IBM.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -63,11 +65,11 @@ public class DR_SubService extends BaseLoggingClass {
                
        public List<DR_Sub> getAllDr_Subs() {
                logger.debug( "enter getAllDR_Subs()");
-               return new ArrayList<DR_Sub>(dr_subs.values());
+               return new ArrayList<>(dr_subs.values());
        }
        
        public ArrayList<DR_Sub> getDr_SubsByFeedId( String pubId ) {
-               ArrayList<DR_Sub> someSubs = new ArrayList<DR_Sub>();
+               ArrayList<DR_Sub> someSubs = new ArrayList<>();
                for( DR_Sub sub : dr_subs.values() ) {
                        if ( pubId.equals(  sub.getFeedId()  )) {
                                someSubs.add( sub );
@@ -94,8 +96,9 @@ public class DR_SubService extends BaseLoggingClass {
                prov = new DrProvConnection();
                prov.makeSubPostConnection( provURL );
                String resp = prov.doPostDr_Sub( sub, apiError );
-               if ( unit_test.equals( "Yes" ) ) {
+               if ( "Yes".equals(unit_test) ) {
                        resp = simulateResp( sub, "POST" );
+                       apiError.setCode(201);
                }
                logger.debug( "addDr_Sub resp=" + resp );
 
@@ -107,7 +110,7 @@ public class DR_SubService extends BaseLoggingClass {
                        snew.setLastMod();
                        addEgressRoute( snew, apiError );
                        dr_subs.put( snew.getSubId(), snew );   
-                       apiError.setCode(200);
+                       apiError.setCode(201);
                } else {
                        apiError.setCode(400);
                }
@@ -147,6 +150,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;
@@ -179,7 +186,7 @@ public class DR_SubService extends BaseLoggingClass {
                        String resp = prov.doDeleteDr_Sub( sub, apiError );
                        logger.debug( "resp=" + resp );
                        
-                       if ( apiError.is2xx() ) {
+                       if ( apiError.is2xx() || unit_test.equals( "Yes" ) ) {
                                dr_subs.remove(key);
                        }
                }
@@ -198,8 +205,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;
        }