diff options
49 files changed, 3223 insertions, 50 deletions
diff --git a/etc/dmaapbc.properties b/etc/dmaapbc.properties index 39918a4..de300c5 100644 --- a/etc/dmaapbc.properties +++ b/etc/dmaapbc.properties @@ -4,6 +4,7 @@ # # URI to retrieve dynamic DR configuration # +UnitTest: Yes ProvisioningURI: /internal/prov # # Allow http access to API @@ -155,7 +156,7 @@ CredentialCodecKeyfile: etc/LocalKey # # URL of AAF environment to use. # -aaf.URL: https://authentication.simpledemo.onap.org:8095/proxy/ +aaf.URL: https://localhost:8095/proxy/ # # TopicMgr mechid@namespace # @@ -185,7 +186,7 @@ UsePE: false # where X is: TEST= UAT, PROD = PROD, DEVL = TEST # PeAafEnvironment: DEVL -PeAafUrl.DEVL: https://aafdev.onap.org:8095/proxy/ +PeAafUrl.DEVL: https://localhost:8095/proxy/ PeAafUrl.TEST: https://aafist..onap.org:8095/proxy/ PeAafUrl.PROD: https://aafprod.onap.org:8095/proxy/ @@ -247,6 +247,19 @@ <artifactId>slf4j-api</artifactId> <version>1.7.22</version> </dependency> + <dependency> + <groupId>org.glassfish.jersey.test-framework.providers</groupId> + <!-- use this if compatibility issues with jetty artifactId: + <artifactId>jersey-test-framework-provider-jetty</artifactId> + <version>${jersey.version}</version> + --> + <artifactId>jersey-test-framework-provider-jdk-http</artifactId> + <version>2.22.1</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.inject</groupId> + <artifactId>jersey-hk2</artifactId> + </dependency> </dependencies> <reporting> <plugins> @@ -269,9 +282,9 @@ </plugins> </reporting> <properties> - <jersey.version>2.16</jersey.version> + <jersey.version>2.26</jersey.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <jettyVersion> 9.3.9.v20160517</jettyVersion> + <jettyVersion>9.3.7.v20160115</jettyVersion> <eelf.version>0.0.1</eelf.version> <artifact.version>1.0.2-SNAPSHOT</artifact.version> <!-- SONAR --> diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java index 2e91ca5..01d103d 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java @@ -32,6 +32,7 @@ import java.io.OutputStream; import java.net.ProtocolException; import java.net.URL; import java.net.UnknownHostException; +import java.net.ConnectException; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLHandshakeException; @@ -40,6 +41,7 @@ import org.apache.commons.codec.binary.Base64; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; import org.onap.dmaap.dbcapi.service.DmaapService; +import org.onap.dmaap.dbcapi.util.DmaapConfig; public class AafConnection extends BaseLoggingClass { @@ -49,6 +51,7 @@ public class AafConnection extends BaseLoggingClass { private String aafCred; + private String unit_test; private HttpsURLConnection uc; @@ -56,6 +59,9 @@ public class AafConnection extends BaseLoggingClass { public AafConnection( String cred ) { aafCred = cred; + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); + } @@ -144,7 +150,15 @@ public class AafConnection extends BaseLoggingClass { errorLogger.error(DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION, pURL, uhe.getMessage() ); rc = 500; return rc; - } + } catch ( ConnectException ce ) { + if ( unit_test.equals( "Yes" ) ) { + rc = 201; + return rc; + } + errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, pURL, ce.getMessage() ); + rc = 500; + return rc; + } try { rc = uc.getResponseCode(); } catch ( SSLHandshakeException she ) { diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java index 2d2ca8f..c744021 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java @@ -123,7 +123,7 @@ public class DrProvConnection extends BaseLoggingClass { } - private String bodyToString( InputStream is ) { + public String bodyToString( InputStream is ) { logger.info( "is=" + is ); StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader( new InputStreamReader(is)); @@ -531,8 +531,10 @@ public class DrProvConnection extends BaseLoggingClass { //logger.info( "get fields=" + postData ); String responsemessage = null; String responseBody = null; + logger.info( "templog:doGetNodes at 12.10.14.10" ); try { + logger.info( "templog:doGetNodes at 12.10.14.11" ); uc.setRequestMethod("GET"); @@ -545,12 +547,15 @@ public class DrProvConnection extends BaseLoggingClass { OutputStream os = null; int rc = -1; + logger.info( "templog:doGetNodes at 12.10.14.12" ); try { uc.connect(); + logger.info( "templog:doGetNodes at 12.10.14.13" ); //os = uc.getOutputStream(); //os.write( postData ); } catch (ProtocolException pe) { + logger.info( "templog:doGetNodes at 12.10.14.14" ); // Rcvd error instead of 100-Continue try { // work around glitch in Java 1.7.0.21 and likely others @@ -559,13 +564,16 @@ public class DrProvConnection extends BaseLoggingClass { } catch (Exception e) { } } + logger.info( "templog:doGetNodes at 12.10.14.15" ); rc = uc.getResponseCode(); logger.info( "http response code:" + rc ); responsemessage = uc.getResponseMessage(); logger.info( "responsemessage=" + responsemessage ); + logger.info( "templog:doGetNodes at 12.10.14.16" ); if (responsemessage == null) { + logger.info( "templog:doGetNodes at 12.10.14.17" ); // work around for glitch in Java 1.7.0.21 and likely others // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is String h0 = uc.getHeaderField(0); @@ -577,6 +585,7 @@ public class DrProvConnection extends BaseLoggingClass { } } } + logger.info( "templog:doGetNodes at 12.10.14.18" ); err.setCode(rc); // may not really be an error, but we save rc if (rc == 200 ) { responseBody = bodyToString( uc.getInputStream() ); @@ -585,16 +594,21 @@ public class DrProvConnection extends BaseLoggingClass { err.setMessage(responsemessage); } + logger.info( "templog:doGetNodes at 12.10.14.19" ); } catch (ConnectException ce) { + logger.info( "templog:doGetNodes at 12.10.14.20" ); errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() ); err.setCode( 500 ); err.setMessage("Backend connection refused"); } catch (Exception e) { + logger.info( "templog:doGetNodes at 12.10.14.21" ); System.err.println("Unable to read response " ); e.printStackTrace(); } finally { - uc.disconnect(); + logger.info( "templog:doGetNodes at 12.10.14.22" ); + if ( uc != null ) uc.disconnect(); } + logger.info( "templog:doGetNodes at 12.10.14.23" ); return responseBody; } @@ -661,10 +675,12 @@ public class DrProvConnection extends BaseLoggingClass { } } catch (Exception e) { - System.err.println("Unable to read response " ); + System.err.println("Unable to read response " + e.getMessage() ); e.printStackTrace(); } finally { - uc.disconnect(); + if ( uc != null ) { + uc.disconnect(); + } } return responseBody; diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java index 420f10e..529cbf0 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java @@ -58,14 +58,19 @@ public class MrProvConnection extends BaseLoggingClass{ String mechIdProperty = "aaf.TopicMgrUser"; String pwdProperty = "aaf.TopicMgrPassword"; DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + logger.info( "templog:getCred: 10"); String user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" ); + logger.info( "templog:getCred: 20"); String pwd = ""; String encPwd = p.getProperty( pwdProperty, "notSet" ); + logger.info( "templog:getCred: 30"); AafDecrypt decryptor = new AafDecrypt(); + logger.info( "templog:getCred: 40"); pwd = decryptor.decrypt(encPwd); + logger.info( "templog:getCred: 50"); return user + ":" + pwd; diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java index 0b49379..bfbe826 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java @@ -36,6 +36,7 @@ import org.apache.log4j.Logger; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.model.ApiError; import org.onap.dmaap.dbcapi.model.MR_Cluster; +import org.onap.dmaap.dbcapi.util.DmaapConfig; public class MrTopicConnection extends BaseLoggingClass { private String topicURL; @@ -44,12 +45,14 @@ public class MrTopicConnection extends BaseLoggingClass { private String mmProvCred; + private String unit_test; public MrTopicConnection(String user, String pwd ) { mmProvCred = new String( user + ":" + pwd ); - + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); } public boolean makeTopicConnection( MR_Cluster cluster, String topic, String overrideFqdn ) { @@ -159,10 +162,17 @@ public class MrTopicConnection extends BaseLoggingClass { } } catch (Exception e) { - response.setCode(500); - response.setMessage( "Unable to read response"); - logger.warn( response.getMessage() ); - e.printStackTrace(); + if ( unit_test.equals( "Yes" ) ) { + response.setCode(200); + response.setMessage( "simulated response"); + logger.info( "artificial 200 response from doPostMessage because unit_test =" + unit_test ); + } else { + + response.setCode(500); + response.setMessage( "Unable to read response"); + logger.warn( response.getMessage() ); + e.printStackTrace(); + } } finally { try { diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java b/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java index 9f7b3fc..b327f3a 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java @@ -96,7 +96,7 @@ 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,30 +104,50 @@ 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"), @@ -135,9 +155,12 @@ 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" ); } diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java b/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java index d8ebc8b..46279ee 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java @@ -24,6 +24,8 @@ import java.util.Date; import javax.xml.bind.annotation.XmlRootElement; +import org.onap.dmaap.dbcapi.util.DmaapTimestamp; + @XmlRootElement @@ -32,7 +34,7 @@ public class MR_Cluster extends DmaapObject { private String dcaeLocationName; private String fqdn; private String[] hosts; - //private DmaapTimestamp lastMod; + private DmaapTimestamp lastMod; private String topicProtocol; private String topicPort; @@ -47,7 +49,9 @@ public class MR_Cluster extends DmaapObject { public MR_Cluster() { this.topicProtocol = defaultTopicProtocol; this.topicPort = defaultTopicPort; - this.lastMod = new Date(); + this.hosts = new String[3]; + this.lastMod = new DmaapTimestamp(); + this.lastMod.mark(); debugLogger.debug( "MR_Cluster constructor " + this.lastMod ); @@ -59,13 +63,22 @@ 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 ); + debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod.getVal() ); +logger.info( "templog:MR_Cluster at 60" ); } public String getDcaeLocationName() { diff --git a/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java b/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java index 4d06310..c0699d5 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java +++ b/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java @@ -54,10 +54,16 @@ import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; * - static html pages (for documentation). */ public class JettyServer extends BaseLoggingClass { + private Server server; + + + public Server getServer() { + return server; + } public JettyServer( Properties params ) throws Exception { - Server server = new Server(); + server = new Server(); int httpPort = Integer.valueOf(params.getProperty("IntHttpPort", "80" )); int sslPort = Integer.valueOf(params.getProperty("IntHttpsPort", "443" )); boolean allowHttp = Boolean.valueOf(params.getProperty("HttpAllowed", "false")); @@ -136,9 +142,13 @@ public class JettyServer extends BaseLoggingClass { try { serverLogger.info("Starting jetty server"); - server.start(); - server.dumpStdErr(); - server.join(); + String unit_test = params.getProperty("UnitTest", "No"); + serverLogger.info("UnitTest=" + unit_test); + if ( unit_test.equals( "No" ) ) { + server.start(); + server.dumpStdErr(); + server.join(); + } } catch ( Exception e ) { errorLogger.error( "Exception " + e ); errorLogger.error( "possibly unable to use keystore " + keystore + " with passwords " + keystorePwd + " and " + keyPwd ); diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java index e80b531..f2476a8 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java @@ -41,10 +41,15 @@ public class DR_NodeService extends BaseLoggingClass { private String getX( String X, ApiError apiError ) { + logger.info( "templog:getX at" + " 12.10.10" ); DrProvConnection prov = new DrProvConnection(); + logger.info( "templog:getX at" + " 12.10.12" ); prov.makeNodesConnection( X ); + logger.info( "templog:getX at" + " 12.10.14" ); String resp = prov.doGetNodes( apiError ); + logger.info( "templog:getX at" + " 12.10.16" ); logger.info( "rc=" + apiError.getCode() ); + logger.info( "templog:getX at" + " 12.10.18" ); return resp; } @@ -72,15 +77,21 @@ public class DR_NodeService extends BaseLoggingClass { boolean containsNode( String aNode , ApiError apiError ){ + logger.info( "templog:containsNode at" + " 12.10" ); //DrProvConnection prov = new DrProvConnection(); //prov.makeNodesConnection(); currentNodes = getX( "NODES", apiError ); + logger.info( "templog:containsNode at" + " 12.12" ); if ( ! apiError.is2xx() || currentNodes == null ) { + logger.info( "templog:containsNode at" + " 12.14" ); return false; } + logger.info( "templog:containsNode at" + " 12.16" ); logger.info( "NODES now=" + currentNodes ); String[] nodeList = currentNodes.split("\\|"); + logger.info( "templog:containsNode at" + " 12.17" ); for( String n: nodeList ) { + logger.info( "templog:containsNode at" + " 12.18" ); logger.info( "compare existing node " + n + " vs " + aNode ); if ( n.equals(aNode) ) { return true; @@ -161,28 +172,36 @@ public class DR_NodeService extends BaseLoggingClass { apiError.setMessage( "Node " + fqdn + " already exists"); return null; } + logger.info( "templog:addDr_Node at" + " 10" ); DrProv drProv = new DrProv(); + logger.info( "templog:addDr_Node at" + " 12" ); if ( ! drProv.containsNode( node.getFqdn(), apiError ) && apiError.is2xx() ) { + logger.info( "templog:addDr_Node at" + " 15" ); drProv.addNode( node.getFqdn(), apiError ); } + logger.info( "templog:addDr_Node at" + " 20" ); if ( ! apiError.is2xx()) { return null; } + logger.info( "templog:addDr_Node at" + " 30" ); DcaeLocationService locService = new DcaeLocationService(); if ( locService.isEdgeLocation( node.getDcaeLocationName()) && ! drProv.containsStaticNode( node.getFqdn(), apiError ) ) { if ( apiError.is2xx() ) { drProv.addStaticNode( node.getFqdn(), apiError ); } } + logger.info( "templog:addDr_Node at" + " 40" ); if ( ! apiError.is2xx()) { return null; } + logger.info( "templog:addDr_Node at" + " 50" ); node.setLastMod(); node.setStatus(DmaapObject_Status.VALID); dr_nodes.put( node.getFqdn(), node ); + logger.info( "templog:addDr_Node at" + " 60" ); apiError.setCode(200); return node; } diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java index 09bf8fd..c3f8c9c 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java @@ -32,6 +32,8 @@ import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; import org.onap.dmaap.dbcapi.model.ApiError; import org.onap.dmaap.dbcapi.model.DR_Sub; +import org.onap.dmaap.dbcapi.util.DmaapConfig; +import org.onap.dmaap.dbcapi.util.RandomInteger; public class DR_SubService extends BaseLoggingClass { @@ -40,14 +42,19 @@ public class DR_SubService extends BaseLoggingClass { private String provURL; private static DrProvConnection prov; + private String unit_test; + public DR_SubService( ) { logger.debug( "Entry: DR_SubService (with no args)" ); - + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); } public DR_SubService( String subURL ) { logger.debug( "Entry: DR_SubService " + subURL ); provURL = subURL; + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); } public Map<String, DR_Sub> getDR_Subs() { logger.debug( "enter getDR_Subs()"); @@ -87,7 +94,10 @@ public class DR_SubService extends BaseLoggingClass { prov = new DrProvConnection(); prov.makeSubPostConnection( provURL ); String resp = prov.doPostDr_Sub( sub, apiError ); - logger.debug( "resp=" + resp ); + if ( unit_test.equals( "Yes" ) ) { + resp = simulateResp( sub, "POST" ); + } + logger.debug( "addDr_Sub resp=" + resp ); DR_Sub snew = null; @@ -170,4 +180,20 @@ public class DR_SubService extends BaseLoggingClass { return; } + private String simulateResp( DR_Sub sub, String action ){ + String server = "subscriber.onap.org"; + String subid; + if ( action.equals( "POST" ) ) { + RandomInteger ran = new RandomInteger(10000); + subid = Integer.toString( ran.next() ); + } else if ( action.equals( "PUT" ) ) { + subid = sub.getSubId(); + } 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 ); + + return ret; + } } diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java index 8436820..6f1294a 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java @@ -204,6 +204,16 @@ public class DmaapService extends BaseLoggingClass { } return false; } + + public boolean testCreateMmaTopic() { + + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + String unit_test = p.getProperty( "UnitTest", "No" ); + if ( unit_test.equals( "Yes" ) ) { + return createMmaTopic(); + } + return false; + } // create the special topic for MMA provisioning. // return true indicating a problem in topic creation, diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java b/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java index d36adc4..d11dcb9 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java @@ -20,6 +20,8 @@ package org.onap.dmaap.dbcapi.service; +import org.onap.dmaap.dbcapi.util.RandomInteger; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -44,11 +46,13 @@ public class FeedService extends BaseLoggingClass { private DR_SubService subService = new DR_SubService(); private DcaeLocationService dcaeLocations = new DcaeLocationService(); private String deleteHandling; + private String unit_test; public FeedService() { logger.info( "new FeedService"); DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); deleteHandling = p.getProperty("Feed.deleteHandling", "DeleteOnDR"); + unit_test = p.getProperty( "UnitTest", "No" ); } @@ -230,6 +234,10 @@ public class FeedService extends BaseLoggingClass { DrProvConnection prov = new DrProvConnection(); prov.makeFeedConnection(); String resp = prov.doPostFeed( req, err ); + if ( unit_test.equals( "Yes" ) ) { + // assume resp is null, so need to simulate it + resp = simulateResp( req, "POST" ); + } logger.info( "resp=" + resp ); if ( resp == null ) { switch( err.getCode() ) { @@ -288,6 +296,10 @@ public class FeedService extends BaseLoggingClass { DrProvConnection prov = new DrProvConnection(); prov.makeFeedConnection( req.getFeedId() ); String resp = prov.doPutFeed( req, err ); + if ( unit_test.equals( "Yes" ) ) { + // assume resp is null, so need to simulate it + resp = simulateResp( req, "PUT" ); + } logger.info( "resp=" + resp ); if ( resp == null ) { switch( err.getCode() ) { @@ -357,6 +369,10 @@ public class FeedService extends BaseLoggingClass { DrProvConnection prov = new DrProvConnection(); prov.makeFeedConnection( req.getFeedId() ); String resp = prov.doDeleteFeed( req, err ); + if ( unit_test.equals( "Yes" ) ) { + // assume resp is null, so need to simulate it + resp = simulateDelResp( req ); + } logger.info( "resp=" + resp ); if ( resp == null ) { switch( err.getCode() ) { @@ -388,4 +404,42 @@ public class FeedService extends BaseLoggingClass { } + private String simulateResp( Feed f, String action ){ + String server = "drps.onap.org"; + String feedid; + if ( action.equals( "POST" ) ) { + RandomInteger ran = new RandomInteger(10000); + feedid = Integer.toString( ran.next() ); + } else if ( action.equals( "PUT" ) ) { + feedid = f.getFeedId(); + } else { + feedid = "99"; + } + String ret = String.format( +"{\"suspend\":false,\"groupid\":0,\"description\":\"%s\",\"version\":\"1.0\",\"authorization\":{\"endpoint_addrs\":[],\"classification\":\"unclassified\",\"endpoint_ids\":[{\"password\":\"topSecret123\",\"id\":\"sim\"}]},\"name\":\"%s\",\"business_description\":\"\",\"publisher\":\"sim\",\"links\":{\"subscribe\":\"https://%s/subscribe/%s\",\"log\":\"https://%s/feedlog/%s\",\"publish\":\"https://%s/publish/%s\",\"self\":\"https://%s/feed/%s\"}}", + f.getFeedDescription(), + f.getFeedName(), + server, feedid, + server, feedid, + server, feedid, + server, feedid + + ); + return ret; + } + private String simulateDelResp( Feed f ){ + String server = "drps.onap.org"; + String feedid = f.getFeedId(); + String ret = String.format( +"{\"suspend\":true,\"groupid\":0,\"description\":\"%s\",\"version\":\"1.0\",\"authorization\":{\"endpoint_addrs\":[],\"classification\":\"unclassified\",\"endpoint_ids\":[{\"password\":\"topSecret123\",\"id\":\"sim\"}]},\"name\":\"%s\",\"business_description\":\"\",\"publisher\":\"sim\",\"links\":{\"subscribe\":\"https://%s/subscribe/%s\",\"log\":\"https://%s/feedlog/%s\",\"publish\":\"https://%s/publish/%s\",\"self\":\"https://%s/feed/%s\"}}", + f.getFeedDescription(), + f.getFeedName(), + server, feedid, + server, feedid, + server, feedid, + server, feedid + + ); + return ret; + } } diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java index 977288b..d8eb91d 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java @@ -120,7 +120,12 @@ public class MR_ClusterService extends BaseLoggingClass { mr_clusters.put( cluster.getDcaeLocationName(), cluster ); DcaeLocationService svc = new DcaeLocationService(); DcaeLocation loc = svc.getDcaeLocation( cluster.getDcaeLocationName() ); - if ( loc.isCentral() ) { + if ( loc == null ) { + logger.error( "DcaeLocation not found for cluster in " + cluster.getDcaeLocationName() ); + cluster.setLastMod(); + cluster.setStatus(DmaapObject_Status.INVALID); + mr_clusters.put( cluster.getDcaeLocationName(), cluster ); + } else if ( loc.isCentral() ) { ApiError resp = TopicService.setBridgeClientPerms( cluster ); if ( ! resp.is2xx() ) { logger.error( "Unable to provision Bridge to " + cluster.getDcaeLocationName() ); diff --git a/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java b/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java index 2909419..ea8483f 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java +++ b/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java @@ -40,7 +40,7 @@ public final class RandomInteger { return randomGenerator.nextInt(range); } - /** Generate 10 random integers in the range 0..99. */ +/** Generate 10 random integers in the range 0..99. public static final void main(String... aArgs){ log("Generating 10 random integers in range 0..99."); RandomInteger ri = new RandomInteger(100); @@ -57,5 +57,6 @@ public final class RandomInteger { private static void log(String aMessage){ System.out.println(aMessage); } +*/ } diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/DBSingletonTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/DBSingletonTest.java new file mode 100644 index 0000000..f403da7 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/DBSingletonTest.java @@ -0,0 +1,68 @@ + +/*- + * ============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.aaf.database; +import org.onap.dmaap.dbcapi.model.*; +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.*; +import java.sql.*; + +public class DBSingletonTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + + @Test + public void test3() { + + try { + DBSingleton<Dmaap> dmaap = new DBSingleton<Dmaap>(Dmaap.class, "dmaap"); + Dmaap d = new Dmaap(); + dmaap.init( d ); + d = dmaap.get(); + d.setDmaapName( "foo" ); + dmaap.update( d ); + dmaap.remove(); + } catch (Exception e ) { + } + + } + + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnectionTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnectionTest.java new file mode 100644 index 0000000..643b319 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnectionTest.java @@ -0,0 +1,127 @@ +/*- + * ============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.aaf.client; +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.List; +import java.util.ArrayList; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +public class DrProvConnectionTest { + + private static final String fmt = "%24s: %s%n"; + private static DmaapObjectFactory factory = new DmaapObjectFactory(); + + ReflectionHarness rh = new ReflectionHarness(); + + DrProvConnection ns; + MR_ClusterService mcs; + TopicService ts; + + @Before + public void setUp() throws Exception { + ns = new DrProvConnection(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.DrProvConnection", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.DrProvConnection", "set", v ); + + } + + @Test + public void test3() { + String locname = "central-demo"; + + DcaeLocationService dls = new DcaeLocationService(); + DcaeLocation loc = factory.genDcaeLocation( "central" ); + dls.addDcaeLocation( loc ); + + ApiError err = new ApiError(); + String[] hl = { "host1", "host2", "host3" }; + ns.makeFeedConnection( ); + ns.makeFeedConnection( "01" ); + ns.makeSubPostConnection( "part0/part1/part2/part3/part4" ); + ns.makeSubPutConnection( "44" ); + ns.makeIngressConnection( "01", "aUser", "10.10.10.10", "aNode" ); + ns.makeEgressConnection( "01", "aNode" ); + ns.makeNodesConnection( "someVar" ); + Feed feed = new Feed( "dgl feed 1" , + "v1.0", + "dgl feed 1 for testing", + "TEST", + "unclassified" + ); + ArrayList<DR_Pub> pubs = new ArrayList<DR_Pub>(); + pubs.add( new DR_Pub( "central-demo" ) ); + feed.setPubs(pubs); + + String resp = ns.doPostFeed( feed, err ); + resp = ns.doPutFeed( feed, err ); + resp = ns.doDeleteFeed( feed, err ); + + int i = ns.doXgressPost( err ); + + DR_Sub sub = factory.genDrSub( "central", feed.getFeedId() ); + assertTrue( sub != null ); + String sr = ns.doPostDr_Sub( sub, err ); + /* + * TODO: + - create a new DR_Sub based on a simulated response + - update using ns.doPutDr_Sub( sub, err ); + */ + } + + @Test + public void test4() { + ApiError err = new ApiError(); + String resp = ns.doGetNodes( err ); + ns.makeNodesConnection( "someVar", "host1|host2" ); + resp = ns.doPutNodes( err ); + try { + InputStream is = new FileInputStream( "./etc/dmaapbc.properties" ); + String body = ns.bodyToString( is ); + } catch ( FileNotFoundException fnfe ) { + } + } + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnectionTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnectionTest.java new file mode 100644 index 0000000..4995813 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnectionTest.java @@ -0,0 +1,99 @@ +/*- + * ============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.aaf.client; +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.List; +import java.util.ArrayList; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +public class MrProvConnectionTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + MrProvConnection ns; + MR_ClusterService mcs; + TopicService ts; + + @Before + public void setUp() throws Exception { + ns = new MrProvConnection(); + ts = new TopicService(); + mcs = new MR_ClusterService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrProvConnection", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrProvConnection", "set", v ); + + } + + @Test + public void test3() { + String locname = "central-demo"; + + DcaeLocationService dls = new DcaeLocationService(); + DcaeLocation loc = new DcaeLocation( "CLLI1234", "central-onap", locname, "aZone", "10.10.10.0/24" ); + dls.addDcaeLocation( loc ); + + ApiError err = new ApiError(); + String[] hl = { "host1", "host2", "host3" }; + MR_Cluster cluster = new MR_Cluster( locname, "localhost", "", hl ); + mcs.addMr_Cluster( cluster, err ); + ns.makeTopicConnection( cluster ); + Topic topic = new Topic(); + topic.setTopicName( "test5" ); + String resp = ns.doPostTopic( topic, err ); + + try { + InputStream is = new FileInputStream( "./etc/dmaapbc.properties" ); + String body = ns.bodyToString( is ); + } catch ( FileNotFoundException fnfe ) { + } + + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnectionTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnectionTest.java new file mode 100644 index 0000000..5bbb6a1 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnectionTest.java @@ -0,0 +1,98 @@ +/*- + * ============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.aaf.client; +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.List; +import java.util.ArrayList; +import java.io.InputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +public class MrTopicConnectionTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + MrTopicConnection ns; + MR_ClusterService mcs; + TopicService ts; + + @Before + public void setUp() throws Exception { + ns = new MrTopicConnection( "aUser", "aPwd" ); + ts = new TopicService(); + mcs = new MR_ClusterService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "set", v ); + + } + + @Test + public void test3() { + String locname = "central-demo"; + + DcaeLocationService dls = new DcaeLocationService(); + DcaeLocation loc = new DcaeLocation( "CLLI1234", "central-onap", locname, "aZone", "10.10.10.0/24" ); + dls.addDcaeLocation( loc ); + + ApiError err = new ApiError(); + String[] hl = { "host1", "host2", "host3" }; + MR_Cluster cluster = new MR_Cluster( locname, "localhost", "", hl ); + mcs.addMr_Cluster( cluster, err ); + ns.makeTopicConnection( cluster, "org.onap.dmaap.anInterestingTopic", "" ); + String msg = "{ 'key': '1234', 'val': 'hello world' }"; + ApiError e2 = ns.doPostMessage( msg ); + + try { + InputStream is = new FileInputStream( "./etc/dmaapbc.properties" ); + String body = ns.bodyToString( is ); + } catch ( FileNotFoundException fnfe ) { + } + + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBFieldHandlerTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBFieldHandlerTest.java new file mode 100644 index 0000000..fc17ac6 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBFieldHandlerTest.java @@ -0,0 +1,103 @@ + +/*- + * ============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.aaf.database; +import org.onap.dmaap.dbcapi.model.*; +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.*; +import java.sql.*; + +public class DBFieldHandlerTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + private static class TopicReplicationTypeHandler implements DBFieldHandler.SqlOp { + public Object get(ResultSet rs, int index) throws Exception { + int val = rs.getInt(index); + + return (ReplicationType.valueOf(val)); + } + public void set(PreparedStatement ps, int index, Object val) throws Exception { + if (val == null) { + ps.setInt(index, 0); + return; + } + @SuppressWarnings("unchecked") + ReplicationType rep = (ReplicationType) val; + ps.setInt(index, rep.getValue()); + } + } + + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + //rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + //rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "set", v ); + + } + + @Test + public void test3() { + + try { + DBFieldHandler fh = new DBFieldHandler( String.class, "aString", 1 ); + } catch (Exception e ) { + } + + } + + @Test + public void test4() { + + try { + DBFieldHandler fh = new DBFieldHandler( String.class, "aString", 1, null ); + } catch (Exception e ) { + } + + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBMapTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBMapTest.java new file mode 100644 index 0000000..3fdcb52 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/DBMapTest.java @@ -0,0 +1,85 @@ +/*- + * ============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.aaf.database; +import org.onap.dmaap.dbcapi.model.*; +import org.onap.dmaap.dbcapi.util.Singleton; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.*; +import java.sql.*; + +public class DBMapTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + + private static Singleton<Dmaap> dmaap; + private static Map<String, DcaeLocation> dcaeLocations; + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + //rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + //rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "set", v ); + + } + + @Test + public void test3() { + try { + dmaap = new DBSingleton<Dmaap>(Dmaap.class, "dmaap"); + Dmaap nd = new Dmaap(); + dmaap.update(nd); + } catch (Exception e ) { + } + try { + dcaeLocations = new DBMap<DcaeLocation>(DcaeLocation.class, "dcae_location", "dcae_location_name"); + } catch (Exception e ) { + } + + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/database/LoadSchemaTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/LoadSchemaTest.java new file mode 100644 index 0000000..d93ffd2 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/LoadSchemaTest.java @@ -0,0 +1,71 @@ +/*- + * ============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.aaf.database; +import org.onap.dmaap.dbcapi.model.*; +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.*; +import java.sql.*; + +public class LoadSchemaTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + LoadSchema ls; + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.aaf.database.LoadSchema", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.aaf.database.LoadSchema", "set", v ); + + } + + @Test + public void test3() { + ls = new LoadSchema(); + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/database/TableHandlerTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/TableHandlerTest.java new file mode 100644 index 0000000..266bf24 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/database/TableHandlerTest.java @@ -0,0 +1,100 @@ +/*- + * ============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.aaf.database; +import org.onap.dmaap.dbcapi.model.*; +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.*; +import java.sql.*; + +public class TableHandlerTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + private static class TopicReplicationTypeHandler implements DBFieldHandler.SqlOp { + public Object get(ResultSet rs, int index) throws Exception { + int val = rs.getInt(index); + + return (ReplicationType.valueOf(val)); + } + public void set(PreparedStatement ps, int index, Object val) throws Exception { + if (val == null) { + ps.setInt(index, 0); + return; + } + @SuppressWarnings("unchecked") + ReplicationType rep = (ReplicationType) val; + ps.setInt(index, rep.getValue()); + } + } + + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + //rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + //rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "set", v ); + + } + + @Test + public void test3() { + TableHandler.setSpecialCase("topic", "replication_case", new TopicReplicationTypeHandler()); + + try { + ConnectionFactory cf = new ConnectionFactory(); + TableHandler th = new TableHandler( cf, TopicReplicationTypeHandler.class, "foo", "bar" ); + } catch (Exception e ) { + } + try { + ConnectionFactory cf = new ConnectionFactory(); + TableHandler th = new TableHandler( TopicReplicationTypeHandler.class, "foo", "bar" ); + th.getSpecialCase( "foo", "bar" ); + } catch (Exception e ) { + } + + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java index 251d975..e2e48cc 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/model/DRSubTest.java @@ -37,7 +37,7 @@ public class DRSubTest { d = "central-onap"; un = "user1"; up = "secretW0rd"; - f = "234"; + f = "22"; s = "sub123"; du = "sub.server.onap.org:8443/deliver/here"; lu = "https://drps.onap.org:8443/sublog/123"; @@ -105,4 +105,34 @@ public class DRSubTest { assertTrue( lu.equals( t.getLogURL() ) ); } + + @Test + public void test3() { + String json = String.format( "{ \"%s\": \"%s\", \"%s\": false, \"%s\": { \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\" }, \"%s\": { \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": true } }", + "subscriber", "owner", + "suspend", + "links", + "feed", "https://feed.onap.org/publish/22", + "self", "https://feed.onap.org/subscriber/44", + "log" , lu, + "delivery" , + "url", du, + "user", un, + "password", up, + "use100" + ); + + + DR_Sub t = new DR_Sub( json ); + + assertTrue( un.equals( t.getUsername() )); + assertTrue( up.equals( t.getUserpwd() )); + assertTrue( f.equals( t.getFeedId() )); + assertTrue( du.equals( t.getDeliveryURL() ) ); + assertTrue( lu.equals( t.getLogURL() ) ); + assertTrue( ! t.isSuspended() ); + + String o = t.toString(); + + } } diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java index cc8b259..4e9a022 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/model/FeedTest.java @@ -25,6 +25,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.util.ArrayList; + public class FeedTest { @@ -60,6 +62,10 @@ public class FeedTest { public void test2() { Feed t = new Feed( n, v, d, o, a ); + ArrayList<DR_Sub> subs = new ArrayList<DR_Sub>(); + DR_Sub sub = new DR_Sub( "central", "user", "pwd", "22", "server.onap.org/deliv", "log.onap.org/logs", true ); + subs.add( sub ); + t.setSubs( subs ); assertTrue( n.equals( t.getFeedName() )); assertTrue( v.equals( t.getFeedVersion() )); @@ -76,4 +82,33 @@ public class FeedTest { rh.reflect( "org.onap.dmaap.dbcapi.model.Feed", "set", v ); } + @Test + public void test4() { + String s = String.format( "{ \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": false, \"%s\": { \"%s\": \"%s\", \"%s\": \"%s\", \"%s\": \"%s\" }, \"%s\": { \"%s\": \"%s\", \"%s\": [ { \"%s\": \"%s\", \"%s\": \"%s\" } ] } }", + "name", n, + "version", v, + "description", d, + "publisher", a, + "suspend", + "links", + "publish", "https://feed.onap.org/publish/22", + "subscribe" , Feed.getSubProvURL( "22" ), + "log" , "https://feed.onap.org/log/22", + "authorization", + "classification", a, + "endpoint_ids" , "id", "king", "password", "henry" ); + + + Feed t = new Feed( s ); + + assertTrue( n.equals( t.getFeedName() )); + assertTrue( v.equals( t.getFeedVersion() )); + assertTrue( d.equals( t.getFeedDescription() )); + assertTrue( a.equals( t.getAsprClassification() ) ); + assertTrue( ! t.isSuspended() ); + + String o = t.toString(); + + } + } diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/MR_ClusterTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/MR_ClusterTest.java new file mode 100644 index 0000000..ac7f9c4 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/MR_ClusterTest.java @@ -0,0 +1,95 @@ +/*- + * ============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.model; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +public class MR_ClusterTest { + String d, fqdn, a; + + ReflectionHarness rh = new ReflectionHarness(); + + @Before + public void setUp() throws Exception { + d = "central-onap"; + fqdn = "mr.onap.org"; + a = "ignore"; + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void testMR_ClusterClassDefaultConstructor() { + + MR_Cluster t = new MR_Cluster(); + + assertTrue( t.getDcaeLocationName() == null ); + assertTrue( t.getFqdn() == null ); + + } + + @Test + public void testMR_ClusterClassConstructor() { + + String[] h = { "host1", "host2", "host3" }; + MR_Cluster t = new MR_Cluster( d, fqdn, a, h ); + + t.getHosts(); + + assertTrue( t.getDcaeLocationName() == d ); + assertTrue( t.getFqdn() == fqdn ); + } + + @Test + public void testw3() { + + MR_Cluster t = new MR_Cluster(); + String[] h = { "host1", "host2", "host3" }; + t.setHosts( h ); + + assertTrue( t.getDcaeLocationName() == null ); + assertTrue( t.getFqdn() == null ); + + String fqtn = t.genTopicURL( "cluster2.onap.org", "org.onap.topic2" ); + } + + + + @Test + public void testsetter() { + + String v = "validate"; + + + rh.reflect( "org.onap.dmaap.dbcapi.model.MR_Cluster", "set", v ); + + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java index 1949820..6c35b93 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/model/MirrorMakerTest.java @@ -25,6 +25,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.util.ArrayList; + public class MirrorMakerTest { @@ -32,12 +34,9 @@ public class MirrorMakerTest { ReflectionHarness rh = new ReflectionHarness(); - String s, t; @Before public void setUp() throws Exception { - s = "source"; - t = "target"; } @After @@ -52,21 +51,52 @@ public class MirrorMakerTest { rh.reflect( "org.onap.dmaap.dbcapi.model.MirrorMaker", "get", null ); } - @Test public void test2() { - MirrorMaker m = new MirrorMaker( s, t ); - - assertTrue( s.equals( m.getSourceCluster() )); - assertTrue( t.equals( m.getTargetCluster() )); + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.model.MirrorMaker", "set", v ); } @Test public void test3() { + String f = "org.onap.interestingTopic"; + String c1 = "cluster1.onap.org"; + String c2 = "cluster2.onap.org"; + MirrorMaker t = new MirrorMaker( c1, c2 ); + String m = t.getMmName(); + + MirrorMaker.genKey( c1, c2 ); + + assertTrue( c1.equals( t.getSourceCluster() )); + assertTrue( c2.equals( t.getTargetCluster() )); + } + + + @Test + public void test4() { + String f = "org.onap.interestingTopic"; + String c1 = "cluster1.onap.org"; + String c2 = "cluster2.onap.org"; + MirrorMaker t = new MirrorMaker( c1, c2 ); + String m = t.getMmName(); + + t.addVector( f, c1, c2 ); + ArrayList<String> topics = new ArrayList<String>(); + topics.add( f ); + t.setTopics( topics ); + t.addTopic( "org.onap.topic2" ); + + int i = t.getTopicCount(); + + String s = t.toJSON(); + + s = t.updateWhiteList(); + + s = t.createMirrorMaker(); + + t.delVector( f, c1, c2 ); - String v = "Validate"; - rh.reflect( "org.onap.dmaap.dbcapi.model.MirrorMaker", "set", v ); } } diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/ReplicationVectorTest.java b/src/test/java/org/onap/dmaap/dbcapi/model/ReplicationVectorTest.java new file mode 100644 index 0000000..0655b75 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/model/ReplicationVectorTest.java @@ -0,0 +1,91 @@ +/*- + * ============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.model; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + + +public class ReplicationVectorTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.model.ReplicationVector", "get", null ); + + } + @Test + public void test2() { + + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.model.ReplicationVector", "set", v ); + } + + @Test + public void test3() { + String f = "org.onap.interestingTopic"; + String c1 = "cluster1.onap.org"; + String c2 = "cluster2.onap.org"; + ReplicationVector t = new ReplicationVector( f, c1, c2 ); + + + assertTrue( f.equals( t.getFqtn() )); + assertTrue( c1.equals( t.getSourceCluster() )); + assertTrue( c2.equals( t.getTargetCluster() )); + } + + + @Test + public void test4() { + String f = "org.onap.interestingTopic"; + String c1 = "cluster1.onap.org"; + String c2 = "cluster2.onap.org"; + ReplicationVector t = new ReplicationVector( f, c1, c2 ); + + int i = t.hashCode(); + + ReplicationVector t2 = new ReplicationVector(f, c1, c2 ); + + assertTrue( t.equals( t2 )); + assertTrue( t.equals( t )); + assertTrue( ! t.equals( f )); + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/resource/DcaeLocationResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resource/DcaeLocationResourceTest.java new file mode 100644 index 0000000..dd2525f --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/resource/DcaeLocationResourceTest.java @@ -0,0 +1,90 @@ +/*- + * ============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 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 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; + + +public class DcaeLocationResourceTest extends JerseyTest { + + static DmaapObjectFactory factory = new DmaapObjectFactory(); + + @Override + protected Application configure() { + return new ResourceConfig( DcaeLocationResource.class ); + } + + private static final String fmt = "%24s: %s%n"; + + + +/* may conflict with test framework! + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } +*/ + + + + @Test + public void GetTest() { + Response resp = target( "dcaeLocations").request().get( Response.class ); + System.out.println( "GET feed resp=" + resp.getStatus() ); + + assertTrue( resp.getStatus() == 200 ); + } + @Test + public void PostTest() { + 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 ); + } + + @Test + public void PutTest() { + } + + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/resource/DmaapResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resource/DmaapResourceTest.java new file mode 100644 index 0000000..4f8f602 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/resource/DmaapResourceTest.java @@ -0,0 +1,98 @@ +/*- + * ============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 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 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; + + +public class DmaapResourceTest extends JerseyTest { + + static DmaapObjectFactory factory = new DmaapObjectFactory(); + + @Override + protected Application configure() { + return new ResourceConfig( DmaapResource.class ); + //return new ResourceConfig( HelloResource.class ); + } + + private static final String fmt = "%24s: %s%n"; + + + +/* may conflict with test framework! + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } +*/ + + + + @Test + public void GetTest() { + Response resp = target( "dmaap").request().get( Response.class ); + assertTrue( resp.getStatus() == 200 ); + } + @Test + public void PostTest() { + + Dmaap dmaap = factory.genDmaap(); + Entity<Dmaap> reqEntity = Entity.entity( dmaap, MediaType.APPLICATION_JSON ); + Response resp = target( "dmaap").request().post( reqEntity, Response.class ); + System.out.println( resp.getStatus() ); + assertTrue( resp.getStatus() == 200 ); + } + + @Test + public void PutTest() { + + Dmaap dmaap = factory.genDmaap(); + Entity<Dmaap> reqEntity = Entity.entity( dmaap, MediaType.APPLICATION_JSON ); + + dmaap.setVersion( "2" ); + Response resp = target( "dmaap").request().put( reqEntity, Response.class ); + System.out.println( resp.getStatus() ); + assertTrue( resp.getStatus() == 200 ); + } + + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/resource/FeedResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resource/FeedResourceTest.java new file mode 100644 index 0000000..89dca8a --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/resource/FeedResourceTest.java @@ -0,0 +1,104 @@ +/*- + * ============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 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 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; + + +public class FeedResourceTest extends JerseyTest { + + @Override + protected Application configure() { + return new ResourceConfig( FeedResource.class ); + } + + private static final String fmt = "%24s: %s%n"; + + + +/* may conflict with test framework! + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } +*/ + + + + @Test + public void GetTest() { + Response resp = target( "feeds").request().get( Response.class ); + System.out.println( "GET feed resp=" + resp.getStatus() ); + + assertTrue( resp.getStatus() == 200 ); + } + @Test + public void PostTest() { + Feed feed = new Feed( "aPostTest", "1.0", "a unit test", "dgl", "unrestricted" ); + Entity<Feed> reqEntity = Entity.entity( feed, MediaType.APPLICATION_JSON ); + Response resp = target( "feeds").request().post( reqEntity, Response.class ); + System.out.println( "POST feed resp=" + resp.getStatus() ); + assertTrue( resp.getStatus() == 200 ); + } + +/* + @Test + public void PutTest() { + + Feed feed = new Feed( "aPutTest", "1.0", "a unit test", "dgl", "unrestricted" ); + Entity<Feed> reqEntity = Entity.entity( feed, MediaType.APPLICATION_JSON ); + Response resp = target( "feeds").request().post( reqEntity, Response.class ); + System.out.println( "POST feed resp=" + resp.getStatus() ); + String postResp = resp.readEntity( String.class ); + System.out.println( "postResp=" + postResp ); + Feed rFeed = new Feed( postResp ); getting a null pointer here + rFeed.setSuspended( true ); + String target = new String ("feeds/" + rFeed.getFeedId() ); + System.out.println( "PUT feed target=" + target ); + reqEntity = Entity.entity( rFeed, MediaType.APPLICATION_JSON ); + resp = target( target ).request().put( reqEntity, Response.class ); + System.out.println( "PUT feed resp=" + resp.getStatus() ); + assertTrue( resp.getStatus() == 200 ); + } +*/ + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/resource/InfoResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resource/InfoResourceTest.java new file mode 100644 index 0000000..3f57f58 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/resource/InfoResourceTest.java @@ -0,0 +1,71 @@ +/*- + * ============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 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 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; + + +public class InfoResourceTest extends JerseyTest { + + @Override + protected Application configure() { + return new ResourceConfig( InfoResource.class ); + } + + private static final String fmt = "%24s: %s%n"; + + + +/* may conflict with test framework! + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } +*/ + + + + @Test + public void GetTest() { + Response resp = target( "info").request().get( Response.class ); + assertTrue( resp.getStatus() == 204 ); + } + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/resource/MR_ClusterResourceTest.java b/src/test/java/org/onap/dmaap/dbcapi/resource/MR_ClusterResourceTest.java new file mode 100644 index 0000000..1f78c3f --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/resource/MR_ClusterResourceTest.java @@ -0,0 +1,127 @@ +/*- + * ============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 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 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; + + +public class MR_ClusterResourceTest extends JerseyTest { + + static DmaapObjectFactory factory = new DmaapObjectFactory(); + + @Override + protected Application configure() { + return new ResourceConfig( MR_ClusterResource.class ); + } + + private static final String fmt = "%24s: %s%n"; + + + +/* may conflict with test framework! + @Before + public void preTest() throws Exception { + } + + @After + public void tearDown() throws Exception { + } +*/ + + + @Test + public void GetTest() { + Response resp = target( "mr_clusters").request().get( Response.class ); + System.out.println( "GET feed resp=" + resp.getStatus() ); + + assertTrue( resp.getStatus() == 200 ); + } + @Test + public void PostTest() { + 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 ) ); + assertTrue( resp.getStatus() == 201 ); + } + + @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 ); + } catch (Exception e ) { + } +*/ + String h[] = {"host4", "host5", "host6" }; + MR_Cluster cluster = factory.genMR_Cluster( "edge" ); + 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 ); + + // now change a field + cluster.setHosts( h ); + reqEntity = Entity.entity( cluster, MediaType.APPLICATION_JSON ); + + // update with incorrect key + resp = target( "mr_clusters") + .path( cluster.getFqdn()) + .request() + .put( reqEntity, Response.class ); + System.out.println( "PUT MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity(String.class)); + assertTrue( resp.getStatus() == 404 ); + + // update with correct key + resp = target( "mr_clusters") + .path( cluster.getDcaeLocationName()) + .request() + .put( reqEntity, Response.class ); + System.out.println( "PUT MR_Cluster resp=" + resp.getStatus() + " " + resp.readEntity(String.class)); + assertTrue( resp.getStatus() == 200 ); + } + + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/server/JettyServerTest.java b/src/test/java/org/onap/dmaap/dbcapi/server/JettyServerTest.java new file mode 100644 index 0000000..26ba3a6 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/server/JettyServerTest.java @@ -0,0 +1,80 @@ +/*- + * ============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.server; +import org.onap.dmaap.dbcapi.model.*; +import org.onap.dmaap.dbcapi.util.DmaapConfig; +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import java.util.ArrayList; +import java.util.Properties; + +public class JettyServerTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + + JettyServer m = null; + + @Before + public void setUp() throws Exception { + Properties p = DmaapConfig.getConfig(); + try { + m = new JettyServer(p); + } catch (Exception e ) { + } + } + + @After + public void tearDown() throws Exception { + try { + m.getServer().stop(); + } catch (Exception e ) { + } + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.server.JettyServer", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.server.JettyServer", "set", v ); + + } + + @Test + public void test3() { + } + + + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/server/MainTest.java b/src/test/java/org/onap/dmaap/dbcapi/server/MainTest.java new file mode 100644 index 0000000..496a93d --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/server/MainTest.java @@ -0,0 +1,79 @@ +/*- + * ============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.server; +import org.onap.dmaap.dbcapi.model.*; +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import java.util.ArrayList; + +public class MainTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + Main m; + + + @Before + public void setUp() throws Exception { + //m = new Main(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.server.Main", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.server.Main", "set", v ); + + } + +/* + @Test + public void test3() { + String[] args = { "--help", "--version" }; + + try { + m.main( args ); + } catch (Exception e ) { + } + + } +*/ + + + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/ApiServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/ApiServiceTest.java new file mode 100644 index 0000000..e429fbd --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/ApiServiceTest.java @@ -0,0 +1,90 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; +import org.onap.dmaap.dbcapi.aaf.*; +import org.onap.dmaap.dbcapi.resources.*; +import org.onap.dmaap.dbcapi.aaf.authentication.AuthenticationErrorException; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import javax.ws.rs.core.Response; + +public class ApiServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + ApiService ds; + + @Before + public void setUp() throws Exception { + ds = new ApiService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + //rh.reflect( "org.onap.dmaap.dbcapi.service.ApiService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.ApiService", "set", v ); + + } + + @Test + public void test3() { + ApiService nd = new ApiService(); + nd.setAuth( "auth" ); + try { + nd.required( "aName", null, "anExpr" ); + } catch ( RequiredFieldException rfe ) { + } + String out = nd.toString(); + Response r = nd.unauthorized( "aMessage" ); + r = nd.unauthorized(); + r = nd.unavailable(); + r = nd.notFound(); + r = nd.error(); + try { + nd.checkAuthorization( "authval", "/uri/Path", "GET" ); + nd.checkAuthorization(); + } catch ( AuthenticationErrorException aee ) { + } catch ( Exception e ) { + } + } + + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/DR_NodeServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/DR_NodeServiceTest.java new file mode 100644 index 0000000..4f92bcd --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/DR_NodeServiceTest.java @@ -0,0 +1,126 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import java.util.ArrayList; + +public class DR_NodeServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + DR_NodeService ns; + + @Before + public void setUp() throws Exception { + ns = new DR_NodeService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.service.DR_NodeService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.DR_NodeService", "set", v ); + + } + + @Test + public void test3() { + String f = "drsn01.onap.org"; + String locname = "central-demo"; + + DcaeLocationService dls = new DcaeLocationService(); + DcaeLocation loc = new DcaeLocation( "CLLI1234", "central-onap", locname, "aZone", "10.10.10.0/24" ); + dls.addDcaeLocation( loc ); + + ApiError err = new ApiError(); + DR_Node node = new DR_Node( f, locname, "zplvm009.onap.org", "1.0.46" ); + DR_Node n2 = ns.addDr_Node( node, err ); + + if ( n2 != null ) { + n2 = ns.getDr_Node( f, err ); + } + + List<DR_Node> l = ns.getAllDr_Nodes(); + if ( n2 != null ) { + n2.setVersion( "1.0.47" ); + n2 = ns.updateDr_Node( n2, err ); + } + + n2 = ns.removeDr_Node( f, err ); + + + } + +/* + @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 ); + } + } +*/ + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/DcaeLocationServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/DcaeLocationServiceTest.java new file mode 100644 index 0000000..e8c7229 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/DcaeLocationServiceTest.java @@ -0,0 +1,96 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; + +public class DcaeLocationServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + DcaeLocationService ds; + + @Before + public void setUp() throws Exception { + ds = new DcaeLocationService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + //rh.reflect( "org.onap.dmaap.dbcapi.service.DcaeLocationService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.DcaeLocationService", "set", v ); + + } + + @Test + public void test3() { + String n = "demo-network-c"; + DcaeLocation nd = new DcaeLocation( "CLLI0123", "central-layer", n, "zoneA", "10.10.10.0/24" ); + + DcaeLocation gd = ds.addDcaeLocation( nd ); + + assertTrue( nd.getDcaeLocationName().equals( gd.getDcaeLocationName() )); + } + + @Test + public void test4() { + List<DcaeLocation> d = ds.getAllDcaeLocations(); + + } + + @Test + public void test5() { + String n = "demo-network-c"; + DcaeLocation nd = new DcaeLocation( "CLLI9999", "central-layer", n, "zoneA", "10.10.10.0/24" ); + DcaeLocation gd = ds.updateDcaeLocation( nd ); + + assertTrue( nd.getDcaeLocationName().equals( gd.getDcaeLocationName() )); + + } + + @Test + public void test6() { + + String n = "demo-network-c"; + DcaeLocation gd = ds.removeDcaeLocation( n ); + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java new file mode 100644 index 0000000..e40488e --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/DmaapServiceTest.java @@ -0,0 +1,93 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; +import org.onap.dmaap.dbcapi.aaf.*; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; + +public class DmaapServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + DmaapService ds; + + @Before + public void setUp() throws Exception { + ds = new DmaapService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + //rh.reflect( "org.onap.dmaap.dbcapi.service.DmaapService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.DmaapService", "set", v ); + + } + + @Test + public void test3() { + Dmaap nd = new Dmaap( "1", "org.onap.dmaap", "onap-demo", "drps.demo.onap.org", "", "MMAGENT_TOPIC", "", "" ); + ds.addDmaap( nd ); + } + + @Test + public void test4() { + Dmaap d = ds.getDmaap(); + + } + + @Test + public void test5() { + Dmaap nd = new Dmaap( "2", "org.onap.dmaap", "onap-demo", "drps.demo.onap.org", "", "MMAGENT_TOPIC", "", "" ); + ds.updateDmaap( nd ); + + } + + @Test + public void test6() { + String t = ds.getTopicPerm(); + String t2 = ds.getTopicPerm( "val2" ); + String t3 = ds.getBridgeAdminFqtn(); + + boolean b = ds.testCreateMmaTopic(); + + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/Dr_PubServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/Dr_PubServiceTest.java new file mode 100644 index 0000000..5c93dbf --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/Dr_PubServiceTest.java @@ -0,0 +1,108 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import java.util.ArrayList; + +public class Dr_PubServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + DR_PubService ns; + FeedService fs; + + @Before + public void setUp() throws Exception { + ns = new DR_PubService(); + fs = new FeedService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.service.DR_PubService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.DR_PubService", "set", v ); + + } + + @Test + public void test3() { + String locname = "central-demo"; + + DcaeLocationService dls = new DcaeLocationService(); + DcaeLocation loc = new DcaeLocation( "CLLI1234", "central-onap", locname, "aZone", "10.10.10.0/24" ); + dls.addDcaeLocation( loc ); + + ApiError err = new ApiError(); + Feed f = new Feed( "aTest", "1.0", "a unit test", "dgl", "unrestricted" ); + f = fs.addFeed( f, err ); +/* +TODO: make this not be null... + assertTrue( f != null ); + DR_Pub node = new DR_Pub( locname, "aUser", "aPwd", f.getFeedId(), "pubId01" ); + DR_Pub n2 = ns.addDr_Pub( node ); + DR_Pub node2 = new DR_Pub( locname, "aUser", "aPwd", f.getFeedId() ); + n2 = ns.addDr_Pub( node2 ); + + if ( n2 != null ) { + n2 = ns.getDr_Pub( n2.getPubId(), err ); + } + + List<DR_Pub> l = ns.getAllDr_Pubs(); + if ( n2 != null ) { + n2 = ns.updateDr_Pub( n2 ); + } + + n2 = ns.removeDr_Pub( n2.getPubId(), err ); +*/ + + + } + + @Test + public void test4() { + ArrayList<DR_Pub> l = ns.getDr_PubsByFeedId( "1" ); + + + } + + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/FeedServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/FeedServiceTest.java new file mode 100644 index 0000000..832237e --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/FeedServiceTest.java @@ -0,0 +1,97 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; +import org.onap.dmaap.dbcapi.aaf.*; +import org.onap.dmaap.dbcapi.resources.*; +import org.onap.dmaap.dbcapi.aaf.authentication.AuthenticationErrorException; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import javax.ws.rs.core.Response; + +public class FeedServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + FeedService ds; + + @Before + public void setUp() throws Exception { + ds = new FeedService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.service.FeedService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.FeedService", "set", v ); + + } + + @Test + public void test3() { + ApiError err = new ApiError(); + + Feed f = new Feed( "aTest", "1.0", "a unit test", "dgl", "unrestricted" ); + f = ds.addFeed( f, err ); + System.out.println( "f=" + f ); + + ds.updateFeed( f, err ); + + ds.removeFeed( f, err ); + } + + @Test + public void test4() { + ApiError err = new ApiError(); + Feed f = ds.getFeed( "aName", err ); + + f = ds.getFeedByName( "aName", "1.0", err ); + + f = ds.getFeedPure( "aName", err ); + } + + @Test + public void test5() { + List<Feed> f = ds.getAllFeeds( "aName", "1.0", "startsWith" ); + + } + + +} 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 new file mode 100644 index 0000000..470ca6c --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClientServiceTest.java @@ -0,0 +1,127 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import java.util.ArrayList; + +public class MR_ClientServiceTest { + + private static final String fmt = "%24s: %s%n"; + + private static DmaapObjectFactory factory = new DmaapObjectFactory(); + + ReflectionHarness rh = new ReflectionHarness(); + + private TopicService ts; + private MR_ClusterService mcs; + private MR_ClientService cls; + private DcaeLocationService dls; + + private String f; + private String locname; + + @Before + public void setUp() throws Exception { + ts = new TopicService(); + mcs = new MR_ClusterService(); + cls = new MR_ClientService(); + f = "mrsn01.onap.org"; + locname = "central-demo"; + + dls = new DcaeLocationService(); + DcaeLocation loc = factory.genDcaeLocation( "central" ); + dls.addDcaeLocation( loc ); + + ApiError err = new ApiError(); + String[] h = { "zplvm009.onap.org", "zplvm007.onap.org", "zplvm008.onap.org" }; + MR_Cluster node = factory.genMR_Cluster( "central" ); + MR_Cluster n2 = mcs.addMr_Cluster( node, err ); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClientService", "set", v ); + + } + + @Test + public void test3() { + Topic topic = factory.genSimpleTopic( "test3" ); + ApiError err = new ApiError(); + Topic nTopic = ts.addTopic( topic, err ); + 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 ); + + } + + @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 = factory.genSimpleTopic( "test5" ); + ApiError err = new ApiError(); + Topic nTopic = ts.addTopic( topic, err ); + if ( nTopic != null ) { + assertTrue( nTopic.getTopicName().equals( topic.getTopicName() )); + } + MR_Client c = factory.genPublisher( "edge", topic.getFqtn() ); + + c = cls.addMr_Client( c, topic, err ); + if ( c != null ) { + c = factory.genSubscriber( "edge", topic.getFqtn() ); + c = cls.updateMr_Client( c, err ); + assertTrue( err.getCode() == 200 ); + } + } + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClusterServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClusterServiceTest.java new file mode 100644 index 0000000..cbf9931 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/service/MR_ClusterServiceTest.java @@ -0,0 +1,126 @@ +/*- + * ============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.service; +import org.onap.dmaap.dbcapi.model.*; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.util.List; +import java.util.ArrayList; + +public class MR_ClusterServiceTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + MR_ClusterService ns; + + @Before + public void setUp() throws Exception { + ns = new MR_ClusterService(); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClusterService", "get", null ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.service.MR_ClusterService", "set", v ); + + } + + @Test + public void test3() { + String f = "mrsn01.onap.org"; + String locname = "central-demo"; + + DcaeLocationService dls = new DcaeLocationService(); + DcaeLocation loc = new DcaeLocation( "CLLI1234", "central-onap", locname, "aZone", "10.10.10.0/24" ); + dls.addDcaeLocation( loc ); + + ApiError err = new ApiError(); + String[] h = { "zplvm009.onap.org", "zplvm007.onap.org", "zplvm008.onap.org" }; + MR_Cluster node = new MR_Cluster( locname, f, "ignore", h ); + MR_Cluster n2 = ns.addMr_Cluster( node, err ); + + if ( n2 != null ) { + n2 = ns.getMr_Cluster( f, err ); + } + + List<MR_Cluster> l = ns.getAllMr_Clusters(); + if ( n2 != null ) { + n2 = ns.updateMr_Cluster( n2, err ); + } + + n2 = ns.removeMr_Cluster( f, err ); + + + } + +/* + @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 ); + } + } +*/ + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java index 0d39350..5757522 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/service/TopicServiceTest.java @@ -26,6 +26,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.List; +import java.util.ArrayList; public class TopicServiceTest { @@ -34,10 +35,13 @@ public class TopicServiceTest { ReflectionHarness rh = new ReflectionHarness(); TopicService ts; + MR_ClusterService mcs; + String locname = "central-onap"; @Before public void setUp() throws Exception { ts = new TopicService(); + mcs = new MR_ClusterService(); } @After @@ -75,26 +79,62 @@ public class TopicServiceTest { } @Test + public void test3a() { + Topic topic = new Topic(); + ApiError err = new ApiError(); + topic.setTopicName( "test3" ); + topic.setFqtnStyle( FqtnType.Validator("none") ); + topic.getFqtn(); + String t = "org.onap.dmaap.interestingTopic"; + String f = "mrc.onap.org:3904/events/org.onap.dmaap.interestingTopic"; + String c = "publisher"; + String[] a = { "sub", "view" }; + MR_Client sub = new MR_Client( locname, f, c, a ); + String[] b = { "pub", "view" }; + MR_Client pub = new MR_Client( "edge", f, c, b ); + ArrayList<MR_Client> clients = new ArrayList<MR_Client>(); + + clients.add( sub ); + clients.add( pub ); + + topic.setClients( clients ); + + ts.reviewTopic( topic ); + ts.checkForBridge( topic, err ); + + Topic nTopic = ts.addTopic( topic, err ); + if ( nTopic != null ) { + assertTrue( nTopic.getTopicName().equals( topic.getTopicName() )); + } + + + ts.removeTopic( "test3", err ); + } + + @Test public void test4() { List<Topic> l = ts.getAllTopics(); } -/* @Test public void test5() { - Topic topic = new Topic(); ApiError err = new ApiError(); +/* + +TODO: find a null pointer in here... + String[] hl = { "host1", "host2", "host3" }; + String loc = "central-onap"; + MR_Cluster cluster = new MR_Cluster( loc, "localhost", "", hl ); + mcs.addMr_Cluster( cluster, err ); + Topic topic = new Topic(); topic.setTopicName( "test5" ); topic.setFqtnStyle( FqtnType.Validator("none") ); topic.setReplicationCase( ReplicationType.Validator("none") ); - topic.getFqtn(); + String f = topic.getFqtn(); Topic nTopic = ts.updateTopic( topic, err ); - if ( nTopic != null ) { - assertTrue( nTopic.getTopicName().equals( topic.getTopicName() )); - } - - } */ + assertTrue( err.getCode() == 0 ); + } } diff --git a/src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java b/src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java new file mode 100644 index 0000000..18a397f --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/testframework/DmaapObjectFactory.java @@ -0,0 +1,122 @@ +/* + * ============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.model; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Type; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static java.lang.System.out; +import static java.lang.System.err; + +public class DmaapObjectFactory { + + /* + * we use localhost for most references so that connection attempts will resolve and not retry + * but still we expect that requests will fail. + */ + private static final String fmt = "%24s: %s%n"; + private static final String dmaap_name = "onap-ut"; + private static final String dmaap_ver = "1"; + private static final String dmaap_topic_root = "org.onap.dmaap"; + private static final String dmaap_dr = "https://localhost:8443"; + private static final String dmaap_log_url = "http://localhost:8080/log"; + private static final String dmaap_mm_topic = "org.onap.dmaap.dcae.MM_AGENT_TOPIC"; + private static final String central_loc = "SanFrancisco"; + private static final String central_layer = "central-cloud"; + private static final String central_clli = "SFCAL19240"; + private static final String central_zone = "osaz01"; + private static final String central_subnet = "10.10.10.0/24"; + private static final String central_cluster_fqdn = "localhost"; + private static final String pub_role = "org.onap.vnfapp.publisher"; + private static final String sub_role = "org.onap.vnfapp.subscriber"; + private static final String edge_loc = "Atlanta"; + private static final String edge_layer = "edge-cloud"; + private static final String edge_clli = "ATLGA10245"; + private static final String edge_zone = "osaz02"; + private static final String edge_subnet = "10.10.20.0/24"; + private static final String edge_cluster_fqdn = "localhost"; + private static final String[]hosts = { "host1", "host2", "host3" }; + + public Dmaap genDmaap() { + return new Dmaap( dmaap_ver, dmaap_topic_root, dmaap_name, dmaap_dr, dmaap_log_url, dmaap_mm_topic, "nk", "ako" ); + } + + public DcaeLocation genDcaeLocation( String layer ) { + if ( layer.contains( "edge" ) ) { + return new DcaeLocation( edge_clli, edge_layer, edge_loc, edge_zone, edge_subnet ); + } + return new DcaeLocation( central_clli, central_layer, central_loc, central_zone, central_subnet ); + } + + + public MR_Cluster genMR_Cluster( String layer ) { + if ( layer.contains( "edge" ) ) { + return new MR_Cluster( edge_loc, edge_cluster_fqdn, "ignore", hosts ); + } + return new MR_Cluster( central_loc, central_cluster_fqdn, "ignore", hosts ); + } + + public Topic genSimpleTopic( String tname ) { + Topic t = new Topic(); + t.setTopicName( tname ); + t.setFqtnStyle( FqtnType.Validator("none") ); + t.getFqtn(); + return t; + } + + public MR_Client genMR_Client( String l, String f, String r, String[] a ) { + if ( l.contains( "edge" ) ) { + return new MR_Client( edge_loc, f, r, a ); + } + return new MR_Client( central_loc, f, r, a ); + } + + public MR_Client genPublisher( String layer, String fqtn ) { + String[] actions = { "pub", "view" }; + return genMR_Client( layer, fqtn, pub_role, actions ); + } + public MR_Client genSubscriber( String layer, String fqtn ) { + String[] actions = { "sub", "view" }; + return genMR_Client( layer, fqtn, sub_role, actions ); + } + + public DR_Sub genDrSub( String l, String feed ) { + String un = "user1"; + String up = "secretW0rd"; + String du = "sub.server.onap.org:8443/deliver/here"; + String lu = "https://drps.onap.org:8443/sublog/123"; + boolean u100 = true; + + if ( l.contains( "edge" ) ) { + return new DR_Sub( edge_loc, un, up, feed, du, lu, u100 ); + } + return new DR_Sub( central_loc, un, up, feed, du, lu, u100 ); + } + + +} diff --git a/src/test/java/org/onap/dmaap/dbcapi/model/ReflectionHarness.java b/src/test/java/org/onap/dmaap/dbcapi/testframework/ReflectionHarness.java index 76167ce..8f70eca 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/model/ReflectionHarness.java +++ b/src/test/java/org/onap/dmaap/dbcapi/testframework/ReflectionHarness.java @@ -52,10 +52,10 @@ public class ReflectionHarness { } private void testGetter( Class<?> c, Method m, Class<?>[] pType, String val ) { - //out.format( fmt, "testGetter: Method Name", m.getName() ); + out.format( fmt, "testGetter: Method Name", m.getName() ); Class retType = m.getReturnType(); - //out.format( fmt, "testGetter: Return Type ", retType ); - //out.format( fmt, "testGetter: val ", (val != null)?val:"null" ); + out.format( fmt, "testGetter: Return Type ", retType ); + out.format( fmt, "testGetter: val ", (val != null)?val:"null" ); assertTrue( pType.length == 0 ); try { @@ -67,10 +67,10 @@ public class ReflectionHarness { if( retType.equals( Class.forName( "java.lang.String" ) ) ) { if ( val == null ) { - //out.format( fmt, "testGetter: expected null, got ", (o != null)?o:"null" ); + out.format( fmt, "testGetter: expected null, got ", (o != null)?o:"null" ); assert( o == null ); } else { - //out.format( fmt, "testGetter: expected val, got ", (o != null)?o:"null" ); + out.format( fmt, "testGetter: expected val, got ", (o != null)?o:"null" ); assert( o.equals( val ) ); } } else { diff --git a/src/test/java/org/onap/dmaap/dbcapi/util/DmaapConfigTest.java b/src/test/java/org/onap/dmaap/dbcapi/util/DmaapConfigTest.java new file mode 100644 index 0000000..29de17d --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/util/DmaapConfigTest.java @@ -0,0 +1,73 @@ +/*- + * ============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.util; +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.*; + +public class DmaapConfigTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + DmaapConfig g; + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.util.DmaapConfig", "get", "" ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.util.DmaapConfig", "set", v ); + + } + + @Test + public void test3() { + + String f = g.getConfigFileName(); + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/util/GraphTest.java b/src/test/java/org/onap/dmaap/dbcapi/util/GraphTest.java new file mode 100644 index 0000000..2d5b429 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/util/GraphTest.java @@ -0,0 +1,100 @@ +/*- + * ============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.util; +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.*; + +public class GraphTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + Graph g; + + + @Before + public void setUp() throws Exception { + HashMap<String, String> hm = new HashMap<String,String>(); + g = new Graph( hm ); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.util.Graph", "get", "idNotSet@namespaceNotSet:pwdNotSet" ); + + } + + @Test + public void test2() { + String v = "Validate"; + //rh.reflect( "org.onap.dmaap.dbcapi.util.Graph", "set", v ); + + } + + @Test + public void test3() { + String loc = "central-onap"; + String[] actions = { "pub", "sub" }; + DcaeLocationService dls = new DcaeLocationService(); + DcaeLocation dl = new DcaeLocation( "CLLI123", "central-layer", loc, "aZone", "10.10.10.10" ); + dls.addDcaeLocation( dl ); + MR_Client mrc = new MR_Client(); + mrc.setAction( actions ); + List<MR_Client> cl = new ArrayList<MR_Client>(); + cl.add( mrc ); + cl.add( new MR_Client( loc, "aTopic", "ignore", actions ) ); + + g = new Graph( cl, true ); + + HashMap<String, String> hm = new HashMap<String, String>(); + + + String s = g.put( "aKey", "aVal" ); + s = g.get( "aKey" ); + + s = g.getCentralLoc(); + g.setHasCentral( true ); + g.isHasCentral(); + + hm = g.getGraph(); + + Collection<String> k = g.getKeys(); + + } + + + +} + diff --git a/src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java b/src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java new file mode 100644 index 0000000..b489608 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java @@ -0,0 +1,74 @@ +/*- + * ============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.util; +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.*; + +public class RandomIntegerTest { + + private static final String fmt = "%24s: %s%n"; + + ReflectionHarness rh = new ReflectionHarness(); + + RandomInteger ri; + + + @Before + public void setUp() throws Exception { + ri = new RandomInteger( 12434 ); + } + + @After + public void tearDown() throws Exception { + } + + + @Test + public void test1() { + + + rh.reflect( "org.onap.dmaap.dbcapi.util.RandomInteger", "get", "" ); + + } + + @Test + public void test2() { + String v = "Validate"; + rh.reflect( "org.onap.dmaap.dbcapi.util.RandomInteger", "set", v ); + + } + + @Test + public void test3() { + int i = ri.next(); + + } + + + +} + |