aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov
diff options
context:
space:
mode:
authoreconwar <conor.ward@ericsson.com>2018-08-29 12:31:10 +0000
committereconwar <conor.ward@ericsson.com>2018-08-29 13:03:37 +0000
commite240b998e7c4bff081abafe54d0d2aea73983f0b (patch)
tree047c21bb8e7738a07af774a33184cfb16456d2fe /datarouter-prov
parent04dd60b7f0ebdadd5af0a4147a3e601734d6e3dc (diff)
Add BaseLogRecord Unit Tests
Change-Id: I77b16aa1a7e8a7135ced8c5c5d33be939f565e56 Signed-off-by: Conor Ward <conor.ward@ericsson.com> Issue-ID: DMAAP-101
Diffstat (limited to 'datarouter-prov')
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java
new file mode 100644
index 00000000..69016f24
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/BaseLogRecordTest.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * ============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.jetbrains.annotations.NotNull;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
+
+import java.text.ParseException;
+
+public class BaseLogRecordTest {
+
+ private BaseLogRecord baseLogRecord;
+
+ @Test
+ public void Validate_Constructor_Creates_Object_With_Get_Methods() throws ParseException {
+ String[] args = {"2018-08-29-10-10-10-543.", "DLX", "238465493.fileName",
+ "1", "/publish/1/fileName", "285"};
+ baseLogRecord = new BaseLogRecord(args);
+ Assert.assertEquals("238465493.fileName", baseLogRecord.getPublishId());
+ Assert.assertEquals(1, baseLogRecord.getFeedid());
+ Assert.assertEquals("", baseLogRecord.getRequestUri());
+ Assert.assertEquals("GET", baseLogRecord.getMethod());
+ Assert.assertEquals("", baseLogRecord.getContentType());
+ Assert.assertEquals(285, baseLogRecord.getContentLength());
+ }
+
+ @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", "", "/delete/1", "DELETE", "application/octet-stream", "285"};
+ baseLogRecord = new BaseLogRecord(args);
+ baseLogRecord.setContentLength(265);
+ baseLogRecord.setEventTime(1535533810543L);
+ baseLogRecord.setPublishId("2345657324.fileName");
+ baseLogRecord.setFeedid(2);
+ baseLogRecord.setRequestUri("/delete/2");
+ baseLogRecord.setMethod("PUT");
+ baseLogRecord.setContentType("application/json");
+ LOGJSONObject baseLogRecordJson = createBaseLogRecordJson();
+ String baseLogRecordString = stripBracketFromJson(baseLogRecordJson);
+ String baseLogRecordStringObject = stripBracketFromJson(baseLogRecord.asJSONObject());
+ Assert.assertTrue(baseLogRecordStringObject.matches(baseLogRecordString));
+ }
+
+ private LOGJSONObject createBaseLogRecordJson() {
+ LOGJSONObject baseLogRecordJson = new LOGJSONObject();
+ baseLogRecordJson.put("date", "2018-08-29T[0-1][0-9]:10:10.543Z");
+ baseLogRecordJson.put("publishId", "2345657324.fileName");
+ baseLogRecordJson.put("requestURI", "/delete/2");
+ baseLogRecordJson.put("method", "PUT");
+ baseLogRecordJson.put("contentType", "application/json");
+ baseLogRecordJson.put("contentLength", 265);
+ return baseLogRecordJson;
+ }
+
+ private String stripBracketFromJson(LOGJSONObject baseLogRecordJson) {
+ String baseLogRecordString = baseLogRecordJson.toString();
+ baseLogRecordString = baseLogRecordString.substring(1, baseLogRecordString.length() - 1);
+ return baseLogRecordString;
+ }
+}