Add unit test cases to increase sonar coverage
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / dal / aai / ActiveInventoryAdapterTest.java
1 /**\r
2  * ============LICENSE_START=======================================================\r
3  * org.onap.aai\r
4  * ================================================================================\r
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright © 2017 Amdocs\r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  *       http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END=========================================================\r
20  *\r
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  */\r
23 package org.onap.aai.sparky.dal.aai;\r
24 \r
25 import java.io.File;\r
26 import java.io.IOException;\r
27 import java.util.NoSuchElementException;\r
28 \r
29 import org.junit.Before;\r
30 import org.junit.Test;\r
31 import org.mockito.Mockito;\r
32 import org.onap.aai.sparky.config.oxm.OxmModelLoader;\r
33 import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;\r
34 import org.onap.aai.sparky.dal.rest.RestClientBuilder;\r
35 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;\r
36 \r
37 public class ActiveInventoryAdapterTest {\r
38     \r
39     OxmModelLoader oxmModelLoader;\r
40     ActiveInventoryAdapter adapter;\r
41         \r
42     @Before\r
43     public void init() throws IOException, ElasticSearchOperationException {\r
44         String version = "v11";\r
45         System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
46         TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";\r
47         oxmModelLoader = Mockito.spy(new OxmModelLoader());\r
48         Mockito.when(oxmModelLoader.loadOxmFileName(version)).thenReturn(\r
49         System.getProperty("AJSC_HOME") + "/bundleconfig-local/oxm/aai_oxm_" + version + ".xml");\r
50                     \r
51         adapter = new ActiveInventoryAdapter(new RestClientBuilder());\r
52     }\r
53         \r
54     @Test\r
55     public void testQueryActiveInventoryWithRetries() {\r
56 \r
57         adapter.queryActiveInventoryWithRetries("https://localhost:9517/model/aai/webapp/index.html", "response-type-1", 1);\r
58     }\r
59         \r
60     @Test(expected=NullPointerException.class)\r
61     public void testGetSelfLinkForEntity_NullEntityType() throws Exception {\r
62 \r
63         adapter.getSelfLinkForEntity(null, "key", "value");\r
64     }\r
65         \r
66     @Test(expected=NullPointerException.class)\r
67     public void testGetSelfLinkForEntity_NullKeyName() throws Exception {\r
68 \r
69         adapter.getSelfLinkForEntity("entity", null, "value");\r
70     }\r
71         \r
72     @Test(expected=NullPointerException.class)\r
73     public void testGetSelfLinkForEntity_NullKeyValue() throws Exception {\r
74 \r
75         adapter.getSelfLinkForEntity("entity", "key", null);\r
76     }\r
77         \r
78     @Test\r
79     public void testGetSelfLinkForEntity_ServiceInstance() throws Exception {\r
80 \r
81         adapter.getSelfLinkForEntity("service-instance", "key", "value");\r
82     }\r
83         \r
84     @Test\r
85     public void testGetSelfLinkForEntity_NotServiceInstance() throws Exception {\r
86         \r
87         adapter.getSelfLinkForEntity("service", "key", "value");\r
88     }\r
89         \r
90     @Test(expected=NullPointerException.class)\r
91     public void testGetSelfLinkByEntityType_NullEntity() throws Exception {\r
92 \r
93         adapter.getSelfLinksByEntityType(null);\r
94     }\r
95         \r
96     @Test(expected=NoSuchElementException.class)\r
97     public void testGetSelfLinkByEntityType_NullEntityDescriptor() throws Exception {\r
98 \r
99         adapter.getSelfLinksByEntityType("entity-1");\r
100     }\r
101 \r
102 }\r