Merge "[AAI] Fix doc config files"
[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
21 package org.onap.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.junit.Ignore;
32 import org.junit.Test;
33 import org.onap.aai.AAISetup;
34 import org.onap.aai.exceptions.AAIException;
35 import org.onap.aai.introspection.ModelType;
36 import org.onap.aai.serialization.engines.JanusGraphDBEngine;
37 import org.onap.aai.serialization.engines.QueryStyle;
38 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
39 import org.onap.aai.setup.SchemaVersion;
40
41 @Ignore
42 public class LegacyQueryTest extends AAISetup {
43
44     private TransactionalGraphEngine dbEngine;
45     private SchemaVersion version;
46
47     public void setup() {
48         version = new SchemaVersion("v10");
49         dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
50                 loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
51     }
52
53     /**
54      * Parent query.
55      *
56      * @throws JAXBException the JAXB exception
57      * @throws UnsupportedEncodingException the unsupported encoding exception
58      * @throws AAIException the AAI exception
59      */
60     @Test
61     public void parentQuery() throws UnsupportedEncodingException, AAIException {
62
63         URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
64
65         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
66
67         String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
68         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
69         assertEquals("parent gremlin query should be equal to normal query", expected,
70                 query.getQueryBuilder().getParentQuery().getQuery());
71         assertEquals("result type should be pserver", "pserver", query.getResultType());
72
73     }
74
75     /**
76      * Child query.
77      *
78      * @throws JAXBException the JAXB exception
79      * @throws UnsupportedEncodingException the unsupported encoding exception
80      * @throws AAIException the AAI exception
81      */
82     @Test
83     public void childQuery() throws UnsupportedEncodingException, AAIException {
84         URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2")
85                 .build();
86         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
87
88         String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
89                 + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')" + ".has('interface-name', 'key2')";
90         String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
91         assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
92         assertEquals("parent gremlin query should be for parent", parentExpected,
93                 query.getQueryBuilder().getParentQuery().getQuery());
94         assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
95     }
96
97     /**
98      * Naming exceptions.
99      *
100      * @throws JAXBException the JAXB exception
101      * @throws UnsupportedEncodingException the unsupported encoding exception
102      * @throws AAIException the AAI exception
103      */
104     @Test
105     public void namingExceptions() throws UnsupportedEncodingException, AAIException {
106         URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
107                 .build();
108
109         QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
110         String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
111                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
112                 + ".has('interface-id', 'key2')"
113                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
114                 + ".has('cvlan-tag', 655)";
115         String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
116                 + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
117                 + ".has('interface-id', 'key2')";
118         assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
119         assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
120                 query.getQueryBuilder().getParentQuery().getQuery());
121         assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
122
123     }
124
125 }