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