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 ******************************************************************************/
23 package org.onap.dmaap.datarouter.provisioning.beans;
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
30 import java.text.ParseException;
31 import java.util.LinkedHashMap;
33 public class PublishRecordTest {
35 private PublishRecord publishRecord;
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);
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());
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 LOGJSONObject publishRecordJson = createPublishRecordJson();
60 Assert.assertEquals(publishRecordJson.toString(), publishRecord.asJSONObject().toString());
63 private LOGJSONObject createPublishRecordJson() {
64 LinkedHashMap<String, Object> publishRecordMap = new LinkedHashMap<>();
65 publishRecordMap.put("statusCode", 201);
66 publishRecordMap.put("publishId", "238465493.fileName");
67 publishRecordMap.put("requestURI", "/publish/1/fileName");
68 publishRecordMap.put("sourceIP", "172.100.0.4");
69 publishRecordMap.put("method", "PUT");
70 publishRecordMap.put("contentType", "application/octet-stream");
71 publishRecordMap.put("endpointId", "user2");
72 publishRecordMap.put("type", "pub");
73 publishRecordMap.put("date", "2018-08-29T10:10:10.543Z");
74 publishRecordMap.put("contentLength", 285);
75 return new LOGJSONObject(publishRecordMap);