1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
24 package org.onap.dmaap.datarouter.provisioning.beans;
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
30 import java.text.ParseException;
32 public class DeliveryRecordTest {
34 private DeliveryRecord deliveryRecord;
37 public void Validate_Constructor_Creates_Object_With_Get_Methods() throws ParseException {
38 String[] args = {"2018-08-29-10-10-10-543.", "del", "238465493.fileName", "1","285", "123/file.txt","GET","application/json","2000","example","100"};
39 deliveryRecord = new DeliveryRecord(args);
40 Assert.assertEquals("238465493.fileName", deliveryRecord.getPublishId());
41 Assert.assertEquals(1, deliveryRecord.getFeedid());
42 Assert.assertEquals(285, deliveryRecord.getSubid());
43 Assert.assertEquals("123/file.txt", deliveryRecord.getRequestUri());
44 Assert.assertEquals("GET", deliveryRecord.getMethod());
45 Assert.assertEquals("file.txt", deliveryRecord.getFileid());
46 Assert.assertEquals("application/json", deliveryRecord.getContentType());
47 Assert.assertEquals(2000, deliveryRecord.getContentLength());
48 Assert.assertEquals("example", deliveryRecord.getUser());
49 Assert.assertEquals(100, deliveryRecord.getResult());
53 public void Validate_AsJsonObject_Correct_Json_Object_After_Set_Methods() throws ParseException {
54 String[] args = {"2018-08-29-10-10-10-543.", "del", "238465493.fileName", "1","285", "123/file.txt","GET","application/json","2000","example","100"};
55 deliveryRecord = new DeliveryRecord(args);
56 deliveryRecord.setContentLength(265);
57 deliveryRecord.setEventTime(1535533810543L);
58 deliveryRecord.setPublishId("2345657324.fileName");
59 deliveryRecord.setSubid(287);
60 deliveryRecord.setFeedid(2);
61 deliveryRecord.setRequestUri("/delete/2");
62 deliveryRecord.setMethod("PUT");
63 deliveryRecord.setContentType("application/json");
64 deliveryRecord.setFileid("file2.txt");
65 deliveryRecord.setUser("example2");
66 deliveryRecord.setResult(300);
67 LOGJSONObject deliveryRecordJson = createBaseLogRecordJson();
68 String deliveryRecordString = stripBracketFromJson(deliveryRecordJson);
69 String deliveryRecordStringObject = stripBracketFromJson(deliveryRecord.asJSONObject());
70 Assert.assertTrue(deliveryRecordStringObject.matches(deliveryRecordString));
73 private LOGJSONObject createBaseLogRecordJson() {
74 LOGJSONObject deliveryRecordJson = new LOGJSONObject();
75 deliveryRecordJson.put("statusCode", 300);
76 deliveryRecordJson.put("deliveryId", "example2");
77 deliveryRecordJson.put("publishId", "2345657324.fileName");
78 deliveryRecordJson.put("requestURI", "/delete/2");
79 deliveryRecordJson.put("method", "PUT");
80 deliveryRecordJson.put("contentType", "application/json");
81 deliveryRecordJson.put("type", "del");
82 deliveryRecordJson.put("date", "2018-08-29T[0-1][0-9]:10:10.543Z");
83 deliveryRecordJson.put("contentLength", 265);
85 return deliveryRecordJson;
88 private String stripBracketFromJson(LOGJSONObject deliveryRecordJson) {
89 String deliveryRecordString = deliveryRecordJson.toString();
90 deliveryRecordString = deliveryRecordString.substring(1, deliveryRecordString.length() - 1);
91 return deliveryRecordString;