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