diff options
Diffstat (limited to 'datarouter-prov/src')
30 files changed, 864 insertions, 374 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java index 412e1322..047043b1 100644..100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java @@ -319,7 +319,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { * @return an error string, or null if all is OK */ String isAuthorizedForProvisioning(HttpServletRequest request) { - if (Boolean.parseBoolean(isAddressAuthEnabled)) { + if (!Boolean.parseBoolean(isAddressAuthEnabled)) { return null; } // Is the request https? @@ -369,7 +369,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { boolean isAuthorizedForInternal(HttpServletRequest request) { try { - if (Boolean.parseBoolean(isAddressAuthEnabled)) { + if (!Boolean.parseBoolean(isAddressAuthEnabled)) { return true; } InetAddress ip = InetAddress.getByName(request.getRemoteAddr()); @@ -492,9 +492,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { // Normalize the nodes, and fill in nodeAddresses InetAddress[] na = new InetAddress[nodes.length]; for (int i = 0; i < nodes.length; i++) { - if (nodes[i].indexOf('.') < 0) { - nodes[i] += "." + provDomain; - } try { na[i] = InetAddress.getByName(nodes[i]); intlogger.debug("PROV0003 DNS lookup: " + nodes[i] + " => " + na[i].toString()); @@ -520,9 +517,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { String[] pods = getPods(); na = new InetAddress[pods.length]; for (int i = 0; i < pods.length; i++) { - if (pods[i].indexOf('.') < 0) { - pods[i] += "." + provDomain; - } try { na[i] = InetAddress.getByName(pods[i]); intlogger.debug("PROV0003 DNS lookup: " + pods[i] + " => " + na[i].toString()); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java index 87979be6..800bd9af 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java @@ -185,8 +185,6 @@ public class Main { sslContextFactory.setTrustStorePath(DEFAULT_TRUSTSTORE); sslContextFactory.setTrustStorePassword("changeit"); } - sslContextFactory.setTrustStorePath("/opt/app/datartr/self_signed/cacerts.jks"); - sslContextFactory.setTrustStorePassword("changeit"); sslContextFactory.setWantClientAuth(true); // Servlet and Filter configuration 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 c560299a..8d6bfcf0 100644..100755 --- 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 @@ -35,12 +35,10 @@ import java.security.KeyStoreException; import java.util.Collections; import java.util.List; import java.util.Properties; - import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; @@ -57,16 +55,16 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB; import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; /** - * This class is the base class for those servlets that need to proxy their requests from the - * standby to active server. Its methods perform the proxy function to the active server. If the - * active server is not reachable, a 503 (SC_SERVICE_UNAVAILABLE) is returned. Only - * DELETE/GET/PUT/POST are supported. + * This class is the base class for those servlets that need to proxy their requests from the standby to active server. + * Its methods perform the proxy function to the active server. If the active server is not reachable, a 503 + * (SC_SERVICE_UNAVAILABLE) is returned. Only DELETE/GET/PUT/POST are supported. * * @author Robert Eby * @version $Id: ProxyServlet.java,v 1.3 2014/03/24 18:47:10 eby Exp $ */ @SuppressWarnings("serial") public class ProxyServlet extends BaseServlet { + private boolean inited = false; private Scheme sch; @@ -80,13 +78,13 @@ public class ProxyServlet extends BaseServlet { try { // Set up keystore Properties props = (new DB()).getProperties(); - String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks"); + String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks"); String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY); - String pass = props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY); + String pass = props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY); KeyStore keyStore = readStore(store, pass, type); store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY); - pass = props.getProperty(Main.TRUSTSTORE_PASSWORD_PROPERTY); + pass = props.getProperty(Main.TRUSTSTORE_PASSWORD_PROPERTY); if (store == null || store.length() == 0) { store = Main.DEFAULT_TRUSTSTORE; pass = "changeit"; @@ -95,30 +93,34 @@ public class ProxyServlet extends BaseServlet { // We are connecting with the node name, but the certificate will have the CNAME // So we need to accept a non-matching certificate name - SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, "changeit", trustStore); + SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, + props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY), trustStore); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); sch = new Scheme("https", 443, socketFactory); inited = true; } catch (Exception e) { e.printStackTrace(); } - intlogger.info("ProxyServlet: inited = "+inited); + intlogger.info("ProxyServlet: inited = " + inited); } - private KeyStore readStore(String store, String pass, String type) throws KeyStoreException, FileNotFoundException { + + private KeyStore readStore(String store, String pass, String type) throws KeyStoreException { KeyStore ks = KeyStore.getInstance(type); - FileInputStream instream = new FileInputStream(new File(store)); - try { + try (FileInputStream instream = new FileInputStream(new File(store))) { ks.load(instream, pass.toCharArray()); + } catch (FileNotFoundException fileNotFoundException) { + System.err.println("ProxyServlet: " + fileNotFoundException); + fileNotFoundException.printStackTrace(); } catch (Exception x) { - System.err.println("READING TRUSTSTORE: "+x); - } finally { - try { instream.close(); } catch (Exception ignore) {} + System.err.println("READING TRUSTSTORE: " + x); } return ks; } + /** - * Return <i>true</i> if the requester has NOT set the <i>noproxy</i> CGI variable. - * If they have, this indicates they want to forcibly turn the proxy off. + * Return <i>true</i> if the requester has NOT set the <i>noproxy</i> CGI variable. If they have, this indicates + * they want to forcibly turn the proxy off. + * * @param req the HTTP request * @return true or false */ @@ -127,22 +129,25 @@ public class ProxyServlet extends BaseServlet { if (t != null) { t = t.replaceAll("&", "&"); for (String s : t.split("&")) { - if (s.equals("noproxy") || s.startsWith("noproxy=")) + if (s.equals("noproxy") || s.startsWith("noproxy=")) { return false; + } } } return true; } + /** - * Is this the standby server? If it is, the proxy functions can be used. - * If not, the proxy functions should not be called, and will send a response of 500 - * (Internal Server Error). + * Is this the standby server? If it is, the proxy functions can be used. If not, the proxy functions should not be + * called, and will send a response of 500 (Internal Server Error). + * * @return true if this server is the standby (and hence a proxy server). */ public boolean isProxyServer() { SynchronizerTask st = SynchronizerTask.getSynchronizer(); return st.getState() == SynchronizerTask.STANDBY; } + /** * Issue a proxy DELETE to the active provisioning server. */ @@ -150,6 +155,7 @@ public class ProxyServlet extends BaseServlet { public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException { doProxy(req, resp, "DELETE"); } + /** * Issue a proxy GET to the active provisioning server. */ @@ -157,6 +163,7 @@ public class ProxyServlet extends BaseServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { doProxy(req, resp, "GET"); } + /** * Issue a proxy PUT to the active provisioning server. */ @@ -164,6 +171,7 @@ public class ProxyServlet extends BaseServlet { public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException { doProxy(req, resp, "PUT"); } + /** * Issue a proxy POST to the active provisioning server. */ @@ -171,58 +179,61 @@ public class ProxyServlet extends BaseServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { doProxy(req, resp, "POST"); } + /** - * Issue a proxy GET to the active provisioning server. Unlike doGet() above, - * this method will allow the caller to fall back to other code if the remote server is unreachable. + * Issue a proxy GET to the active provisioning server. Unlike doGet() above, this method will allow the caller to + * fall back to other code if the remote server is unreachable. + * * @return true if the proxy succeeded */ public boolean doGetWithFallback(HttpServletRequest req, HttpServletResponse resp) throws IOException { boolean rv = false; if (inited) { String url = buildUrl(req); - intlogger.info("ProxyServlet: proxying with fallback GET "+url); - try(AbstractHttpClient httpclient = new DefaultHttpClient()){ - HttpRequestBase proxy = new HttpGet(url); - try { - httpclient.getConnectionManager().getSchemeRegistry().register(sch); - - // Copy request headers and request body - copyRequestHeaders(req, 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); - - HttpEntity entity = pxy_response.getEntity(); - if (entity != null) { - InputStream in = entity.getContent(); - IOUtils.copy(in, resp.getOutputStream()); - in.close(); + intlogger.info("ProxyServlet: proxying with fallback GET " + url); + try (AbstractHttpClient httpclient = new DefaultHttpClient()) { + HttpRequestBase proxy = new HttpGet(url); + try { + httpclient.getConnectionManager().getSchemeRegistry().register(sch); + + // Copy request headers and request body + copyRequestHeaders(req, 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); + + HttpEntity entity = pxy_response.getEntity(); + if (entity != null) { + InputStream in = entity.getContent(); + IOUtils.copy(in, resp.getOutputStream()); + in.close(); + } + rv = true; + + } catch (IOException e) { + System.err.println("ProxyServlet: " + e); + e.printStackTrace(); + } finally { + proxy.releaseConnection(); + httpclient.getConnectionManager().shutdown(); } - rv = true; - - } catch (IOException e) { - System.err.println("ProxyServlet: "+e); - e.printStackTrace(); - } finally { - proxy.releaseConnection(); - httpclient.getConnectionManager().shutdown(); - } } } else { intlogger.warn("ProxyServlet: proxy disabled"); } return rv; } + private void doProxy(HttpServletRequest req, HttpServletResponse resp, final String method) throws IOException { if (inited && isProxyServer()) { String url = buildUrl(req); - intlogger.info("ProxyServlet: proxying "+method + " "+url); - try(AbstractHttpClient httpclient = new DefaultHttpClient()) { + intlogger.info("ProxyServlet: proxying " + method + " " + url); + try (AbstractHttpClient httpclient = new DefaultHttpClient()) { ProxyHttpRequest proxy = new ProxyHttpRequest(method, url); try { httpclient.getConnectionManager().getSchemeRegistry().register(sch); @@ -264,33 +275,40 @@ public class ProxyServlet extends BaseServlet { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } + private String buildUrl(HttpServletRequest req) { StringBuilder sb = new StringBuilder("https://"); sb.append(URLUtilities.getPeerPodName()); sb.append(req.getRequestURI()); String q = req.getQueryString(); - if (q != null) + if (q != null) { sb.append("?").append(q); + } return sb.toString(); } + private void copyRequestHeaders(HttpServletRequest from, HttpRequestBase to) { @SuppressWarnings("unchecked") List<String> list = Collections.list(from.getHeaderNames()); for (String name : list) { // Proxy code will add this one - if (!name.equalsIgnoreCase("Content-Length")) + if (!name.equalsIgnoreCase("Content-Length")) { to.addHeader(name, from.getHeader(name)); + } } } + private void copyResponseHeaders(HttpResponse from, HttpServletResponse to) { for (Header hdr : from.getAllHeaders()) { // Don't copy Date: our Jetty will add another Date header - if (!hdr.getName().equals("Date")) + if (!hdr.getName().equals("Date")) { to.addHeader(hdr.getName(), hdr.getValue()); + } } } public class ProxyHttpRequest extends HttpEntityEnclosingRequestBase { + private final String method; public ProxyHttpRequest(final String method, final String uri) { @@ -298,6 +316,7 @@ public class ProxyServlet extends BaseServlet { this.method = method; setURI(URI.create(uri)); } + @Override public String getMethod() { return method; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java index 134a595b..e79d4705 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java @@ -293,13 +293,13 @@ public class StatisticsServlet extends BaseServlet { /**
* getFeedIdsByGroupId - Getting FEEDID's by GROUP ID.
*
- * @throws SQL Query SQLException.
+ * @throws SQLException Query SQLException.
*/
public StringBuffer getFeedIdsByGroupId(int groupIds) throws SQLException {
DB db = null;
Connection conn = null;
- PreparedStatement prepareStatement = null;
+ //PreparedStatement prepareStatement = null;
ResultSet resultSet = null;
String sqlGoupid = null;
StringBuffer feedIds = new StringBuffer();
@@ -308,16 +308,16 @@ public class StatisticsServlet extends BaseServlet { db = new DB();
conn = db.getConnection();
sqlGoupid = " SELECT FEEDID from FEEDS WHERE GROUPID = ?";
- prepareStatement = conn.prepareStatement(sqlGoupid);
- prepareStatement.setInt(1, groupIds);
- resultSet = prepareStatement.executeQuery();
- while (resultSet.next()) {
- feedIds.append(resultSet.getInt("FEEDID"));
- feedIds.append(",");
+ try(PreparedStatement prepareStatement = conn.prepareStatement(sqlGoupid)) {
+ prepareStatement.setInt(1, groupIds);
+ resultSet = prepareStatement.executeQuery();
+ while (resultSet.next()) {
+ feedIds.append(resultSet.getInt("FEEDID"));
+ feedIds.append(",");
+ }
+ feedIds.deleteCharAt(feedIds.length() - 1);
+ System.out.println("feedIds" + feedIds.toString());
}
- feedIds.deleteCharAt(feedIds.length() - 1);
- System.out.println("feedIds" + feedIds.toString());
-
} catch (SQLException e) {
e.printStackTrace();
} finally {
@@ -326,13 +326,7 @@ public class StatisticsServlet extends BaseServlet { resultSet.close();
resultSet = null;
}
-
- if (prepareStatement != null) {
- prepareStatement.close();
- prepareStatement = null;
- }
-
- if (conn != null) {
+ if (conn != null) {
db.release(conn);
}
} catch (Exception e) {
@@ -571,33 +565,44 @@ public class StatisticsServlet extends BaseServlet { intlogger.info("Error parsing time=" + s);
return -1;
}
-
-
private ResultSet getRecordsForSQL(String sql) {
- intlogger.debug(sql);
- long start = System.currentTimeMillis();
- DB db = new DB();
- Connection conn = null;
- ResultSet rs = null;
-
- try {
- conn = db.getConnection();
- Statement stmt = conn.createStatement();
- PreparedStatement pst = conn.prepareStatement(sql);
- rs = pst.executeQuery();
- //this.rsToJson(rs)
- //rs.close();
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (conn != null) {
- db.release(conn);
- }
- }
+ intlogger.debug(sql);
+ long start = System.currentTimeMillis();
+ DB db = new DB();
+ Connection conn = null;
+ ResultSet rs = null;
+ Statement stmt = null;
+ PreparedStatement pst = null;
+ try {
+ conn = db.getConnection();
+ stmt = conn.createStatement();
+ pst = conn.prepareStatement(sql);
+ rs = pst.executeQuery();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ } finally {
+
+ try {
+ if (conn != null) {
+ db.release(conn);
+ }
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (pst != null) {
+ pst.close();
+ }
+ if (rs != null) {
+ rs.close();
+ }
+
+ } catch (SQLException sqlException) {
+ intlogger.error("Exception in getting SQl Records",sqlException);
+ }
- intlogger.debug("Time: " + (System.currentTimeMillis() - start) + " ms");
+ intlogger.debug("Time: " + (System.currentTimeMillis() - start) + " ms");
- return rs;
+ return rs;
+ }
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java index 2ea60d26..a021a60e 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java @@ -60,7 +60,7 @@ public class Group extends Syncable { public static Group getGroupMatching(Group gup) {
String sql = String.format(
- "select * from GROUPS where NAME = \"%s\"",
+ "select * from GROUPS where NAME='%s'",
gup.getName()
);
List<Group> list = getGroupsForSQL(sql);
@@ -69,7 +69,7 @@ public class Group extends Syncable { public static Group getGroupMatching(Group gup, int groupid) {
String sql = String.format(
- "select * from GROUPS where NAME = \"%s\" and GROUPID != %d ",
+ "select * from GROUPS where NAME = '%s' and GROUPID != %d ",
gup.getName(),
gup.getGroupid()
);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java index 4c140490..f3eb1eb6 100644..100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java @@ -32,7 +32,6 @@ import java.util.HashMap; import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-
import org.apache.log4j.Logger;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
@@ -43,6 +42,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB; * @version $Id: NodeClass.java,v 1.2 2014/01/15 16:08:43 eby Exp $
*/
public abstract class NodeClass extends Syncable {
+
private static Map<String, Integer> map;
private static Logger intLogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
public NodeClass() {
@@ -53,19 +53,20 @@ public abstract class NodeClass extends Syncable { }
/**
- * Add nodes to the NODES table, when the NODES parameter value is changed.
- * Nodes are only added to the table, they are never deleted. The node name is normalized
- * to contain the domain (if missing).
+ * Add nodes to the NODES table, when the NODES parameter value is changed. Nodes are only added to the table, they
+ * are never deleted. The node name is normalized to contain the domain (if missing).
*
* @param nodes a pipe separated list of the current nodes
*/
public static void setNodes(String[] nodes) {
- if (map == null)
+ if (map == null) {
reload();
+ }
int nextid = 0;
for (Integer n : map.values()) {
- if (n >= nextid)
+ if (n >= nextid) {
nextid = n + 1;
+ }
}
// take | separated list, add domain if needed.
@@ -136,8 +137,9 @@ public abstract class NodeClass extends Syncable { public static Integer lookupNodeName(final String name) {
Integer n = map.get(name);
- if (n == null)
+ if (n == null) {
throw new IllegalArgumentException("Invalid node name: " + name);
+ }
return n;
}
@@ -148,8 +150,9 @@ public abstract class NodeClass extends Syncable { if (s.endsWith("*")) {
s = s.substring(0, s.length() - 1);
for (String s2 : keyset) {
- if (s2.startsWith(s))
+ if (s2.startsWith(s)) {
coll.add(s2);
+ }
}
} else if (keyset.contains(s)) {
coll.add(s);
@@ -162,14 +165,6 @@ public abstract class NodeClass extends Syncable { return coll;
}
- protected String lookupNodeID(int n) {
- for (String s : map.keySet()) {
- if (map.get(s) == n)
- return s;
- }
- return null;
- }
-
public static String normalizeNodename(String s) {
if (s != null && s.indexOf('.') <= 0) {
Parameters p = Parameters.getParameter(Parameters.PROV_DOMAIN);
@@ -184,4 +179,13 @@ public abstract class NodeClass extends Syncable { }
}
+
+ protected String lookupNodeID(int n) {
+ for (String s : map.keySet()) {
+ if (map.get(s) == n) {
+ return s;
+ }
+ }
+ return null;
+ }
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java index afb0de24..dec3cc13 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java @@ -29,14 +29,7 @@ import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.Enumeration; -import java.util.LinkedHashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.Set; +import java.util.*; import org.json.JSONArray; import org.json.JSONException; @@ -140,6 +133,46 @@ public class LOGJSONObject { } /** + * Returns a hash code value for the object. This method is + * supported for the benefit of hash tables such as those provided by + * {@link HashMap}. + * <p> + * The general contract of {@code hashCode} is: + * <ul> + * <li>Whenever it is invoked on the same object more than once during + * an execution of a Java application, the {@code hashCode} method + * must consistently return the same integer, provided no information + * used in {@code equals} comparisons on the object is modified. + * This integer need not remain consistent from one execution of an + * application to another execution of the same application. + * <li>If two objects are equal according to the {@code equals(Object)} + * method, then calling the {@code hashCode} method on each of + * the two objects must produce the same integer result. + * <li>It is <em>not</em> required that if two objects are unequal + * according to the {@link Object#equals(Object)} + * method, then calling the {@code hashCode} method on each of the + * two objects must produce distinct integer results. However, the + * programmer should be aware that producing distinct integer results + * for unequal objects may improve the performance of hash tables. + * </ul> + * <p> + * As much as is reasonably practical, the hashCode method defined by + * class {@code Object} does return distinct integers for distinct + * objects. (This is typically implemented by converting the internal + * address of the object into an integer, but this implementation + * technique is not required by the + * Java™ programming language.) + * + * @return a hash code value for this object. + * @see Object#equals(Object) + * @see System#identityHashCode + */ + @Override + public int hashCode() { + return super.hashCode(); + } + + /** * Get the "null" string value. * * @return The string "null". diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java index a5281c06..28740c0f 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java @@ -152,41 +152,40 @@ public class DailyLatencyReport extends ReportBase { DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);
- ps.setLong(1, from);
- ps.setLong(2, to);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- String id = rs.getString("PUBLISH_ID");
- int feed = rs.getInt("FEEDID");
- long etime = rs.getLong("EVENT_TIME");
- String type = rs.getString("TYPE");
- String fid = rs.getString("FEED_FILEID");
- long clen = rs.getLong("CONTENT_LENGTH");
- String date = sdf.format(new Date(getPstart(id)));
- String key = date + "," + feed;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters(date, feed);
- map.put(key, c);
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
+ ps.setLong(1, from);
+ ps.setLong(2, to);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ String id = rs.getString("PUBLISH_ID");
+ int feed = rs.getInt("FEEDID");
+ long etime = rs.getLong("EVENT_TIME");
+ String type = rs.getString("TYPE");
+ String fid = rs.getString("FEED_FILEID");
+ long clen = rs.getLong("CONTENT_LENGTH");
+ String date = sdf.format(new Date(getPstart(id)));
+ String key = date + "," + feed;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters(date, feed);
+ map.put(key, c);
+ }
+ c.addEvent(etime, type, id, fid, clen);
+ }
}
- c.addEvent(etime, type, id, fid, clen);
+
+ db.release(conn);
}
- rs.close();
- ps.close();
- db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
}
logger.debug("Query time: " + (System.currentTimeMillis()-start) + " ms");
- try {
- PrintWriter os = new PrintWriter(outfile);
+ try (PrintWriter os = new PrintWriter(outfile)){
os.println("date,feedid,minsize,maxsize,avgsize,minlat,maxlat,avglat,fanout");
for (String key : new TreeSet<String>(map.keySet())) {
Counters c = map.get(key);
os.println(c.toString());
}
- os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: "+outfile);
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java index ba8f15a0..549511b7 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java @@ -145,40 +145,38 @@ public class LatencyReport extends ReportBase { DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)){
ps.setLong(1, from);
ps.setLong(2, to);
- ResultSet rs = ps.executeQuery();
- PrintWriter os = new PrintWriter(outfile);
- os.println("recordid,feedid,uri,size,min,max,avg,fanout");
- Counters c = null;
- while (rs.next()) {
- long etime = rs.getLong("EVENT_TIME");
- String type = rs.getString("TYPE");
- String id = rs.getString("PUBLISH_ID");
- String fid = rs.getString("FEED_FILEID");
- int feed = rs.getInt("FEEDID");
- long clen = rs.getLong("CONTENT_LENGTH");
- if (c != null && !id.equals(c.id)) {
- String line = id + "," + c.toString();
- os.println(line);
- c = null;
+ try(ResultSet rs = ps.executeQuery()) {
+ try(PrintWriter os = new PrintWriter(outfile)) {
+ os.println("recordid,feedid,uri,size,min,max,avg,fanout");
+ Counters c = null;
+ while (rs.next()) {
+ long etime = rs.getLong("EVENT_TIME");
+ String type = rs.getString("TYPE");
+ String id = rs.getString("PUBLISH_ID");
+ String fid = rs.getString("FEED_FILEID");
+ int feed = rs.getInt("FEEDID");
+ long clen = rs.getLong("CONTENT_LENGTH");
+ if (c != null && !id.equals(c.id)) {
+ String line = id + "," + c.toString();
+ os.println(line);
+ c = null;
+ }
+ if (c == null) {
+ c = new Counters(id, feed, clen, fid);
+ }
+ if (feed != c.feedid)
+ System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);
+ if (clen != c.clen)
+ System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);
+ c.addEvent(type, etime);
+ }
}
- if (c == null) {
- c = new Counters(id, feed, clen, fid);
- }
- if (feed != c.feedid)
- System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);
- if (clen != c.clen)
- System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);
-// if (fid != c.fileid)
-// System.err.println("File ID mismatch, "+fid+" <=> "+c.fileid);
- c.addEvent(type, etime);
+ db.release(conn);
+ }
}
- rs.close();
- ps.close();
- db.release(conn);
- os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
} catch (SQLException e) {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java index e00c3944..51beac92 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java @@ -98,62 +98,61 @@ public class SubscriberReport extends ReportBase { public void run() {
Map<String, Counters> map = new HashMap<String, Counters>();
long start = System.currentTimeMillis();
+
try {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);
- ps.setLong(1, from);
- ps.setLong(2, to);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- String date = rs.getString("DATE");
- int sub = rs.getInt("DELIVERY_SUBID");
- int res = rs.getInt("RESULT");
- int count = rs.getInt("COUNT");
- String key = date + "," + sub;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters(date, sub);
- map.put(key, c);
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
+ ps.setLong(1, from);
+ ps.setLong(2, to);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ String date = rs.getString("DATE");
+ int sub = rs.getInt("DELIVERY_SUBID");
+ int res = rs.getInt("RESULT");
+ int count = rs.getInt("COUNT");
+ String key = date + "," + sub;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters(date, sub);
+ map.put(key, c);
+ }
+ c.addCounts(res, count);
+ }
}
- c.addCounts(res, count);
}
- rs.close();
- ps.close();
- ps = conn.prepareStatement(SELECT_SQL2);
- ps.setLong(1, from);
- ps.setLong(2, to);
- rs = ps.executeQuery();
- while (rs.next()) {
- String date = rs.getString("DATE");
- int sub = rs.getInt("DELIVERY_SUBID");
- int count = rs.getInt("COUNT");
- String key = date + "," + sub;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters(date, sub);
- map.put(key, c);
- }
- c.addDlxCount(count);
- }
- rs.close();
- ps.close();
+ try( PreparedStatement ps2 = conn.prepareStatement(SELECT_SQL2)) {
+ ps2.setLong(1, from);
+ ps2.setLong(2, to);
+ try(ResultSet rs2 = ps2.executeQuery()) {
+ while (rs2.next()) {
+ String date = rs2.getString("DATE");
+ int sub = rs2.getInt("DELIVERY_SUBID");
+ int count = rs2.getInt("COUNT");
+ String key = date + "," + sub;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters(date, sub);
+ map.put(key, c);
+ }
+ c.addDlxCount(count);
+ }
+ }
+ }
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
}
logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
- try {
- PrintWriter os = new PrintWriter(outfile);
+ try (PrintWriter os = new PrintWriter(outfile)){
os.println("date,subid,count100,count200,count300,count400,count500,countminus1,countdlx");
for (String key : new TreeSet<String>(map.keySet())) {
Counters c = map.get(key);
os.println(c.toString());
}
- os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java index 169db0d2..34e158a7 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java @@ -36,6 +36,7 @@ import java.util.HashMap; import java.util.Map;
import java.util.TreeSet;
+import org.apache.log4j.Logger;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
/**
@@ -57,7 +58,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB; public class VolumeReport extends ReportBase {
private static final String SELECT_SQL = "select EVENT_TIME, TYPE, FEEDID, CONTENT_LENGTH, RESULT" +
" from LOG_RECORDS where EVENT_TIME >= ? and EVENT_TIME <= ? LIMIT ?, ?";
-
+ private Logger loggerVolumeReport=Logger.getLogger("org.onap.dmaap.datarouter.reports");
private class Counters {
public int filespublished, filesdelivered, filesexpired;
public long bytespublished, bytesdelivered, bytesexpired;
@@ -83,58 +84,64 @@ public class VolumeReport extends ReportBase { final long stepsize = 6000000L;
boolean go_again = true;
for (long i = 0; go_again; i += stepsize) {
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);
- ps.setLong(1, from);
- ps.setLong(2, to);
- ps.setLong(3, i);
- ps.setLong(4, stepsize);
- ResultSet rs = ps.executeQuery();
- go_again = false;
- while (rs.next()) {
- go_again = true;
- long etime = rs.getLong("EVENT_TIME");
- String type = rs.getString("TYPE");
- int feed = rs.getInt("FEEDID");
- long clen = rs.getLong("CONTENT_LENGTH");
- String key = sdf.format(new Date(etime)) + ":" + feed;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters();
- map.put(key, c);
- }
- if (type.equalsIgnoreCase("pub")) {
- c.filespublished++;
- c.bytespublished += clen;
- } else if (type.equalsIgnoreCase("del")) {
- // Only count successful deliveries
- int statusCode = rs.getInt("RESULT");
- if (statusCode >= 200 && statusCode < 300) {
- c.filesdelivered++;
- c.bytesdelivered += clen;
+ try (PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
+ ps.setLong(1, from);
+ ps.setLong(2, to);
+ ps.setLong(3, i);
+ ps.setLong(4, stepsize);
+ try(ResultSet rs = ps.executeQuery()) {
+ go_again = false;
+ while (rs.next()) {
+ go_again = true;
+ long etime = rs.getLong("EVENT_TIME");
+ String type = rs.getString("TYPE");
+ int feed = rs.getInt("FEEDID");
+ long clen = rs.getLong("CONTENT_LENGTH");
+ String key = sdf.format(new Date(etime)) + ":" + feed;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters();
+ map.put(key, c);
+ }
+ if (type.equalsIgnoreCase("pub")) {
+ c.filespublished++;
+ c.bytespublished += clen;
+ } else if (type.equalsIgnoreCase("del")) {
+ // Only count successful deliveries
+ int statusCode = rs.getInt("RESULT");
+ if (statusCode >= 200 && statusCode < 300) {
+ c.filesdelivered++;
+ c.bytesdelivered += clen;
+ }
+ } else if (type.equalsIgnoreCase("exp")) {
+ c.filesexpired++;
+ c.bytesexpired += clen;
+ }
}
- } else if (type.equalsIgnoreCase("exp")) {
- c.filesexpired++;
- c.bytesexpired += clen;
}
+
+ }
+ catch (SQLException sqlException)
+ {
+ loggerVolumeReport.error("SqlException",sqlException);
}
- rs.close();
- ps.close();
}
+
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
}
logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
- try {
- PrintWriter os = new PrintWriter(outfile);
+ try (PrintWriter os = new PrintWriter(outfile)) {
os.println("date,feedid,filespublished,bytespublished,filesdelivered,bytesdelivered,filesexpired,bytesexpired");
- for (String key : new TreeSet<String>(map.keySet())) {
+ for(String key :new TreeSet<String>(map.keySet()))
+ {
Counters c = map.get(key);
String[] p = key.split(":");
os.println(String.format("%s,%s,%s", p[0], p[1], c.toString()));
}
- os.close();
- } catch (FileNotFoundException e) {
+ }
+ catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
}
}
diff --git a/datarouter-prov/src/main/resources/misc/sql_init_01.sql b/datarouter-prov/src/main/resources/misc/sql_init_01.sql index e01ce3b0..356a67a9 100644..100755 --- a/datarouter-prov/src/main/resources/misc/sql_init_01.sql +++ b/datarouter-prov/src/main/resources/misc/sql_init_01.sql @@ -124,18 +124,18 @@ CREATE TABLE GROUPS ( ); INSERT INTO PARAMETERS VALUES - ('ACTIVE_POD', 'prov.datarouternew.com'), - ('PROV_ACTIVE_NAME', 'prov.datarouternew.com'), + ('ACTIVE_POD', 'dmaap-dr-prov'), + ('PROV_ACTIVE_NAME', 'dmaap-dr-prov'), ('STANDBY_POD', ''), - ('PROV_NAME', 'prov.datarouternew.com'), - ('NODES', '172.100.0.1|node.datarouternew.com'), - ('PROV_DOMAIN', 'datarouternew.com'), + ('PROV_NAME', 'dmaap-dr-prov'), + ('NODES', 'dmaap-dr-node'), + ('PROV_DOMAIN', ''), ('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_ADDRESSES', 'dmaap-dr-prov|dmaap-dr-node'), ('PROV_AUTH_SUBJECTS', ''), ('PROV_MAXFEED_COUNT', '10000'), ('PROV_MAXSUB_COUNT', '100000'), diff --git a/datarouter-prov/src/main/resources/provserver.properties b/datarouter-prov/src/main/resources/provserver.properties index 7758a64d..744bc9ce 100644..100755 --- a/datarouter-prov/src/main/resources/provserver.properties +++ b/datarouter-prov/src/main/resources/provserver.properties @@ -27,11 +27,11 @@ 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.keymanager.password = Qgw77oaQcdP*F8Pwa[&.,.Ab +org.onap.dmaap.datarouter.provserver.keystore.path = /opt/app/datartr/aaf_certs/org.onap.dmaap-dr.jks +org.onap.dmaap.datarouter.provserver.keystore.password = Qgw77oaQcdP*F8Pwa[&.,.Ab +org.onap.dmaap.datarouter.provserver.truststore.path = /opt/app/datartr/aaf_certs/org.onap.dmaap-dr.trust.jks +org.onap.dmaap.datarouter.provserver.truststore.password = 9M?)?:KAj1z6gpLhNrVUG@0T org.onap.dmaap.datarouter.provserver.accesslog.dir = /opt/app/datartr/logs org.onap.dmaap.datarouter.provserver.spooldir = /opt/app/datartr/spool diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java index 71446219..3e5e1d04 100644..100755 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java @@ -114,7 +114,7 @@ public class IntegrationTestBase { } } - SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, "changeit", trustStore); + SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, props.getProperty("test.kspassword"), trustStore); Scheme sch = new Scheme("https", 443, socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); @@ -164,7 +164,7 @@ public class IntegrationTestBase { // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); - FileUtils.deleteDirectory(new File("./unit-test-logs")); + FileUtils.deleteDirectory(new File("." + File.pathSeparator+ "unit-test-logs")); } protected void ckResponse(HttpResponse response, int expect) { diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java index 61d030d9..8cc48683 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java @@ -40,6 +40,7 @@ import java.util.HashSet; import java.util.Set; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.mock; @@ -84,7 +85,7 @@ public class BaseServletTest extends DrServletTestBase { authAddressesAndNetworks.add(("127.0.0.1")); FieldUtils.writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, true); FieldUtils.writeDeclaredStaticField(BaseServlet.class, "requireCert", true, true); - assertThat(baseServlet.isAuthorizedForProvisioning(request), is("Client certificate is missing.")); + assertNull(baseServlet.isAuthorizedForProvisioning(request)); } @Test diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java index 35bc85d8..87390bc5 100644..100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java @@ -22,6 +22,21 @@ ******************************************************************************/ package org.onap.dmaap.datarouter.provisioning; +import static org.hamcrest.Matchers.notNullValue; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.argThat; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; + +import java.util.HashSet; +import java.util.Set; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; @@ -38,20 +53,11 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashSet; -import java.util.Set; - -import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.*; -import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; - @RunWith(PowerMockRunner.class) @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Feed") public class DRFeedsServletTest extends DrServletTestBase { + private static DRFeedsServlet drfeedsServlet; @Mock @@ -77,14 +83,17 @@ public class DRFeedsServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() + throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); drfeedsServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @Test - public void Given_Request_Is_HTTP_GET_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_GET_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated() + throws Exception { setBehalfHeader(null); drfeedsServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class))); @@ -92,7 +101,8 @@ public class DRFeedsServletTest extends DrServletTestBase { @Test - public void Given_Request_Is_HTTP_GET_And_URL_Path_Not_Valid_Then_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_GET_And_URL_Path_Not_Valid_Then_Bad_Request_Response_Is_Generated() + throws Exception { when(request.getRequestURI()).thenReturn("/123"); drfeedsServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class))); @@ -100,7 +110,8 @@ public class DRFeedsServletTest extends DrServletTestBase { @Test - public void Given_Request_Is_HTTP_GET_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_GET_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() + throws Exception { setAuthoriserToReturnRequestNotAuthorized(); drfeedsServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); @@ -146,14 +157,17 @@ public class DRFeedsServletTest extends DrServletTestBase { @Test - public void Given_Request_Is_HTTP_POST_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() + throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); drfeedsServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @Test - public void Given_Request_Is_HTTP_POST_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated() + throws Exception { setBehalfHeader(null); drfeedsServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class))); @@ -161,7 +175,8 @@ public class DRFeedsServletTest extends DrServletTestBase { @Test - public void Given_Request_Is_HTTP_POST_And_URL_Path_Not_Valid_Then_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_URL_Path_Not_Valid_Then_Bad_Request_Response_Is_Generated() + throws Exception { when(request.getRequestURI()).thenReturn("/123"); drfeedsServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class))); @@ -169,28 +184,33 @@ public class DRFeedsServletTest extends DrServletTestBase { @Test - public void Given_Request_Is_HTTP_POST_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() + throws Exception { when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.feed; version=1.1"); when(request.getContentType()).thenReturn("stub_contentType"); drfeedsServlet.doPost(request, response); - verify(response).sendError(eq(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), argThat(notNullValue(String.class))); + verify(response) + .sendError(eq(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), argThat(notNullValue(String.class))); } @Test - public void Given_Request_Is_HTTP_POST_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() + throws Exception { setAuthoriserToReturnRequestNotAuthorized(); drfeedsServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @Test - public void Given_Request_Is_HTTP_POST_And_Request_Contains_Badly_Formed_JSON_Then_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Request_Contains_Badly_Formed_JSON_Then_Bad_Request_Response_Is_Generated() + throws Exception { drfeedsServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class))); } @Test - public void Given_Request_Is_HTTP_POST_And_Active_Feeds_Equals_Max_Feeds_Then_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Active_Feeds_Equals_Max_Feeds_Then_Bad_Request_Response_Is_Generated() + throws Exception { FieldUtils.writeDeclaredStaticField(BaseServlet.class, "maxFeeds", 0, true); DRFeedsServlet drfeedsServlet = new DRFeedsServlet() { protected JSONObject getJSONfromInput(HttpServletRequest req) { @@ -202,7 +222,8 @@ public class DRFeedsServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_HTTP_POST_And_Feed_Is_Not_Valid_Object_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Feed_Is_Not_Valid_Object_Bad_Request_Response_Is_Generated() + throws Exception { when(request.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")).thenReturn(null); JSONObject JSObject = buildRequestJsonObject(); @@ -218,7 +239,8 @@ public class DRFeedsServletTest extends DrServletTestBase { } @Test - public void Given_Request_Is_HTTP_POST_And_Feed_Already_Exists_Bad_Request_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Feed_Already_Exists_Bad_Request_Response_Is_Generated() + throws Exception { setFeedToReturnInvalidFeedIdSupplied(); JSONObject JSObject = buildRequestJsonObject(); DRFeedsServlet drfeedsServlet = new DRFeedsServlet() { @@ -252,12 +274,14 @@ public class DRFeedsServletTest extends DrServletTestBase { } }; drfeedsServlet.doPost(request, response); - verify(response).sendError(eq(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), argThat(notNullValue(String.class))); + verify(response) + .sendError(eq(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), argThat(notNullValue(String.class))); } @Test - public void Given_Request_Is_HTTP_POST_And_Change_On_Feeds_Succeeds_A_STATUS_OK_Response_Is_Generated() throws Exception { + public void Given_Request_Is_HTTP_POST_And_Change_On_Feeds_Succeeds_A_STATUS_OK_Response_Is_Generated() + throws Exception { ServletOutputStream outStream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(outStream); JSONObject JSObject = buildRequestJsonObject(); @@ -301,7 +325,9 @@ public class DRFeedsServletTest extends DrServletTestBase { when(request.isSecure()).thenReturn(true); Set<String> authAddressesAndNetworks = new HashSet<String>(); authAddressesAndNetworks.add(("127.0.0.1")); - FieldUtils.writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, true); + FieldUtils + .writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, + true); FieldUtils.writeDeclaredStaticField(BaseServlet.class, "requireCert", false, true); FieldUtils.writeDeclaredStaticField(BaseServlet.class, "maxFeeds", 100, true); } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java index 414fc185..c7f639ed 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java @@ -38,8 +38,8 @@ public class DrServletTestBase { public void setUp() throws Exception { Properties props = new Properties(); props.setProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false"); - props.setProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir", "datarouter-prov/unit-test-logs"); - props.setProperty("org.onap.dmaap.datarouter.provserver.spooldir", "resources/spooldir"); + props.setProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir", "unit-test-logs"); + props.setProperty("org.onap.dmaap.datarouter.provserver.spooldir", "unit-test-logs/spool"); props.setProperty("org.onap.dmaap.datarouter.provserver.https.relaxation", "false"); FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true); FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true); diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java index f5302cb9..cb8a28da 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java @@ -76,6 +76,7 @@ public class FeedServletTest extends DrServletTestBase { public void Given_Request_Is_HTTP_DELETE_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); feedServlet.doDelete(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -147,6 +148,7 @@ public class FeedServletTest extends DrServletTestBase { public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); feedServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -200,6 +202,7 @@ public class FeedServletTest extends DrServletTestBase { public void Given_Request_Is_HTTP_PUT_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); feedServlet.doPut(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java index a0831b73..fa0caea6 100644..100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java @@ -76,6 +76,7 @@ public class GroupServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); groupServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -105,6 +106,7 @@ public class GroupServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_PUT_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); groupServlet.doPut(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -184,6 +186,7 @@ public class GroupServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_POST_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); groupServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java index f8342449..5f6b7ae3 100755..100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java @@ -31,6 +31,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; +import java.io.File; import java.net.InetAddress; import java.util.HashMap; import java.util.Map; @@ -89,6 +90,8 @@ public class InternalServletTest extends DrServletTestBase { public void Given_Request_Is_HTTP_GET_And_Address_Not_Authorized_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.getRemoteAddr()).thenReturn("127.100.0.3"); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); + internalServlet.doGet(request, response); verify(response) .sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); @@ -152,6 +155,19 @@ public class InternalServletTest extends DrServletTestBase { } @Test + public void Given_Request_Is_HTTP_GET_Starts_With_Logs_In_Endpoint_And_File_Exists_Then_Request_Returns_Ok() + throws Exception { + when(request.getPathInfo()).thenReturn("/logs/testFile.txt"); + File testFile = new File("unit-test-logs/testFile.txt"); + testFile.createNewFile(); + testFile.deleteOnExit(); + ServletOutputStream outStream = mock(ServletOutputStream.class); + when(response.getOutputStream()).thenReturn(outStream); + internalServlet.doGet(request, response); + verify(response).setStatus(eq(HttpServletResponse.SC_OK)); + } + + @Test public void Given_Request_Is_HTTP_GET_With_Api_In_Endpoint_Request_Succeeds() throws Exception { when(request.getPathInfo()).thenReturn("/api/Key"); setParametersToNotContactDb(false); @@ -165,10 +181,7 @@ public class InternalServletTest extends DrServletTestBase { public void Given_Request_Is_HTTP_GET_With_Drlogs_In_Endpoint_Request_Succeeds() throws Exception { when(request.getPathInfo()).thenReturn("/drlogs/"); - PowerMockito.mockStatic(LogfileLoader.class); - LogfileLoader logfileLoader = mock(LogfileLoader.class); - when(logfileLoader.getBitSet()).thenReturn(new RLEBitSet()); - PowerMockito.when(LogfileLoader.getLoader()).thenReturn(logfileLoader); + mockLogfileLoader(); ServletOutputStream outStream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(outStream); internalServlet.doGet(request, response); @@ -188,6 +201,7 @@ public class InternalServletTest extends DrServletTestBase { public void Given_Request_Is_HTTP_PUT_And_Address_Not_Authorized_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.getRemoteAddr()).thenReturn("127.100.0.3"); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); internalServlet.doPut(request, response); verify(response) .sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); @@ -232,6 +246,7 @@ public class InternalServletTest extends DrServletTestBase { public void Given_Request_Is_HTTP_DELETE_And_Address_Not_Authorized_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.getRemoteAddr()).thenReturn("127.100.0.3"); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); internalServlet.doDelete(request, response); verify(response) .sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); @@ -278,6 +293,7 @@ public class InternalServletTest extends DrServletTestBase { throws Exception { when(request.getRemoteAddr()).thenReturn("127.100.0.3"); internalServlet.doPost(request, response); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); verify(response) .sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -327,6 +343,21 @@ public class InternalServletTest extends DrServletTestBase { } @Test + public void Given_Request_Is_HTTP_POST_To_Logs_Then_Request_Succeeds() + throws Exception { + when(request.getHeader("Content-Encoding")).thenReturn("gzip"); + when(request.getPathInfo()).thenReturn("/logs/"); + ServletInputStream inStream = mock(ServletInputStream.class); + when(request.getInputStream()).thenReturn(inStream); + File testDir = new File("unit-test-logs/spool"); + testDir.mkdirs(); + testDir.deleteOnExit(); + mockLogfileLoader(); + internalServlet.doPost(request, response); + verify(response).setStatus(eq(HttpServletResponse.SC_CREATED)); + } + + @Test public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated() throws Exception { when(request.getHeader("Content-Type")).thenReturn("stub_contentType"); @@ -447,4 +478,11 @@ public class InternalServletTest extends DrServletTestBase { Map<String, Integer> map = new HashMap<>(); FieldUtils.writeDeclaredStaticField(NodeClass.class, "map", map, true); } + + private void mockLogfileLoader() { + PowerMockito.mockStatic(LogfileLoader.class); + LogfileLoader logfileLoader = mock(LogfileLoader.class); + when(logfileLoader.getBitSet()).thenReturn(new RLEBitSet()); + PowerMockito.when(LogfileLoader.getLoader()).thenReturn(logfileLoader); + } } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java index 63715804..34421f52 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java @@ -69,6 +69,7 @@ public class RouteServletTest extends DrServletTestBase @Test public void Given_Request_Is_HTTP_DELETE_And_Is_Not_Authorized() throws Exception { + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); routeServlet.doDelete(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -207,6 +208,7 @@ public class RouteServletTest extends DrServletTestBase @Test public void Given_Request_Is_HTTP_GET_And_Is_Not_Authorized() throws Exception { + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); routeServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -290,6 +292,7 @@ public class RouteServletTest extends DrServletTestBase @Test public void Given_Request_Is_HTTP_POST_And_Is_Not_Authorized() throws Exception { routeServlet.doPost(request, response); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java index cdf96ba6..25341d42 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java @@ -81,6 +81,7 @@ public class SubscribeServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); subscribeServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -137,6 +138,7 @@ public class SubscribeServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_POST_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); subscribeServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java index b42e3a76..c5660672 100644..100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java @@ -73,6 +73,7 @@ public class SubscriptionServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_DELETE_SC_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); subscriptionServlet.doDelete(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -130,6 +131,7 @@ public class SubscriptionServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); subscriptionServlet.doGet(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -184,6 +186,7 @@ public class SubscriptionServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_PUT_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); subscriptionServlet.doPut(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } @@ -323,6 +326,7 @@ public class SubscriptionServletTest extends DrServletTestBase { @Test public void Given_Request_Is_HTTP_POST_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception { when(request.isSecure()).thenReturn(false); + FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true); subscriptionServlet.doPost(request, response); verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class))); } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryRecordTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryRecordTest.java new file mode 100644 index 00000000..3329b732 --- /dev/null +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryRecordTest.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============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.beans; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject; + +import java.text.ParseException; + +public class DeliveryRecordTest { + + private DeliveryRecord deliveryRecord; + + @Test + public void Validate_Constructor_Creates_Object_With_Get_Methods() throws ParseException { + String[] args = {"2018-08-29-10-10-10-543.", "del", "238465493.fileName", "1","285", "123/file.txt","GET","application/json","2000","example","100"}; + deliveryRecord = new DeliveryRecord(args); + Assert.assertEquals("238465493.fileName", deliveryRecord.getPublishId()); + Assert.assertEquals(1, deliveryRecord.getFeedid()); + Assert.assertEquals(285, deliveryRecord.getSubid()); + Assert.assertEquals("123/file.txt", deliveryRecord.getRequestUri()); + Assert.assertEquals("GET", deliveryRecord.getMethod()); + Assert.assertEquals("file.txt", deliveryRecord.getFileid()); + Assert.assertEquals("application/json", deliveryRecord.getContentType()); + Assert.assertEquals(2000, deliveryRecord.getContentLength()); + Assert.assertEquals("example", deliveryRecord.getUser()); + Assert.assertEquals(100, deliveryRecord.getResult()); + } + + @Test + public void Validate_AsJsonObject_Correct_Json_Object_After_Set_Methods() throws ParseException { + String[] args = {"2018-08-29-10-10-10-543.", "del", "238465493.fileName", "1","285", "123/file.txt","GET","application/json","2000","example","100"}; + deliveryRecord = new DeliveryRecord(args); + deliveryRecord.setContentLength(265); + deliveryRecord.setEventTime(1535533810543L); + deliveryRecord.setPublishId("2345657324.fileName"); + deliveryRecord.setSubid(287); + deliveryRecord.setFeedid(2); + deliveryRecord.setRequestUri("/delete/2"); + deliveryRecord.setMethod("PUT"); + deliveryRecord.setContentType("application/json"); + deliveryRecord.setFileid("file2.txt"); + deliveryRecord.setUser("example2"); + deliveryRecord.setResult(300); + LOGJSONObject deliveryRecordJson = createBaseLogRecordJson(); + String deliveryRecordString = stripBracketFromJson(deliveryRecordJson); + String deliveryRecordStringObject = stripBracketFromJson(deliveryRecord.asJSONObject()); + Assert.assertTrue(deliveryRecordStringObject.matches(deliveryRecordString)); + } + + private LOGJSONObject createBaseLogRecordJson() { + LOGJSONObject deliveryRecordJson = new LOGJSONObject(); + deliveryRecordJson.put("statusCode", 300); + deliveryRecordJson.put("deliveryId", "example2"); + deliveryRecordJson.put("publishId", "2345657324.fileName"); + deliveryRecordJson.put("requestURI", "/delete/2"); + deliveryRecordJson.put("method", "PUT"); + deliveryRecordJson.put("contentType", "application/json"); + deliveryRecordJson.put("type", "del"); + deliveryRecordJson.put("date", "2018-08-29T[0-1][0-9]:10:10.543Z"); + deliveryRecordJson.put("contentLength", 265); + + return deliveryRecordJson; + } + + private String stripBracketFromJson(LOGJSONObject deliveryRecordJson) { + String deliveryRecordString = deliveryRecordJson.toString(); + deliveryRecordString = deliveryRecordString.substring(1, deliveryRecordString.length() - 1); + return deliveryRecordString; + } +} diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java index 098765cf..91d72af7 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/GroupTest.java @@ -22,62 +22,80 @@ ******************************************************************************/ package org.onap.dmaap.datarouter.provisioning.beans; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; -import org.powermock.modules.junit4.PowerMockRunner; +import org.junit.*; +import org.onap.dmaap.datarouter.provisioning.utils.DB; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.util.Collection; import java.util.Date; +import java.util.List; - -@RunWith(PowerMockRunner.class) -@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Group"}) public class GroupTest { - private Group group; + private static EntityManagerFactory emf; + private static EntityManager em; + private Group group; + private DB db; + + @BeforeClass + public static void init() { + emf = Persistence.createEntityManagerFactory("dr-unit-tests"); + em = emf.createEntityManager(); + System.setProperty( + "org.onap.dmaap.datarouter.provserver.properties", + "src/test/resources/h2Database.properties"); + } + + @AfterClass + public static void tearDownClass() { + em.clear(); + em.close(); + emf.close(); + } + + @Before + public void setUp() throws Exception { + db = new DB(); + group = new Group("GroupTest", "", ""); + group.doInsert(db.getConnection()); + } + + @Test + public void Given_Group_Exists_In_Db_GetAllGroups_Returns_Correct_Group() { + Collection<Group> groups = Group.getAllgroups(); + Assert.assertEquals("Group1", ((List<Group>) groups).get(0).getName()); + } + + @Test + public void Given_Group_Inserted_Into_Db_GetGroupMatching_Returns_Created_Group() { + Assert.assertEquals(group, Group.getGroupMatching(group)); + } + + @Test + public void Given_Group_Inserted_With_Same_Name_GetGroupMatching_With_Id_Returns_Correct_Group() + throws Exception { + Group sameGroupName = new Group("GroupTest", "This group has a description", ""); + sameGroupName.doInsert(db.getConnection()); + Assert.assertEquals( + "This group has a description", Group.getGroupMatching(group, 2).getDescription()); + sameGroupName.doDelete(db.getConnection()); + } - @Test - public void Validate_Group_Created_With_Default_Contructor() { - group = new Group(); - Assert.assertEquals(group.getGroupid(), -1); - Assert.assertEquals(group.getName(), ""); - } + @Test + public void Given_Group_Inserted_GetGroupById_Returns_Correct_Group() { + Assert.assertEquals(group, Group.getGroupById(group.getGroupid())); + } - @Test - public void Validate_Getters_And_Setters() { - group = new Group(); - group.setGroupid(1); - group.setAuthid("Auth"); - group.setClassification("Class"); - group.setDescription("Description"); - Date date = new Date(); - group.setLast_mod(date); - group.setMembers("Members"); - group.setName("NewName"); - Assert.assertEquals(1, group.getGroupid()); - Assert.assertEquals("Auth", group.getAuthid()); - Assert.assertEquals("Class", group.getClassification()); - Assert.assertEquals("Description", group.getDescription()); - Assert.assertEquals(date, group.getLast_mod()); - Assert.assertEquals("Members", group.getMembers()); - } + @Test + public void Given_Group_AuthId_Updated_GetGroupByAuthId_Returns_Correct_Group() throws Exception { + group.setAuthid("Basic TmFtZTp6Z04wMFkyS3gybFppbXltNy94ZDhuMkdEYjA9"); + group.doUpdate(db.getConnection()); + Assert.assertEquals(group, Group.getGroupByAuthId("Basic TmFtZTp6Z04wMFkyS3gybFppbXltNy94ZDhuMkdEYjA9")); + } - @Test - public void Validate_Equals() { - group = new Group(); - group.setGroupid(1); - group.setAuthid("Auth"); - group.setClassification("Class"); - group.setDescription("Description"); - Date date = new Date(); - group.setLast_mod(date); - group.setMembers("Members"); - group.setName("NewName"); - Group group2 = new Group("NewName", "Description", "Members"); - group2.setGroupid(1); - group2.setAuthid("Auth"); - group2.setClassification("Class"); - group2.setLast_mod(date); - Assert.assertEquals(group, group2); - } + @After + public void tearDown() throws Exception { + group.doDelete(db.getConnection()); + } } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecordTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecordTest.java new file mode 100644 index 00000000..dd798ab6 --- /dev/null +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecordTest.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * ============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.beans; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.text.ParseException; + +@RunWith(PowerMockRunner.class) +public class PubFailRecordTest { + + private PubFailRecord pubFailRecord; + + + @Test + public void Validate_PubFailRecord_Created_With_Default_Constructor() throws ParseException { + String[] args = {"2018-08-29-10-10-10-543.", "PBF", "238465493.fileName", + "1", "/publish/1/fileName", "PUT", "application/octet-stream", "285", "200", + "172.100.0.3", "user1", "403"}; + pubFailRecord = new PubFailRecord(args); + + Assert.assertEquals("user1", pubFailRecord.getUser()); + Assert.assertEquals("172.100.0.3", pubFailRecord.getSourceIP()); + Assert.assertEquals("403", pubFailRecord.getError()); + Assert.assertEquals(200, pubFailRecord.getContentLengthReceived()); + } +} diff --git a/datarouter-prov/src/test/resources/META-INF/persistence.xml b/datarouter-prov/src/test/resources/META-INF/persistence.xml new file mode 100755 index 00000000..6b42f8a9 --- /dev/null +++ b/datarouter-prov/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence + http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + <persistence-unit name="dr-unit-tests" transaction-type="RESOURCE_LOCAL"> + <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> + <properties> + <!-- Configuring JDBC properties --> + <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=MySQL;INIT=RUNSCRIPT FROM 'classpath:create.sql';DB_CLOSE_DELAY=-1"/> + <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/> + + <!-- Hibernate properties --> + <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> + <property name="hibernate.hbm2ddl.auto" value="validate"/> + <property name="hibernate.format_sql" value="false"/> + <property name="hibernate.show_sql" value="true"/> + + </properties> + </persistence-unit> +</persistence>
\ No newline at end of file diff --git a/datarouter-prov/src/test/resources/create.sql b/datarouter-prov/src/test/resources/create.sql new file mode 100755 index 00000000..6e6af1d4 --- /dev/null +++ b/datarouter-prov/src/test/resources/create.sql @@ -0,0 +1,146 @@ +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', 'dmaap-dr-prov'), + ('PROV_ACTIVE_NAME', 'dmaap-dr-prov'), + ('STANDBY_POD', ''), + ('PROV_NAME', 'dmaap-dr-prov'), + ('NODES', 'dmaap-dr-node'), + ('PROV_DOMAIN', ''), + ('DELIVERY_INIT_RETRY_INTERVAL', '10'), + ('DELIVERY_MAX_AGE', '86400'), + ('DELIVERY_MAX_RETRY_INTERVAL', '3600'), + ('DELIVERY_RETRY_RATIO', '2'), + ('LOGROLL_INTERVAL', '300'), + ('PROV_AUTH_ADDRESSES', 'dmaap-dr-prov|dmaap-dr-node'), + ('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') + ; + +INSERT INTO GROUPS(GROUPID, AUTHID, NAME, DESCRIPTION, CLASSIFICATION, MEMBERS) +VALUES (1, 'Basic dXNlcjE6cGFzc3dvcmQx', 'Group1', 'First Group for testing', 'Class1', 'Member1'); diff --git a/datarouter-prov/src/test/resources/h2Database.properties b/datarouter-prov/src/test/resources/h2Database.properties new file mode 100755 index 00000000..5bc20ed4 --- /dev/null +++ b/datarouter-prov/src/test/resources/h2Database.properties @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------- +# ============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. +# * +#------------------------------------------------------------------------------- + +# Database access +org.onap.dmaap.datarouter.db.driver = org.h2.Driver +org.onap.dmaap.datarouter.db.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 diff --git a/datarouter-prov/src/test/resources/integration_test.properties b/datarouter-prov/src/test/resources/integration_test.properties index 36b2ac3c..9ac1850a 100644 --- a/datarouter-prov/src/test/resources/integration_test.properties +++ b/datarouter-prov/src/test/resources/integration_test.properties @@ -1,5 +1,5 @@ -test.keystore=self_signed/keystore.jks -test.kspassword=changeit -test.truststore=self_signed/cacerts.jks -test.tspassword=changeit -test.host=https://prov.datarouternew.com:8443
\ No newline at end of file +test.keystore=aaf_certs/org.onap.dmaap-dr.jks +test.kspassword=Qgw77oaQcdP*F8Pwa[&.,.Ab +test.truststore=aaf_certs/org.onap.dmaap-dr.trust.jks +test.tspassword=9M?)?:KAj1z6gpLhNrVUG@0T +test.host=https://dmaap-dr-prov:8443
\ No newline at end of file |