From: Conor Ward Date: Thu, 21 Mar 2019 17:35:28 +0000 (+0000) Subject: Merge "small, multi-platform docker images" X-Git-Tag: 2.1.0~26 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=commitdiff_plain;h=0312e2224f81619699151718622b44db699bcce8;hp=efad46124485f1572765fad05284d8a070fb9277 Merge "small, multi-platform docker images" --- diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java index 96e523df..42d2b113 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java @@ -26,6 +26,7 @@ package org.onap.dmaap.datarouter.provisioning; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; + import java.io.IOException; import java.util.*; import javax.servlet.ServletConfig; @@ -42,7 +43,6 @@ import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord; import org.onap.dmaap.datarouter.provisioning.beans.IngressRoute; import org.onap.dmaap.datarouter.provisioning.eelf.EelfMsgs; import org.onap.dmaap.datarouter.provisioning.utils.DB; -import org.slf4j.MDC; /** * This servlet handles redirects for the <publishURL> on the provisioning server, which is generated by the @@ -74,7 +74,7 @@ public class PublishServlet extends BaseServlet { } @Override - public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException { + public void doDelete(HttpServletRequest req, HttpServletResponse resp) { setUpEelfForPublishServlet(req, "doDelete"); eelflogger.info(EelfMsgs.ENTRY); try { @@ -86,7 +86,7 @@ public class PublishServlet extends BaseServlet { } @Override - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { + public void doGet(HttpServletRequest req, HttpServletResponse resp) { setUpEelfForPublishServlet(req, "doGet"); eelflogger.info(EelfMsgs.ENTRY); try { @@ -98,7 +98,7 @@ public class PublishServlet extends BaseServlet { } @Override - public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException { + public void doPut(HttpServletRequest req, HttpServletResponse resp) { setUpEelfForPublishServlet(req, "doPut"); eelflogger.info(EelfMsgs.ENTRY); try { @@ -110,7 +110,7 @@ public class PublishServlet extends BaseServlet { } @Override - public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException { + public void doPost(HttpServletRequest req, HttpServletResponse resp) { setUpEelfForPublishServlet(req, "doPost"); eelflogger.info(EelfMsgs.ENTRY); try { @@ -130,7 +130,7 @@ public class PublishServlet extends BaseServlet { } } - private void redirect(HttpServletRequest req, HttpServletResponse resp) throws ServletException { + private void redirect(HttpServletRequest req, HttpServletResponse resp) { try { String[] nodes = getNodes(); if (nodes == null || nodes.length == 0) { @@ -170,7 +170,6 @@ public class PublishServlet extends BaseServlet { } } catch (IOException ioe) { intlogger.error("IOException" + ioe.getMessage()); - } } diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecordTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecordTest.java new file mode 100644 index 00000000..0c7b7e51 --- /dev/null +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecordTest.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2019 Nordix Foundation. + * * =========================================================================== + * * 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.*; +import org.onap.dmaap.datarouter.provisioning.utils.DB; +import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.ParseException; + +public class LogRecordTest { + + private LogRecord logRecord; + private static EntityManagerFactory emf; + private static EntityManager em; + private DB db; + private static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + private PreparedStatement ps; + + @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 ParseException, SQLException { + db = new DB(); + String[] args = {"2018-08-29-10-10-10-543.", "LOG","ID","1","URL/file123","PUT","application/vnd.dmaap-.log-list; version=1.0","100","pub", "1","172.0.0.8","user", "204","1","1","204","0","other","1","100","file123"}; + Connection conn = db.getConnection(); + ps = conn.prepareStatement(INSERT_SQL); + logRecord = new LogRecord(args); + } + + @Test + public void Validate_Load_For_Pub_Type_Sets_Correct_Values() throws SQLException { + logRecord.load(ps); + Assert.assertEquals(ps.toString().substring(128), "3: 'ID', 4: 1, 5: 'URL/file123', 6: 'PUT', 7: 'application/vnd.dmaap-.log-list; version=1.0', 8: 100, 9: '1', 10: '172.0.0.8', 11: 'user', 12: 204, 13: NULL, 14: NULL, 15: NULL, 16: NULL, 17: NULL, 18: 1, 19: NULL, 20: 'file123'}"); + } + + @Test + public void Validate_Load_For_Del_Type_Sets_Correct_Values() throws SQLException, ParseException { + setArgsLoadAndAssertEquals("del", "3: 'ID', 4: 1, 5: 'URL/file123', 6: 'PUT', 7: 'application/vnd.dmaap-.log-list; version=1.0', 8: 100, 9: NULL, 10: NULL, 11: 'user', 12: NULL, 13: 1, 14: '1', 15: 204, 16: NULL, 17: NULL, 18: 1, 19: NULL, 20: 'file123'}"); + } + + @Test + public void Validate_Load_For_Exp_Type_Sets_Correct_Values() throws SQLException, ParseException { + setArgsLoadAndAssertEquals("exp", "3: 'ID', 4: 1, 5: 'URL/file123', 6: 'PUT', 7: 'application/vnd.dmaap-.log-list; version=1.0', 8: 100, 9: NULL, 10: NULL, 11: NULL, 12: NULL, 13: 1, 14: '1', 15: NULL, 16: 0, 17: 'other', 18: 1, 19: NULL, 20: 'file123'}"); + } + + @Test + public void Validate_Load_For_Pbf_Type_Sets_Correct_Values() throws SQLException, ParseException { + setArgsLoadAndAssertEquals("pbf", "3: 'ID', 4: 1, 5: 'URL/file123', 6: 'PUT', 7: 'application/vnd.dmaap-.log-list; version=1.0', 8: 100, 9: '1', 10: '172.0.0.8', 11: 'user', 12: NULL, 13: NULL, 14: NULL, 15: NULL, 16: NULL, 17: NULL, 18: 1, 19: 100, 20: 'file123'}"); + } + + @Test + public void Validate_Load_For_Dlx_Type_Sets_Correct_Values() throws SQLException, ParseException { + setArgsLoadAndAssertEquals("dlx", "3: 'ID', 4: 1, 5: 'URL/file123', 6: 'PUT', 7: 'application/vnd.dmaap-.log-list; version=1.0', 8: 100, 9: NULL, 10: NULL, 11: NULL, 12: NULL, 13: 1, 14: NULL, 15: NULL, 16: NULL, 17: NULL, 18: 1, 19: 100, 20: 'file123'}"); + } + + @Test + public void Validate_printLogRecords_Prints_Correct_Values() throws IOException { + ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + String[] rlebitset = {"0-1,2-2"}; + LogRecord.printLogRecords(System.out, new RLEBitSet(rlebitset[0])); + Assert.assertEquals(outContent.toString().substring(25), "LOG|ID|1|URL/file123|PUT|application/vnd.dmaap-dr.log-list; version=1.0|100|pub|1|172.0.0.8|user|204|1|1|204|0|other|1|0\n"); + } + + private void setArgsLoadAndAssertEquals(String type, String s) throws ParseException, SQLException { + String[] args = {"2018-08-29-10-10-10-543.", "LOG", "ID", "1", "URL/file123", "PUT", "application/vnd.dmaap-.log-list; version=1.0", "100", type, "1", "172.0.0.8", "user", "204", "1", "1", "204", "0", "other", "1", "100", "file123"}; + logRecord = new LogRecord(args); + logRecord.load(ps); + Assert.assertEquals(ps.toString().substring(128), s); + } +}