diff options
Diffstat (limited to 'common/src/test/java')
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java | 3 | ||||
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java | 3 | ||||
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java | 3 | ||||
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java | 83 | ||||
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java | 20 | ||||
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java | 20 | ||||
-rw-r--r-- | common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java (renamed from common/src/test/java/org/onap/so/client/aai/AAIPatchConverterTest.java) | 16 |
7 files changed, 138 insertions, 10 deletions
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java index ad15417b71..95b30f934b 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java @@ -41,6 +41,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.client.RestClientSSL; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -68,7 +69,7 @@ public class AAIRestClientTest { public void verifyPatchValidation() throws URISyntaxException { AAIRestClient client = new AAIRestClient(props, new URI("")); AAIRestClient spy = spy(client); - AAIPatchConverter patchValidatorMock = mock(AAIPatchConverter.class); + GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class); doReturn(patchValidatorMock).when(spy).getPatchConverter(); String payload = "{}"; doReturn(Response.ok().build()).when(spy).method(eq("PATCH"), any()); diff --git a/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java index 428fa276db..27637126c6 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java @@ -45,6 +45,7 @@ import org.onap.so.client.aai.entities.singletransaction.SingleTransactionRespon import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; @@ -117,7 +118,7 @@ public class AAISingleTransactionClientTest { @Test public void confirmPatchFormat() { AAISingleTransactionClient singleTransaction = spy(new AAISingleTransactionClient(AAIVersion.LATEST)); - AAIPatchConverter mock = mock(AAIPatchConverter.class); + GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class); doReturn(mock).when(singleTransaction).getPatchConverter(); singleTransaction.update(uriA, "{}"); verify(mock, times(1)).convertPatchFormat(any()); diff --git a/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java index 621375882b..342e3b1aa4 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java @@ -43,6 +43,7 @@ import org.onap.aai.domain.yang.Relationship; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; @@ -143,7 +144,7 @@ public class AAITransactionalClientTest { @Test public void confirmPatchFormat() { AAITransactionalClient client = spy(new AAITransactionalClient(AAIVersion.LATEST)); - AAIPatchConverter mock = mock(AAIPatchConverter.class); + GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class); doReturn(mock).when(client).getPatchConverter(); client.update(uriA, "{}"); verify(mock, times(1)).convertPatchFormat(any()); diff --git a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java new file mode 100644 index 0000000000..e66f43fa5f --- /dev/null +++ b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.aai; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.so.client.aai.entities.DSLNode; +import org.onap.so.client.aai.entities.DSLQueryBuilder; +import org.onap.so.client.aai.entities.__; + +public class DSLQueryBuilderTest { + + + @Test + public void whereTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + __.key("cloud-owner", "att-nc"), + __.key("cloud-region-id", "test"))); + + builder.to(__.node(AAIObjectType.VLAN_TAG)).where( + __.node(AAIObjectType.OWNING_ENTITY, + __.key("owning-entity-name", "name") + ) + ).to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", "108")).output()); + + assertEquals("cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'test') > " + + "vlan-tag (> owning-entity('owning-entity-name', 'name')) > " + + "vlan-tag*('vlan-id-outer', '108')", builder.build()); + } + + @Test + public void unionTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, + __.key("vnf-id", "vnfId")).output()); + + builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()), + __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()))); + + assertEquals("generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + + "vserver > pserver* > complex* ]", builder.build()); + } + + @Test + public void whereUnionTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.GENERIC_VNF, + __.key("vnf-id", "vnfId")).output()); + + builder.where( + __.union( + __.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")), + __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1"))))); + + assertEquals("generic-vnf*('vnf-id', 'vnfId') (> [ pserver('hostname', 'hostname1'), " + + "vserver > pserver('hostname', 'hostname1') ])", builder.build()); + } + + @Test + public void notNullTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + __.key("cloud-owner", "", "null").not()).output()); + + assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build()); + } +} diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java index 729f0e50e9..e84326e95f 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.so.client.aai.entities.uri; import static org.hamcrest.CoreMatchers.equalTo; diff --git a/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java b/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java index b964e905de..3979902962 100644 --- a/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java +++ b/common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.so.client.aai.objects; import org.onap.so.client.aai.AAINamespaceConstants; diff --git a/common/src/test/java/org/onap/so/client/aai/AAIPatchConverterTest.java b/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java index 0d4490f51d..d24b3ff147 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIPatchConverterTest.java +++ b/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.client.aai; +package org.onap.so.client.graphinventory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -35,6 +35,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; @@ -42,13 +44,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(MockitoJUnitRunner.class) -public class AAIPatchConverterTest { +public class GraphInventoryPatchConverterTest { private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper(); @Test public void convertObjectToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); GenericVnf vnf = new GenericVnf(); vnf.setIpv4Loopback0Address(""); String result = validator.marshallObjectToPatchFormat(vnf); @@ -60,7 +62,7 @@ public class AAIPatchConverterTest { @Test public void convertStringToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String payload = "{\"ipv4-loopback0-address\":\"\"}"; String result = validator.marshallObjectToPatchFormat(payload); @@ -69,7 +71,7 @@ public class AAIPatchConverterTest { @Test public void convertStringToPatchFormatNull_Test() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String payload = "{\"ipv4-loopback0-address\": null}"; String result = validator.marshallObjectToPatchFormat(payload); System.out.println(result); @@ -78,7 +80,7 @@ public class AAIPatchConverterTest { @Test public void convertMapToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); HashMap<String, String> map = new HashMap<>(); map.put("ipv4-loopback0-address", ""); map.put("ipv4-loopback1-address", "192.168.1.1"); @@ -89,7 +91,7 @@ public class AAIPatchConverterTest { @Test public void hasComplexObjectTest() { - AAIPatchConverter validator = new AAIPatchConverter(); + GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String hasNesting = "{ \"hello\" : \"world\", \"nested\" : { \"key\" : \"value\" } }"; String noNesting = "{ \"hello\" : \"world\" }"; String arrayCase = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"nestedComplex\" : [{\"key\" : \"value\"}]}"; |