Toggle
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / UtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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
21 package org.openecomp.sdc.asdctool;
22
23 import org.apache.commons.configuration.Configuration;
24 import org.apache.tinkerpop.gremlin.structure.Element;
25 import org.janusgraph.core.JanusGraph;
26 import org.junit.Assert;
27 import org.junit.Test;
28
29 import javax.ws.rs.core.Response;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 public class UtilsTest {
34
35         @Test
36         public void testBuildOkResponse() throws Exception {
37                 int status = 200;
38                 Object entity = null;
39                 Map<String, String> additionalHeaders = null;
40                 Response result;
41
42                 // test with mock entity
43                 Object mockEntity = new Object();
44                 result = Utils.buildOkResponse(status, entity, additionalHeaders);
45                 Assert.assertNotNull(result);
46
47                 // test with mock headers
48                 Map<String, String> mockAdditionalHeaders = new HashMap<>();
49                 mockAdditionalHeaders.put("stam", "stam");
50                 result = Utils.buildOkResponse(status, mockEntity, mockAdditionalHeaders);
51                 Assert.assertNotNull(result);
52         }
53
54         @Test
55         public void testOpenGraph() throws Exception {
56                 Configuration conf = null;
57                 JanusGraph result;
58
59                 // default test with null
60                 result = Utils.openGraph(conf);
61         }
62
63         @Test
64         public void testVertexLeftContainsRightProps() throws Exception {
65                 Map<String, Object> leftProps = new HashMap<>();
66                 Map<String, Object> rightProps = null;
67                 boolean result;
68
69                 // test 1 with null
70                 rightProps = null;
71                 result = Utils.vertexLeftContainsRightProps(leftProps, rightProps);
72                 Assert.assertEquals(true, result);
73
74                 // test 2 with mocks
75                 Map<String, Object> mockLeftProps = new HashMap<>();
76                 mockLeftProps.put("stam", new Object());
77                 Map<String, Object> mockRightProps = new HashMap<>();
78                 mockRightProps.put("stam", new Object());
79                 result = Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps);
80                 Assert.assertEquals(false, result);
81
82                 // test 3 with mocks
83                 Object mockObject = new Object();
84                 mockLeftProps = new HashMap<>();
85                 mockLeftProps.put("stam", mockObject);
86                 mockRightProps = new HashMap<>();
87                 mockRightProps.put("stam", mockObject);
88                 result = Utils.vertexLeftContainsRightProps(mockLeftProps, mockRightProps);
89                 Assert.assertEquals(true, result);
90         }
91
92         @Test(expected=IllegalArgumentException.class)
93         public void testSetProperties() throws Exception {
94                 Element element = null;
95                 Map<String, Object> properties = null;
96
97                 // test 1
98                 properties = null;
99                 Utils.setProperties(element, properties);
100                 
101                 // test 2
102                 properties = new HashMap<>();
103                 properties.put("stam", new Object());
104                 Utils.setProperties(element, properties);
105         }
106
107         @Test(expected=NullPointerException.class)
108         public void testGetProperties() throws Exception {
109                 Element element = null;
110                 Map<String, Object> result;
111
112                 // default test
113                 result = Utils.getProperties(element);
114         }
115 }