aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java14
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java65
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java6
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql145
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/docker-compose.yml96
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/node_data/node.properties112
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/cacerts.jksbin1936 -> 0 bytes
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/keystore.jksbin2273 -> 0 bytes
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/mykey.cerbin921 -> 0 bytes
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/nodekey.cerbin921 -> 0 bytes
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/prov_data/addFeed3.txt44
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/prov_data/addSubscriber.txt36
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties49
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/cacerts.jksbin983 -> 0 bytes
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/keystore.jksbin2272 -> 0 bytes
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/mykey.cerbin921 -> 0 bytes
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java5
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLITest.java215
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java498
19 files changed, 761 insertions, 524 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
index 8614a6e8..101c9e6f 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
@@ -417,13 +417,13 @@ public class LogServlet extends BaseServlet {
Connection conn = null;
try {
conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- rh.handleRow(rs);
- }
- rs.close();
- stmt.close();
+ try( Statement stmt = conn.createStatement()){
+ try(ResultSet rs = stmt.executeQuery(sql)){
+ while (rs.next()) {
+ rh.handleRow(rs);
+ }
+ }
+ }
} catch (SQLException sqlException) {
intlogger.info("Failed to get Records. Exception = " +sqlException.getMessage(),sqlException);
} finally {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
index 6564e175..c560299a 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
@@ -181,7 +181,7 @@ public class ProxyServlet extends BaseServlet {
if (inited) {
String url = buildUrl(req);
intlogger.info("ProxyServlet: proxying with fallback GET "+url);
- AbstractHttpClient httpclient = new DefaultHttpClient();
+ try(AbstractHttpClient httpclient = new DefaultHttpClient()){
HttpRequestBase proxy = new HttpGet(url);
try {
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
@@ -204,6 +204,7 @@ public class ProxyServlet extends BaseServlet {
in.close();
}
rv = true;
+
} catch (IOException e) {
System.err.println("ProxyServlet: "+e);
e.printStackTrace();
@@ -211,6 +212,7 @@ public class ProxyServlet extends BaseServlet {
proxy.releaseConnection();
httpclient.getConnectionManager().shutdown();
}
+ }
} else {
intlogger.warn("ProxyServlet: proxy disabled");
}
@@ -220,41 +222,42 @@ public class ProxyServlet extends BaseServlet {
if (inited && isProxyServer()) {
String url = buildUrl(req);
intlogger.info("ProxyServlet: proxying "+method + " "+url);
- AbstractHttpClient httpclient = new DefaultHttpClient();
- ProxyHttpRequest proxy = new ProxyHttpRequest(method, url);
- try {
- httpclient.getConnectionManager().getSchemeRegistry().register(sch);
+ try(AbstractHttpClient httpclient = new DefaultHttpClient()) {
+ ProxyHttpRequest proxy = new ProxyHttpRequest(method, url);
+ try {
+ httpclient.getConnectionManager().getSchemeRegistry().register(sch);
- // Copy request headers and request body
- copyRequestHeaders(req, proxy);
- if (method.equals("POST") || method.equals("PUT")){
- BasicHttpEntity body = new BasicHttpEntity();
- body.setContent(req.getInputStream());
- body.setContentLength(-1); // -1 = unknown
- proxy.setEntity(body);
- }
+ // Copy request headers and request body
+ copyRequestHeaders(req, proxy);
+ if (method.equals("POST") || method.equals("PUT")) {
+ BasicHttpEntity body = new BasicHttpEntity();
+ body.setContent(req.getInputStream());
+ body.setContentLength(-1); // -1 = unknown
+ proxy.setEntity(body);
+ }
- // Execute the request
- HttpResponse pxy_response = httpclient.execute(proxy);
+ // Execute the request
+ HttpResponse pxy_response = httpclient.execute(proxy);
- // Get response headers and body
- int code = pxy_response.getStatusLine().getStatusCode();
- resp.setStatus(code);
- copyResponseHeaders(pxy_response, resp);
+ // Get response headers and body
+ int code = pxy_response.getStatusLine().getStatusCode();
+ resp.setStatus(code);
+ copyResponseHeaders(pxy_response, resp);
- HttpEntity entity = pxy_response.getEntity();
- if (entity != null) {
- InputStream in = entity.getContent();
- IOUtils.copy(in, resp.getOutputStream());
- in.close();
+ HttpEntity entity = pxy_response.getEntity();
+ if (entity != null) {
+ InputStream in = entity.getContent();
+ IOUtils.copy(in, resp.getOutputStream());
+ in.close();
+ }
+ } catch (IOException e) {
+ intlogger.warn("ProxyServlet: " + e);
+ resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+ e.printStackTrace();
+ } finally {
+ proxy.releaseConnection();
+ httpclient.getConnectionManager().shutdown();
}
- } catch (IOException e) {
- intlogger.warn("ProxyServlet: "+e);
- resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- e.printStackTrace();
- } finally {
- proxy.releaseConnection();
- httpclient.getConnectionManager().shutdown();
}
} else {
intlogger.warn("ProxyServlet: proxy disabled");
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
index a907a03b..bbcacb53 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
@@ -38,14 +38,12 @@ import java.util.*;
*/
public class DB {
- /**
- * The name of the properties file (in CLASSPATH)
- */
+ private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
+
private static String DB_URL;
private static String DB_LOGIN;
private static String DB_PASSWORD;
private static Properties props;
- private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
private static final Queue<Connection> queue = new LinkedList<>();
public static String HTTPS_PORT;
diff --git a/datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql b/datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql
deleted file mode 100644
index e01ce3b0..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql
+++ /dev/null
@@ -1,145 +0,0 @@
-use datarouter;
-
-CREATE TABLE FEEDS (
- FEEDID INT UNSIGNED NOT NULL PRIMARY KEY,
- GROUPID INT(10) UNSIGNED NOT NULL DEFAULT 0,
- NAME VARCHAR(255) NOT NULL,
- VERSION VARCHAR(20) NOT NULL,
- DESCRIPTION VARCHAR(1000),
- BUSINESS_DESCRIPTION VARCHAR(1000) DEFAULT NULL,
- AUTH_CLASS VARCHAR(32) NOT NULL,
- PUBLISHER VARCHAR(8) NOT NULL,
- SELF_LINK VARCHAR(256),
- PUBLISH_LINK VARCHAR(256),
- SUBSCRIBE_LINK VARCHAR(256),
- LOG_LINK VARCHAR(256),
- DELETED BOOLEAN DEFAULT FALSE,
- LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- SUSPENDED BOOLEAN DEFAULT FALSE,
- CREATED_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP
-);
-
-CREATE TABLE FEED_ENDPOINT_IDS (
- FEEDID INT UNSIGNED NOT NULL,
- USERID VARCHAR(20) NOT NULL,
- PASSWORD VARCHAR(32) NOT NULL
-);
-
-CREATE TABLE FEED_ENDPOINT_ADDRS (
- FEEDID INT UNSIGNED NOT NULL,
- ADDR VARCHAR(44) NOT NULL
-);
-
-CREATE TABLE SUBSCRIPTIONS (
- SUBID INT UNSIGNED NOT NULL PRIMARY KEY,
- FEEDID INT UNSIGNED NOT NULL,
- GROUPID INT(10) UNSIGNED NOT NULL DEFAULT 0,
- DELIVERY_URL VARCHAR(256),
- DELIVERY_USER VARCHAR(20),
- DELIVERY_PASSWORD VARCHAR(32),
- DELIVERY_USE100 BOOLEAN DEFAULT FALSE,
- METADATA_ONLY BOOLEAN DEFAULT FALSE,
- SUBSCRIBER VARCHAR(8) NOT NULL,
- SELF_LINK VARCHAR(256),
- LOG_LINK VARCHAR(256),
- LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- SUSPENDED BOOLEAN DEFAULT FALSE,
- CREATED_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP
-
-);
-
-CREATE TABLE PARAMETERS (
- KEYNAME VARCHAR(32) NOT NULL PRIMARY KEY,
- VALUE VARCHAR(4096) NOT NULL
-);
-
-CREATE TABLE LOG_RECORDS (
- TYPE ENUM('pub', 'del', 'exp', 'pbf', 'dlx') NOT NULL,
- EVENT_TIME BIGINT NOT NULL, /* time of the publish request */
- PUBLISH_ID VARCHAR(64) NOT NULL, /* unique ID assigned to this publish attempt */
- FEEDID INT UNSIGNED NOT NULL, /* pointer to feed in FEEDS */
- REQURI VARCHAR(256) NOT NULL, /* request URI */
- METHOD ENUM('DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'POST', 'TRACE') NOT NULL, /* HTTP method */
- CONTENT_TYPE VARCHAR(256) NOT NULL, /* content type of published file */
- CONTENT_LENGTH BIGINT NOT NULL, /* content length of published file */
-
- FEED_FILEID VARCHAR(256), /* file ID of published file */
- REMOTE_ADDR VARCHAR(40), /* IP address of publishing endpoint */
- USER VARCHAR(50), /* user name of publishing endpoint */
- STATUS SMALLINT, /* status code returned to delivering agent */
-
- DELIVERY_SUBID INT UNSIGNED, /* pointer to subscription in SUBSCRIPTIONS */
- DELIVERY_FILEID VARCHAR(256), /* file ID of file being delivered */
- RESULT SMALLINT, /* result received from subscribing agent */
-
- ATTEMPTS INT, /* deliveries attempted */
- REASON ENUM('notRetryable', 'retriesExhausted', 'diskFull', 'other'),
-
- RECORD_ID BIGINT UNSIGNED NOT NULL PRIMARY KEY, /* unique ID for this record */
- CONTENT_LENGTH_2 BIGINT,
-
- INDEX (FEEDID) USING BTREE,
- INDEX (DELIVERY_SUBID) USING BTREE,
- INDEX (RECORD_ID) USING BTREE
-) ENGINE = MyISAM;
-
-CREATE TABLE INGRESS_ROUTES (
- SEQUENCE INT UNSIGNED NOT NULL,
- FEEDID INT UNSIGNED NOT NULL,
- USERID VARCHAR(20),
- SUBNET VARCHAR(44),
- NODESET INT UNSIGNED NOT NULL
-);
-
-CREATE TABLE EGRESS_ROUTES (
- SUBID INT UNSIGNED NOT NULL PRIMARY KEY,
- NODEID INT UNSIGNED NOT NULL
-);
-
-CREATE TABLE NETWORK_ROUTES (
- FROMNODE INT UNSIGNED NOT NULL,
- TONODE INT UNSIGNED NOT NULL,
- VIANODE INT UNSIGNED NOT NULL
-);
-
-CREATE TABLE NODESETS (
- SETID INT UNSIGNED NOT NULL,
- NODEID INT UNSIGNED NOT NULL
-);
-
-CREATE TABLE NODES (
- NODEID INT UNSIGNED NOT NULL PRIMARY KEY,
- NAME VARCHAR(255) NOT NULL,
- ACTIVE BOOLEAN DEFAULT TRUE
-);
-
-CREATE TABLE GROUPS (
- GROUPID INT UNSIGNED NOT NULL PRIMARY KEY,
- AUTHID VARCHAR(100) NOT NULL,
- NAME VARCHAR(50) NOT NULL,
- DESCRIPTION VARCHAR(255),
- CLASSIFICATION VARCHAR(20) NOT NULL,
- MEMBERS TINYTEXT,
- LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP
-);
-
-INSERT INTO PARAMETERS VALUES
- ('ACTIVE_POD', 'prov.datarouternew.com'),
- ('PROV_ACTIVE_NAME', 'prov.datarouternew.com'),
- ('STANDBY_POD', ''),
- ('PROV_NAME', 'prov.datarouternew.com'),
- ('NODES', '172.100.0.1|node.datarouternew.com'),
- ('PROV_DOMAIN', 'datarouternew.com'),
- ('DELIVERY_INIT_RETRY_INTERVAL', '10'),
- ('DELIVERY_MAX_AGE', '86400'),
- ('DELIVERY_MAX_RETRY_INTERVAL', '3600'),
- ('DELIVERY_RETRY_RATIO', '2'),
- ('LOGROLL_INTERVAL', '300'),
- ('PROV_AUTH_ADDRESSES', '172.100.0.1|prov.datarouternew.com|node.datarouternew.com'),
- ('PROV_AUTH_SUBJECTS', ''),
- ('PROV_MAXFEED_COUNT', '10000'),
- ('PROV_MAXSUB_COUNT', '100000'),
- ('PROV_REQUIRE_CERT', 'false'),
- ('PROV_REQUIRE_SECURE', 'false'),
- ('_INT_VALUES', 'LOGROLL_INTERVAL|PROV_MAXFEED_COUNT|PROV_MAXSUB_COUNT|DELIVERY_INIT_RETRY_INTERVAL|DELIVERY_MAX_RETRY_INTERVAL|DELIVERY_RETRY_RATIO|DELIVERY_MAX_AGE')
- ;
diff --git a/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml b/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml
deleted file mode 100644
index 6aee4dbd..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml
+++ /dev/null
@@ -1,96 +0,0 @@
-#-------------------------------------------------------------------------------
-# ============LICENSE_START==================================================
-# * org.onap.dmaap
-# * ===========================================================================
-# * Copyright © 2017 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====================================================
-# *
-# * ECOMP is a trademark and service mark of AT&T Intellectual Property.
-# *
-#-------------------------------------------------------------------------------
-version: '2.1'
-services:
- datarouter-prov:
- image: nexus3.onap.org:10003/onap/dmaap/datarouter-prov
- container_name: datarouter-prov
- hostname: prov.datarouternew.com
- ports:
- - "8443:8443"
- - "8080:8080"
- volumes:
- - ./prov_data/provserver.properties:/opt/app/datartr/etc/provserver.properties
- - ./prov_data/addSubscriber.txt:/opt/app/datartr/addSubscriber.txt
- - ./prov_data/addFeed3.txt:/opt/app/datartr/addFeed3.txt
- depends_on:
- mariadb_container:
- condition: service_healthy
- healthcheck:
- test: ["CMD", "curl", "-f", "http://prov.datarouternew.com:8080/internal/prov"]
- interval: 10s
- timeout: 10s
- retries: 5
- extra_hosts:
- - "node.datarouternew.com:172.100.0.4"
- networks:
- testing_net:
- ipv4_address: 172.100.0.3
-
- datarouter-node:
- image: nexus3.onap.org:10003/onap/dmaap/datarouter-node
- container_name: datarouter-node
- hostname: node.datarouternew.com
- ports:
- - "9443:8443"
- - "9090:8080"
- volumes:
- - ./node_data/node.properties:/opt/app/datartr/etc/node.properties
- depends_on:
- datarouter-prov:
- condition: service_healthy
- extra_hosts:
- - "prov.datarouternew.com:172.100.0.3"
- networks:
- testing_net:
- ipv4_address: 172.100.0.4
-
- mariadb_container:
- image: mariadb:10.2.14
- container_name: mariadb
- ports:
- - "3306:3306"
-# volumes:
-# - ./database/sql_init_01.sql:/docker-entrypoint-initdb.d/sql_init_01.sql
- environment:
- MYSQL_ROOT_PASSWORD: datarouter
- MYSQL_DATABASE: datarouter
- MYSQL_USER: datarouter
- MYSQL_PASSWORD: datarouter
- healthcheck:
- test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "--silent"]
- interval: 10s
- timeout: 30s
- retries: 5
-
- networks:
- testing_net:
- ipv4_address: 172.100.0.2
-
-networks:
- testing_net:
- driver: bridge
- ipam:
- driver: default
- config:
- - subnet: 172.100.0.0/16
diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/node.properties b/datarouter-prov/src/main/resources/docker-compose/node_data/node.properties
deleted file mode 100644
index 48485023..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/node_data/node.properties
+++ /dev/null
@@ -1,112 +0,0 @@
-#-------------------------------------------------------------------------------
-# ============LICENSE_START==================================================
-# * org.onap.dmaap
-# * ===========================================================================
-# * Copyright © 2017 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====================================================
-# *
-# * ECOMP is a trademark and service mark of AT&T Intellectual Property.
-# *
-#-------------------------------------------------------------------------------
-#
-# Configuration parameters fixed at startup for the DataRouter node
-#
-# URL to retrieve dynamic configuration
-#
-#ProvisioningURL: ${DRTR_PROV_INTURL:-https://feeds-drtr.web.att.com/internal/prov}
-ProvisioningURL=https://prov.datarouternew.com:8443/internal/prov
-
-#
-# URL to upload PUB/DEL/EXP logs
-#
-#LogUploadURL: ${DRTR_LOG_URL:-https://feeds-drtr.web.att.com/internal/logs}
-LogUploadURL=https://prov.datarouternew.com:8443/internal/logs
-
-#
-# The port number for http as seen within the server
-#
-#IntHttpPort: ${DRTR_NODE_INTHTTPPORT:-8080}
-IntHttpPort=8080
-#
-# The port number for https as seen within the server
-#
-IntHttpsPort=8443
-#
-# The external port number for https taking port mapping into account
-#
-ExtHttpsPort=443
-#
-# The minimum interval between fetches of the dynamic configuration
-# from the provisioning server
-#
-MinProvFetchInterval=10000
-#
-# The minimum interval between saves of the redirection data file
-#
-MinRedirSaveInterval=10000
-#
-# The path to the directory where log files are stored
-#
-LogDir=/opt/app/datartr/logs
-#
-# The retention interval (in days) for log files
-#
-LogRetention=30
-#
-# The path to the directories where data and meta data files are stored
-#
-SpoolDir=/opt/app/datartr/spool
-#
-# The path to the redirection data file
-#
-#RedirectionFile: etc/redirections.dat
-#
-# The type of keystore for https
-#
-KeyStoreType: jks
-#
-# The path to the keystore for https
-#
-KeyStoreFile:/opt/app/datartr/self_signed/keystore.jks
-#
-# The password for the https keystore
-#
-KeyStorePassword=changeit
-#
-# The password for the private key in the https keystore
-#
-KeyPassword=changeit
-#
-# The type of truststore for https
-#
-TrustStoreType=jks
-#
-# The path to the truststore for https
-#
-#TrustStoreFile=/usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts
-TrustStoreFile=/opt/app/datartr/self_signed/cacerts.jks
-#
-# The password for the https truststore
-#
-TrustStorePassword=changeit
-#
-# The path to the file used to trigger an orderly shutdown
-#
-QuiesceFile=etc/SHUTDOWN
-#
-# The key used to generate passwords for node to node transfers
-#
-NodeAuthKey=Node123!
-
diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/cacerts.jks b/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/cacerts.jks
deleted file mode 100644
index dfd81433..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/cacerts.jks
+++ /dev/null
Binary files differ
diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/keystore.jks b/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/keystore.jks
deleted file mode 100644
index e5a4e781..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/keystore.jks
+++ /dev/null
Binary files differ
diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/mykey.cer b/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/mykey.cer
deleted file mode 100644
index 2a5c9d70..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/mykey.cer
+++ /dev/null
Binary files differ
diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/nodekey.cer b/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/nodekey.cer
deleted file mode 100644
index 4cdfdfe3..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/nodekey.cer
+++ /dev/null
Binary files differ
diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/addFeed3.txt b/datarouter-prov/src/main/resources/docker-compose/prov_data/addFeed3.txt
deleted file mode 100644
index 21000d0a..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/prov_data/addFeed3.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-#-------------------------------------------------------------------------------
-# ============LICENSE_START==================================================
-# * org.onap.dmaap
-# * ===========================================================================
-# * Copyright © 2017 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====================================================
-# *
-# * ECOMP is a trademark and service mark of AT&T Intellectual Property.
-# *
-#-------------------------------------------------------------------------------
-{
- "name": "Jettydemo",
- "version": "m1.0",
- "description": "Jettydemo",
- "business_description": "Jettydemo",
- "suspend": false,
- "deleted": false,
- "changeowner": true,
- "authorization": {
- "classification": "unclassified",
- "endpoint_addrs": [
- "172.100.0.3",
- ],
- "endpoint_ids": [
- {
- "password": "rs873m",
- "id": "rs873m"
- }
- ]
- },
-}
-
diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/addSubscriber.txt b/datarouter-prov/src/main/resources/docker-compose/prov_data/addSubscriber.txt
deleted file mode 100644
index 45e12732..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/prov_data/addSubscriber.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-#-------------------------------------------------------------------------------
-# ============LICENSE_START==================================================
-# * org.onap.dmaap
-# * ===========================================================================
-# * Copyright © 2017 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====================================================
-# *
-# * ECOMP is a trademark and service mark of AT&T Intellectual Property.
-# *
-#-------------------------------------------------------------------------------
-{
- "delivery" :
-
- {
- "url" : "http://172.100.0.3:7070/",
- "user" : "datarouter",
- "password" : "datarouter",
- "use100" : true
- },
- "metadataOnly" : false,
- "suspend" : false,
- "groupid" : 29,
- "subscriber" : "sg481n"
-}
diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties b/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties
deleted file mode 100644
index 7758a64d..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties
+++ /dev/null
@@ -1,49 +0,0 @@
-#-------------------------------------------------------------------------------
-# ============LICENSE_START==================================================
-# * org.onap.dmaap
-# * ===========================================================================
-# * Copyright � 2017 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====================================================
-# *
-# * ECOMP is a trademark and service mark of AT&T Intellectual Property.
-# *
-#-------------------------------------------------------------------------------
-
-#Jetty Server properties
-org.onap.dmaap.datarouter.provserver.http.port = 8080
-org.onap.dmaap.datarouter.provserver.https.port = 8443
-org.onap.dmaap.datarouter.provserver.https.relaxation = true
-
-org.onap.dmaap.datarouter.provserver.keystore.type = jks
-org.onap.dmaap.datarouter.provserver.keymanager.password = changeit
-org.onap.dmaap.datarouter.provserver.keystore.path = /opt/app/datartr/self_signed/keystore.jks
-org.onap.dmaap.datarouter.provserver.keystore.password = changeit
-org.onap.dmaap.datarouter.provserver.truststore.path = /opt/app/datartr/self_signed/cacerts.jks
-org.onap.dmaap.datarouter.provserver.truststore.password = changeit
-
-org.onap.dmaap.datarouter.provserver.accesslog.dir = /opt/app/datartr/logs
-org.onap.dmaap.datarouter.provserver.spooldir = /opt/app/datartr/spool
-org.onap.dmaap.datarouter.provserver.dbscripts = /opt/app/datartr/etc/misc
-org.onap.dmaap.datarouter.provserver.logretention = 30
-
-#DMAAP-597 (Tech Dept) REST request source IP auth
-# relaxation to accommodate OOM kubernetes deploy
-org.onap.dmaap.datarouter.provserver.isaddressauthenabled = false
-
-# Database access
-org.onap.dmaap.datarouter.db.driver = org.mariadb.jdbc.Driver
-org.onap.dmaap.datarouter.db.url = jdbc:mariadb://172.100.0.2:3306/datarouter
-org.onap.dmaap.datarouter.db.login = datarouter
-org.onap.dmaap.datarouter.db.password = datarouter
diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/cacerts.jks b/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/cacerts.jks
deleted file mode 100644
index 76a480ad..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/cacerts.jks
+++ /dev/null
Binary files differ
diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/keystore.jks b/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/keystore.jks
deleted file mode 100644
index 2c22b4ac..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/keystore.jks
+++ /dev/null
Binary files differ
diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/mykey.cer b/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/mykey.cer
deleted file mode 100644
index 2a5c9d70..00000000
--- a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/mykey.cer
+++ /dev/null
Binary files differ
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java
index 0a9632eb..0babdc47 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java
@@ -105,6 +105,8 @@ public class StatisticsServletTest extends DrServletTestBase {
when(response.getOutputStream()).thenReturn(outStream);
statisticsServlet = PowerMockito.mock(StatisticsServlet.class);
PowerMockito.doReturn(null).when(statisticsServlet, "getRecordsForSQL", anyString());
+ PowerMockito.doCallRealMethod().when(statisticsServlet, "buildMapFromRequest", anyObject());
+ PowerMockito.doCallRealMethod().when(statisticsServlet, "getTimeFromParam", anyString());
doNothing().when(statisticsServlet).rsToCSV(anyObject(), anyObject());
doCallRealMethod().when(statisticsServlet).doGet(request, response);
when(statisticsServlet.getFeedIdsByGroupId(anyInt())).thenReturn(new StringBuffer("1"));
@@ -116,10 +118,13 @@ public class StatisticsServletTest extends DrServletTestBase {
public void Given_Request_Is_HTTP_GET_With_GroupId_And_FeedId_Parameters_Then_Request_Succeeds()
throws Exception {
when(request.getParameter("feedid")).thenReturn("1");
+ when(request.getParameter("statusCode")).thenReturn("500");
ServletOutputStream outStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outStream);
statisticsServlet = PowerMockito.mock(StatisticsServlet.class);
PowerMockito.doReturn(null).when(statisticsServlet, "getRecordsForSQL", anyString());
+ PowerMockito.doCallRealMethod().when(statisticsServlet, "buildMapFromRequest", anyObject());
+ PowerMockito.doCallRealMethod().when(statisticsServlet, "getTimeFromParam", anyString());
doNothing().when(statisticsServlet).rsToCSV(anyObject(), anyObject());
doCallRealMethod().when(statisticsServlet).doGet(request, response);
doCallRealMethod().when(statisticsServlet).queryGeneretor(anyObject());
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLITest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLITest.java
new file mode 100755
index 00000000..dc8d4c79
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLITest.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package org.onap.dmaap.datarouter.provisioning.utils;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(PowerMockRunner.class)
+public class DRRouteCLITest {
+
+ @Mock
+ private AbstractHttpClient httpClient;
+
+ @Mock
+ private CloseableHttpResponse httpResponse;
+
+ @Mock
+ private HttpEntity httpEntity;
+
+ @Mock
+ private StatusLine statusLine;
+
+ private DRRouteCLI drRouteCLI;
+
+ @Before
+ public void setUp() throws IllegalAccessException{
+ drRouteCLI = mock(DRRouteCLI.class);
+ doCallRealMethod().when(drRouteCLI).runCommand(anyObject());
+ FieldUtils.writeField(drRouteCLI, "server", "prov.datarouternew.com", true);
+ }
+
+ @Test
+ public void Given_Add_Egress_Then_RunCommand_Returns_True() throws Exception{
+ mockHttpClientForRestCall();
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"add", "egress", "1", "node.datarouternew.com"}));
+ }
+
+ @Test
+ public void Given_Add_Network_Then_RunCommand_Returns_True() throws Exception{
+ mockHttpClientForRestCall();
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"add", "network", "prov.datarouternew.com", "node.datarouternew.com", "172.100.0.1"}));
+ }
+
+ @Test
+ public void Given_Add_Egress_With_Incorrect_Args_Then_RunCommand_Returns_False() throws Exception{
+ mockHttpClientForRestCall();
+ Assert.assertFalse(drRouteCLI.runCommand(new String[]{"add", "egress", "1", "user1", "172.100.0.0", "node.datarouternew.com"}));
+ }
+
+ @Test
+ public void Given_Error_On_Post_Rest_Call_RunCommand_Returns_False() throws Exception{
+ mockErrorResponseFromRestCall();
+ Assert.assertFalse(drRouteCLI.runCommand(new String[]{"add", "network", "prov.datarouternew.com", "node.datarouternew.com"}));
+ }
+
+ @Test
+ public void Given_Delete_Ingress_Then_RunCommand_Returns_True() throws Exception{
+ mockHttpClientForRestCall();
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"del", "ingress", "1", "user1", "172.100.0.0"}));
+ }
+
+ @Test
+ public void Given_Delete_Egress_Then_RunCommand_Returns_True() throws Exception{
+ mockHttpClientForRestCall();
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"del", "egress", "1"}));
+ }
+
+ @Test
+ public void Given_Delete_Network_Then_RunCommand_Returns_True() throws Exception{
+ mockHttpClientForRestCall();
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"del", "network", "prov.datarouternew.com", "node.datarouternew.com"}));
+ }
+
+ @Test
+ public void Given_Delete_Ingress_With_Incorrect_Args_Then_RunCommand_Returns_False() throws Exception{
+ mockHttpClientForRestCall();
+ Assert.assertFalse(drRouteCLI.runCommand(new String[]{"del", "ingress", "prov.datarouternew.com", "node.datarouternew.com"}));
+ }
+
+ @Test
+ public void Given_Error_On_Delete_Rest_Call_RunCommand_Returns_False() throws Exception{
+ mockErrorResponseFromRestCall();
+ Assert.assertFalse(drRouteCLI.runCommand(new String[]{"del", "network", "prov.datarouternew.com", "node.datarouternew.com"}));
+ }
+
+ @Test
+ public void Given_List_Args_Then_RunCommand_Returns_True() throws Exception{
+ mockHttpClientForGetRequest();
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"list"}));
+ }
+
+ @Test
+ public void Given_Error_On_Get_Rest_Call_RunCommand_Returns_True() throws Exception{
+ mockErrorResponseFromRestCall();
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"list"}));
+ }
+
+ @Test
+ public void Given_Width_Arg_Then_RunCommand_Returns_True() {
+ Assert.assertTrue(drRouteCLI.runCommand(new String[]{"width", "130"}));
+ }
+
+ @Test
+ public void Given_Usage_Arg_Then_RunCommand_Returns_False() {
+ Assert.assertFalse(drRouteCLI.runCommand(new String[]{"usage"}));
+ }
+
+ private void mockHttpClientForRestCall() throws Exception{
+ when(httpResponse.getEntity()).thenReturn(httpEntity);
+ when(statusLine.getStatusCode()).thenReturn(200);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpClient.execute(anyObject())).thenReturn(httpResponse);
+ FieldUtils.writeField(drRouteCLI, "httpclient", httpClient, true);
+ }
+
+ private void mockHttpClientForGetRequest() throws Exception{
+ mockResponseFromGet();
+ when(httpResponse.getEntity()).thenReturn(httpEntity);
+ when(statusLine.getStatusCode()).thenReturn(200);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpClient.execute(anyObject())).thenReturn(httpResponse);
+ FieldUtils.writeField(drRouteCLI, "httpclient", httpClient, true);
+ }
+
+ private void mockResponseFromGet() throws IOException {
+ JSONObject response = new JSONObject();
+ response.put("ingress", addIngressObject());
+ response.put("egress", addEgressObject());
+ response.put("routing", addRoutingObject());
+ InputStream in = new ByteArrayInputStream(response.toString().getBytes());
+ when(httpEntity.getContent()).thenReturn(in);
+ }
+
+ private JSONArray addRoutingObject() {
+ JSONArray routing = new JSONArray();
+ JSONObject route = new JSONObject();
+ route.put("from", "prov.datarouternew.com");
+ route.put("to", "node.datarouternew.com");
+ route.put("via", "172.100.0.1");
+ routing.put(route);
+ return routing;
+ }
+
+ private JSONObject addEgressObject() {
+ JSONObject egress = new JSONObject();
+ egress.put("1", "node.datarouternew.com");
+ egress.put("2", "172.0.0.1");
+ return egress;
+ }
+
+ private JSONArray addIngressObject() {
+ JSONArray ingresses = new JSONArray();
+ JSONObject ingress = new JSONObject();
+ ingress.put("seq", 21);
+ ingress.put("feedid", 1);
+ ingress.put("user", "user1");
+ ingress.put("subnet", "172.0.0.0");
+ JSONArray nodes = new JSONArray();
+ nodes.put("node.datarouternew.com");
+ nodes.put("172.0.0.1");
+ ingress.put("node", nodes);
+ ingresses.put(ingress);
+ return ingresses;
+ }
+
+ private void mockErrorResponseFromRestCall() throws Exception{
+ InputStream in = new ByteArrayInputStream("<pre> Server Not Found </pre>".getBytes());
+ when(httpEntity.getContent()).thenReturn(in);
+ when(httpResponse.getEntity()).thenReturn(httpEntity);
+ when(statusLine.getStatusCode()).thenReturn(400);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpClient.execute(anyObject())).thenReturn(httpResponse);
+ FieldUtils.writeField(drRouteCLI, "httpclient", httpClient, true);
+ }
+}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
new file mode 100755
index 00000000..7cfe68f9
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
@@ -0,0 +1,498 @@
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+
+package org.onap.dmaap.datarouter.provisioning.utils;
+
+import java.io.CharArrayWriter;
+import java.io.Writer;
+import org.json.JSONArray;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+import java.util.HashMap;
+import java.util.Map;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+
+@RunWith(PowerMockRunner.class)
+public class LOGJSONObjectTest {
+
+ private static LOGJSONObject logJO;
+
+ @Before
+ public void setUp() throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", null);
+ logJO = new LOGJSONObject(map);
+ }
+
+ @Test
+ public void Given_Method_Is_Accumulate_And_Value_Is_Valid_Put_Value_Into_New_JSONArray()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", 3);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ logJObject.accumulate(s, null);
+ assertThat(logJObject.get("key").toString(), is("[3,null]"));
+ }
+
+ @Test
+ public void Given_Method_Is_Accumulate_And_Value_Is_Null_Dont_Add_Key_Value_Pair()
+ throws Exception {
+ String s = "key";
+ logJO.accumulate(s, null);
+ assertThat(logJO.has("key"), is(false));
+ }
+
+ @Test
+ public void Given_Method_Is_Append_And_Value_Is_Null_Append_New_Value()
+ throws Exception {
+ String s = "key";
+ double d = 2.0;
+ logJO.append(s, d);
+ assertThat(logJO.getJSONArray("key").get(0), is(2.0));
+ }
+
+
+ @Test
+ public void Given_Method_Is_DoubleToString_And_Value_Is_NaN_Return_Null()
+ throws Exception {
+ double d = 2.0;
+ assertThat(logJO.doubleToString(d), is("2"));
+ }
+
+
+ @Test
+ public void Given_Method_Is_GetBoolean_And_Value_Is_False_Return_False()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", false);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getBoolean(s), is(false));
+ }
+
+ @Test
+ public void Given_Method_Is_GetBoolean_And_Value_Is_True_Return_True()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", true);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getBoolean(s), is(true));
+ }
+
+ @Test
+ public void Given_Method_Is_GetDouble_And_Value_Is_A_Double_Return_Value()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", 2.0);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getDouble(s), is(2.0));
+ }
+
+ @Test
+ public void Given_Method_Is_GetInt_And_Value_Is_An_Int_Return_Value()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", 3);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getInt(s), is(3));
+ }
+
+ @Test
+ public void Given_Method_Is_GetJSONArray_And_Value_Is_A_JSONArray_Return_Value()
+ throws Exception {
+ JSONArray jA = new JSONArray();
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", jA);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getJSONArray(s), is(jA));
+ }
+
+ @Test
+ public void Given_Method_Is_GetJSONObject_And_Value_Is_A_JSONObject_Return_Value()
+ throws Exception {
+ LOGJSONObject logJObj = new LOGJSONObject();
+ logJObj.put("stub_key", 1);
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", logJObj);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getJSONObject(s), is(logJObj));
+ }
+
+ @Test
+ public void Given_Method_Is_GetLong_And_Value_Is_A_Long_Return_Value()
+ throws Exception {
+ long l = 5;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", l);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getLong(s), is(5L));
+ }
+
+ @Test
+ public void Given_Method_Is_getNames_And_Value_Is_A_LOGJSONObject_Return_StringArray()
+ throws Exception {
+ LOGJSONObject logJObj = new LOGJSONObject();
+ logJObj.put("name", "stub_name");
+ String[] sArray = new String[logJObj.length()];
+ sArray[0] = "name";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", sArray);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getNames(logJObj), is(sArray));
+ }
+
+ @Test
+ public void Given_Method_Is_GetString_And_Value_Is_A_String_Return_Value()
+ throws Exception {
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.getString(s), is("value"));
+ }
+
+ @Test
+ public void Given_Method_Is_Increment_And_Value_Is_Null_Put_Defualt_Value()
+ throws Exception {
+ Map<String, Object> mapResult = new HashMap<>();
+ mapResult.put("key", 1);
+ LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
+
+ String val = null;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ logJObject.increment(s);
+ assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
+ }
+
+ @Test
+ public void Given_Method_Is_Increment_And_Value_Is_An_Int_Put_Value_Plus_One()
+ throws Exception {
+ Map<String, Object> mapResult = new HashMap<>();
+ mapResult.put("key", 3);
+ LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
+
+ int val = 2;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ logJObject.increment(s);
+ assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
+ }
+
+ @Test
+ public void Given_Method_Is_Increment_And_Value_Is_A_Long_Put_Value_Plus_One()
+ throws Exception {
+ Map<String, Object> mapResult = new HashMap<>();
+ mapResult.put("key", 4L);
+ LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
+
+ long val = 3;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ logJObject.increment(s);
+ assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
+ }
+
+ @Test
+ public void Given_Method_Is_Increment_And_Value_Is_A_Double_Put_Value_Plus_One()
+ throws Exception {
+ Map<String, Object> mapResult = new HashMap<>();
+ mapResult.put("key", 5.0);
+ LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
+
+ double val = 4.0;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ logJObject.increment(s);
+ assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
+ }
+
+ @Test
+ public void Given_Method_Is_Increment_And_Value_Is_A_Float_Put_Value_Plus_One()
+ throws Exception {
+ Map<String, Object> mapResult = new HashMap<>();
+ mapResult.put("key", 5.0);
+ LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
+
+ float val = 4.0f;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ logJObject.increment(s);
+ assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
+ }
+
+ @Test
+ public void Given_Method_Is_Names_And_Object_Contains_Keys_Put_Keys_Into_New_JSONArray()
+ throws Exception {
+ JSONArray ja = new JSONArray();
+ ja.put("key");
+
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.names().get(0), is(ja.get(0)));
+ }
+
+ @Test
+ public void Given_Method_Is_NumberToString_And_Number_is_Not_Null_Return_Reformatted_Number_As_String()
+ throws Exception {
+ Number num = 3.0;
+
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.numberToString(num), is("3"));
+ }
+
+ @Test
+ public void Given_Method_Is_OptBoolean_And_Value_is_Boolean_Return_Value()
+ throws Exception {
+ boolean val = true;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optBoolean(s, false), is(true));
+ }
+
+ @Test
+ public void Given_Method_Is_OptBoolean_And_Value_is_Not_Boolean_Return_Default_Value()
+ throws Exception {
+ String val = "not_boolean";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optBoolean(s, false), is(false));
+ }
+
+ @Test
+ public void Given_Method_Is_OptDouble_And_Value_is_Double_Return_Value()
+ throws Exception {
+ double val = 2.0;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optDouble(s, 0.0), is(2.0));
+ }
+
+ @Test
+ public void Given_Method_Is_OptDouble_And_Value_is_Not_Double_Return_Default_Value()
+ throws Exception {
+ String val = "not_double";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optDouble(s, 0.0), is(0.0));
+ }
+
+ @Test
+ public void Given_Method_Is_OptInt_And_Value_is_Int_Return_Value()
+ throws Exception {
+ int val = 1;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optInt(s, 0), is(1));
+ }
+
+ @Test
+ public void Given_Method_Is_OptInt_And_Value_Is_Null_Return_Default_Value()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", null);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optInt(s, 0), is(0));
+ }
+
+ @Test
+ public void Given_Method_Is_OptLong_And_Value_is_Long_Return_Value()
+ throws Exception {
+ long val = 4;
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optLong(s, 0), is(4L));
+ }
+
+ @Test
+ public void Given_Method_Is_OptLong_And_Value_is_Not_Long_Return_Default_Value()
+ throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", null);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optLong(s, 0), is(0L));
+ }
+
+ @Test
+ public void Given_Method_Is_OptString_And_Value_is_String_Return_Value()
+ throws Exception {
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", val);
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.optString(s, "default_value"), is("value"));
+ }
+
+ @Test
+ public void Given_Method_Is_putOnce_And_KeyValuePair_Does_Not_Exist_In_logJObject_Put_KeyValuePair_Into_logJObject()
+ throws Exception {
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ String s = "key";
+ assertThat(logJObject.putOnce(s, val).get("key"), is("value"));
+ }
+
+ @Test
+ public void Given_Method_Is_StringToValue_And_Value_Is_Number_Return_Number()
+ throws Exception {
+ String val = "312";
+ Map<String, Object> map = new HashMap<>();
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ assertThat(logJObject.stringToValue(val), is(312));
+ }
+
+ @Test
+ public void Given_Method_Is_ToJSONArray_And_KeyValue_Exists_Return_Value_Array()
+ throws Exception {
+ JSONArray names = new JSONArray();
+ Map<String, Object> map = new HashMap<>();
+ map.put("name", "value");
+ names.put("name");
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ assertThat(logJObject.toJSONArray(names).get(0), is("value"));
+ }
+
+ @Test
+ public void Given_Method_Is_ValueToString_And_Value_Is_JSONArray_Return_Value_To_String()
+ throws Exception {
+ JSONArray val = new JSONArray();
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", "value");
+ val.put("value");
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ assertThat(logJObject.valueToString(val), is("[\"value\"]"));
+ }
+
+ @Test
+ public void Given_Method_Is_writeValue_And_Value_IS_Not_Null_Return_Writer_With_Value()
+ throws Exception {
+ Writer writer = new CharArrayWriter();
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", "value");
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ assertThat(logJObject.writeValue(writer, val, 3, 1).toString(), is("\"value\""));
+ }
+
+ @Test
+ public void Given_Method_Is_write_And_Length_Of_logJObject_Is_One_Write_Value_With_Indent()
+ throws Exception {
+ Writer writer = new CharArrayWriter();
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", "value");
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ assertThat(logJObject.write(writer, 3, 1).toString(), is("{\"key\": \"value\"}"));
+ }
+
+ @Test
+ public void Given_Method_Is_write_And_Length_Of_logJObject_Is_Not_One_Or_Zero_Write_Value_With_New_Indent()
+ throws Exception {
+ Writer writer = new CharArrayWriter();
+ String val = "value";
+ Map<String, Object> map = new HashMap<>();
+ map.put("key", "value");
+ map.put("key1", "value1");
+ LOGJSONObject logJObject = new LOGJSONObject(map);
+
+ assertThat(logJObject.write(writer, 3, 1).toString(), is("{\n \"key1\": \"value1\",\n \"key\": \"value\"\n }"));
+ }
+}