summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorMax Benjamin <max.benjamin@att.com>2019-06-06 17:37:59 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-06 17:37:59 +0000
commitc4b90365d5c117bc6fd64af421a1468539a8aec3 (patch)
tree7b81c7516ecb099c880c3d878c1f828f3785fe23 /common
parentfd0b48f7130300c70395742341a0cec2487bd6fa (diff)
parent560e84158798cb884de65e3cf33ab657f0e6e6df (diff)
Merge "Merge remote-tracking branch 'origin/dublin' into 'origin/master'"
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/uri/HttpLookupUri.java23
-rw-r--r--common/src/main/java/org/onap/so/utils/TargetEntity.java3
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java46
-rw-r--r--common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java58
4 files changed, 68 insertions, 62 deletions
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 f086a6abcf..37d21b375e 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
@@ -21,6 +21,8 @@
package org.onap.so.client.aai.entities.uri;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.net.URI;
import java.util.Map;
import java.util.Optional;
@@ -42,7 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri {
- private Optional<String> cachedValue = Optional.empty();
+ private transient Optional<String> cachedValue = Optional.empty();
private final AAIObjectType aaiType;
protected HttpLookupUri(AAIObjectType type, Object... values) {
@@ -78,8 +80,7 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri
throw new GraphInventoryPayloadException("could not map payload: " + resultJson, e);
}
}
- Optional<String> cachedValueOpt = this.getCachedValue();
- return cachedValueOpt.isPresent() ? cachedValueOpt.get() : "";
+ return cachedValue.get();
}
protected Optional<String> extractRelatedLink(String jsonString) throws IOException {
@@ -139,6 +140,22 @@ public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri
return new AAIResourcesClient();
}
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+
+ oos.writeUTF(this.cachedValue.orElse(""));
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException {
+
+ String value = ois.readUTF();
+ if ("".equals(value)) {
+ this.cachedValue = Optional.empty();
+ } else {
+ this.cachedValue = Optional.ofNullable(value);
+ }
+
+ }
+
@Override
public abstract URI buildNoNetwork();
}
diff --git a/common/src/main/java/org/onap/so/utils/TargetEntity.java b/common/src/main/java/org/onap/so/utils/TargetEntity.java
index 0c59887de7..0f1fe51114 100644
--- a/common/src/main/java/org/onap/so/utils/TargetEntity.java
+++ b/common/src/main/java/org/onap/so/utils/TargetEntity.java
@@ -36,7 +36,8 @@ public enum TargetEntity {
SNIRO,
SDC,
EXTERNAL,
- MULTICLOUD;
+ MULTICLOUD,
+ OOF;
private static final String PREFIX = "SO";
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
index e829666577..9bef35e3b5 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
@@ -31,8 +31,14 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
@@ -50,9 +56,11 @@ import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.client.aai.AAIClient;
+import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
+import org.onap.so.client.graphinventory.entities.uri.Depth;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
@@ -227,4 +235,42 @@ public class ServiceInstanceUriTest {
exception.expect(NotFoundException.class);
spy.build();
}
+
+ @Test
+ public void serializeTest() throws IOException, ClassNotFoundException, GraphInventoryUriNotFoundException,
+ GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ final String content = new String(
+ Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
+
+ ServiceInstanceUri spy = spy(instance);
+ AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
+ AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
+ when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class),
+ ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
+ when(wrapper.getJson()).thenReturn(content);
+ when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
+ spy.build();
+ instance = spy.clone();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
+ objectOutputStream.writeObject(instance);
+ objectOutputStream.flush();
+ objectOutputStream.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+
+ ObjectInputStream objectInputStream = new ObjectInputStream(bis);
+ ServiceInstanceUri e2 = (ServiceInstanceUri) objectInputStream.readObject();
+ objectInputStream.close();
+
+ ServiceInstanceUri spy2 = spy(e2);
+
+ assertEquals(spy2.build().toString(), instance.build().toString());
+
+ // use the cached value do not call out to external system
+ verify(spy2, times(0)).getResourcesClient();
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java b/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java
deleted file mode 100644
index 4bfac38151..0000000000
--- a/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2018 Huawei 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.dmaap;
-
-import org.junit.Test;
-import javax.ws.rs.ProcessingException;
-import java.io.IOException;
-import java.util.Optional;
-
-public class DmaapPublisherTest {
-
- DmaapPublisher dmaapPublisher = new DmaapPublisher(120) {
- @Override
- public String getAuth() {
- return "8F73A1691F6271E769329C176EE3EA48F52786AF12A3E16259007EED2A0F0CC3CB965F4AB5318483015723CCE1C0B48AB6C4DED6E251869393B01E4EC532FC88D4A128B92F4CDB34719B171923";
- }
-
- @Override
- public String getKey() {
- return "07a7159d3bf51a0e53be7a8f89699be7";
- }
-
- @Override
- public String getTopic() {
- return "test";
- }
-
- @Override
- public Optional<String> getHost() {
- return Optional.of("http://test");
- }
- };
-
- public DmaapPublisherTest() throws IOException {}
-
- @Test(expected = ProcessingException.class)
- public void sendTest() throws Exception {
- dmaapPublisher.send("{'key': 'value'}");
- }
-
-}