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