aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/test
diff options
context:
space:
mode:
authorEmmett Cox <emmett.cox@ericsson.com>2018-08-29 16:39:53 +0100
committerEmmett Cox <emmett.cox@ericsson.com>2018-08-29 17:08:09 +0100
commitd35b6c5932e32a52b15aaee9d8d5c6f1661af706 (patch)
tree818e3dca29e1089ffc3065ecf8bfda2249621188 /datarouter-prov/src/test
parentfbb33454e311e72bd2f4fb0290babb92fd15b93c (diff)
Unit tests for ExpiryRecord
Change-Id: I03af7430b696c128cb587f5639c6ef4ad26d4210 Signed-off-by: Emmett Cox <emmett.cox@ericsson.com> Issue-ID: DMAAP-101
Diffstat (limited to 'datarouter-prov/src/test')
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecordTest.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecordTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecordTest.java
new file mode 100644
index 00000000..34a6d979
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecordTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * ============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 ExpiryRecordTest {
+
+
+ private ExpiryRecord expiryRecord;
+
+ @Test
+ public void Validate_Constructor_Creates_Object_With_Get_Methods() throws ParseException {
+ String[] args = {"2018-08-29-10-10-10-543.", "EXP", "238465493.fileName", "1","285", "123/file.txt","GET","","2000","example","100"};
+ expiryRecord = new ExpiryRecord(args);
+ Assert.assertEquals("238465493.fileName", expiryRecord.getPublishId());
+ Assert.assertEquals(1, expiryRecord.getFeedid());
+ Assert.assertEquals("123/file.txt", expiryRecord.getRequestUri());
+ Assert.assertEquals("GET", expiryRecord.getMethod());
+ Assert.assertEquals("", expiryRecord.getContentType());
+ Assert.assertEquals(2000, expiryRecord.getContentLength());
+ Assert.assertEquals(285, expiryRecord.getSubid());
+ Assert.assertEquals("file.txt", expiryRecord.getFileid());
+ Assert.assertEquals(100, expiryRecord.getAttempts());
+ Assert.assertEquals("other", expiryRecord.getReason());
+ }
+
+ @Test
+ public void Validate_AsJsonObject_Correct_Json_Object_After_Set_Methods() throws ParseException {
+ String[] args = {"2018-08-29-10-10-10-543.", "EXP", "238465493.fileName", "1","285", "123/file.txt","GET","","2000","example","100"};
+ expiryRecord = new ExpiryRecord(args);
+ expiryRecord.setContentLength(265);
+ expiryRecord.setEventTime(1535533810543L);
+ expiryRecord.setPublishId("2345657324.fileName");
+ expiryRecord.setFeedid(2);
+ expiryRecord.setRequestUri("/delete/2");
+ expiryRecord.setContentType("application/json");
+ expiryRecord.setMethod("PUT");
+ expiryRecord.setSubid(322);
+ expiryRecord.setFileid("file.txt");
+ expiryRecord.setAttempts(125);
+ expiryRecord.setReason("Out of memory");
+
+ LOGJSONObject expiryRecordJson = createBaseLogRecordJson();
+ String expiryRecordString = stripBracketFromJson(expiryRecordJson);
+ String expiryRecordObject = stripBracketFromJson(expiryRecord.asJSONObject());
+ Assert.assertTrue(expiryRecordObject.matches(expiryRecordString));
+ }
+
+ private LOGJSONObject createBaseLogRecordJson() {
+ LOGJSONObject expiryRecordJson = new LOGJSONObject();
+ expiryRecordJson.put("expiryReason", "Out of memory");
+ expiryRecordJson.put("publishId", "2345657324.fileName");
+ expiryRecordJson.put("attempts", 125);
+ expiryRecordJson.put("requestURI", "/delete/2");
+ expiryRecordJson.put("method", "PUT");
+ expiryRecordJson.put("contentType", "application/json");
+ expiryRecordJson.put("type", "exp");
+ expiryRecordJson.put("date", "2018-08-29T[0-1][0-9]:10:10.543Z");
+ expiryRecordJson.put("contentLength", 265);
+ return expiryRecordJson;
+ }
+
+ private String stripBracketFromJson(LOGJSONObject expiryRecordJson) {
+ String expiryRecordString = expiryRecordJson.toString();
+ expiryRecordString = expiryRecordString.substring(1, expiryRecordString.length() - 1);
+ return expiryRecordString;
+ }
+}
+