2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.aai;
23 import static org.junit.Assert.assertEquals;
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.__;
30 public class DSLQueryBuilderTest {
34 public void whereTest() {
35 DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION,
36 __.key("cloud-owner", "att-nc"),
37 __.key("cloud-region-id", "test")));
39 builder.to(__.node(AAIObjectType.VLAN_TAG)).where(
40 __.node(AAIObjectType.OWNING_ENTITY,
41 __.key("owning-entity-name", "name")
43 ).to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", "108")).output());
45 assertEquals("cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'test') > "
46 + "vlan-tag (> owning-entity('owning-entity-name', 'name')) > "
47 + "vlan-tag*('vlan-id-outer', '108')", builder.build());
51 public void unionTest() {
52 DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF,
53 __.key("vnf-id", "vnfId")).output());
55 builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()),
56 __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output())));
58 assertEquals("generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, "
59 + "vserver > pserver* > complex* ]", builder.build());
63 public void whereUnionTest() {
64 DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF,
65 __.key("vnf-id", "vnfId")).output());
69 __.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")),
70 __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")))));
72 assertEquals("generic-vnf*('vnf-id', 'vnfId') (> [ pserver('hostname', 'hostname1'), "
73 + "vserver > pserver('hostname', 'hostname1') ])", builder.build());
77 public void notNullTest() {
78 DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION,
79 __.key("cloud-owner", "", "null").not()).output());
81 assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build());
85 public void shortCutToTest() {
86 DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER,
87 __.key("hostname", "my-hostname")).output());
89 builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
90 assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')", builder.build());