Add unit test cases to increase sonar coverage
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / viewandinspect / services / VisualizationServiceTest.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.viewandinspect.services;\r
24 \r
25 import java.io.File;\r
26 \r
27 import org.junit.Assert;\r
28 import org.junit.Before;\r
29 import org.junit.Test;\r
30 import org.onap.aai.sparky.config.oxm.OxmModelLoader;\r
31 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;\r
32 import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;\r
33 \r
34 public class VisualizationServiceTest {\r
35 \r
36         VisualizationService service;\r
37         \r
38         @Before\r
39         public void init() throws Exception {\r
40                 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
41             TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";\r
42             //TierSupportUiConstants.CONFIG_OXM_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";\r
43             TierSupportUiConstants.STATIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/bundleconfig-local/etc/appprops";\r
44                 OxmModelLoader loader = OxmModelLoader.getInstance();\r
45                 service = new VisualizationService(loader);\r
46         }\r
47         \r
48         @Test\r
49         public void testAnalyzeQueryRequestBody_InvalidQuery() {\r
50                 QueryRequest request = service.analyzeQueryRequestBody("query-json-1");\r
51                 Assert.assertNull(request);\r
52         }\r
53         \r
54         @Test\r
55         public void testAnalyzeQueryRequestBody_ValidQuery() {\r
56                 QueryRequest request = service.analyzeQueryRequestBody("{\"hashId\":\"hashid-1\"}");\r
57                 Assert.assertNotNull(request);\r
58         }\r
59         @Test\r
60         public void testBuildVisualizationUsingGenericQuery_UnsuccessfulOperationResult() {\r
61                 QueryRequest queryRequest = new QueryRequest();\r
62                 queryRequest.setHashId("hash-id-1");\r
63                 service.buildVisualizationUsingGenericQuery(queryRequest);\r
64         }\r
65 \r
66         String queryRequest = "{\r\n" + \r
67                         "       \"variables\": [],\r\n" + \r
68                         "       \"info\": {\r\n" + \r
69                         "               \"name\": \"NamedQuery\",\r\n" + \r
70                         "               \"_postman_id\": \"8006823d-35ce-16ef-88e9-cd5b873c9e7b\",\r\n" + \r
71                         "               \"schema\": \"https://schema.getpostman.com/json/collection/v2.0.0/collection.json\"\r\n" + \r
72                         "       },\r\n" + \r
73                         "       \"item\": [\r\n" + \r
74                         "               {\r\n" + \r
75                         "                       \"name\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + \r
76                         "                       \"request\": {\r\n" + \r
77                         "                               \"url\": \"https://127.0.0.1:8443/aai/v11/service-design-and-creation/named-queries/named-query/0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\",\r\n" + \r
78                         "                               \"method\": \"POST\",\r\n" + \r
79                         "                               \"header\": [\r\n" + \r
80                         "                                       {\r\n" + \r
81                         "                                               \"key\": \"Content-Type\",\r\n" + \r
82                         "                                               \"value\": \"application/json\",\r\n" + \r
83                         "                                               \"description\": \"\"\r\n" + \r
84                         "                                       },\r\n" + \r
85                         "                                       {\r\n" + \r
86                         "                                               \"key\": \"X-TransactionId\",\r\n" + \r
87                         "                                               \"value\": \"9999\",\r\n" + \r
88                         "                                               \"description\": \"\"\r\n" + \r
89                         "                                       },\r\n" + \r
90                         "                                       {\r\n" + \r
91                         "                                               \"key\": \"X-FromAppId\",\r\n" + \r
92                         "                                               \"value\": \"jimmy-postman\",\r\n" + \r
93                         "                                               \"description\": \"\"\r\n" + \r
94                         "                                       },\r\n" + \r
95                         "                                       {\r\n" + \r
96                         "                                               \"key\": \"Authorization\",\r\n" + \r
97                         "                                               \"value\": \"Basic QUFJOkFBSQ==\",\r\n" + \r
98                         "                                               \"description\": \"\"\r\n" + \r
99                         "                                       }\r\n" + \r
100                         "                               ],\r\n" + \r
101                         "                               \"body\": {\r\n" + \r
102                         "                                       \"mode\": \"raw\",\r\n" + \r
103                         "                                       \"raw\": \"{\\n   \\\"named-query-uuid\\\" : \\\"0367193e-c785-4d5f-9cb8-7bc89dc9ddb7\\\",\\n   \\\"named-query-name\\\" : \\\"get-component-list\\\",\\n   \\\"named-query-version\\\" : \\\"1.1\\\",\\n   \\\"description\\\" : \\\"Named Query - Get Component List\\\",\\n   \\\"named-query-elements\\\" : {\\n      \\\"named-query-element\\\" : [ {\\n         \\\"property-collect-list\\\" : [ \\\"service-instance-id\\\", \\\"service-instance-name\\\" ],\\n         \\\"named-query-elements\\\" : {\\n            \\\"named-query-element\\\" : [ {\\n               \\\"named-query-elements\\\" : {\\n                  \\\"named-query-element\\\" : [ {\\n                     \\\"relationship-list\\\" : {\\n                        \\\"relationship\\\" : [ {\\n                           \\\"related-to\\\" : \\\"model\\\",\\n                           \\\"relationship-data\\\" : [ {\\n                              \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                              \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n                           } ]\\n                        } ]\\n                     }\\n                  } ]\\n               },\\n               \\\"relationship-list\\\" : {\\n                  \\\"relationship\\\" : [ {\\n                     \\\"related-to\\\" : \\\"model\\\",\\n                     \\\"relationship-data\\\" : [ {\\n                        \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                        \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n                     } ]\\n                  } ]\\n               }\\n            }, {\\n               \\\"named-query-elements\\\" : {\\n                  \\\"named-query-element\\\" : [ {\\n                     \\\"relationship-list\\\" : {\\n                        \\\"relationship\\\" : [ {\\n                           \\\"related-to\\\" : \\\"model\\\",\\n                           \\\"relationship-data\\\" : [ {\\n                              \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                              \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n                           } ]\\n                        } ]\\n                     }\\n                  }, {\\n                     \\\"named-query-elements\\\" : {\\n                        \\\"named-query-element\\\" : [ {\\n                           \\\"relationship-list\\\" : {\\n                              \\\"relationship\\\" : [ {\\n                                 \\\"related-to\\\" : \\\"model\\\",\\n                                 \\\"relationship-data\\\" : [ {\\n                                    \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                                    \\\"relationship-value\\\" : \\\"ff69d4e0-a8e8-4108-bdb0-dd63217e63c7\\\"\\n                                 } ]\\n                              } ]\\n                           }\\n                        }, {\\n                           \\\"relationship-list\\\" : {\\n                              \\\"relationship\\\" : [ {\\n                                 \\\"related-to\\\" : \\\"model\\\",\\n                                 \\\"relationship-data\\\" : [ {\\n                                    \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                                    \\\"relationship-value\\\" : \\\"fcec1b02-b2d0-4834-aef8-d71be04717dd\\\"\\n                                 } ]\\n                              } ]\\n                           }\\n                        }, {\\n                           \\\"named-query-elements\\\" : {\\n                              \\\"named-query-element\\\" : [ {\\n                                 \\\"relationship-list\\\" : {\\n                                    \\\"relationship\\\" : [ {\\n                                       \\\"related-to\\\" : \\\"model\\\",\\n                                       \\\"relationship-data\\\" : [ {\\n                                          \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                                          \\\"relationship-value\\\" : \\\"1b2c9ba7-e449-4831-ba15-3073672f5ef2\\\"\\n                                       } ]\\n                                    } ]\\n                                 }\\n                              } ]\\n                           },\\n                           \\\"relationship-list\\\" : {\\n                              \\\"relationship\\\" : [ {\\n                                 \\\"related-to\\\" : \\\"model\\\",\\n                                 \\\"relationship-data\\\" : [ {\\n                                    \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                                    \\\"relationship-value\\\" : \\\"3d560d81-57d0-438b-a2a1-5334dba0651a\\\"\\n                                 } ]\\n                              } ]\\n                           }\\n                        } ]\\n                     },\\n                     \\\"relationship-list\\\" : {\\n                        \\\"relationship\\\" : [ {\\n                           \\\"related-to\\\" : \\\"model\\\",\\n                           \\\"relationship-data\\\" : [ {\\n                              \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                              \\\"relationship-value\\\" : \\\"ef86f9c5-2165-44f3-8fc3-96018b609ea5\\\"\\n                           } ]\\n                        } ]\\n                     }\\n                  } ]\\n               },\\n               \\\"relationship-list\\\" : {\\n                  \\\"relationship\\\" : [ {\\n                     \\\"related-to\\\" : \\\"model\\\",\\n                     \\\"relationship-data\\\" : [ {\\n                        \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                        \\\"relationship-value\\\" : \\\"acc6edd8-a8d4-4b93-afaa-0994068be14c\\\"\\n                     } ]\\n                  } ]\\n               }\\n            } ]\\n         },\\n         \\\"relationship-list\\\" : {\\n            \\\"relationship\\\" : [ {\\n               \\\"related-to\\\" : \\\"model\\\",\\n               \\\"relationship-data\\\" : [ {\\n                  \\\"relationship-key\\\" : \\\"model.model-invariant-id\\\",\\n                  \\\"relationship-value\\\" : \\\"82194af1-3c2c-485a-8f44-420e22a9eaa4\\\"\\n               } ]\\n            } ]\\n         }\\n      } ]\\n   }\\n}\\n\"\r\n" + \r
104                         "                               },\r\n" + \r
105                         "                               \"description\": \"\"\r\n" + \r
106                         "                       },\r\n" + \r
107                         "                       \"response\": []\r\n" + \r
108                         "               }\r\n" + \r
109                         "       ]\r\n" + \r
110                         "}";\r
111 }\r