Removed below sonar issues:
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / parsers / query / LegacyQueryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 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.aai.parsers.query;
22
23 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
24 import org.junit.Ignore;
25 import org.junit.Test;
26 import org.openecomp.aai.AAISetup;
27 import org.openecomp.aai.exceptions.AAIException;
28 import org.openecomp.aai.introspection.LoaderFactory;
29 import org.openecomp.aai.introspection.ModelInjestor;
30 import org.openecomp.aai.introspection.ModelType;
31 import org.openecomp.aai.introspection.Version;
32 import org.openecomp.aai.serialization.engines.QueryStyle;
33 import org.openecomp.aai.serialization.engines.TitanDBEngine;
34 import org.openecomp.aai.serialization.engines.TransactionalGraphEngine;
35
36 import javax.ws.rs.core.UriBuilder;
37 import javax.xml.bind.JAXBException;
38 import java.io.UnsupportedEncodingException;
39 import java.net.URI;
40
41 import static org.junit.Assert.assertEquals;
42
43
44 @Ignore
45 public class LegacyQueryTest extends AAISetup {
46
47         private ModelInjestor injestor = ModelInjestor.getInstance();
48
49         private TransactionalGraphEngine dbEngine =
50                         new TitanDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
51                                 LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.v8),
52                                 false); 
53         private final Version version = Version.v8;
54         private DynamicJAXBContext context = injestor.getContextForVersion(version);
55         
56
57         /**
58          * Parent query.
59          *
60          * @throws JAXBException the JAXB exception
61          * @throws UnsupportedEncodingException the unsupported encoding exception
62          * @throws AAIException the AAI exception
63          */
64         @Test
65     public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
66                 
67                 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
68
69                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
70
71                 String expected = 
72                                 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
73                 assertEquals(
74                                 "gremlin query should be " + expected,
75                                 expected,
76                                 query.getQueryBuilder().getQuery());
77                 assertEquals(
78                                 "parent gremlin query should be equal to normal query",
79                                 expected,
80                                 query.getQueryBuilder().getParentQuery().getQuery());
81                 assertEquals(
82                                 "result type should be pserver",
83                                 "pserver",
84                                 query.getResultType());
85                 
86     }
87
88         /**
89          * Child query.
90          *
91          * @throws JAXBException the JAXB exception
92          * @throws UnsupportedEncodingException the unsupported encoding exception
93          * @throws AAIException the AAI exception
94          */
95         @Test
96     public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
97                 URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
98                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
99
100                 String expected =
101                                 ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
102                                 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')"
103                                 + ".has('interface-name', 'key2')";
104                 String parentExpected = 
105                                 ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
106                 assertEquals(
107                                 "gremlin query should be for node",
108                                 expected,
109                                 query.getQueryBuilder().getQuery());
110                 assertEquals(
111                                 "parent gremlin query should be for parent",
112                                 parentExpected,
113                                 query.getQueryBuilder().getParentQuery().getQuery());
114                 assertEquals(
115                                 "result type should be lag-interface",
116                                 "lag-interface",
117                                 query.getResultType());
118     }
119         
120         /**
121          * Naming exceptions.
122          *
123          * @throws JAXBException the JAXB exception
124          * @throws UnsupportedEncodingException the unsupported encoding exception
125          * @throws AAIException the AAI exception
126          */
127         @Test
128     public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
129                 URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
130         
131                 QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
132                 String expected = 
133                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
134                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
135                                 + ".has('interface-id', 'key2')"
136                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
137                                 + ".has('cvlan-tag', 655)";
138                 String expectedParent = 
139                                                 ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
140                                                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
141                                                 + ".has('interface-id', 'key2')";
142                 assertEquals(
143                                 "gremlin query should be " + expected,
144                                 expected,
145                                 query.getQueryBuilder().getQuery());
146                 assertEquals(
147                                 "parent gremlin query should be equal the query for port group",
148                                 expectedParent,
149                                 query.getQueryBuilder().getParentQuery().getQuery());
150                 assertEquals(
151                                 "result type should be cvlan-tag",
152                                 "cvlan-tag",
153                                 query.getResultType());
154                 
155     }
156         
157 }