adding FILENAME value to LOG_RECORDS table.
[dmaap/datarouter.git] / datarouter-prov / src / test / java / org / onap / dmaap / datarouter / provisioning / beans / PublishRecordTest.java
1 /*******************************************************************************
2  * ============LICENSE_START==================================================
3  * * org.onap.dmaap
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
10  * *
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * *
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====================================================
19  * *
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  * *
22  ******************************************************************************/
23 package org.onap.dmaap.datarouter.provisioning.beans;
24
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
29
30 import java.text.ParseException;
31 import java.util.LinkedHashMap;
32
33 public class PublishRecordTest {
34
35   private PublishRecord publishRecord;
36
37   @Before
38   public void setUp() throws ParseException {
39     String[] args = {"2018-08-29-10-10-10-543.", "PUB", "238465493.fileName",
40         "1", "/publish/1/fileName", "PUT", "application/octet-stream", "285",
41         "172.100.0.3", "user1", "301"};
42     publishRecord = new PublishRecord(args);
43   }
44
45   @Test
46   public void Validate_Contructor_Creates_Object_With_Get_Methods() {
47     Assert.assertEquals("fileName", publishRecord.getFeedFileid());
48     Assert.assertEquals("172.100.0.3", publishRecord.getRemoteAddr());
49     Assert.assertEquals("user1", publishRecord.getUser());
50     Assert.assertEquals(301, publishRecord.getStatus());
51   }
52
53   @Test
54   public void Validate_AsJsonObject_Correct_Json_Object_After_Set_Methods() {
55     publishRecord.setFeedFileid("fileName2");
56     publishRecord.setRemoteAddr("172.100.0.4");
57     publishRecord.setStatus(201);
58     publishRecord.setUser("user2");
59     publishRecord.setFileName("fileName");
60     LOGJSONObject publishRecordJson = createPublishRecordJson();
61     Assert.assertEquals(publishRecordJson.toString(), publishRecord.asJSONObject().toString());
62   }
63
64   private LOGJSONObject createPublishRecordJson() {
65     LinkedHashMap<String, Object> publishRecordMap = new LinkedHashMap<>();
66     publishRecordMap.put("statusCode", 201);
67     publishRecordMap.put("publishId", "238465493.fileName");
68     publishRecordMap.put("requestURI", "/publish/1/fileName");
69     publishRecordMap.put("sourceIP", "172.100.0.4");
70     publishRecordMap.put("method", "PUT");
71     publishRecordMap.put("contentType", "application/octet-stream");
72     publishRecordMap.put("endpointId", "user2");
73     publishRecordMap.put("type", "pub");
74     publishRecordMap.put("date", "2018-08-29T10:10:10.543Z");
75     publishRecordMap.put("contentLength", 285);
76     publishRecordMap.put("fileName", "fileName");
77     return  new LOGJSONObject(publishRecordMap);
78   }
79 }