Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / client / aai / DSLQueryBuilderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 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.so.client.aai;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import org.junit.Test;
26 import org.onap.so.client.graphinventory.entities.DSLNode;
27 import org.onap.so.client.graphinventory.entities.DSLQueryBuilder;
28 import org.onap.so.client.graphinventory.entities.__;
29
30 public class DSLQueryBuilderTest {
31
32
33     @Test
34     public void whereTest() {
35         DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION,
36                 __.key("cloud-owner", "att-nc"), __.key("cloud-region-id", "test")));
37
38         builder.to(__.node(AAIObjectType.VLAN_TAG))
39                 .where(__.node(AAIObjectType.OWNING_ENTITY, __.key("owning-entity-name", "name")))
40                 .to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", "108")).output());
41
42         assertEquals("cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'test') > "
43                 + "vlan-tag (> owning-entity('owning-entity-name', 'name')) > " + "vlan-tag*('vlan-id-outer', '108')",
44                 builder.build());
45     }
46
47     @Test
48     public void unionTest() {
49         DSLQueryBuilder<DSLNode, DSLNode> builder =
50                 new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output());
51
52         builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()),
53                 __.node(AAIObjectType.VSERVER)
54                         .to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output())));
55
56         assertEquals(
57                 "generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]",
58                 builder.build());
59     }
60
61     @Test
62     public void whereUnionTest() {
63         DSLQueryBuilder<DSLNode, DSLNode> builder =
64                 new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output());
65
66         builder.where(__.union(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")),
67                 __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")))));
68
69         assertEquals("generic-vnf*('vnf-id', 'vnfId') (> [ pserver('hostname', 'hostname1'), "
70                 + "vserver > pserver('hostname', 'hostname1') ])", builder.build());
71     }
72
73     @Test
74     public void notNullTest() {
75         DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(
76                 new DSLNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "", "null").not()).output());
77
78         assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build());
79     }
80
81     @Test
82     public void shortCutToTest() {
83         DSLQueryBuilder<DSLNode, DSLNode> builder =
84                 new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
85
86         builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
87         assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')",
88                 builder.build());
89     }
90
91     @Test
92     public void limitTest() {
93         DSLQueryBuilder<DSLNode, DSLNode> builder =
94                 new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
95
96         builder.to(AAIObjectType.P_INTERFACE).limit(2).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
97         assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id') LIMIT 2",
98                 builder.build());
99     }
100
101     @Test
102     public void equalsTest() {
103         DSLQueryBuilder<DSLNode, DSLNode> builder =
104                 new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
105
106         builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
107         assertTrue(
108                 builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')"));
109         assertTrue(builder.equals(builder));
110     }
111 }