Update the dependencies to use project version
[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 =\r
42         System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/";\r
43     // TierSupportUiConstants.CONFIG_OXM_LOCATION =\r
44     // System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";\r
45     TierSupportUiConstants.STATIC_CONFIG_APP_LOCATION =\r
46         System.getProperty("AJSC_HOME") + "/bundleconfig-local/etc/appprops";\r
47     OxmModelLoader loader = OxmModelLoader.getInstance();\r
48     service = new VisualizationService(loader);\r
49   }\r
50 \r
51   @Test\r
52   public void testAnalyzeQueryRequestBody_InvalidQuery() {\r
53     QueryRequest request = service.analyzeQueryRequestBody("query-json-1");\r
54     Assert.assertNull(request);\r
55   }\r
56 \r
57   @Test\r
58   public void testAnalyzeQueryRequestBody_ValidQuery() {\r
59     QueryRequest request = service.analyzeQueryRequestBody("{\"hashId\":\"hashid-1\"}");\r
60     Assert.assertNotNull(request);\r
61   }\r
62 \r
63   @Test\r
64   public void testBuildVisualizationUsingGenericQuery_UnsuccessfulOperationResult() {\r
65     QueryRequest queryRequest = new QueryRequest();\r
66     queryRequest.setHashId("hash-id-1");\r
67     service.buildVisualizationUsingGenericQuery(queryRequest);\r
68   }\r
69 \r
70   String queryRequest = "{\r\n" + "     \"variables\": [],\r\n" + "     \"info\": {\r\n"\r
71       + "               \"name\": \"NamedQuery\",\r\n"\r
72       + "               \"_postman_id\": \"8006823d-35ce-16ef-88e9-cd5b873c9e7b\",\r\n"\r
73       + "               \"schema\": \"https://schema.getpostman.com/json/collection/v2.0.0/collection.json\"\r\n"\r
74       + "       },\r\n" + "     \"item\": [\r\n" + "            {\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" + "                          \"header\": [\r\n"\r
79       + "                                       {\r\n" + "                                              \"key\": \"Content-Type\",\r\n"\r
80       + "                                               \"value\": \"application/json\",\r\n"\r
81       + "                                               \"description\": \"\"\r\n" + "                                  },\r\n"\r
82       + "                                       {\r\n" + "                                              \"key\": \"X-TransactionId\",\r\n"\r
83       + "                                               \"value\": \"9999\",\r\n"\r
84       + "                                               \"description\": \"\"\r\n" + "                                  },\r\n"\r
85       + "                                       {\r\n" + "                                              \"key\": \"X-FromAppId\",\r\n"\r
86       + "                                               \"value\": \"jimmy-postman\",\r\n"\r
87       + "                                               \"description\": \"\"\r\n" + "                                  },\r\n"\r
88       + "                                       {\r\n" + "                                              \"key\": \"Authorization\",\r\n"\r
89       + "                                               \"value\": \"Basic QUFJOkFBSQ==\",\r\n"\r
90       + "                                               \"description\": \"\"\r\n" + "                                  }\r\n"\r
91       + "                               ],\r\n" + "                             \"body\": {\r\n"\r
92       + "                                       \"mode\": \"raw\",\r\n"\r
93       + "                                       \"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
94       + "                               },\r\n" + "                             \"description\": \"\"\r\n" + "                  },\r\n"\r
95       + "                       \"response\": []\r\n" + "               }\r\n" + "      ]\r\n" + "}";\r
96 }\r