aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java1
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIObjectType.java6
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java14
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java14
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java11
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java50
6 files changed, 92 insertions, 4 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java
index 4f3816ad90..b3bfcc1648 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java
@@ -30,6 +30,7 @@ public enum AAIObjectPlurals implements GraphInventoryObjectPlurals {
CUSTOMER(AAINamespaceConstants.BUSINESS, "/customers"),
GENERIC_VNF(AAINamespaceConstants.NETWORK, "/generic-vnfs"),
+ PORT_GROUP(AAIObjectType.VCE.uriTemplate(), "/port-groups"),
PSERVER(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, "/pservers"),
P_INTERFACE(AAIObjectType.PSERVER.uriTemplate(), "/p-interfaces"),
L3_NETWORK(AAINamespaceConstants.NETWORK, "/l3-networks"),
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
index f003dc0628..0237f91833 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
@@ -45,9 +45,10 @@ import org.onap.aai.domain.yang.OwningEntity;
import org.onap.aai.domain.yang.PInterface;
import org.onap.aai.domain.yang.PhysicalLink;
import org.onap.aai.domain.yang.Platform;
+import org.onap.aai.domain.yang.PortGroup;
import org.onap.aai.domain.yang.Project;
import org.onap.aai.domain.yang.Pserver;
-import org.onap.aai.domain.yang.RouteTableReferences;
+import org.onap.aai.domain.yang.RouteTableReference;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.ServiceSubscription;
import org.onap.aai.domain.yang.SpPartner;
@@ -80,9 +81,10 @@ public enum AAIObjectType implements GraphInventoryObjectType {
NETWORK_POLICY(AAINamespaceConstants.NETWORK, NetworkPolicy.class),
NODES_QUERY("/search", "/nodes-query"),
CUSTOM_QUERY("/query", ""),
- ROUTE_TABLE_REFERENCE(AAINamespaceConstants.NETWORK, RouteTableReferences.class),
+ ROUTE_TABLE_REFERENCE(AAINamespaceConstants.NETWORK, RouteTableReference.class),
DEFAULT_TENANT(AAINamespaceConstants.CLOUD_INFRASTRUCTURE + "/cloud-regions/cloud-region/" + Defaults.CLOUD_OWNER + "/AAIAIC25", "/tenants/tenant/{tenant-id}"),
VCE(AAINamespaceConstants.NETWORK, Vce.class),
+ PORT_GROUP(AAIObjectType.VCE.uriTemplate(), PortGroup.class),
VPN_BINDING(AAINamespaceConstants.NETWORK, VpnBinding.class),
CONFIGURATION(AAINamespaceConstants.NETWORK, Configuration.class),
PSERVER(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Pserver.class),
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java
index 884f8c6ac4..324bb8abad 100644
--- a/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java
+++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java
@@ -22,7 +22,6 @@ package org.onap.so.client.aai.entities.uri;
import java.io.IOException;
import java.net.URI;
-import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
@@ -38,6 +37,7 @@ import org.onap.so.client.graphinventory.entities.uri.HttpAwareUri;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
+import org.onap.so.client.graphinventory.exceptions.IncorrectNumberOfUriKeys;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -118,6 +118,18 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri
@Override
public abstract HttpLookupUri clone();
+ @Override
+ public void validateValuesSize(String template, Object... values) {
+ try {
+ super.validateValuesSize(template, values);
+ } catch (IncorrectNumberOfUriKeys e) {
+ if (values.length == 1) {
+ //Special case where we perform an http look up
+ } else {
+ throw e;
+ }
+ }
+ }
public AAIResourcesClient getResourcesClient() {
return new AAIResourcesClient();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
index 2876f77d82..93de9139f9 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
@@ -24,11 +24,11 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import javax.ws.rs.core.UriBuilder;
@@ -39,6 +39,7 @@ import org.onap.so.client.graphinventory.GraphInventoryObjectPlurals;
import org.onap.so.client.graphinventory.GraphInventoryObjectType;
import org.onap.so.client.graphinventory.entities.uri.parsers.UriParser;
import org.onap.so.client.graphinventory.entities.uri.parsers.UriParserSpringImpl;
+import org.onap.so.client.graphinventory.exceptions.IncorrectNumberOfUriKeys;
import org.springframework.web.util.UriUtils;
public class SimpleUri implements GraphInventoryResourceUri, Serializable {
@@ -56,6 +57,7 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
this.pluralType = null;
this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
this.values = values;
+ validateValuesSize(this.getTemplate(type), values);
}
protected SimpleUri(GraphInventoryObjectType type, URI uri) {
this.type = type;
@@ -86,12 +88,14 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
this.pluralType = type;
this.internalURI = UriBuilder.fromPath(this.getTemplate(type));
this.values = values;
+ validateValuesSize(this.getTemplate(type), values);
}
protected SimpleUri(GraphInventoryResourceUri parentUri, GraphInventoryObjectType childType, Object... childValues) {
this.type = childType;
this.pluralType = null;
this.internalURI = UriBuilder.fromUri(parentUri.build()).path(childType.partialUri());
this.values = childValues;
+ validateValuesSize(childType.partialUri(), values);
}
protected void setInternalURI(UriBuilder builder) {
@@ -232,6 +236,14 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
return this;
}
+ public void validateValuesSize(String template, Object... values) {
+ UriParser parser = new UriParserSpringImpl(template);
+ Set<String> variables = parser.getVariables();
+ if (variables.size() != values.length) {
+ throw new IncorrectNumberOfUriKeys(String.format("Expected %s variables: %s", variables.size(), variables));
+ }
+ }
+
protected String getTemplate(GraphInventoryObjectType type) {
return type.uriTemplate();
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java
new file mode 100644
index 0000000000..c94e561274
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/exceptions/IncorrectNumberOfUriKeys.java
@@ -0,0 +1,11 @@
+package org.onap.so.client.graphinventory.exceptions;
+
+public class IncorrectNumberOfUriKeys extends RuntimeException {
+
+ private static final long serialVersionUID = 2189285428827817518L;
+
+ public IncorrectNumberOfUriKeys(String message) {
+ super(message);
+ }
+
+}
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
new file mode 100644
index 0000000000..729f0e50e9
--- /dev/null
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java
@@ -0,0 +1,50 @@
+package org.onap.so.client.aai.entities.uri;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.client.aai.AAIObjectPlurals;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.graphinventory.exceptions.IncorrectNumberOfUriKeys;
+
+public class IncorrectNumberOfUriKeysTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void verifyIncorrectNumberOfKeysSingle() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ thrown.expectMessage(equalTo("Expected 3 variables: [cloud-owner, cloud-region-id, volume-group-id]"));
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, "volume-group-id");
+
+ }
+
+ @Test
+ public void verifyIncorrectNumberOfKeysPlural() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, "my-cloud-owner");
+
+ }
+
+ @Test
+ public void verifyIncorrectNumberOfKeysFromParent() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ AAIResourceUri parentUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "my-cloud-owner", "my-cloud-region-id");
+ AAIResourceUri uri = AAIUriFactory.createResourceFromParentURI(parentUri, AAIObjectType.VOLUME_GROUP);
+ }
+
+ @Test
+ public void verifyIncorrectNumberOfKeysHttpAware() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "customer-id", "subscription-id");
+ }
+}