aboutsummaryrefslogtreecommitdiffstats
path: root/graph-inventory
diff options
context:
space:
mode:
Diffstat (limited to 'graph-inventory')
-rw-r--r--graph-inventory/aai-client/pom.xml2
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIClient.java19
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIDSLQueryClient.java6
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java3
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClient.java7
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryClient.java15
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryQueryClient.java4
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLNodeBase.java22
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java17
-rw-r--r--graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java12
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIDSLQueryClientTest.java17
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIRestClientTest.java29
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java20
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java26
-rw-r--r--graph-inventory/fluent-builder-maven-plugin/pom.xml2
-rw-r--r--graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java7
-rw-r--r--graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java2
-rw-r--r--graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java6
-rw-r--r--graph-inventory/pom.xml2
19 files changed, 185 insertions, 33 deletions
diff --git a/graph-inventory/aai-client/pom.xml b/graph-inventory/aai-client/pom.xml
index 8c7be3eb7e..dc9bf47070 100644
--- a/graph-inventory/aai-client/pom.xml
+++ b/graph-inventory/aai-client/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.onap.so</groupId>
<artifactId>graph-inventory</artifactId>
- <version>1.6.0-SNAPSHOT</version>
+ <version>1.7.1-SNAPSHOT</version>
</parent>
<artifactId>aai-client</artifactId>
<build>
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIClient.java
index 1cd23614b5..1f747e6c8c 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIClient.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIClient.java
@@ -21,11 +21,13 @@
package org.onap.aaiclient.client.aai;
import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.UriBuilder;
-import org.onap.so.client.RestClient;
import org.onap.aaiclient.client.graphinventory.GraphInventoryClient;
import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException;
+import org.onap.so.client.RestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,11 +38,20 @@ public class AAIClient extends GraphInventoryClient {
protected AAIVersion version;
protected AAIClient() {
- super(AAIProperties.class);
+ super(AAIProperties.class, new HashMap<String, String>());
}
protected AAIClient(AAIVersion version) {
- super(AAIProperties.class);
+ super(AAIProperties.class, new HashMap<String, String>());
+ this.version = version;
+ }
+
+ protected AAIClient(Map<String, String> additionalHeaders) {
+ super(AAIProperties.class, additionalHeaders);
+ }
+
+ protected AAIClient(AAIVersion version, Map<String, String> additionalHeaders) {
+ super(AAIProperties.class, additionalHeaders);
this.version = version;
}
@@ -54,7 +65,7 @@ public class AAIClient extends GraphInventoryClient {
protected RestClient createClient(URI uri) {
try {
- return new AAIRestClient(getRestProperties(), constructPath(uri));
+ return new AAIRestClient(getRestProperties(), constructPath(uri), additionalHeaders);
} catch (GraphInventoryUriComputationException | NotFoundException e) {
logger.debug("failed to construct A&AI uri", e);
throw e;
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIDSLQueryClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIDSLQueryClient.java
index 238e87392f..378db87d9b 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIDSLQueryClient.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIDSLQueryClient.java
@@ -26,16 +26,17 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
import org.onap.aaiclient.client.graphinventory.GraphInventoryQueryClient;
import org.onap.aaiclient.client.graphinventory.entities.DSLQuery;
import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryUri;
+import com.google.common.collect.ImmutableMap;
public class AAIDSLQueryClient
extends GraphInventoryQueryClient<AAIDSLQueryClient, DSLQuery, AAIResultWrapper, AAIObjectType> {
public AAIDSLQueryClient() {
- super(new AAIClient());
+ super(new AAIClient(ImmutableMap.of("X-DslApiVersion", "V2")));
}
public AAIDSLQueryClient(AAIVersion version) {
- super(new AAIClient(version));
+ super(new AAIClient(version, ImmutableMap.of("X-DslApiVersion", "V2")));
}
@Override
@@ -53,5 +54,4 @@ public class AAIDSLQueryClient
public AAIObjectType createType(String name, String uri) {
return new AAIFluentTypeReverseLookup().fromName(name, uri);
}
-
}
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java
index b3402fa221..2335a48d43 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java
@@ -63,6 +63,7 @@ import org.onap.aai.domain.yang.ServiceSubscription;
import org.onap.aai.domain.yang.SliceProfile;
import org.onap.aai.domain.yang.SpPartner;
import org.onap.aai.domain.yang.SriovPf;
+import org.onap.aai.domain.yang.SriovVf;
import org.onap.aai.domain.yang.Subnet;
import org.onap.aai.domain.yang.Tenant;
import org.onap.aai.domain.yang.TunnelXconnect;
@@ -184,6 +185,8 @@ public class AAIObjectType implements AAIObjectBase, GraphInventoryObjectType, S
new AAIObjectType(AAINamespaceConstants.NETWORK, AggregateRoute.class);
public static final AAIObjectType L_INTERFACE =
new AAIObjectType(AAIObjectType.VSERVER.uriTemplate(), LInterface.class);
+ public static final AAIObjectType SRIOV_VF =
+ new AAIObjectType(AAIObjectType.L_INTERFACE.uriTemplate(), SriovVf.class);
public static final AAIObjectType SUB_L_INTERFACE = new AAIObjectType(AAIObjectType.L_INTERFACE.uriTemplate(),
"/l-interfaces/l-interface/{sub-interface-name}", "sub-l-interface");
public static final AAIObjectType IMAGE = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Image.class);
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClient.java
index 9a8a2a53c0..0f69b0cc8f 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClient.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClient.java
@@ -23,18 +23,20 @@ package org.onap.aaiclient.client.aai;
import java.net.URI;
import java.util.Map;
import java.util.Optional;
-import org.onap.so.client.ResponseExceptionMapper;
import org.onap.aaiclient.client.graphinventory.GraphInventoryPatchConverter;
import org.onap.aaiclient.client.graphinventory.GraphInventoryRestClient;
import org.onap.logging.filter.base.ONAPComponents;
+import org.onap.so.client.ResponseExceptionMapper;
public class AAIRestClient extends GraphInventoryRestClient {
private final AAIProperties aaiProperties;
+ private final Map<String, String> additionalHeaders;
- protected AAIRestClient(AAIProperties props, URI uri) {
+ protected AAIRestClient(AAIProperties props, URI uri, Map<String, String> additionalHeaders) {
super(props, uri);
this.aaiProperties = props;
+ this.additionalHeaders = additionalHeaders;
}
@Override
@@ -46,6 +48,7 @@ public class AAIRestClient extends GraphInventoryRestClient {
protected void initializeHeaderMap(Map<String, String> headerMap) {
headerMap.put("X-FromAppId", aaiProperties.getSystemName());
headerMap.put("X-TransactionId", requestId);
+ headerMap.putAll(additionalHeaders);
String auth = aaiProperties.getAuth();
String key = aaiProperties.getKey();
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryClient.java
index a2bb8bc141..f8f977d117 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryClient.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryClient.java
@@ -21,20 +21,25 @@
package org.onap.aaiclient.client.graphinventory;
import java.net.URI;
+import java.util.Map;
+import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryUri;
+import org.onap.aaiclient.client.graphinventory.entities.uri.HttpAwareUri;
import org.onap.so.client.RestClient;
import org.onap.so.client.RestProperties;
import org.onap.so.client.RestPropertiesLoader;
-import org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryUri;
-import org.onap.aaiclient.client.graphinventory.entities.uri.HttpAwareUri;
+import com.google.common.collect.ImmutableMap;
public abstract class GraphInventoryClient {
private RestProperties props;
+ protected final Map<String, String> additionalHeaders;
- protected GraphInventoryClient(Class<? extends RestProperties> propertiesClass) {
+ protected GraphInventoryClient(Class<? extends RestProperties> propertiesClass,
+ Map<String, String> additionalHeaders) {
RestProperties props = RestPropertiesLoader.getInstance().getNewImpl(propertiesClass);
this.props = props;
+ this.additionalHeaders = additionalHeaders;
}
protected abstract URI constructPath(URI uri);
@@ -64,4 +69,8 @@ public abstract class GraphInventoryClient {
public abstract GraphInventoryVersion getVersion();
public abstract String getGraphDBName();
+
+ public Map<String, String> getAdditionalHeaders() {
+ return ImmutableMap.copyOf(this.additionalHeaders);
+ }
}
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryQueryClient.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryQueryClient.java
index c749561e5f..a192e3828a 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryQueryClient.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/GraphInventoryQueryClient.java
@@ -138,4 +138,8 @@ public abstract class GraphInventoryQueryClient<S, I, Wrapper extends GraphInven
}
return clone;
}
+
+ public GraphInventoryClient getClient() {
+ return this.client;
+ }
}
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLNodeBase.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLNodeBase.java
index c071e24391..5c88e8e42e 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLNodeBase.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLNodeBase.java
@@ -22,13 +22,17 @@ package org.onap.aaiclient.client.graphinventory.entities;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.stream.Collectors;
import org.onap.aaiclient.client.aai.entities.QueryStep;
import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectName;
public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep {
protected final String nodeName;
+ protected final Collection<String> fields;
protected final List<DSLNodeKey> nodeKeys;
protected final StringBuilder query;
protected boolean output = false;
@@ -37,6 +41,7 @@ public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep
this.nodeName = "";
this.nodeKeys = new ArrayList<>();
this.query = new StringBuilder();
+ this.fields = new LinkedHashSet<>();
}
@@ -44,6 +49,7 @@ public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep
this.nodeName = name.typeName();
this.nodeKeys = new ArrayList<>();
this.query = new StringBuilder();
+ this.fields = new LinkedHashSet<>();
query.append(nodeName);
}
@@ -51,6 +57,7 @@ public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep
this.nodeName = name.typeName();
this.nodeKeys = Arrays.asList(key);
this.query = new StringBuilder();
+ this.fields = new LinkedHashSet<>();
query.append(nodeName);
}
@@ -58,6 +65,7 @@ public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep
this.nodeName = copy.nodeName;
this.nodeKeys = copy.nodeKeys;
this.query = new StringBuilder(copy.query);
+ this.fields = copy.fields;
this.output = copy.output;
}
@@ -67,6 +75,12 @@ public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep
return new DSLOutputNode(this);
}
+ public DSLOutputNode output(String... fields) {
+ this.output = true;
+ this.fields.addAll(Arrays.asList(fields));
+ return new DSLOutputNode(this);
+ }
+
public T and(DSLNodeKey... key) {
this.nodeKeys.addAll(Arrays.asList(key));
@@ -77,7 +91,13 @@ public abstract class DSLNodeBase<T extends DSLNodeBase<?>> implements QueryStep
public String build() {
StringBuilder result = new StringBuilder(query);
if (output) {
- result.append("*");
+ if (fields.isEmpty()) {
+ result.append("*");
+ } else {
+ String items =
+ fields.stream().map(item -> String.format("'%s'", item)).collect(Collectors.joining(", "));
+ result.append("{").append(items).append("}");
+ }
}
for (DSLNodeKey key : nodeKeys) {
result.append(key.build());
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java
index 762203258a..c56ce0bfee 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/DSLQueryBuilder.java
@@ -24,6 +24,7 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.onap.aaiclient.client.aai.entities.QueryStep;
import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectName;
@@ -49,9 +50,20 @@ public class DSLQueryBuilder<S, E> {
}
public DSLQueryBuilder<S, Node> output() {
+ callOnLambda(item -> item.output());
+ return (DSLQueryBuilder<S, Node>) this;
+ }
+
+ public DSLQueryBuilder<S, Node> output(String... fields) {
+ callOnLambda(item -> item.output(fields));
+ return (DSLQueryBuilder<S, Node>) this;
+ }
+
+ protected void callOnLambda(Consumer<DSLNodeBase> consumer) {
+
Object obj = steps.get(steps.size() - 1);
if (obj instanceof DSLNodeBase) {
- ((DSLNodeBase) steps.get(steps.size() - 1)).output();
+ consumer.accept((DSLNodeBase) steps.get(steps.size() - 1));
} else if (obj.getClass().getName().contains("$$Lambda$")) {
// process lambda expressions
for (Field f : obj.getClass().getDeclaredFields()) {
@@ -60,7 +72,7 @@ public class DSLQueryBuilder<S, E> {
try {
o = f.get(obj);
if (o instanceof DSLQueryBuilder && ((DSLQueryBuilder) o).steps.get(0) instanceof DSLNodeBase) {
- ((DSLNodeBase) ((DSLQueryBuilder) o).steps.get(0)).output();
+ consumer.accept(((DSLNodeBase) ((DSLQueryBuilder) o).steps.get(0)));
}
} catch (IllegalArgumentException | IllegalAccessException e) {
}
@@ -68,7 +80,6 @@ public class DSLQueryBuilder<S, E> {
break;
}
}
- return (DSLQueryBuilder<S, Node>) this;
}
@SafeVarargs
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java
index 48feba25df..881b7e9a8e 100644
--- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java
+++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/graphinventory/entities/GraphInventoryRelationships.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectName;
import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType;
@@ -56,6 +57,11 @@ public abstract class GraphInventoryRelationships<Wrapper extends GraphInventory
return this.getAll(Optional.of(type));
}
+ public List<Wrapper> getByType(GraphInventoryObjectName type, UnaryOperator<Uri> func) {
+
+ return this.getAll(Optional.of(type), func);
+ }
+
public List<Wrapper> getAll() {
return this.getAll(Optional.empty());
@@ -99,6 +105,10 @@ public abstract class GraphInventoryRelationships<Wrapper extends GraphInventory
protected List<Wrapper> getAll(final Optional<GraphInventoryObjectName> type) {
+ return getAll(type, UnaryOperator.identity());
+ }
+
+ protected List<Wrapper> getAll(final Optional<GraphInventoryObjectName> type, UnaryOperator<Uri> func) {
List<Uri> relatedLinks;
if (type.isPresent()) {
relatedLinks = this.getRelatedUris(type.get());
@@ -107,7 +117,7 @@ public abstract class GraphInventoryRelationships<Wrapper extends GraphInventory
}
ArrayList<Wrapper> result = new ArrayList<>();
for (Uri link : relatedLinks) {
- result.add(this.get(link));
+ result.add(this.get(func.apply(link)));
}
return result;
}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIDSLQueryClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIDSLQueryClientTest.java
new file mode 100644
index 0000000000..36fc1db57c
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIDSLQueryClientTest.java
@@ -0,0 +1,17 @@
+package org.onap.aaiclient.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import java.net.URISyntaxException;
+import org.junit.Test;
+
+public class AAIDSLQueryClientTest {
+
+
+
+ @Test
+ public void verifyHeadersTest() throws URISyntaxException {
+
+ AAIDSLQueryClient client = new AAIDSLQueryClient();
+ assertEquals("V2", client.getClient().getAdditionalHeaders().get("X-DslApiVersion"));
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIRestClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIRestClientTest.java
index 86738beabb..b73454fe67 100644
--- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIRestClientTest.java
+++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIRestClientTest.java
@@ -20,6 +20,13 @@
package org.onap.aaiclient.client.aai;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.matching;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.hamcrest.CoreMatchers.containsString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -30,6 +37,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.HashMap;
import javax.ws.rs.core.Response;
import org.junit.Rule;
import org.junit.Test;
@@ -37,10 +45,12 @@ import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.so.client.RestClientSSL;
+import org.onap.aaiclient.client.defaultproperties.DefaultAAIPropertiesImpl;
import org.onap.aaiclient.client.graphinventory.GraphInventoryPatchConverter;
import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.google.common.collect.ImmutableMap;
@RunWith(MockitoJUnitRunner.class)
public class AAIRestClientTest {
@@ -53,9 +63,12 @@ public class AAIRestClientTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
@Test
public void failPatchOnComplexObject() throws URISyntaxException {
- AAIRestClient client = new AAIRestClient(props, new URI(""));
+ AAIRestClient client = new AAIRestClient(props, new URI(""), new HashMap<String, String>());
this.thrown.expect(GraphInventoryPatchDepthExceededException.class);
this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action"));
client.patch(
@@ -64,7 +77,7 @@ public class AAIRestClientTest {
@Test
public void verifyPatchValidation() throws URISyntaxException {
- AAIRestClient client = new AAIRestClient(props, new URI(""));
+ AAIRestClient client = new AAIRestClient(props, new URI(""), new HashMap<String, String>());
AAIRestClient spy = spy(client);
GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class);
doReturn(patchValidatorMock).when(spy).getPatchConverter();
@@ -73,4 +86,14 @@ public class AAIRestClientTest {
spy.patch(payload);
verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object) payload));
}
+
+ @Test
+ public void verifyAdditionalHeadersTest() throws URISyntaxException {
+ AAIRestClient client = new AAIRestClient(new DefaultAAIPropertiesImpl(wireMockRule.port()), new URI("/test"),
+ ImmutableMap.of("test", "value"));
+ wireMockRule.stubFor(get(urlPathEqualTo("/test")).willReturn(aResponse().withStatus(200)));
+ client.get();
+ wireMockRule.verify(getRequestedFor(urlPathEqualTo("/test")).withHeader("X-FromAppId", equalTo("MSO"))
+ .withHeader("X-TransactionId", matching(".*")).withHeader("test", equalTo("value")));
+ }
}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java
index 965770c796..b0b0c6aca9 100644
--- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java
+++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
import org.onap.aaiclient.client.graphinventory.entities.DSLNodeKey;
import org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder;
import org.onap.aaiclient.client.graphinventory.entities.DSLStartNode;
+import org.onap.aaiclient.client.graphinventory.entities.Node;
import org.onap.aaiclient.client.graphinventory.entities.Output;
import org.onap.aaiclient.client.graphinventory.entities.Start;
import org.onap.aaiclient.client.graphinventory.entities.TraversalBuilder;
@@ -146,4 +147,23 @@ public class DSLQueryBuilderTest {
"generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]",
builder.build().get());
}
+
+ @Test
+ public void selectOutputFilterTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder
+ .traversal(new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "CloudOwner"))
+ .output("cloud-region-id", "a", "b"));
+ builder.to(__.node(AAIObjectType.PSERVER)).output("x", "y", "z");
+
+ assertEquals("cloud-region{'cloud-region-id', 'a', 'b'}('cloud-owner', 'CloudOwner') > pserver{'x', 'y', 'z'}",
+ builder.build().toString());
+ }
+
+ @Test
+ public void selectOutputFilterOnNodeTest() {
+ DSLStartNode node = new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "CloudOwner"));
+ DSLQueryBuilder<Start, Node> builder = TraversalBuilder.fragment(node).output("cloud-region-id");
+
+ assertEquals("cloud-region{'cloud-region-id'}('cloud-owner', 'CloudOwner')", builder.build().toString());
+ }
}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java
index 10162f83ee..9e106fab85 100644
--- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java
+++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java
@@ -21,12 +21,15 @@
package org.onap.aaiclient.client.aai.entities;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
import org.onap.aaiclient.client.aai.AAIObjectType;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
@@ -53,4 +56,27 @@ public class RelationshipsTest {
}
+ @Test
+ public void getByTypeTest() throws IOException {
+ final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json")));
+
+ AAIResultWrapper wrapper = new AAIResultWrapper(content);
+ Relationships relationships = wrapper.getRelationships().get();
+
+ Relationships spy = Mockito.spy(relationships);
+ ArgumentCaptor<AAIResourceUri> argument = ArgumentCaptor.forClass(AAIResourceUri.class);
+ doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture());
+
+ spy.getByType(AAIObjectType.VCE, uri -> uri.nodesOnly(true));
+
+ assertTrue(argument.getAllValues().stream().allMatch(item -> item.build().toString().contains("nodes-only")));
+
+ argument = ArgumentCaptor.forClass(AAIResourceUri.class);
+
+ doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture());
+ spy.getByType(AAIObjectType.VCE);
+
+ assertTrue(argument.getAllValues().stream().allMatch(item -> !item.build().toString().contains("?")));
+
+ }
}
diff --git a/graph-inventory/fluent-builder-maven-plugin/pom.xml b/graph-inventory/fluent-builder-maven-plugin/pom.xml
index 7833bce48e..f0884758b8 100644
--- a/graph-inventory/fluent-builder-maven-plugin/pom.xml
+++ b/graph-inventory/fluent-builder-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.onap.so</groupId>
<artifactId>graph-inventory</artifactId>
- <version>1.6.0-SNAPSHOT</version>
+ <version>1.7.1-SNAPSHOT</version>
</parent>
<artifactId>fluent-builder-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java
index 23a1a812df..4a8b7d90c6 100644
--- a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java
+++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/FluentGenerator.java
@@ -325,13 +325,8 @@ public class FluentGenerator {
String value;
String name;
- if (params.group(2) != null) {
- name = params.group(2);
- } else {
- name = params.group(1);
- }
value = params.group(1);
-
+ name = params.group(2);
name = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, name);
classFields.add(FieldSpec.builder(String.class, name, Modifier.PUBLIC, Modifier.FINAL)
diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java
index 8be22e1dcc..d27794c127 100644
--- a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java
+++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/Patterns.java
@@ -7,5 +7,5 @@ public class Patterns {
public static final Pattern pluralPattern = Pattern.compile(".*(?<partial>/(?<name>[^{]*$))");
public static final Pattern singularPattern = Pattern.compile(".*(?<partial>/(?<name>[^/{}]*)/\\{.*$)");
public static final Pattern topLevelPattern = Pattern.compile("^/([^/]+)/.*");
- public static final Pattern urlTemplatePattern = Pattern.compile("\\{([^}.]+(?:\\.([^}]+))?)\\}");
+ public static final Pattern urlTemplatePattern = Pattern.compile("\\{((?:.+\\.)?([^}.]+))\\}");
}
diff --git a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java
index 42305488bc..ec09af8a4e 100644
--- a/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java
+++ b/graph-inventory/fluent-builder-maven-plugin/src/main/java/org/onap/graphinventory/generate/SwaggerConverter.java
@@ -125,8 +125,6 @@ public class SwaggerConverter {
}
}
- log.debug(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(output));
-
for (Map.Entry<String, ObjectType> item : output.entrySet()) {
if (item.getValue().getType().equals("plural")) {
@@ -156,7 +154,7 @@ public class SwaggerConverter {
Matcher templates = Patterns.urlTemplatePattern.matcher(item.getValue().getPartialUri());
List<String> localFields = new ArrayList<>();
while (templates.find()) {
- localFields.add(templates.group(1));
+ localFields.add(templates.group(2));
}
item.getValue().setFields(item.getValue().getFields().stream()
.filter(f -> localFields.contains(f.getName())).collect(Collectors.toList()));
@@ -166,6 +164,8 @@ public class SwaggerConverter {
output.values().stream().filter(item -> item.getType().equals("plural"))
.forEach(item -> item.getChildren().clear());
+ log.debug(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(output));
+
return output;
}
}
diff --git a/graph-inventory/pom.xml b/graph-inventory/pom.xml
index 0f465b03b1..f5ccbc0244 100644
--- a/graph-inventory/pom.xml
+++ b/graph-inventory/pom.xml
@@ -4,7 +4,7 @@
<parent>
<groupId>org.onap.so</groupId>
<artifactId>so</artifactId>
- <version>1.6.0-SNAPSHOT</version>
+ <version>1.7.1-SNAPSHOT</version>
</parent>
<artifactId>graph-inventory</artifactId>
<packaging>pom</packaging>