4992af7bd9e34f05d0aef36228413ac37436309d
[music.git] / music-core / src / test / java / org / onap / music / unittests / jsonobjects / JsonInsertTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  *  Modifications Copyright (c) 2019 IBM.
8  * ===================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  * 
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  * 
21  * ============LICENSE_END=============================================
22  * ====================================================================
23  */
24
25 package org.onap.music.unittests.jsonobjects;
26
27 import static org.junit.Assert.assertArrayEquals;
28 import static org.junit.Assert.assertEquals;
29
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import org.apache.commons.lang3.SerializationUtils;
34 import org.junit.Test;
35 import org.onap.music.datastore.jsonobjects.JsonInsert;
36
37 public class JsonInsertTest {
38     
39     JsonInsert ji = new JsonInsert();
40
41     @Test
42     public void testGetKeyspaceName() {
43         ji.setKeyspaceName("keyspace");
44         assertEquals("keyspace",ji.getKeyspaceName());
45     }
46
47     @Test
48     public void testGetTableName() {
49         ji.setTableName("table");
50         assertEquals("table",ji.getTableName());
51     }
52
53     @Test
54     public void testGetConsistencyInfo() {
55         Map<String,String> cons = new HashMap<>();
56         cons.put("test","true");
57         ji.setConsistencyInfo(cons);
58         assertEquals("true",ji.getConsistencyInfo().get("test"));
59     }
60
61     @Test
62     public void testGetTtl() {
63         ji.setTtl("ttl");
64         assertEquals("ttl",ji.getTtl());
65     }
66
67     @Test
68     public void testGetTimestamp() {
69         ji.setTimestamp("10:30");
70         assertEquals("10:30",ji.getTimestamp());
71     }
72
73     @Test
74     public void testGetValues() {
75         Map<String,Object> cons = new HashMap<>();
76         cons.put("val1","one");
77         cons.put("val2","two");
78         ji.setValues(cons);
79         assertEquals("one",ji.getValues().get("val1"));
80     }
81
82     @Test
83     public void testGetRowSpecification() {
84         Map<String,Object> cons = new HashMap<>();
85         cons.put("val1","one");
86         cons.put("val2","two");
87         ji.setRowSpecification(cons);
88         assertEquals("two",ji.getRowSpecification().get("val2"));
89     }
90
91     @Test
92     public void testSerialize() {
93         Map<String,Object> cons = new HashMap<>();
94         cons.put("val1","one");
95         cons.put("val2","two");
96         ji.setTimestamp("10:30");
97         ji.setRowSpecification(cons);
98         byte[] test1 = ji.serialize();
99         byte[] ji1 = SerializationUtils.serialize(ji);
100         assertArrayEquals(ji1,test1);
101     }
102
103     @Test
104     public void testObjectMap()
105     {
106         Map<String, byte[]> map = new HashMap<>();
107         ji.setObjectMap(map);
108         assertEquals(map, ji.getObjectMap());
109     }
110
111 }