AAI-1523 checkstyle warnings for aai-core parsers
[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
28 import org.onap.aai.introspection.ModelType;
29 import org.onap.aai.serialization.engines.QueryStyle;
30 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
31 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
32 import org.onap.aai.setup.SchemaVersion;
33
34 import javax.ws.rs.core.UriBuilder;
35 import javax.xml.bind.JAXBException;
36 import java.io.UnsupportedEncodingException;
37 import java.net.URI;
38
39 import static org.junit.Assert.assertEquals;
40
41
42 @Ignore
43 public class LegacyQueryTest extends AAISetup {
44
45
46     private TransactionalGraphEngine dbEngine;
47     private SchemaVersion version;
48     private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version);
49
50     public void setup(){
51         version = new SchemaVersion("v10");
52         dbEngine =
53             new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
54                 loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
55                 false);
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 }