summaryrefslogtreecommitdiffstats
path: root/common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/test')
-rw-r--r--common/src/test/java/org/onap/so/BeansTest.java76
-rw-r--r--common/src/test/java/org/onap/so/NonSpringSuite.java1
-rw-r--r--common/src/test/java/org/onap/so/SpringSuite.java1
-rw-r--r--common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java63
-rw-r--r--common/src/test/java/org/onap/so/client/HttpClientTest.java85
-rw-r--r--common/src/test/java/org/onap/so/client/RestClientTest.java80
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java64
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java225
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java100
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java119
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java36
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java170
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java326
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java140
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java59
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java150
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java219
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIURITest.java21
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java52
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java135
-rw-r--r--common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java159
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java131
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java46
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java26
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java64
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java156
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java74
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java32
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java69
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java309
-rw-r--r--common/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java26
-rw-r--r--common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java5
-rw-r--r--common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java65
-rw-r--r--common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java23
-rw-r--r--common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java104
-rw-r--r--common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java16
-rw-r--r--common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java8
-rw-r--r--common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java138
-rw-r--r--common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java32
-rw-r--r--common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java36
-rw-r--r--common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java128
-rw-r--r--common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java107
-rw-r--r--common/src/test/java/org/onap/so/client/grm/exception/GRMClientCallFailedTest.java1
-rw-r--r--common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java195
-rw-r--r--common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java36
-rw-r--r--common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java129
-rw-r--r--common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java36
-rw-r--r--common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java120
-rw-r--r--common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java47
-rw-r--r--common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java128
-rw-r--r--common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java36
-rw-r--r--common/src/test/java/org/onap/so/configuration/rest/BasicHttpHeadersProviderTest.java2
-rw-r--r--common/src/test/java/org/onap/so/configuration/rest/HttpComponentsClientConfigurationTest.java1
-rw-r--r--common/src/test/java/org/onap/so/constants/DefaultsTest.java11
-rw-r--r--common/src/test/java/org/onap/so/entity/MsoRequestTest.java10
-rw-r--r--common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java8
-rw-r--r--common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java54
-rw-r--r--common/src/test/java/org/onap/so/serviceinstancebeans/RequestStatusTest.java27
-rw-r--r--common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java68
-rw-r--r--common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java28
-rw-r--r--common/src/test/java/org/onap/so/test/categories/SpringAware.java2
-rw-r--r--common/src/test/java/org/onap/so/utils/CheckResultsTest.java41
-rw-r--r--common/src/test/java/org/onap/so/utils/TestAppender.java13
-rw-r--r--common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java19
-rw-r--r--common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java16
-rw-r--r--common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java52
66 files changed, 2435 insertions, 2521 deletions
diff --git a/common/src/test/java/org/onap/so/BeansTest.java b/common/src/test/java/org/onap/so/BeansTest.java
index 54cbced563..8bde3c4eb7 100644
--- a/common/src/test/java/org/onap/so/BeansTest.java
+++ b/common/src/test/java/org/onap/so/BeansTest.java
@@ -24,17 +24,14 @@ import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.onap.so.openpojo.rules.HasAnnotationMatcher.hasAnnotation;
import static org.onap.so.openpojo.rules.HasAnnotationPropertyWithValueMatcher.hasAnnotationPropertyWithValue;
-
import javax.persistence.Column;
import javax.persistence.Temporal;
-
import org.junit.Test;
import org.onap.so.openpojo.rules.CustomSetterMustExistRule;
import org.onap.so.openpojo.rules.EqualsAndHashCodeTester;
import org.onap.so.openpojo.rules.HasEqualsAndHashCodeRule;
import org.onap.so.openpojo.rules.HasToStringRule;
import org.onap.so.openpojo.rules.ToStringTester;
-
import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.PojoClassFilter;
import com.openpojo.reflection.filters.FilterEnum;
@@ -55,42 +52,39 @@ import com.openpojo.validation.test.impl.SetterTester;
public class BeansTest {
- private PojoClassFilter filterTestClasses = new FilterTestClasses();
-
- private PojoClassFilter enumFilter = new FilterEnum();
-
-
-
- @Test
- public void pojoStructure() {
- test("org.onap.so.client.policy.entities");
- test("org.onap.so.client.grm.beans");
- test("org.onap.so.client.ruby.beans");
- test("org.onap.so.client.sdno.beans");
- test("org.onap.so.entity");
- test("org.onap.so.serviceinstancebeans");
- }
-
- private void test(String pojoPackage) {
- Validator validator = ValidatorBuilder.create()
- .with(new GetterMustExistRule())
- .with(new NoNestedClassRule())
- .with(new NoStaticExceptFinalRule())
- .with(new SerializableMustHaveSerialVersionUIDRule())
- .with(new NoPublicFieldsExceptStaticFinalRule())
- .with(new SetterTester())
- .with(new GetterTester())
-
-
-
- .build();
-
-
- validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete());
- }
- private static class FilterTestClasses implements PojoClassFilter {
- public boolean include(PojoClass pojoClass) {
- return !pojoClass.getSourcePath().contains("/test-classes/");
- }
- }
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ private PojoClassFilter enumFilter = new FilterEnum();
+
+
+
+ @Test
+ public void pojoStructure() {
+ test("org.onap.so.client.policy.entities");
+ test("org.onap.so.client.grm.beans");
+ test("org.onap.so.client.ruby.beans");
+ test("org.onap.so.client.sdno.beans");
+ test("org.onap.so.entity");
+ test("org.onap.so.serviceinstancebeans");
+ }
+
+ private void test(String pojoPackage) {
+ Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new NoNestedClassRule())
+ .with(new NoStaticExceptFinalRule()).with(new SerializableMustHaveSerialVersionUIDRule())
+ .with(new NoPublicFieldsExceptStaticFinalRule()).with(new SetterTester()).with(new GetterTester())
+
+
+
+ .build();
+
+
+ validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses, enumFilter,
+ new FilterNonConcrete());
+ }
+
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
}
diff --git a/common/src/test/java/org/onap/so/NonSpringSuite.java b/common/src/test/java/org/onap/so/NonSpringSuite.java
index 86bb421123..f7a36768b2 100644
--- a/common/src/test/java/org/onap/so/NonSpringSuite.java
+++ b/common/src/test/java/org/onap/so/NonSpringSuite.java
@@ -22,7 +22,6 @@ package org.onap.so;
import org.junit.runner.RunWith;
import org.onap.so.test.categories.SpringAware;
-
import com.googlecode.junittoolbox.ExcludeCategories;
import com.googlecode.junittoolbox.SuiteClasses;
import com.googlecode.junittoolbox.WildcardPatternSuite;
diff --git a/common/src/test/java/org/onap/so/SpringSuite.java b/common/src/test/java/org/onap/so/SpringSuite.java
index 93d4d31f5c..1bd019f69b 100644
--- a/common/src/test/java/org/onap/so/SpringSuite.java
+++ b/common/src/test/java/org/onap/so/SpringSuite.java
@@ -22,7 +22,6 @@ package org.onap.so;
import org.junit.runner.RunWith;
import org.onap.so.test.categories.SpringAware;
-
import com.googlecode.junittoolbox.IncludeCategories;
import com.googlecode.junittoolbox.SuiteClasses;
import com.googlecode.junittoolbox.WildcardPatternSuite;
diff --git a/common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java b/common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java
index 418220778a..1c7c472830 100644
--- a/common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java
+++ b/common/src/test/java/org/onap/so/adapter_utils/tests/CryptoTest.java
@@ -24,12 +24,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
import java.security.GeneralSecurityException;
-
import org.junit.BeforeClass;
import org.junit.Test;
-
import org.onap.so.utils.CryptoUtils;
/**
@@ -39,45 +36,45 @@ import org.onap.so.utils.CryptoUtils;
*/
public class CryptoTest {
- private static String testKey = "546573746F736973546573746F736973";
+ private static String testKey = "546573746F736973546573746F736973";
- /**
- * This method is called before any test occurs.
- * It creates a fake tree from scratch
+ /**
+ * This method is called before any test occurs. It creates a fake tree from scratch
*/
@BeforeClass
- public static final void prepare () {
-
+ public static final void prepare() {
+
}
/**
* This method implements a test of tree structure, mainly the storage of the leaves structure.
- * @throws GeneralSecurityException
+ *
+ * @throws GeneralSecurityException
*/
@Test
- public final void testEncryption () throws GeneralSecurityException {
- String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes());
-
- final String testData = "This is a test string";
- final String nonTestData = "This is not the right String";
-
- String encodeString = CryptoUtils.encrypt(testData, testKey);
-
- assertNotNull(encodeString);
-
- assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey)));
- assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey)));
-
- String encode2String = CryptoUtils.encrypt(testData, testKey);
- assertNotNull(encode2String);
-
- assertEquals(CryptoUtils.decrypt(encodeString, testKey),CryptoUtils.decrypt(encode2String, testKey));
-
- encodeString = CryptoUtils.encryptCloudConfigPassword(testData);
-
- assertEquals(testData, CryptoUtils.decryptCloudConfigPassword(encodeString));
-
- System.out.println(CryptoUtils.encrypt("poBpmn:password1$", "aa3871669d893c7fb8abbcda31b88b4f"));
+ public final void testEncryption() throws GeneralSecurityException {
+ String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes());
+
+ final String testData = "This is a test string";
+ final String nonTestData = "This is not the right String";
+
+ String encodeString = CryptoUtils.encrypt(testData, testKey);
+
+ assertNotNull(encodeString);
+
+ assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey)));
+ assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey)));
+
+ String encode2String = CryptoUtils.encrypt(testData, testKey);
+ assertNotNull(encode2String);
+
+ assertEquals(CryptoUtils.decrypt(encodeString, testKey), CryptoUtils.decrypt(encode2String, testKey));
+
+ encodeString = CryptoUtils.encryptCloudConfigPassword(testData);
+
+ assertEquals(testData, CryptoUtils.decryptCloudConfigPassword(encodeString));
+
+ System.out.println(CryptoUtils.encrypt("poBpmn:password1$", "aa3871669d893c7fb8abbcda31b88b4f"));
}
}
diff --git a/common/src/test/java/org/onap/so/client/HttpClientTest.java b/common/src/test/java/org/onap/so/client/HttpClientTest.java
index 346bf1426d..b12ed5956a 100644
--- a/common/src/test/java/org/onap/so/client/HttpClientTest.java
+++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java
@@ -28,80 +28,73 @@ import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
-
import java.net.MalformedURLException;
import java.net.URL;
-
import org.junit.Rule;
import org.junit.Test;
import org.onap.so.utils.TargetEntity;
-
import com.github.tomakehurst.wiremock.junit.WireMockRule;
-public class HttpClientTest{
+public class HttpClientTest {
- private final HttpClientFactory httpClientFactory = new HttpClientFactory();
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicHttpsPort());
+ private final HttpClientFactory httpClientFactory = new HttpClientFactory();
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicHttpsPort());
- @Test
- public void testPost_success() throws MalformedURLException{
+ @Test
+ public void testPost_success() throws MalformedURLException {
- wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
- .willReturn(aResponse().withStatus(200)
- .withHeader("Content-Type", "application/json")
- .withBody("")));
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("")));
- URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
- HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
+ URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
- client.addBasicAuthHeader("97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF", "123");
- client.addAdditionalHeader("Accept", "application/json");
+ client.addBasicAuthHeader(
+ "97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF",
+ "123");
+ client.addAdditionalHeader("Accept", "application/json");
- client.post("{}");
+ client.post("{}");
- verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post")));
- }
+ verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post")));
+ }
@Test
- public void testPost_nullHeader() throws MalformedURLException{
+ public void testPost_nullHeader() throws MalformedURLException {
- wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
- .willReturn(aResponse().withStatus(200)
- .withHeader("Content-Type", "application/json")
- .withBody("")));
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("")));
- URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
- HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
+ URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
- client.addAdditionalHeader("Accept", "application/json");
- client.addAdditionalHeader("id", null);
+ client.addAdditionalHeader("Accept", "application/json");
+ client.addAdditionalHeader("id", null);
- client.post("{}");
+ client.post("{}");
- verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post"))
- .withHeader("Accept", equalTo("application/json")));
- }
+ verify(exactly(1),
+ postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/json")));
+ }
@Test
- public void testPost_nullBasicAuth() throws MalformedURLException{
+ public void testPost_nullBasicAuth() throws MalformedURLException {
- wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
- .willReturn(aResponse().withStatus(200)
- .withHeader("Content-Type", "application/json")
- .withBody("")));
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
+ .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("")));
- URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
- HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
+ URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
+ HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
- client.addBasicAuthHeader("", "12345");
- client.addAdditionalHeader("Accept", "application/json");
+ client.addBasicAuthHeader("", "12345");
+ client.addAdditionalHeader("Accept", "application/json");
- client.post("{}");
+ client.post("{}");
- verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post"))
- .withHeader("Accept", equalTo("application/json")));
- }
+ verify(exactly(1),
+ postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/json")));
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java
index 06196fd73e..b550079607 100644
--- a/common/src/test/java/org/onap/so/client/RestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/RestClientTest.java
@@ -28,15 +28,12 @@ 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.net.MalformedURLException;
import java.net.SocketTimeoutException;
-
import javax.ws.rs.NotFoundException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriBuilderException;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -48,44 +45,45 @@ import org.mockito.junit.MockitoJUnitRunner;
public class RestClientTest {
- private final HttpClientFactory httpClientFactory = new HttpClientFactory();
- @Mock
- private RestProperties props;
+ private final HttpClientFactory httpClientFactory = new HttpClientFactory();
+ @Mock
+ private RestProperties props;
+
+
+ @Test
+ public void retries() throws Exception {
+ RestClient spy = buildSpy();
+ RestRequest mockCallable = mock(RestRequest.class);
+ when(mockCallable.call()).thenThrow(new WebApplicationException(new SocketTimeoutException()));
+ doReturn(mockCallable).when(spy).buildRequest(any(String.class), ArgumentMatchers.isNull());
+ try {
+ spy.get();
+ } catch (Exception e) {
+ // we expect an exception, ignore it
+ }
+ verify(mockCallable, times(3)).call();
+
+ }
+
+ @Test
+ public void exceptionDoNotRetry() throws Exception {
+ RestClient spy = buildSpy();
+ RestRequest mockCallable = mock(RestRequest.class);
+ when(mockCallable.call()).thenThrow(new WebApplicationException(new NotFoundException()));
+ doReturn(mockCallable).when(spy).buildRequest(any(String.class), ArgumentMatchers.isNull());
+ try {
+ spy.get();
+ } catch (Exception e) {
+ // we expect an exception, ignore it
+ }
+ verify(mockCallable, times(1)).call();
+
+ }
+ private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException {
+ RestClient client = httpClientFactory.newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(),
+ TargetEntity.BPMN);
- @Test
- public void retries() throws Exception {
- RestClient spy = buildSpy();
- RestRequest mockCallable = mock(RestRequest.class);
- when(mockCallable.call()).thenThrow(new WebApplicationException(new SocketTimeoutException()));
- doReturn(mockCallable).when(spy).buildRequest(any(String.class), ArgumentMatchers.isNull());
- try {
- spy.get();
- } catch (Exception e) {
- //we expect an exception, ignore it
- }
- verify(mockCallable, times(3)).call();
-
- }
-
- @Test
- public void exceptionDoNotRetry() throws Exception {
- RestClient spy = buildSpy();
- RestRequest mockCallable = mock(RestRequest.class);
- when(mockCallable.call()).thenThrow(new WebApplicationException(new NotFoundException()));
- doReturn(mockCallable).when(spy).buildRequest(any(String.class), ArgumentMatchers.isNull());
- try {
- spy.get();
- } catch (Exception e) {
- //we expect an exception, ignore it
- }
- verify(mockCallable, times(1)).call();
-
- }
- private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException {
- RestClient client = httpClientFactory
- .newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), TargetEntity.BPMN);
-
- return spy(client);
- }
+ return spy(client);
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java b/common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java
index 981a4ddacc..7af36b0bdd 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java
@@ -21,50 +21,48 @@
package org.onap.so.client.aai;
import static org.junit.Assert.assertEquals;
-
import java.util.Arrays;
import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
import org.onap.so.client.aai.entities.AAIError;
import org.onap.so.client.aai.entities.RequestError;
import org.onap.so.client.aai.entities.ServiceException;
-
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class AAIClientResponseExceptionMapperTest {
- AAIClientResponseExceptionMapper mapper;
- String errorMsg;
-
- @Before
- public void before() {
- mapper = new AAIClientResponseExceptionMapper();
- errorMsg = "Error calling A&AI. Request-Id=" + mapper.getRequestId() + " ";
- }
-
- @Test
- public void testExtractMessageWithEntity() throws JsonProcessingException {
- ServiceException svcException = new ServiceException();
- svcException.setText("test %1 message - %2");
- svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
-
- RequestError requestError = new RequestError();
- requestError.setServiceException(svcException);
-
- AAIError error = new AAIError();
- error.setRequestError(requestError);
-
- ObjectMapper objMapper = new ObjectMapper();
- String strRequestError = objMapper.writeValueAsString(error);
+ AAIClientResponseExceptionMapper mapper;
+ String errorMsg;
+
+ @Before
+ public void before() {
+ mapper = new AAIClientResponseExceptionMapper();
+ errorMsg = "Error calling A&AI. Request-Id=" + mapper.getRequestId() + " ";
+ }
+
+ @Test
+ public void testExtractMessageWithEntity() throws JsonProcessingException {
+ ServiceException svcException = new ServiceException();
+ svcException.setText("test %1 message - %2");
+ svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
+
+ RequestError requestError = new RequestError();
+ requestError.setServiceException(svcException);
+
+ AAIError error = new AAIError();
+ error.setRequestError(requestError);
+
+ ObjectMapper objMapper = new ObjectMapper();
+ String strRequestError = objMapper.writeValueAsString(error);
+
+ assertEquals(errorMsg + "test error message - service exception error test",
+ mapper.extractMessage(strRequestError).get());
+ }
- assertEquals(errorMsg + "test error message - service exception error test", mapper.extractMessage(strRequestError).get());
- }
-
- @Test
- public void testExtractMessageWithoutEntity() {
- assertEquals(errorMsg, mapper.extractMessage("").get());
- }
+ @Test
+ public void testExtractMessageWithoutEntity() {
+ assertEquals(errorMsg, mapper.extractMessage("").get());
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java
index 525dff7562..cf87355ec7 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java
@@ -26,10 +26,8 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-
import java.util.Optional;
import java.util.UUID;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -40,116 +38,119 @@ import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.RequestDetails;
-@RunWith(MockitoJUnitRunner.class)
+
+@RunWith(MockitoJUnitRunner.class)
public class AAIConfigurationClientTest {
- @Mock
- AAIResourcesClient aaiClient;
-
- @InjectMocks
- AAIConfigurationClient aaiConfigurationClient = new AAIConfigurationClient();
-
- @Test
- public void verifyCreate() {
- ModelInfo modelInfo = new ModelInfo();
- modelInfo.setModelInvariantId("testInvariantID");
- modelInfo.setModelVersionId("testVersionID");
- modelInfo.setModelCustomizationId("testCustomizationID");
-
- RequestDetails requestDetails = new RequestDetails();
- requestDetails.setModelInfo(modelInfo);
-
- String configurationId = UUID.randomUUID().toString();
- String configurationType = "test";
- String configurationSubType = "test";
-
- // Test Create Configuration
- doNothing().when(aaiClient).create(isA(AAIResourceUri.class), isA(Object.class));
- aaiConfigurationClient.createConfiguration(requestDetails, configurationId, configurationType, configurationSubType);
- verify(aaiClient, times(1)).create(isA(AAIResourceUri.class), isA(Object.class));
- }
-
- @Test
- public void verifyConfigurePayload() {
- ModelInfo modelInfo = new ModelInfo();
- modelInfo.setModelInvariantId("testInvariantID");
- modelInfo.setModelVersionId("testVersionID");
- modelInfo.setModelCustomizationId("testCustomizationID");
-
- RequestDetails requestDetails = new RequestDetails();
- requestDetails.setModelInfo(modelInfo);
-
- String configurationId = UUID.randomUUID().toString();
- String configurationType = "test";
- String configurationSubType = "test";
- AAIResourceUri uri = aaiConfigurationClient.getConfigurationURI(configurationId);
-
- Configuration payload = aaiConfigurationClient.configurePayload(requestDetails, configurationId, configurationType, configurationSubType);
-
- assertEquals(configurationId, payload.getConfigurationId());
- assertEquals(configurationType, payload.getConfigurationType());
- assertEquals(configurationSubType, payload.getConfigurationSubType());
- assertEquals(uri.build().getPath(), payload.getConfigurationSelflink());
- assertEquals("PreCreated", payload.getOrchestrationStatus());
- assertEquals("", payload.getOperationalStatus());
- assertEquals(modelInfo.getModelVersionId(), payload.getModelVersionId());
- assertEquals(modelInfo.getModelInvariantId(), payload.getModelInvariantId());
- assertEquals(modelInfo.getModelCustomizationId(), payload.getModelCustomizationId());
- }
-
- @Test
- public void testDeleteConfiguration() {
- String uuid = UUID.randomUUID().toString();
- doNothing().when(aaiClient).delete(isA(AAIResourceUri.class));
- aaiConfigurationClient.deleteConfiguration(uuid);
- verify(aaiClient, times(1)).delete(aaiConfigurationClient.getConfigurationURI(uuid));
- }
-
- @Test
- public void testUpdateOrchestrationStatus() {
- String uuid = UUID.randomUUID().toString();
- doNothing().when(aaiClient).update(isA(AAIResourceUri.class), isA(Object.class));
- aaiConfigurationClient.updateOrchestrationStatus(uuid, "testPayload");
- verify(aaiClient, times(1)).update(aaiConfigurationClient.getConfigurationURI(uuid), "testPayload");
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testGetConfiguration() {
- String uuid = UUID.randomUUID().toString();
- Optional<Configuration> expectedConfiguration = Optional.of(new Configuration());
- expectedConfiguration.get().setConfigurationId(uuid);
-
- doReturn(expectedConfiguration).when(aaiClient).get(isA(Class.class), isA(AAIResourceUri.class));
- Configuration actualConfiguration = aaiConfigurationClient.getConfiguration(uuid);
- verify(aaiClient, times(1)).get(Configuration.class, aaiConfigurationClient.getConfigurationURI(uuid));
- assertEquals(expectedConfiguration.get(), actualConfiguration);
- }
-
- @Test
- public void testConfigurationExists() {
- String uuid = UUID.randomUUID().toString();
- AAIResourceUri uri = aaiConfigurationClient.getConfigurationURI(uuid);
- boolean expectedResult;
- boolean actualResult;
-
- expectedResult = true;
- doReturn(expectedResult).when(aaiClient).exists(isA(AAIResourceUri.class));
- actualResult = aaiConfigurationClient.configurationExists(uuid);
- assertEquals(expectedResult, actualResult);
-
- expectedResult = false;
- doReturn(expectedResult).when(aaiClient).exists(isA(AAIResourceUri.class));
- actualResult = aaiConfigurationClient.configurationExists(uuid);
- assertEquals(expectedResult, actualResult);
-
- verify(aaiClient, times(2)).exists(uri);
- }
-
- @Test
- public void testGetConfigurationURI() {
- String uuid = UUID.randomUUID().toString();
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, uuid);
- assertEquals(uri, aaiConfigurationClient.getConfigurationURI(uuid));
- }
+ @Mock
+ AAIResourcesClient aaiClient;
+
+ @InjectMocks
+ AAIConfigurationClient aaiConfigurationClient = new AAIConfigurationClient();
+
+ @Test
+ public void verifyCreate() {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelInvariantId("testInvariantID");
+ modelInfo.setModelVersionId("testVersionID");
+ modelInfo.setModelCustomizationId("testCustomizationID");
+
+ RequestDetails requestDetails = new RequestDetails();
+ requestDetails.setModelInfo(modelInfo);
+
+ String configurationId = UUID.randomUUID().toString();
+ String configurationType = "test";
+ String configurationSubType = "test";
+
+ // Test Create Configuration
+ doNothing().when(aaiClient).create(isA(AAIResourceUri.class), isA(Object.class));
+ aaiConfigurationClient.createConfiguration(requestDetails, configurationId, configurationType,
+ configurationSubType);
+ verify(aaiClient, times(1)).create(isA(AAIResourceUri.class), isA(Object.class));
+ }
+
+ @Test
+ public void verifyConfigurePayload() {
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelInvariantId("testInvariantID");
+ modelInfo.setModelVersionId("testVersionID");
+ modelInfo.setModelCustomizationId("testCustomizationID");
+
+ RequestDetails requestDetails = new RequestDetails();
+ requestDetails.setModelInfo(modelInfo);
+
+ String configurationId = UUID.randomUUID().toString();
+ String configurationType = "test";
+ String configurationSubType = "test";
+ AAIResourceUri uri = aaiConfigurationClient.getConfigurationURI(configurationId);
+
+ Configuration payload = aaiConfigurationClient.configurePayload(requestDetails, configurationId,
+ configurationType, configurationSubType);
+
+ assertEquals(configurationId, payload.getConfigurationId());
+ assertEquals(configurationType, payload.getConfigurationType());
+ assertEquals(configurationSubType, payload.getConfigurationSubType());
+ assertEquals(uri.build().getPath(), payload.getConfigurationSelflink());
+ assertEquals("PreCreated", payload.getOrchestrationStatus());
+ assertEquals("", payload.getOperationalStatus());
+ assertEquals(modelInfo.getModelVersionId(), payload.getModelVersionId());
+ assertEquals(modelInfo.getModelInvariantId(), payload.getModelInvariantId());
+ assertEquals(modelInfo.getModelCustomizationId(), payload.getModelCustomizationId());
+ }
+
+ @Test
+ public void testDeleteConfiguration() {
+ String uuid = UUID.randomUUID().toString();
+ doNothing().when(aaiClient).delete(isA(AAIResourceUri.class));
+ aaiConfigurationClient.deleteConfiguration(uuid);
+ verify(aaiClient, times(1)).delete(aaiConfigurationClient.getConfigurationURI(uuid));
+ }
+
+ @Test
+ public void testUpdateOrchestrationStatus() {
+ String uuid = UUID.randomUUID().toString();
+ doNothing().when(aaiClient).update(isA(AAIResourceUri.class), isA(Object.class));
+ aaiConfigurationClient.updateOrchestrationStatus(uuid, "testPayload");
+ verify(aaiClient, times(1)).update(aaiConfigurationClient.getConfigurationURI(uuid), "testPayload");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetConfiguration() {
+ String uuid = UUID.randomUUID().toString();
+ Optional<Configuration> expectedConfiguration = Optional.of(new Configuration());
+ expectedConfiguration.get().setConfigurationId(uuid);
+
+ doReturn(expectedConfiguration).when(aaiClient).get(isA(Class.class), isA(AAIResourceUri.class));
+ Configuration actualConfiguration = aaiConfigurationClient.getConfiguration(uuid);
+ verify(aaiClient, times(1)).get(Configuration.class, aaiConfigurationClient.getConfigurationURI(uuid));
+ assertEquals(expectedConfiguration.get(), actualConfiguration);
+ }
+
+ @Test
+ public void testConfigurationExists() {
+ String uuid = UUID.randomUUID().toString();
+ AAIResourceUri uri = aaiConfigurationClient.getConfigurationURI(uuid);
+ boolean expectedResult;
+ boolean actualResult;
+
+ expectedResult = true;
+ doReturn(expectedResult).when(aaiClient).exists(isA(AAIResourceUri.class));
+ actualResult = aaiConfigurationClient.configurationExists(uuid);
+ assertEquals(expectedResult, actualResult);
+
+ expectedResult = false;
+ doReturn(expectedResult).when(aaiClient).exists(isA(AAIResourceUri.class));
+ actualResult = aaiConfigurationClient.configurationExists(uuid);
+ assertEquals(expectedResult, actualResult);
+
+ verify(aaiClient, times(2)).exists(uri);
+ }
+
+ @Test
+ public void testGetConfigurationURI() {
+ String uuid = UUID.randomUUID().toString();
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, uuid);
+ assertEquals(uri, aaiConfigurationClient.getConfigurationURI(uuid));
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java b/common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java
index bea927afa5..2ef50dd77b 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java
@@ -22,11 +22,9 @@ package org.onap.so.client.aai;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -37,52 +35,54 @@ import org.onap.so.client.aai.entities.ServiceException;
public class AAIErrorFormatterTest {
- @Mock private AAIError errorObj;
-
- @Before
- public void init() {
- MockitoAnnotations.initMocks(this);
- }
- @Test
- public void testFillInTemplateWithReplace() {
- String error = "Error %1 on %2";
- List<String> list = Arrays.asList("PUT", "hello %1");
- AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
- String result = formatter.fillInTemplate(error, list);
- assertEquals("equal", "Error PUT on hello PUT", result);
-
- }
-
- @Test
- public void testFillInTemplateWithoutReplace() {
- String error = "Error";
- List<String> list = new ArrayList<>();
- AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
- String result = formatter.fillInTemplate(error, list);
- assertEquals("equal", "Error", result);
- }
-
- @Test
- public void testGetMessage() {
- ServiceException svcException = new ServiceException();
- svcException.setText("test %1 message - %2");
- svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
-
- RequestError requestError = new RequestError();
- requestError.setServiceException(svcException);
-
- doReturn(requestError).when(errorObj).getRequestError();
-
- AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
- String result = formatter.getMessage();
- assertEquals("equal", "test error message - service exception error test", result);
- }
-
- @Test
- public void testGetMessageNoParsable() {
- errorObj.setRequestError(null);
- AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
- String result = formatter.getMessage();
- assertEquals("equal", "no parsable error message found", result);
- }
+ @Mock
+ private AAIError errorObj;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testFillInTemplateWithReplace() {
+ String error = "Error %1 on %2";
+ List<String> list = Arrays.asList("PUT", "hello %1");
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.fillInTemplate(error, list);
+ assertEquals("equal", "Error PUT on hello PUT", result);
+
+ }
+
+ @Test
+ public void testFillInTemplateWithoutReplace() {
+ String error = "Error";
+ List<String> list = new ArrayList<>();
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.fillInTemplate(error, list);
+ assertEquals("equal", "Error", result);
+ }
+
+ @Test
+ public void testGetMessage() {
+ ServiceException svcException = new ServiceException();
+ svcException.setText("test %1 message - %2");
+ svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
+
+ RequestError requestError = new RequestError();
+ requestError.setServiceException(svcException);
+
+ doReturn(requestError).when(errorObj).getRequestError();
+
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.getMessage();
+ assertEquals("equal", "test error message - service exception error test", result);
+ }
+
+ @Test
+ public void testGetMessageNoParsable() {
+ errorObj.setRequestError(null);
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.getMessage();
+ assertEquals("equal", "no parsable error message found", result);
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java b/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java
index 64a83f92ab..8f449c21f3 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java
@@ -21,70 +21,71 @@
package org.onap.so.client.aai;
import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import org.onap.so.client.aai.entities.uri.AAIUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
public class AAIObjectTypeTest {
-
- @Test
- public void fromTypeNameTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException {
- AAIObjectType type = AAIObjectType.fromTypeName("allotted-resource");
- assertEquals("allotted-resource", type.typeName());
-
- }
-
- @Test
- public void customTypeTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException {
- AAIObjectType type = AAIObjectType.fromTypeName("my-custom-name");
- assertEquals("my-custom-name", type.typeName());
- }
- @Test
- public void verifyDefaultCase() {
- assertEquals("default removed for tenant", "tenant", AAIObjectType.DEFAULT_TENANT.typeName());
- assertEquals("default removed for cloud-region", "cloud-region", AAIObjectType.DEFAULT_CLOUD_REGION.typeName());
- }
-
- @Test
- public void verifyRegularCase() {
- assertEquals("default removed for tenant", "allotted-resource", AAIObjectType.ALLOTTED_RESOURCE.typeName());
- }
-
- @Test
- public void instanceGroupObjectTypeTest() {
- final String id = "test1";
- AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, id);
- assertEquals("/network/instance-groups/instance-group/test1", aaiUri.build().toString());
- }
-
- @Test
- public void collectionObjectTypeTest() {
- final String id = "test1";
- AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, id);
- assertEquals("/network/collections/collection/test1", aaiUri.build().toString());
- }
-
- @Test
- public void genericVnfTest() {
- AAIObjectType type = AAIObjectType.GENERIC_VNF;
- assertEquals("/network/generic-vnfs/generic-vnf/{vnf-id}", type.uriTemplate());
- assertEquals("/generic-vnfs/generic-vnf/{vnf-id}", type.partialUri());
- }
-
- @Test
- public void pInterfaceTest() {
- AAIObjectType type = AAIObjectType.P_INTERFACE;
- assertEquals("/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name}", type.uriTemplate());
- assertEquals("/p-interfaces/p-interface/{interface-name}", type.partialUri());
- }
-
- @Test
- public void networkPolicyObjectTypeTest() {
- final String id = "test1";
- AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, id);
- assertEquals("/network/network-policies/network-policy/test1", aaiUri.build().toString());
- }
+ @Test
+ public void fromTypeNameTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException {
+ AAIObjectType type = AAIObjectType.fromTypeName("allotted-resource");
+ assertEquals("allotted-resource", type.typeName());
+
+ }
+
+ @Test
+ public void customTypeTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException {
+ AAIObjectType type = AAIObjectType.fromTypeName("my-custom-name");
+ assertEquals("my-custom-name", type.typeName());
+
+ }
+
+ @Test
+ public void verifyDefaultCase() {
+ assertEquals("default removed for tenant", "tenant", AAIObjectType.DEFAULT_TENANT.typeName());
+ assertEquals("default removed for cloud-region", "cloud-region", AAIObjectType.DEFAULT_CLOUD_REGION.typeName());
+ }
+
+ @Test
+ public void verifyRegularCase() {
+ assertEquals("default removed for tenant", "allotted-resource", AAIObjectType.ALLOTTED_RESOURCE.typeName());
+ }
+
+ @Test
+ public void instanceGroupObjectTypeTest() {
+ final String id = "test1";
+ AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, id);
+ assertEquals("/network/instance-groups/instance-group/test1", aaiUri.build().toString());
+ }
+
+ @Test
+ public void collectionObjectTypeTest() {
+ final String id = "test1";
+ AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, id);
+ assertEquals("/network/collections/collection/test1", aaiUri.build().toString());
+ }
+
+ @Test
+ public void genericVnfTest() {
+ AAIObjectType type = AAIObjectType.GENERIC_VNF;
+ assertEquals("/network/generic-vnfs/generic-vnf/{vnf-id}", type.uriTemplate());
+ assertEquals("/generic-vnfs/generic-vnf/{vnf-id}", type.partialUri());
+ }
+
+ @Test
+ public void pInterfaceTest() {
+ AAIObjectType type = AAIObjectType.P_INTERFACE;
+ assertEquals("/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name}",
+ type.uriTemplate());
+ assertEquals("/p-interfaces/p-interface/{interface-name}", type.partialUri());
+ }
+
+ @Test
+ public void networkPolicyObjectTypeTest() {
+ final String id = "test1";
+ AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, id);
+ assertEquals("/network/network-policies/network-policy/test1", aaiUri.build().toString());
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java b/common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java
index ba48e4368d..4b3b7e9881 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIPServerTest.java
@@ -21,7 +21,6 @@
package org.onap.so.client.aai;
import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -29,24 +28,25 @@ import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.onap.aai.domain.yang.Pserver;
+
public class AAIPServerTest {
- @Test
- public void pserverTest() throws IOException {
- AAIRestClientImpl client = new AAIRestClientImpl();
- String json = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/aai/pserver.json")));
- List<Pserver> list = client.getListOfPservers(json);
-
- assertEquals("", list.get(0).getHostname(), "test");
- assertEquals("", list.size(), 2);
- }
-
- @Test
- @Ignore // IGNORED FOR 1710 MERGE TO ONAP
- public void pserverActualTest() throws IOException {
- AAIRestClientImpl client = new AAIRestClientImpl();
- List<Pserver> list = client.getPhysicalServerByVnfId("d946afed-8ebe-4c5d-9665-54fcc043b8e7");
- assertEquals("", list.size(), 0);
- }
+ @Test
+ public void pserverTest() throws IOException {
+ AAIRestClientImpl client = new AAIRestClientImpl();
+ String json = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/aai/pserver.json")));
+ List<Pserver> list = client.getListOfPservers(json);
+
+ assertEquals("", list.get(0).getHostname(), "test");
+ assertEquals("", list.size(), 2);
+ }
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ public void pserverActualTest() throws IOException {
+ AAIRestClientImpl client = new AAIRestClientImpl();
+ List<Pserver> list = client.getPhysicalServerByVnfId("d946afed-8ebe-4c5d-9665-54fcc043b8e7");
+ assertEquals("", list.size(), 0);
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
index e648ea38da..5b2bff277d 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
@@ -29,16 +29,13 @@ 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.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-
import javax.ws.rs.core.GenericType;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -58,88 +55,97 @@ import org.onap.so.client.graphinventory.GraphInventoryClient;
import org.onap.so.client.graphinventory.GraphInventorySubgraphType;
import org.onap.so.client.graphinventory.entities.Pathed;
import org.onap.so.client.graphinventory.entities.ResourceAndUrl;
-
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class AAIQueryClientTest {
-
- @Mock
- private RestClient restClient;
-
- @Mock
- private GraphInventoryClient client;
-
- @InjectMocks
- @Spy
- private AAIQueryClient aaiQueryClient = new AAIQueryClient();
-
- private String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/query/";
-
- private ObjectMapper mapper = new ObjectMapper();
- @Test
- public void testQuery() {
- List<AAIResourceUri> uris = Arrays.asList(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
-
- Format format = Format.SIMPLE;
- CustomQuery query = new CustomQuery(uris);
-
- doReturn(restClient).when(client).createClient(isA(AAIUri.class));
- aaiQueryClient.query(format, query);
- verify(client, times(1)).createClient(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", format.toString()));
- verify(restClient, times(1)).put(query, String.class);
- }
-
- @Test
- public void testCreateClient() {
- String depth = "testDepth";
- GraphInventorySubgraphType subgraph = GraphInventorySubgraphType.STAR;
-
- aaiQueryClient.depth(depth);
- aaiQueryClient.nodesOnly();
- aaiQueryClient.subgraph(subgraph);
-
- AAIUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
- doReturn(aaiUri).when(aaiUri).clone();
- aaiQueryClient.setupQueryParams(aaiUri);
-
- verify(aaiUri, times(1)).queryParam("depth", depth);
- verify(aaiUri, times(1)).queryParam("nodesOnly", "");
- verify(aaiUri, times(1)).queryParam("subgraph", subgraph.toString());
- }
-
- @Test
- public void querySingleResourceTest() throws IOException {
- doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL), any(CustomQuery.class));
- List<Complex> result = aaiQueryClient.querySingleResource(new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))), Complex.class);
- assertEquals(2, result.size());
- assertEquals("complex-id-15100-jc689q2", result.get(1).getPhysicalLocationId());
- }
-
- @Test
- public void getResourceAndUrlTest() throws IOException {
- doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL), any(CustomQuery.class));
- List<ResourceAndUrl<AAIResultWrapper>> result = aaiQueryClient.getResourceAndUrl(new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))));
- assertEquals(2, result.size());
-
- assertEquals(1, result.get(1).getWrapper().getRelationships().get().getRelatedUris(AAIObjectType.PSERVER).size());
- }
-
- @Test
- public void querySingleTypeTest() throws IOException {
- when(client.createClient(isA(AAIUri.class))).thenReturn(restClient);
- when(restClient.put(any(Object.class), any(GenericType.class))).thenReturn(mapper.readValue(getJson("pathed-result.json"), new TypeReference<Results<Map<String, Object>>>(){}));
-
-
- List<Pathed> results = aaiQueryClient.queryPathed(new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))));
-
- assertEquals(2, results.size());
- assertEquals("service-instance", results.get(1).getResourceType());
- }
-
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
- }
+
+ @Mock
+ private RestClient restClient;
+
+ @Mock
+ private GraphInventoryClient client;
+
+ @InjectMocks
+ @Spy
+ private AAIQueryClient aaiQueryClient = new AAIQueryClient();
+
+ private String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/query/";
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ public void testQuery() {
+ List<AAIResourceUri> uris = Arrays.asList(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
+
+ Format format = Format.SIMPLE;
+ CustomQuery query = new CustomQuery(uris);
+
+ doReturn(restClient).when(client).createClient(isA(AAIUri.class));
+ aaiQueryClient.query(format, query);
+ verify(client, times(1)).createClient(
+ AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", format.toString()));
+ verify(restClient, times(1)).put(query, String.class);
+ }
+
+ @Test
+ public void testCreateClient() {
+ String depth = "testDepth";
+ GraphInventorySubgraphType subgraph = GraphInventorySubgraphType.STAR;
+
+ aaiQueryClient.depth(depth);
+ aaiQueryClient.nodesOnly();
+ aaiQueryClient.subgraph(subgraph);
+
+ AAIUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
+ doReturn(aaiUri).when(aaiUri).clone();
+ aaiQueryClient.setupQueryParams(aaiUri);
+
+ verify(aaiUri, times(1)).queryParam("depth", depth);
+ verify(aaiUri, times(1)).queryParam("nodesOnly", "");
+ verify(aaiUri, times(1)).queryParam("subgraph", subgraph.toString());
+ }
+
+ @Test
+ public void querySingleResourceTest() throws IOException {
+ doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL),
+ any(CustomQuery.class));
+ List<Complex> result = aaiQueryClient.querySingleResource(
+ new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))),
+ Complex.class);
+ assertEquals(2, result.size());
+ assertEquals("complex-id-15100-jc689q2", result.get(1).getPhysicalLocationId());
+ }
+
+ @Test
+ public void getResourceAndUrlTest() throws IOException {
+ doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL),
+ any(CustomQuery.class));
+ List<ResourceAndUrl<AAIResultWrapper>> result = aaiQueryClient.getResourceAndUrl(
+ new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))));
+ assertEquals(2, result.size());
+
+ assertEquals(1,
+ result.get(1).getWrapper().getRelationships().get().getRelatedUris(AAIObjectType.PSERVER).size());
+ }
+
+ @Test
+ public void querySingleTypeTest() throws IOException {
+ when(client.createClient(isA(AAIUri.class))).thenReturn(restClient);
+ when(restClient.put(any(Object.class), any(GenericType.class))).thenReturn(
+ mapper.readValue(getJson("pathed-result.json"), new TypeReference<Results<Map<String, Object>>>() {}));
+
+
+ List<Pathed> results = aaiQueryClient.queryPathed(
+ new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))));
+
+ assertEquals(2, results.size());
+ assertEquals("service-instance", results.get(1).getResourceType());
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
index c63d602bca..94d14684c7 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
@@ -33,9 +33,7 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
-
import javax.ws.rs.BadRequestException;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -50,7 +48,6 @@ import org.onap.so.client.aai.entities.AAIResultWrapper;
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 com.github.tomakehurst.wiremock.admin.NotFoundException;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -58,186 +55,147 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule;
public class AAIResourcesClientTest {
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
-
- @Spy
- public AAIClient client;
-
- @InjectMocks
- public AAIResourcesClient aaiClient = new AAIResourcesClient();
-
- private String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/query/";
-
- @Before
- public void beforeTest() {
- doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
- }
-
- @Test
- public void verifyNotExists() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
- wireMockRule.stubFor(get(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "text/plain")
- .withBody("hello")
- .withStatus(404)));
- AAIResourcesClient client= aaiClient;
- boolean result = client.exists(path);
- assertEquals("path not found", false, result);
- }
-
- @Test
- public void verifyDelete() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
- wireMockRule.stubFor(get(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "application/json")
- .withBodyFile("aai/resources/mockObject.json")
- .withStatus(200)));
- wireMockRule.stubFor(delete(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
- .withQueryParam("resource-version", equalTo("1234"))
- .willReturn(
- aResponse()
- .withStatus(204)));
- AAIResourcesClient client= aaiClient;
- client.delete(path);
- }
-
- @Test
- public void verifyBasicAuth() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
- wireMockRule.stubFor(get(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
- .withHeader("Authorization", equalTo("Basic dGVzdDp0ZXN0"))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "application/json")
- .withBodyFile("aai/resources/mockObject.json")
- .withStatus(200)));
- AAIResourcesClient client= aaiClient;
- client.get(path);
- }
-
- @Test
- public void verifyConnect() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
- AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
- wireMockRule.stubFor(put(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship"))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "application/json")
- .withStatus(200)));
-
- AAIResourceUri pathClone = path.clone();
- AAIResourcesClient client= aaiClient;
- client.connect(path, path2);
- assertEquals("uri not modified", pathClone.build().toString(), path.build().toString());
- }
-
- @Test
- public void verifyDisconnect() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
- AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
-
- wireMockRule.stubFor(delete(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship"))
- .willReturn(
- aResponse()
- .withStatus(204)));
-
- AAIResourceUri pathClone = path.clone();
- AAIResourcesClient client= aaiClient;
- client.disconnect(path, path2);
- assertEquals("uri not modified", pathClone.build().toString(), path.build().toString());
- }
-
- @Test
- public void verifyPatch() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
-
- wireMockRule.stubFor(post(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
- .willReturn(
- aResponse()
- .withStatus(200)));
-
- AAIResourcesClient client= aaiClient;
-
- client.update(path, "{}");
- }
-
- @Test
- public void verifyNotExistsGet() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
- wireMockRule.stubFor(get(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "text/plain")
- .withBody("hello")
- .withStatus(404)));
- AAIResourcesClient client= aaiClient;
- AAIResultWrapper result = client.get(path);
- assertEquals("is empty", true, result.isEmpty());
- }
-
- @Test
- public void verifyNotExistsGetException() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
- wireMockRule.stubFor(get(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "text/plain")
- .withBody("hello")
- .withStatus(404)));
- AAIResourcesClient client= aaiClient;
- thrown.expect(NotFoundException.class);
- thrown.expectMessage(containsString(path.build() + " not found in A&AI"));
- AAIResultWrapper result = client.get(path, NotFoundException.class);
- }
-
- @Test
- public void verifyFailedCallException() {
- AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
- wireMockRule.stubFor(get(
- urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "text/plain")
- .withBodyFile("aai/error-message.json")
- .withStatus(400)));
- AAIResourcesClient client= aaiClient;
-
- thrown.expect(BadRequestException.class);
- thrown.expectMessage(containsString("Invalid input performing PUT on url (msg=Precondition Required:resource-version not passed for update of url"));
- AAIResultWrapper result = client.get(path);
- }
-
- @Test
- public void buildRelationshipTest() {
- AAIResourcesClient client = aaiClient;
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
- Relationship relationship = new Relationship();
- relationship.setRelatedLink(uri.build().toString());
- Relationship actual = client.buildRelationship(uri);
- assertThat("expect equal no label", actual, sameBeanAs(relationship));
-
- relationship.setRelationshipLabel(AAIEdgeLabel.USES.toString());
- actual = client.buildRelationship(uri, AAIEdgeLabel.USES);
- assertThat("expect equal has label", actual, sameBeanAs(relationship));
-
- }
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+
+ @Spy
+ public AAIClient client;
+
+ @InjectMocks
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ private String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/query/";
+
+ @Before
+ public void beforeTest() {
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
+ }
+
+ @Test
+ public void verifyNotExists() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404)));
+ AAIResourcesClient client = aaiClient;
+ boolean result = client.exists(path);
+ assertEquals("path not found", false, result);
+ }
+
+ @Test
+ public void verifyDelete() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("aai/resources/mockObject.json").withStatus(200)));
+ wireMockRule.stubFor(delete(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .withQueryParam("resource-version", equalTo("1234")).willReturn(aResponse().withStatus(204)));
+ AAIResourcesClient client = aaiClient;
+ client.delete(path);
+ }
+
+ @Test
+ public void verifyBasicAuth() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
+ .withHeader("Authorization", equalTo("Basic dGVzdDp0ZXN0"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("aai/resources/mockObject.json").withStatus(200)));
+ AAIResourcesClient client = aaiClient;
+ client.get(path);
+ }
+
+ @Test
+ public void verifyConnect() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+ AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+ wireMockRule.stubFor(
+ put(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(200)));
+
+ AAIResourceUri pathClone = path.clone();
+ AAIResourcesClient client = aaiClient;
+ client.connect(path, path2);
+ assertEquals("uri not modified", pathClone.build().toString(), path.build().toString());
+ }
+
+ @Test
+ public void verifyDisconnect() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+ AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+
+ wireMockRule.stubFor(
+ delete(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship"))
+ .willReturn(aResponse().withStatus(204)));
+
+ AAIResourceUri pathClone = path.clone();
+ AAIResourcesClient client = aaiClient;
+ client.disconnect(path, path2);
+ assertEquals("uri not modified", pathClone.build().toString(), path.build().toString());
+ }
+
+ @Test
+ public void verifyPatch() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+
+ wireMockRule.stubFor(post(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withStatus(200)));
+
+ AAIResourcesClient client = aaiClient;
+
+ client.update(path, "{}");
+ }
+
+ @Test
+ public void verifyNotExistsGet() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404)));
+ AAIResourcesClient client = aaiClient;
+ AAIResultWrapper result = client.get(path);
+ assertEquals("is empty", true, result.isEmpty());
+ }
+
+ @Test
+ public void verifyNotExistsGetException() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404)));
+ AAIResourcesClient client = aaiClient;
+ thrown.expect(NotFoundException.class);
+ thrown.expectMessage(containsString(path.build() + " not found in A&AI"));
+ AAIResultWrapper result = client.get(path, NotFoundException.class);
+ }
+
+ @Test
+ public void verifyFailedCallException() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())).willReturn(aResponse()
+ .withHeader("Content-Type", "text/plain").withBodyFile("aai/error-message.json").withStatus(400)));
+ AAIResourcesClient client = aaiClient;
+
+ thrown.expect(BadRequestException.class);
+ thrown.expectMessage(containsString(
+ "Invalid input performing PUT on url (msg=Precondition Required:resource-version not passed for update of url"));
+ AAIResultWrapper result = client.get(path);
+ }
+
+ @Test
+ public void buildRelationshipTest() {
+ AAIResourcesClient client = aaiClient;
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ Relationship relationship = new Relationship();
+ relationship.setRelatedLink(uri.build().toString());
+ Relationship actual = client.buildRelationship(uri);
+ assertThat("expect equal no label", actual, sameBeanAs(relationship));
+
+ relationship.setRelationshipLabel(AAIEdgeLabel.USES.toString());
+ actual = client.buildRelationship(uri, AAIEdgeLabel.USES);
+ assertThat("expect equal has label", actual, sameBeanAs(relationship));
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
index 46e4c98b3e..55da6e7d52 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
@@ -28,14 +28,11 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-
import java.util.List;
import java.util.Optional;
-
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -48,80 +45,77 @@ import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.aai.entities.uri.ServiceInstanceUri;
import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
-
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@RunWith(MockitoJUnitRunner.class)
public class AAIResourcesClientWithServiceInstanceUriTest {
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Spy
- public AAIClient client;
-
- @InjectMocks
- public AAIResourcesClient aaiClient = new AAIResourcesClient();
-
- private ServiceInstanceUri uri;
- @Before
- public void setUp() {
- doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
- wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*"))
- .willReturn(aResponse()
- .withStatus(404)
- .withHeader("Content-Type", "application/json")
- .withHeader("Mock", "true")));
-
- uri = spy((ServiceInstanceUri)AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "id"));
- doReturn(aaiClient).when(uri).getResourcesClient();
- }
-
- @Test
- public void getWithClass() {
- AAIResourcesClient client = aaiClient;
- Optional<String> result = client.get(String.class, uri);
-
- assertThat(result.isPresent(), equalTo(false));
- }
-
- @Test
- public void getFullResponse() {
- AAIResourcesClient client = aaiClient;
- Response result = client.getFullResponse(uri);
- assertThat(result.getStatus(), equalTo(Status.NOT_FOUND.getStatusCode()));
- }
-
- @Test
- public void getWithGenericType() {
- AAIResourcesClient client = aaiClient;
- Optional<List<String>> result = client.get(new GenericType<List<String>>() {}, uri);
- assertThat(result.isPresent(), equalTo(false));
- }
-
- @Test
- public void getAAIWrapper() {
- AAIResourcesClient client = aaiClient;
- AAIResultWrapper result = client.get(uri);
- assertThat(result.isEmpty(), equalTo(true));
- }
-
- @Test
- public void getWithException() {
- AAIResourcesClient client = aaiClient;
- this.thrown.expect(IllegalArgumentException.class);
- AAIResultWrapper result = client.get(uri, IllegalArgumentException.class);
- }
-
- @Test
- public void existsTest() {
- AAIResourcesClient client = aaiClient;
- doReturn(uri).when(uri).clone();
- boolean result = client.exists(uri);
- assertThat(result, equalTo(false));
- }
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Spy
+ public AAIClient client;
+
+ @InjectMocks
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ private ServiceInstanceUri uri;
+
+ @Before
+ public void setUp() {
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
+ wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*")).willReturn(
+ aResponse().withStatus(404).withHeader("Content-Type", "application/json").withHeader("Mock", "true")));
+
+ uri = spy((ServiceInstanceUri) AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "id"));
+ doReturn(aaiClient).when(uri).getResourcesClient();
+ }
+
+ @Test
+ public void getWithClass() {
+ AAIResourcesClient client = aaiClient;
+ Optional<String> result = client.get(String.class, uri);
+
+ assertThat(result.isPresent(), equalTo(false));
+ }
+
+ @Test
+ public void getFullResponse() {
+ AAIResourcesClient client = aaiClient;
+ Response result = client.getFullResponse(uri);
+ assertThat(result.getStatus(), equalTo(Status.NOT_FOUND.getStatusCode()));
+ }
+
+ @Test
+ public void getWithGenericType() {
+ AAIResourcesClient client = aaiClient;
+ Optional<List<String>> result = client.get(new GenericType<List<String>>() {}, uri);
+ assertThat(result.isPresent(), equalTo(false));
+ }
+
+ @Test
+ public void getAAIWrapper() {
+ AAIResourcesClient client = aaiClient;
+ AAIResultWrapper result = client.get(uri);
+ assertThat(result.isEmpty(), equalTo(true));
+ }
+
+ @Test
+ public void getWithException() {
+ AAIResourcesClient client = aaiClient;
+ this.thrown.expect(IllegalArgumentException.class);
+ AAIResultWrapper result = client.get(uri, IllegalArgumentException.class);
+ }
+
+ @Test
+ public void existsTest() {
+ AAIResourcesClient client = aaiClient;
+ doReturn(uri).when(uri).clone();
+ boolean result = client.exists(uri);
+ assertThat(result, equalTo(false));
+ }
}
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 95b30f934b..2f551fecc4 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
@@ -28,12 +28,9 @@ 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 java.net.URI;
import java.net.URISyntaxException;
-
import javax.ws.rs.core.Response;
-
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -43,37 +40,37 @@ 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;
@RunWith(MockitoJUnitRunner.class)
public class AAIRestClientTest {
- @Mock
- private AAIProperties props;
-
- private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void failPatchOnComplexObject() throws URISyntaxException {
- AAIRestClient client = new AAIRestClient(props, new URI(""));
- this.thrown.expect(GraphInventoryPatchDepthExceededException.class);
- this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action"));
- client.patch("{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}");
- }
-
- @Test
- public void verifyPatchValidation() throws URISyntaxException {
- AAIRestClient client = new AAIRestClient(props, new URI(""));
- AAIRestClient spy = spy(client);
- GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class);
- doReturn(patchValidatorMock).when(spy).getPatchConverter();
- String payload = "{}";
- doReturn(Response.ok().build()).when(spy).method(eq("PATCH"), any());
- spy.patch(payload);
- verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object)payload));
- }
+ @Mock
+ private AAIProperties props;
+
+ private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void failPatchOnComplexObject() throws URISyntaxException {
+ AAIRestClient client = new AAIRestClient(props, new URI(""));
+ this.thrown.expect(GraphInventoryPatchDepthExceededException.class);
+ this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action"));
+ client.patch(
+ "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}");
+ }
+
+ @Test
+ public void verifyPatchValidation() throws URISyntaxException {
+ AAIRestClient client = new AAIRestClient(props, new URI(""));
+ AAIRestClient spy = spy(client);
+ GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class);
+ doReturn(patchValidatorMock).when(spy).getPatchConverter();
+ String payload = "{}";
+ doReturn(Response.ok().build()).when(spy).method(eq("PATCH"), any());
+ spy.patch(payload);
+ verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object) payload));
+ }
}
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 d875f384b0..1c49c11382 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
@@ -29,12 +29,10 @@ 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 java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Optional;
-
import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;
@@ -51,7 +49,6 @@ 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;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -60,77 +57,78 @@ import com.fasterxml.jackson.databind.SerializationFeature;
@RunWith(MockitoJUnitRunner.class)
public class AAISingleTransactionClientTest {
- private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/singletransaction/";
- AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "pserver-hostname");
- AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex");
-
- ObjectMapper mapper;
-
- public AAIClient client = new AAIClient();
-
- public AAIResourcesClient aaiClient = new AAIResourcesClient();
-
- @Before
- public void before() throws JsonParseException, JsonMappingException, IOException {
- mapper = new AAICommonObjectMapperProvider().getMapper();
- mapper.enable(SerializationFeature.INDENT_OUTPUT);
- }
-
- @Test
- public void testRequest() throws JSONException,IOException {
- Pserver pserver = new Pserver();
- pserver.setHostname("pserver-hostname");
- pserver.setFqdn("pserver-bulk-process-single-transactions-multiple-actions-1-fqdn");
- Pserver pserver2 = new Pserver();
- pserver2.setFqdn("patched-fqdn");
- Complex complex = new Complex();
- complex.setCity("my-city");
- AAISingleTransactionClient singleTransaction =
- aaiClient.beginSingleTransaction()
- .create(uriA, pserver)
- .update(uriA, pserver2)
- .create(uriB, complex);
-
-
- SingleTransactionRequest actual = singleTransaction.getRequest();
-
- SingleTransactionRequest expected = mapper.readValue(this.getJson("sample-request.json"), SingleTransactionRequest.class);
-
- JSONAssert.assertEquals(mapper.writeValueAsString(expected),mapper.writeValueAsString(actual), false);
- }
-
- @Test
- public void testFailure() throws IOException {
- AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
- SingleTransactionResponse expected = mapper.readValue(this.getJson("sample-response-failure.json"), SingleTransactionResponse.class);
- Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
-
- assertThat(expected.getOperationResponses().size(), greaterThan(0));
- assertThat(errorMessage.isPresent(), equalTo(true));
-
- }
-
- @Test
- public void testSuccessResponse() throws IOException {
- AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
- SingleTransactionResponse expected = mapper.readValue(this.getJson("sample-response.json"), SingleTransactionResponse.class);
- Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
-
- assertThat(expected.getOperationResponses().size(), greaterThan(0));
- assertThat(errorMessage.isPresent(), equalTo(false));
-
- }
-
- @Test
- public void confirmPatchFormat() {
- AAISingleTransactionClient singleTransaction = spy(new AAISingleTransactionClient(aaiClient, client));
- GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class);
- doReturn(mock).when(singleTransaction).getPatchConverter();
- singleTransaction.update(uriA, "{}");
- verify(mock, times(1)).convertPatchFormat(any());
- }
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
- }
-
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/singletransaction/";
+ AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "pserver-hostname");
+ AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex");
+
+ ObjectMapper mapper;
+
+ public AAIClient client = new AAIClient();
+
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ @Before
+ public void before() throws JsonParseException, JsonMappingException, IOException {
+ mapper = new AAICommonObjectMapperProvider().getMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ }
+
+ @Test
+ public void testRequest() throws JSONException, IOException {
+ Pserver pserver = new Pserver();
+ pserver.setHostname("pserver-hostname");
+ pserver.setFqdn("pserver-bulk-process-single-transactions-multiple-actions-1-fqdn");
+ Pserver pserver2 = new Pserver();
+ pserver2.setFqdn("patched-fqdn");
+ Complex complex = new Complex();
+ complex.setCity("my-city");
+ AAISingleTransactionClient singleTransaction =
+ aaiClient.beginSingleTransaction().create(uriA, pserver).update(uriA, pserver2).create(uriB, complex);
+
+
+ SingleTransactionRequest actual = singleTransaction.getRequest();
+
+ SingleTransactionRequest expected =
+ mapper.readValue(this.getJson("sample-request.json"), SingleTransactionRequest.class);
+
+ JSONAssert.assertEquals(mapper.writeValueAsString(expected), mapper.writeValueAsString(actual), false);
+ }
+
+ @Test
+ public void testFailure() throws IOException {
+ AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
+ SingleTransactionResponse expected =
+ mapper.readValue(this.getJson("sample-response-failure.json"), SingleTransactionResponse.class);
+ Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
+
+ assertThat(expected.getOperationResponses().size(), greaterThan(0));
+ assertThat(errorMessage.isPresent(), equalTo(true));
+
+ }
+
+ @Test
+ public void testSuccessResponse() throws IOException {
+ AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
+ SingleTransactionResponse expected =
+ mapper.readValue(this.getJson("sample-response.json"), SingleTransactionResponse.class);
+ Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
+
+ assertThat(expected.getOperationResponses().size(), greaterThan(0));
+ assertThat(errorMessage.isPresent(), equalTo(false));
+
+ }
+
+ @Test
+ public void confirmPatchFormat() {
+ AAISingleTransactionClient singleTransaction = spy(new AAISingleTransactionClient(aaiClient, client));
+ GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class);
+ doReturn(mock).when(singleTransaction).getPatchConverter();
+ singleTransaction.update(uriA, "{}");
+ verify(mock, times(1)).convertPatchFormat(any());
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
+ }
+
}
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 3e2801c452..adbdbb419f 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
@@ -27,7 +27,6 @@ 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 java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -35,7 +34,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,7 +45,6 @@ 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;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -57,109 +54,115 @@ import com.fasterxml.jackson.databind.SerializationFeature;
@RunWith(MockitoJUnitRunner.class)
public class AAITransactionalClientTest {
- private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/bulkprocess/";
- AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
- AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test2");
- AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
- AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4");
- AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5");
- AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6");
-
- ObjectMapper mapper;
-
- public AAIClient client = new AAIClient();
-
- public AAIResourcesClient aaiClient = new AAIResourcesClient();
-
- @Before
- public void before() throws JsonParseException, JsonMappingException, IOException {
- mapper = new AAICommonObjectMapperProvider().getMapper();
- mapper.enable(SerializationFeature.INDENT_OUTPUT);
- }
-
- @Test
- public void testCreate() throws IOException {
- final Relationship body = new Relationship();
- body.setRelatedLink(uriB.build().toString());
-
- AAITransactionalClient transactions = aaiClient.beginTransaction()
- .create(uriA.clone().relationshipAPI(), body);
-
- String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
- Map<String, Object> actual = mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>(){});
- Map<String, Object> expected = mapper.readValue(getJson("test-request-small.json"), new TypeReference<Map<String, Object>>(){});
-
- assertEquals(actual, expected);
- }
-
- @Test
- public void testConnect() throws IOException {
- List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>();
- uris.add(uriB);
-
- AAIResourceUri uriAClone = uriA.clone();
- AAITransactionalClient transactions = aaiClient
- .beginTransaction().connect(uriA, uris).connect(uriC, uriD)
- .beginNewTransaction().connect(uriE, uriF);
-
- String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
- Map<String, Object> actual = mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>(){});
- Map<String, Object> expected = mapper.readValue(getJson("test-request.json"), new TypeReference<Map<String, Object>>(){});
-
- assertEquals(actual, expected);
- assertEquals("uri not manipulated", uriAClone.build().toString(), uriA.build().toString());
- }
-
- @Test
- public void testDisconnect() throws IOException {
- List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>();
- uris.add(uriB);
-
- AAITransactionalClient transactions = aaiClient.beginTransaction()
- .disconnect(uriA, uris);
-
- String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
- Map<String, Object> actual = mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>(){});
- Map<String, Object> expected = mapper.readValue(getJson("test-request-small.json").replace("put", "delete"), new TypeReference<Map<String, Object>>(){});
-
- assertEquals(actual, expected);
- }
-
- @Test
- public void testUpdate() throws IOException {
- final Relationship body = new Relationship();
- body.setRelatedLink(uriB.build().toString());
-
- AAIResourceUri uriAClone = uriA.clone().relationshipAPI();
- AAITransactionalClient transactions = aaiClient.beginTransaction().update(uriAClone, body);
-
- String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
- Map<String, Object> actual = mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>(){});
- Map<String, Object> expected = mapper.readValue(getJson("test-request-small.json").replace("put", "patch"), new TypeReference<Map<String, Object>>(){});
-
- assertEquals(actual, expected);
- }
-
- @Test
- public void verifyResponse() throws IOException {
- AAITransactionalClient transactions = aaiClient
- .beginTransaction();
-
- assertEquals("success status", Optional.empty(), transactions.locateErrorMessages(getJson("response-success.json")));
- assertEquals(transactions.locateErrorMessages(getJson("response-failure.json")).get(), "another error message\nmy great error");
- }
-
- @Test
- public void confirmPatchFormat() {
- AAITransactionalClient transactionClient = spy(new AAITransactionalClient(aaiClient, client));
- GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class);
- doReturn(mock).when(transactionClient).getPatchConverter();
- transactionClient.update(uriA, "{}");
- verify(mock, times(1)).convertPatchFormat(any());
- }
-
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
- }
-
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/bulkprocess/";
+ AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+ AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test2");
+ AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+ AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4");
+ AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5");
+ AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6");
+
+ ObjectMapper mapper;
+
+ public AAIClient client = new AAIClient();
+
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ @Before
+ public void before() throws JsonParseException, JsonMappingException, IOException {
+ mapper = new AAICommonObjectMapperProvider().getMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ }
+
+ @Test
+ public void testCreate() throws IOException {
+ final Relationship body = new Relationship();
+ body.setRelatedLink(uriB.build().toString());
+
+ AAITransactionalClient transactions = aaiClient.beginTransaction().create(uriA.clone().relationshipAPI(), body);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected =
+ mapper.readValue(getJson("test-request-small.json"), new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void testConnect() throws IOException {
+ List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>();
+ uris.add(uriB);
+
+ AAIResourceUri uriAClone = uriA.clone();
+ AAITransactionalClient transactions = aaiClient.beginTransaction().connect(uriA, uris).connect(uriC, uriD)
+ .beginNewTransaction().connect(uriE, uriF);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected =
+ mapper.readValue(getJson("test-request.json"), new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ assertEquals("uri not manipulated", uriAClone.build().toString(), uriA.build().toString());
+ }
+
+ @Test
+ public void testDisconnect() throws IOException {
+ List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>();
+ uris.add(uriB);
+
+ AAITransactionalClient transactions = aaiClient.beginTransaction().disconnect(uriA, uris);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected = mapper.readValue(getJson("test-request-small.json").replace("put", "delete"),
+ new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void testUpdate() throws IOException {
+ final Relationship body = new Relationship();
+ body.setRelatedLink(uriB.build().toString());
+
+ AAIResourceUri uriAClone = uriA.clone().relationshipAPI();
+ AAITransactionalClient transactions = aaiClient.beginTransaction().update(uriAClone, body);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected = mapper.readValue(getJson("test-request-small.json").replace("put", "patch"),
+ new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void verifyResponse() throws IOException {
+ AAITransactionalClient transactions = aaiClient.beginTransaction();
+
+ assertEquals("success status", Optional.empty(),
+ transactions.locateErrorMessages(getJson("response-success.json")));
+ assertEquals(transactions.locateErrorMessages(getJson("response-failure.json")).get(),
+ "another error message\nmy great error");
+ }
+
+ @Test
+ public void confirmPatchFormat() {
+ AAITransactionalClient transactionClient = spy(new AAITransactionalClient(aaiClient, client));
+ GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class);
+ doReturn(mock).when(transactionClient).getPatchConverter();
+ transactionClient.update(uriA, "{}");
+ verify(mock, times(1)).convertPatchFormat(any());
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
+ }
+
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIURITest.java b/common/src/test/java/org/onap/so/client/aai/AAIURITest.java
index cb426c5392..556b4429d4 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIURITest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIURITest.java
@@ -21,24 +21,21 @@
package org.onap.so.client.aai;
import static org.junit.Assert.assertEquals;
-
import javax.ws.rs.core.UriBuilder;
-
import org.junit.Test;
import org.onap.so.client.aai.entities.uri.AAIUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
public class AAIURITest {
-
-
-
- @Test
- public void verifyTemplateReplacement() {
- final String id = "test1";
- AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, id);
- String manualReplace = AAIObjectType.CONFIGURATION.toString().replaceAll("\\{configuration-id\\}", id);
- assertEquals("uri template replaced", aaiUri.build(), UriBuilder.fromPath(manualReplace).build());
- }
+
+ @Test
+ public void verifyTemplateReplacement() {
+ final String id = "test1";
+ AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, id);
+ String manualReplace = AAIObjectType.CONFIGURATION.toString().replaceAll("\\{configuration-id\\}", id);
+ assertEquals("uri template replaced", aaiUri.build(), UriBuilder.fromPath(manualReplace).build());
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java b/common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java
index 3fc97761a4..d18dbec944 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java
@@ -30,31 +30,31 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class AAIUpdatorTest {
-
- @Mock
- protected AAIRestClientI client;
- String vnfName = "testVnf";
- AAIUpdatorImpl updator;
-
- @Before
- public void init(){
- updator = new AAIUpdatorImpl();
- updator.setClient(client);
- }
- @Test
- public void testUpdateVnfToLocked() throws Exception{
- doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class));
- updator.updateVnfToLocked(vnfName);
- verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, true);
- }
-
- @Test
- public void testUpdateVnfToUnLocked() throws Exception {
- doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class));
- updator.updateVnfToUnLocked(vnfName);
- verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, false);
- }
-} \ No newline at end of file
+ @Mock
+ protected AAIRestClientI client;
+ String vnfName = "testVnf";
+ AAIUpdatorImpl updator;
+
+ @Before
+ public void init() {
+ updator = new AAIUpdatorImpl();
+ updator.setClient(client);
+ }
+
+ @Test
+ public void testUpdateVnfToLocked() throws Exception {
+ doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class));
+ updator.updateVnfToLocked(vnfName);
+ verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, true);
+ }
+
+ @Test
+ public void testUpdateVnfToUnLocked() throws Exception {
+ doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class));
+ updator.updateVnfToUnLocked(vnfName);
+ verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, false);
+ }
+}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java b/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java
index 85d690feaf..5fa2ff0295 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java
@@ -22,7 +22,6 @@ package org.onap.so.client.aai;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -34,74 +33,74 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.aai.domain.yang.Pserver;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class AAIValidatorTest {
-
- @Mock
- protected AAIRestClientI client;
- String vnfName = "testVnf";
- String uuid = "UUID";
- AAIValidatorImpl validator;
-
- @Before
- public void init(){
- validator = new AAIValidatorImpl();
- validator.setClient(client);
- }
-
- public List<Pserver> getPserversLocked(){
- Pserver pserver1 = new Pserver();
- pserver1.setInMaint(true);
- Pserver pserver2 = new Pserver();
- pserver2.setInMaint(false);
- List<Pserver> pservers = new ArrayList<Pserver>();
- pservers.add(pserver1);
- pservers.add(pserver2);
- return pservers;
- }
-
- public List<Pserver> getPserversNotLocked(){
- Pserver pserver1 = new Pserver();
- pserver1.setInMaint(false);
- Pserver pserver2 = new Pserver();
- pserver2.setInMaint(false);
- List<Pserver> pservers = new ArrayList<Pserver>();
- pservers.add(pserver1);
- pservers.add(pserver2);
- return pservers;
- }
-
- public GenericVnf createGenericVnfs(boolean locked){
- GenericVnf genericVnf = new GenericVnf();
- genericVnf.setInMaint(locked);
- return genericVnf;
- }
- @Test
- public void test_IsPhysicalServerLocked_True() throws IOException{
- when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversLocked());
- boolean locked = validator.isPhysicalServerLocked(vnfName);
- assertEquals(true, locked);
- }
-
- @Test
- public void test_IsPhysicalServerLocked_False() throws IOException {
- when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversNotLocked());
- boolean locked = validator.isPhysicalServerLocked(vnfName);
- assertEquals(false, locked);
- }
-
- @Test
- public void test_IsVNFLocked_False() {
- when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(false));
- boolean locked = validator.isVNFLocked(vnfName);
- assertEquals(false, locked);
- }
+ @Mock
+ protected AAIRestClientI client;
+ String vnfName = "testVnf";
+ String uuid = "UUID";
+ AAIValidatorImpl validator;
+
+ @Before
+ public void init() {
+ validator = new AAIValidatorImpl();
+ validator.setClient(client);
+ }
+
+ public List<Pserver> getPserversLocked() {
+ Pserver pserver1 = new Pserver();
+ pserver1.setInMaint(true);
+ Pserver pserver2 = new Pserver();
+ pserver2.setInMaint(false);
+ List<Pserver> pservers = new ArrayList<Pserver>();
+ pservers.add(pserver1);
+ pservers.add(pserver2);
+ return pservers;
+ }
+
+ public List<Pserver> getPserversNotLocked() {
+ Pserver pserver1 = new Pserver();
+ pserver1.setInMaint(false);
+ Pserver pserver2 = new Pserver();
+ pserver2.setInMaint(false);
+ List<Pserver> pservers = new ArrayList<Pserver>();
+ pservers.add(pserver1);
+ pservers.add(pserver2);
+ return pservers;
+ }
+
+ public GenericVnf createGenericVnfs(boolean locked) {
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setInMaint(locked);
+ return genericVnf;
+ }
+
+ @Test
+ public void test_IsPhysicalServerLocked_True() throws IOException {
+ when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversLocked());
+ boolean locked = validator.isPhysicalServerLocked(vnfName);
+ assertEquals(true, locked);
+ }
+
+ @Test
+ public void test_IsPhysicalServerLocked_False() throws IOException {
+ when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversNotLocked());
+ boolean locked = validator.isPhysicalServerLocked(vnfName);
+ assertEquals(false, locked);
+ }
+
+ @Test
+ public void test_IsVNFLocked_False() {
+ when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(false));
+ boolean locked = validator.isVNFLocked(vnfName);
+ assertEquals(false, locked);
+ }
- @Test
- public void test_IsVNFLocked_True() {
- when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(true));
- boolean locked = validator.isVNFLocked(vnfName);
- assertEquals(true,locked );
- }
+ @Test
+ public void test_IsVNFLocked_True() {
+ when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(true));
+ boolean locked = validator.isVNFLocked(vnfName);
+ assertEquals(true, locked);
+ }
}
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
index a5bbc64eb9..6e55fe17fa 100644
--- a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
@@ -22,7 +22,6 @@ package org.onap.so.client.aai;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.onap.so.client.graphinventory.entities.DSLNode;
import org.onap.so.client.graphinventory.entities.DSLQueryBuilder;
@@ -30,83 +29,83 @@ import org.onap.so.client.graphinventory.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());
- }
-
- @Test
- public void shortCutToTest() {
- DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER,
- __.key("hostname", "my-hostname")).output());
-
- builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
- assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')", builder.build());
- }
-
- @Test
- public void limitTest() {
- DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER,
- __.key("hostname", "my-hostname")).output());
-
- builder.to(AAIObjectType.P_INTERFACE).limit(2).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
- assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id') LIMIT 2", builder.build());
- }
-
- @Test
- public void equalsTest() {
- DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER,
- __.key("hostname", "my-hostname")).output());
-
- builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
- assertTrue(builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')"));
- assertTrue(builder.equals(builder));
- }
+
+ @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());
+ }
+
+ @Test
+ public void shortCutToTest() {
+ DSLQueryBuilder<DSLNode, DSLNode> builder =
+ new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
+
+ builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
+ assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')",
+ builder.build());
+ }
+
+ @Test
+ public void limitTest() {
+ DSLQueryBuilder<DSLNode, DSLNode> builder =
+ new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
+
+ builder.to(AAIObjectType.P_INTERFACE).limit(2).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
+ assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id') LIMIT 2",
+ builder.build());
+ }
+
+ @Test
+ public void equalsTest() {
+ DSLQueryBuilder<DSLNode, DSLNode> builder =
+ new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
+
+ builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
+ assertTrue(
+ builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')"));
+ assertTrue(builder.equals(builder));
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
index 324be0114d..157109c119 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
@@ -21,7 +21,6 @@
package org.onap.so.client.aai.entities;
import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
import java.io.Serializable;
import java.nio.file.Files;
@@ -29,7 +28,6 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -39,75 +37,74 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.so.client.aai.AAICommonObjectMapperProvider;
import org.springframework.util.SerializationUtils;
-
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(MockitoJUnitRunner.class)
public class AAIResultWrapperTest {
- String json;
- @Rule
- public ExpectedException thrown= ExpectedException.none();
-
- AAIResultWrapper aaiResultWrapper;
- AAIResultWrapper aaiResultWrapperEmpty;
-
- @Before
- public void init() throws IOException {
- final String RESOURCE_PATH = "src/test/resources/__files/aai/resources/";
- json = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "e2e-complex.json")));
-
- aaiResultWrapper = new AAIResultWrapper(json);
- aaiResultWrapperEmpty = new AAIResultWrapper("{}");
- }
-
- @Test
- public void testAAIResultWrapperIsSerializable() throws IOException {
- AAIResultWrapper original = new AAIResultWrapper("");
- byte[] serialized = SerializationUtils.serialize(original);
- AAIResultWrapper deserialized = (AAIResultWrapper) SerializationUtils.deserialize(serialized);
- assertEquals(deserialized.getJson(), original.getJson());
- }
-
- @Test
- public void testGetRelationshipsEmpty() {
- Optional<Relationships> relationships = aaiResultWrapperEmpty.getRelationships();
- assertEquals("Compare relationships", Optional.empty(), relationships);
- }
-
- @Test
- public void testAsMap() throws JsonParseException, JsonMappingException, IOException {
- ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
- Map<String, Object> expected = mapper.readValue(json, new TypeReference<Map<String, Object>>(){});
-
- Map<String, Object> actual = aaiResultWrapper.asMap();
- assertEquals(expected, actual);
- }
-
- @Test
- public void testAsMapEmpty() {
- Map<String, Object> actual = aaiResultWrapperEmpty.asMap();
- assertEquals(new HashMap<>(), actual);
- }
-
- @Test
- public void nullCases() {
-
- AAIResultWrapper wrapper = new AAIResultWrapper(null);
-
- assertEquals(Optional.empty(), wrapper.getRelationships());
- assertEquals("{}", wrapper.getJson());
- assertEquals(Optional.empty(), wrapper.asBean(GenericVnf.class));
- assertEquals(true, wrapper.asMap().isEmpty());
- assertEquals("{}", wrapper.toString());
-
- }
-
- @Test
- public void objectConstructor() {
- AAIResultWrapper wrapper = new AAIResultWrapper(new GenericVnf());
- assertEquals("{}", wrapper.getJson());
- }
+ String json;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ AAIResultWrapper aaiResultWrapper;
+ AAIResultWrapper aaiResultWrapperEmpty;
+
+ @Before
+ public void init() throws IOException {
+ final String RESOURCE_PATH = "src/test/resources/__files/aai/resources/";
+ json = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "e2e-complex.json")));
+
+ aaiResultWrapper = new AAIResultWrapper(json);
+ aaiResultWrapperEmpty = new AAIResultWrapper("{}");
+ }
+
+ @Test
+ public void testAAIResultWrapperIsSerializable() throws IOException {
+ AAIResultWrapper original = new AAIResultWrapper("");
+ byte[] serialized = SerializationUtils.serialize(original);
+ AAIResultWrapper deserialized = (AAIResultWrapper) SerializationUtils.deserialize(serialized);
+ assertEquals(deserialized.getJson(), original.getJson());
+ }
+
+ @Test
+ public void testGetRelationshipsEmpty() {
+ Optional<Relationships> relationships = aaiResultWrapperEmpty.getRelationships();
+ assertEquals("Compare relationships", Optional.empty(), relationships);
+ }
+
+ @Test
+ public void testAsMap() throws JsonParseException, JsonMappingException, IOException {
+ ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
+ Map<String, Object> expected = mapper.readValue(json, new TypeReference<Map<String, Object>>() {});
+
+ Map<String, Object> actual = aaiResultWrapper.asMap();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testAsMapEmpty() {
+ Map<String, Object> actual = aaiResultWrapperEmpty.asMap();
+ assertEquals(new HashMap<>(), actual);
+ }
+
+ @Test
+ public void nullCases() {
+
+ AAIResultWrapper wrapper = new AAIResultWrapper(null);
+
+ assertEquals(Optional.empty(), wrapper.getRelationships());
+ assertEquals("{}", wrapper.getJson());
+ assertEquals(Optional.empty(), wrapper.asBean(GenericVnf.class));
+ assertEquals(true, wrapper.asMap().isEmpty());
+ assertEquals("{}", wrapper.toString());
+
+ }
+
+ @Test
+ public void objectConstructor() {
+ AAIResultWrapper wrapper = new AAIResultWrapper(new GenericVnf());
+ assertEquals("{}", wrapper.getJson());
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
index 8d11f69308..ec7c6434a7 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
@@ -21,13 +21,11 @@
package org.onap.so.client.aai.entities;
import static org.junit.Assert.assertTrue;
-
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.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
@@ -35,27 +33,27 @@ import org.onap.so.client.aai.entities.uri.AAIUriFactory;
public class RelationshipsTest {
- private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
-
- @Test
- public void run() 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();
-
- List<AAIResourceUri> test = relationships.getRelatedUris(AAIObjectType.VCE);
-
- System.out.println(test.get(0).build());
- List<AAIResourceUri> uris = Arrays.asList(
- AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a9fec18e-1ea3-40e4-a6c0-a89b3de07053"),
- AAIUriFactory.createResourceUri(AAIObjectType.VCE, "8ae1e5f8-61f1-4c71-913a-b40cc4593cb9"),
- AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a2935fa9-b743-49f4-9813-a127f13c4e93"),
- AAIUriFactory.createResourceUri(AAIObjectType.VCE, "c7fe7698-8063-4e26-8bd3-ca3edde0b0d4"));
-
-
- assertTrue(uris.containsAll(test) && test.containsAll(uris));
-
- }
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
+
+ @Test
+ public void run() 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();
+
+ List<AAIResourceUri> test = relationships.getRelatedUris(AAIObjectType.VCE);
+
+ System.out.println(test.get(0).build());
+ List<AAIResourceUri> uris = Arrays.asList(
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a9fec18e-1ea3-40e4-a6c0-a89b3de07053"),
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "8ae1e5f8-61f1-4c71-913a-b40cc4593cb9"),
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a2935fa9-b743-49f4-9813-a127f13c4e93"),
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "c7fe7698-8063-4e26-8bd3-ca3edde0b0d4"));
+
+
+ assertTrue(uris.containsAll(test) && test.containsAll(uris));
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java
index beb18a389c..d26ff8d507 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java
@@ -21,21 +21,23 @@
package org.onap.so.client.aai.entities.uri;
import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import org.onap.so.client.aai.AAIObjectType;
public class AAISimpleUriFromParentUriTest {
-
- @Test
- public void appendChildren() {
-
- AAIResourceUri parentUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "key1", "key2", "key3");
-
- AAIUri uri = new AAISimpleUri(parentUri, AAIObjectType.ALLOTTED_RESOURCE, "key4");
-
- assertEquals("path appended", "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4", uri.build().toString());
-
- }
+
+ @Test
+ public void appendChildren() {
+
+ AAIResourceUri parentUri =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "key1", "key2", "key3");
+
+ AAIUri uri = new AAISimpleUri(parentUri, AAIObjectType.ALLOTTED_RESOURCE, "key4");
+
+ assertEquals("path appended",
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4",
+ uri.build().toString());
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java
index 5a69a42f35..ab1529d3ba 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java
@@ -21,40 +21,46 @@
package org.onap.so.client.aai.entities.uri;
import static org.junit.Assert.assertEquals;
-
import javax.ws.rs.core.UriBuilder;
-
import org.junit.Test;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.graphinventory.entities.uri.SimpleUri;
public class AAISimpleUriFromUriTest {
-
-
- @Test
- public void removeHost() {
-
- AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("https://localhost:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build());
-
- assertEquals("root and version removed", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString());
-
- }
- @Test
- public void noChange() {
-
- AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build());
-
- assertEquals("no change", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString());
-
- }
-
- @Test
- public void encodingPreserved() {
-
- AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, UriBuilder.fromUri("/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053").build());
-
- assertEquals("encoding preserved", "/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString());
-
- }
+
+
+ @Test
+ public void removeHost() {
+
+ AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN,
+ UriBuilder
+ .fromUri("https://localhost:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053")
+ .build());
+
+ assertEquals("root and version removed", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053",
+ uri.build().toString());
+
+ }
+
+ @Test
+ public void noChange() {
+
+ AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN,
+ UriBuilder.fromUri("/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build());
+
+ assertEquals("no change", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString());
+
+ }
+
+ @Test
+ public void encodingPreserved() {
+
+ AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN,
+ UriBuilder.fromUri("/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053").build());
+
+ assertEquals("encoding preserved", "/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053",
+ uri.build().toString());
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java
index 2a0e9df9ed..4e9d5aa8e8 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java
@@ -24,7 +24,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.junit.Assert.assertEquals;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
@@ -33,7 +32,6 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
-
import org.junit.Test;
import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
@@ -42,81 +40,81 @@ import org.onap.so.client.graphinventory.entities.uri.SimpleUri;
public class AAISimpleUriTest {
-
-
- @Test
- public void relatedToTestPlural() {
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
- uri.relatedTo(AAIObjectPlurals.PSERVER);
- String uriOutput = uri.build().toString();
- assertEquals(true, uriOutput.contains("related-to"));
- }
-
- @Test
- public void relatedToTestSingular() {
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
- uri.relatedTo(AAIObjectType.PSERVER, "test2");
- String uriOutput = uri.build().toString();
- assertEquals(true, uriOutput.contains("related-to"));
- }
-
- @Test
- public void cloneTestSingular() {
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
- AAIResourceUri cloned = uri.clone();
- Map<String,String> keys = cloned.getURIKeys();
- assertThat(keys.values(), contains("test1"));
- }
-
- @Test
- public void cloneTestPlural() {
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
- AAIResourceUri cloned = uri.clone();
- Map<String,String> keys = cloned.getURIKeys();
- assertThat(keys.values(), empty());
- }
-
- @Test
- public void getKeysTest() {
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1");
- Map<String,String> keys = uri.getURIKeys();
- System.out.println(keys);
- System.out.println(uri.build());
- assertEquals("vserver1", keys.get("vserver-id"));
- }
-
- @Test
- public void getEncodedKeyTest() {
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "test1", "my value", "test3");
- Map<String,String> keys = uri.getURIKeys();
-
- assertEquals("my value", keys.get("service-type"));
- }
-
- @Test
- public void serializeTest() throws IOException, ClassNotFoundException {
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
-
- uri.depth(Depth.ONE);
- uri.limit(1);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- ObjectOutputStream objectOutputStream
- = new ObjectOutputStream(bos);
- objectOutputStream.writeObject(uri);
- objectOutputStream.flush();
- objectOutputStream.close();
-
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
-
- ObjectInputStream objectInputStream
- = new ObjectInputStream(bis);
- AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject();
- objectInputStream.close();
-
- uri.queryParam("test", "value");
- e2.queryParam("test", "value");
-
- assertEquals(e2.build().toString(), uri.build().toString());
- }
+
+
+ @Test
+ public void relatedToTestPlural() {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+ uri.relatedTo(AAIObjectPlurals.PSERVER);
+ String uriOutput = uri.build().toString();
+ assertEquals(true, uriOutput.contains("related-to"));
+ }
+
+ @Test
+ public void relatedToTestSingular() {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+ uri.relatedTo(AAIObjectType.PSERVER, "test2");
+ String uriOutput = uri.build().toString();
+ assertEquals(true, uriOutput.contains("related-to"));
+ }
+
+ @Test
+ public void cloneTestSingular() {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+ AAIResourceUri cloned = uri.clone();
+ Map<String, String> keys = cloned.getURIKeys();
+ assertThat(keys.values(), contains("test1"));
+ }
+
+ @Test
+ public void cloneTestPlural() {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ AAIResourceUri cloned = uri.clone();
+ Map<String, String> keys = cloned.getURIKeys();
+ assertThat(keys.values(), empty());
+ }
+
+ @Test
+ public void getKeysTest() {
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1");
+ Map<String, String> keys = uri.getURIKeys();
+ System.out.println(keys);
+ System.out.println(uri.build());
+ assertEquals("vserver1", keys.get("vserver-id"));
+ }
+
+ @Test
+ public void getEncodedKeyTest() {
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "test1", "my value", "test3");
+ Map<String, String> keys = uri.getURIKeys();
+
+ assertEquals("my value", keys.get("service-type"));
+ }
+
+ @Test
+ public void serializeTest() throws IOException, ClassNotFoundException {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+
+ uri.depth(Depth.ONE);
+ uri.limit(1);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
+ objectOutputStream.writeObject(uri);
+ objectOutputStream.flush();
+ objectOutputStream.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+
+ ObjectInputStream objectInputStream = new ObjectInputStream(bis);
+ AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject();
+ objectInputStream.close();
+
+ uri.queryParam("test", "value");
+ e2.queryParam("test", "value");
+
+ assertEquals(e2.build().toString(), uri.build().toString());
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java
index 0ddf5c707b..9b4f5dafb5 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java
@@ -21,7 +21,6 @@
package org.onap.so.client.aai.entities.uri;
import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
@@ -29,40 +28,41 @@ import org.onap.so.client.graphinventory.entities.uri.SimpleUri;
public class AAIUriFactoryTest {
- @Test
- public void testCreateResourceUri() {
-
- AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
-
- String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
- assertEquals(expected, uri.build().toString());
- }
-
- @Test
- public void testCreateNodesUri() {
-
- AAIUri uri = AAIUriFactory.createNodesUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
-
- String expected = "/nodes/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
- assertEquals(expected, uri.build().toString());
- }
-
- @Test
- public void testCreateResourceFromExistingURI() {
-
- AAIUri uri = new AAISimpleUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
- AAIUri uri2 = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.GENERIC_VNF, uri.build());
-
- String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
- assertEquals(expected, uri2.build().toString());
- }
-
- @Test
- public void testCreateResourceURIForPluralsWithValues() {
-
- AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, "customerId", "serviceType");
-
- String expected = "/business/customers/customer/customerId/service-subscriptions/service-subscription/serviceType/service-instances";
- assertEquals(expected, uri.build().toString());
- }
+ @Test
+ public void testCreateResourceUri() {
+
+ AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
+
+ String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
+ assertEquals(expected, uri.build().toString());
+ }
+
+ @Test
+ public void testCreateNodesUri() {
+
+ AAIUri uri = AAIUriFactory.createNodesUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
+
+ String expected = "/nodes/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
+ assertEquals(expected, uri.build().toString());
+ }
+
+ @Test
+ public void testCreateResourceFromExistingURI() {
+
+ AAIUri uri = new AAISimpleUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
+ AAIUri uri2 = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.GENERIC_VNF, uri.build());
+
+ String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
+ assertEquals(expected, uri2.build().toString());
+ }
+
+ @Test
+ public void testCreateResourceURIForPluralsWithValues() {
+
+ AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, "customerId", "serviceType");
+
+ String expected =
+ "/business/customers/customer/customerId/service-subscriptions/service-subscription/serviceType/service-instances";
+ assertEquals(expected, uri.build().toString());
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java
index 0d2da3339a..4be6753894 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java
@@ -24,29 +24,31 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-
import javax.ws.rs.core.UriBuilder;
-
import org.junit.Test;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
public class AllottedResourceLookupUriTest {
- @Test
- public void oneKey() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-
- AllottedResourceLookupUri instance = new AllottedResourceLookupUri("key1");
- AllottedResourceLookupUri spy = spy(instance);
- doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4").when(spy).getObjectById(any(Object.class));
-
- final URI result = spy.build();
- final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4").build();
- assertEquals("result is equal", expected, result);
-
- }
+ @Test
+ public void oneKey()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ AllottedResourceLookupUri instance = new AllottedResourceLookupUri("key1");
+ AllottedResourceLookupUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.build();
+ final URI expected = UriBuilder.fromPath(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
}
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 e84326e95f..86ee08c4e6 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
@@ -23,7 +23,6 @@ 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;
@@ -33,38 +32,40 @@ 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() {
+ @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");
- }
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "customer-id", "subscription-id");
+ }
}
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 c369767e38..e829666577 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
@@ -32,17 +32,14 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
-
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Optional;
-
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.UriBuilder;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -59,149 +56,175 @@ import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
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 com.github.tomakehurst.wiremock.junit.WireMockRule;
@RunWith(MockitoJUnitRunner.class)
public class ServiceInstanceUriTest {
- private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
-
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
-
- @Rule
- public final ExpectedException exception = ExpectedException.none();
-
- @Spy
- public AAIClient client;
-
- @InjectMocks
- public AAIResourcesClient aaiClient = new AAIResourcesClient();
-
- @Before
- public void beforeTest() {
- doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
- }
- @Test
- public void found() throws IOException {
- final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
-
- ServiceInstanceUri instance = new ServiceInstanceUri("key3");
- final Optional<String> result = instance.extractRelatedLink(content);
- final String expected = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
- assertEquals("result is equal", expected, result.get());
-
- }
-
- @Test
- public void oneKey() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-
- ServiceInstanceUri instance = new ServiceInstanceUri("key1");
- ServiceInstanceUri spy = spy(instance);
- doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getObjectById(any(Object.class));
-
- final URI result = spy.build();
- final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build();
- assertEquals("result is equal", expected, result);
-
- }
-
- @Test
- public void oneKeyQueryParams() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-
- ServiceInstanceUri instance = new ServiceInstanceUri("key1");
- ServiceInstanceUri spy = spy(instance);
- doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getObjectById(any(Object.class));
-
- final URI result = spy.resourceVersion("1234").build();
- final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build();
- assertEquals("result is equal", expected, result);
-
- }
-
- @Test
- public void oneKeyEncoded() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-
- ServiceInstanceUri instance = new ServiceInstanceUri("key1");
- ServiceInstanceUri spy = spy(instance);
- doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").when(spy).getObjectById(any(Object.class));
-
- final URI result = spy.build();
- final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").build();
- assertEquals("result is equal", expected, result);
-
- }
-
- @Test
- public void oneKeyGetKeys() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-
- ServiceInstanceUri instance = new ServiceInstanceUri("key1");
- ServiceInstanceUri spy = spy(instance);
- doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space").when(spy).getObjectById(any(Object.class));
-
- assertThat(spy.getURIKeys().values(), contains("key1", "key2", "key3(space"));
-
- }
- @Test
- public void oneKeyClone() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
- ServiceInstanceUri instance = new ServiceInstanceUri("key1");
- ServiceInstanceUri spy = spy(instance);
- String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
- doReturn(uri).when(spy).getObjectById(any(Object.class));
- doReturn(Optional.of(uri)).when(spy).getCachedValue();
- final URI result = spy.resourceVersion("1234").clone().build();
- final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build();
- assertEquals("result is equal", expected, result);
- }
-
- @Test
- public void threeKey() throws IOException {
-
- ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
- final URI result = instance.build();
- final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build();
- assertEquals("result is equal", expected, result);
-
- }
-
- @Test
- public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
- final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json")));
-
- ServiceInstanceUri instance = new ServiceInstanceUri("key3");
- 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);
- exception.expect(GraphInventoryUriComputationException.class);
- spy.build();
-
- }
-
- @Test
- public void cloneTest() {
- ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
- final URI result = instance.build();
- final URI result2 = instance.clone().queryParam("something", "new").build();
- assertEquals("uris are not equal", false, result.toString().equals(result2.toString()));
-
- }
-
- @Test
- public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
- ServiceInstanceUri instance = new ServiceInstanceUri("key3");
- ServiceInstanceUri spy = spy(instance);
- AAIResourcesClient client = aaiClient;
- doReturn(client).when(spy).getResourcesClient();
- wireMockRule.stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3"))
- .willReturn(aResponse()
- .withStatus(404)
- .withHeader("Content-Type", "application/json")
- .withBodyFile("")));
- exception.expect(NotFoundException.class);
- spy.build();
- }
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+
+ @Spy
+ public AAIClient client;
+
+ @InjectMocks
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ @Before
+ public void beforeTest() {
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
+ }
+
+ @Test
+ public void found() throws IOException {
+ final String content = new String(
+ Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ final Optional<String> result = instance.extractRelatedLink(content);
+ final String expected =
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+ assertEquals("result is equal", expected, result.get());
+
+ }
+
+ @Test
+ public void oneKey()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.build();
+ final URI expected = UriBuilder.fromPath(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void oneKeyQueryParams()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.resourceVersion("1234").build();
+ final URI expected = UriBuilder.fromUri(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void oneKeyEncoded()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.build();
+ final URI expected = UriBuilder.fromUri(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void oneKeyGetKeys()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space")
+ .when(spy).getObjectById(any(Object.class));
+
+ assertThat(spy.getURIKeys().values(), contains("key1", "key2", "key3(space"));
+
+ }
+
+ @Test
+ public void oneKeyClone() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ String uri =
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+ doReturn(uri).when(spy).getObjectById(any(Object.class));
+ doReturn(Optional.of(uri)).when(spy).getCachedValue();
+ final URI result = spy.resourceVersion("1234").clone().build();
+ final URI expected = UriBuilder.fromUri(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234")
+ .build();
+ assertEquals("result is equal", expected, result);
+ }
+
+ @Test
+ public void threeKey() throws IOException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
+ final URI result = instance.build();
+ final URI expected = UriBuilder.fromPath(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ final String content =
+ new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json")));
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ 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);
+ exception.expect(GraphInventoryUriComputationException.class);
+ spy.build();
+
+ }
+
+ @Test
+ public void cloneTest() {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
+ final URI result = instance.build();
+ final URI result2 = instance.clone().queryParam("something", "new").build();
+ assertEquals("uris are not equal", false, result.toString().equals(result2.toString()));
+
+ }
+
+ @Test
+ public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ ServiceInstanceUri spy = spy(instance);
+ AAIResourcesClient client = aaiClient;
+ doReturn(client).when(spy).getResourcesClient();
+ wireMockRule
+ .stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3")).willReturn(
+ aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBodyFile("")));
+ exception.expect(NotFoundException.class);
+ spy.build();
+ }
}
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 3979902962..f437197f71 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
@@ -24,17 +24,19 @@ import org.onap.so.client.aai.AAINamespaceConstants;
import org.onap.so.client.aai.AAIObjectType;
public class CustomAAIObjectType extends AAIObjectType {
-
- private static final long serialVersionUID = 1919729212831978098L;
-
- public static final AAIObjectType CUSTOM = new CustomAAIObjectType(AAINamespaceConstants.NETWORK, "my-url", "my-custom-name");
-
- /* Default constructor automatically called by AAIObjectType */
- public CustomAAIObjectType() {
- super();
- }
- protected CustomAAIObjectType(String parent, String uri, String name) {
- super(parent, uri, name);
- }
+
+ private static final long serialVersionUID = 1919729212831978098L;
+
+ public static final AAIObjectType CUSTOM =
+ new CustomAAIObjectType(AAINamespaceConstants.NETWORK, "my-url", "my-custom-name");
+
+ /* Default constructor automatically called by AAIObjectType */
+ public CustomAAIObjectType() {
+ super();
+ }
+
+ protected CustomAAIObjectType(String parent, String uri, String name) {
+ super(parent, uri, name);
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java b/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java
index f4490faacc..bc600310b3 100644
--- a/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/adapter/rest/AdapterRestClientTest.java
@@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
@@ -80,8 +79,8 @@ public class AdapterRestClientTest {
String encyptedMessage = CryptoUtils.encrypt("testAdapter", CRYPTO_KEY);
when(adapterRestPropertiesMock.getAuth()).thenReturn(encyptedMessage);
when(adapterRestPropertiesMock.getKey()).thenReturn(INVALID_CRYPTO_KEY);
- AdapterRestClient testedObject = new AdapterRestClient(adapterRestPropertiesMock, new URI(""),
- "accept", "contentType");
+ AdapterRestClient testedObject =
+ new AdapterRestClient(adapterRestPropertiesMock, new URI(""), "accept", "contentType");
// when
testedObject.initializeHeaderMap(headerMap);
// then
diff --git a/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java b/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java
index f6bf21458d..18ec9efa50 100644
--- a/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java
+++ b/common/src/test/java/org/onap/so/client/cds/CDSProcessingClientTest.java
@@ -23,7 +23,6 @@ package org.onap.so.client.cds;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
-
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.stub.StreamObserver;
@@ -68,42 +67,40 @@ public class CDSProcessingClientTest {
@Before
public void setUp() throws Exception {
String serverName = InProcessServerBuilder.generateName();
- grpcCleanup.register(InProcessServerBuilder.forName(serverName)
- .fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start());
+ grpcCleanup.register(InProcessServerBuilder.forName(serverName).fallbackHandlerRegistry(serviceRegistry)
+ .directExecutor().build().start());
handler = new CDSProcessingHandler(listener);
- client =
- new CDSProcessingClient(InProcessChannelBuilder.forName(serverName).directExecutor().build(), handler);
+ client = new CDSProcessingClient(InProcessChannelBuilder.forName(serverName).directExecutor().build(), handler);
- final BluePrintProcessingServiceImplBase routeChatImpl =
- new BluePrintProcessingServiceImplBase() {
- @Override
- public StreamObserver<ExecutionServiceInput> process(
+ final BluePrintProcessingServiceImplBase routeChatImpl = new BluePrintProcessingServiceImplBase() {
+ @Override
+ public StreamObserver<ExecutionServiceInput> process(
StreamObserver<ExecutionServiceOutput> responseObserver) {
- responseObserverRef.set(responseObserver);
+ responseObserverRef.set(responseObserver);
- StreamObserver<ExecutionServiceInput> requestObserver = new StreamObserver<ExecutionServiceInput>() {
- @Override
- public void onNext(ExecutionServiceInput message) {
- messagesDelivered.add(message.getActionIdentifiers().getActionName());
- }
+ StreamObserver<ExecutionServiceInput> requestObserver = new StreamObserver<ExecutionServiceInput>() {
+ @Override
+ public void onNext(ExecutionServiceInput message) {
+ messagesDelivered.add(message.getActionIdentifiers().getActionName());
+ }
- @Override
- public void onError(Throwable t) {
+ @Override
+ public void onError(Throwable t) {
- }
+ }
- @Override
- public void onCompleted() {
- allRequestsDelivered.countDown();
- }
- };
+ @Override
+ public void onCompleted() {
+ allRequestsDelivered.countDown();
+ }
+ };
- return requestObserver;
- }
- };
+ return requestObserver;
+ }
+ };
serviceRegistry.addService(routeChatImpl);
}
@@ -122,8 +119,8 @@ public class CDSProcessingClientTest {
@Test
public void testSendMessageFail() throws Exception {
- ExecutionServiceInput fakeRequest1 = ExecutionServiceInput.newBuilder().setActionIdentifiers(
- ActionIdentifiers.newBuilder().setActionName("request1").build()).build();
+ ExecutionServiceInput fakeRequest1 = ExecutionServiceInput.newBuilder()
+ .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("request1").build()).build();
CountDownLatch finishLatch = client.sendRequest(fakeRequest1);
@@ -136,14 +133,14 @@ public class CDSProcessingClientTest {
@Test
public void testSendMessage() throws Exception {
- ExecutionServiceInput fakeRequest1 = ExecutionServiceInput.newBuilder().setActionIdentifiers(
- ActionIdentifiers.newBuilder().setActionName("request1").build()).build();
+ ExecutionServiceInput fakeRequest1 = ExecutionServiceInput.newBuilder()
+ .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("request1").build()).build();
- ExecutionServiceOutput fakeResponse1 = ExecutionServiceOutput.newBuilder().setActionIdentifiers(
- ActionIdentifiers.newBuilder().setActionName("response1").build()).build();
+ ExecutionServiceOutput fakeResponse1 = ExecutionServiceOutput.newBuilder()
+ .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("response1").build()).build();
- ExecutionServiceOutput fakeResponse2 = ExecutionServiceOutput.newBuilder().setActionIdentifiers(
- ActionIdentifiers.newBuilder().setActionName("response2").build()).build();
+ ExecutionServiceOutput fakeResponse2 = ExecutionServiceOutput.newBuilder()
+ .setActionIdentifiers(ActionIdentifiers.newBuilder().setActionName("response2").build()).build();
CountDownLatch finishLatch = client.sendRequest(fakeRequest1);
diff --git a/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java b/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java
index 636f92835f..e233db48b0 100644
--- a/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java
+++ b/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java
@@ -1,17 +1,14 @@
/*
* Copyright (C) 2019 Bell Canada.
*
- * 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
+ * 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
+ * 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.
+ * 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.
*/
package org.onap.so.client.cds;
@@ -63,8 +60,8 @@ public class TestCDSPropertiesImpl implements CDSProperties {
return false;
}
- @Override
- public int getTimeout() {
- return 60;
- }
+ @Override
+ public int getTimeout() {
+ return 60;
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java b/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
index 65c76561dc..7789386667 100644
--- a/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
+++ b/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
@@ -29,65 +29,67 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-
import org.onap.so.client.aai.AAIProperties;
import org.onap.so.client.aai.AAIVersion;
public class DefaultAAIPropertiesImpl implements AAIProperties {
-
- final Map<Object, Object> props;
- public DefaultAAIPropertiesImpl() {
- File initialFile = new File("src/test/resources/aai.properties");
- Map<Object, Object> temp;
- try (InputStream targetStream = new FileInputStream(initialFile)) {
- Properties properties = new Properties();
- properties.load(targetStream);
- temp = properties;
- } catch (IOException e) {
- temp = new HashMap<>();
- }
- this.props = temp;
- }
-
- public DefaultAAIPropertiesImpl(int port) {
- File initialFile = new File("src/test/resources/aai.properties");
- Map<Object, Object> temp;
- try (InputStream targetStream = new FileInputStream(initialFile)) {
- Properties properties = new Properties();
- properties.load(targetStream);
- temp = properties;
- } catch (IOException e) {
- temp = new HashMap<>();
- }
- this.props = temp;
- this.props.put("aai.endpoint", this.props.get("aai.endpoint").toString().replaceFirst(":\\d+", ":" + port));
+ final Map<Object, Object> props;
+
+ public DefaultAAIPropertiesImpl() {
+ File initialFile = new File("src/test/resources/aai.properties");
+ Map<Object, Object> temp;
+ try (InputStream targetStream = new FileInputStream(initialFile)) {
+ Properties properties = new Properties();
+ properties.load(targetStream);
+ temp = properties;
+ } catch (IOException e) {
+ temp = new HashMap<>();
+ }
+ this.props = temp;
+
+ }
+
+ public DefaultAAIPropertiesImpl(int port) {
+ File initialFile = new File("src/test/resources/aai.properties");
+ Map<Object, Object> temp;
+ try (InputStream targetStream = new FileInputStream(initialFile)) {
+ Properties properties = new Properties();
+ properties.load(targetStream);
+ temp = properties;
+ } catch (IOException e) {
+ temp = new HashMap<>();
+ }
+ this.props = temp;
+ this.props.put("aai.endpoint", this.props.get("aai.endpoint").toString().replaceFirst(":\\d+", ":" + port));
+
+ }
+
+ @Override
+ public URL getEndpoint() throws MalformedURLException {
+ return new URL(props.get("aai.endpoint").toString());
+ }
- }
- @Override
- public URL getEndpoint() throws MalformedURLException {
- return new URL(props.get("aai.endpoint").toString());
- }
+ @Override
+ public String getSystemName() {
+ return "MSO";
+ }
- @Override
- public String getSystemName() {
- return "MSO";
- }
- @Override
- public AAIVersion getDefaultVersion() {
- return AAIVersion.LATEST;
- }
+ @Override
+ public AAIVersion getDefaultVersion() {
+ return AAIVersion.LATEST;
+ }
- @Override
- public String getAuth() {
- Object value = props.get("aai.auth");
- return value == null ? null : value.toString();
- }
+ @Override
+ public String getAuth() {
+ Object value = props.get("aai.auth");
+ return value == null ? null : value.toString();
+ }
- @Override
- public String getKey() {
- Object value = props.get("mso.msoKey");
- return value == null ? null : value.toString();
- }
+ @Override
+ public String getKey() {
+ Object value = props.get("mso.msoKey");
+ return value == null ? null : value.toString();
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java b/common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java
index 4b90cfe021..26fb1cd336 100644
--- a/common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java
+++ b/common/src/test/java/org/onap/so/client/dmaap/DmaapClientTest.java
@@ -21,21 +21,19 @@
package org.onap.so.client.dmaap;
import static org.junit.Assert.assertEquals;
-
import java.io.FileNotFoundException;
import java.io.IOException;
-
import org.junit.Test;
import org.onap.so.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer;
public class DmaapClientTest {
- @Test
- public void deobfuscateTest() throws FileNotFoundException, IOException {
- String encodedBase64 = "dGVzdHBhc3N3b3Jk";
- String notEncoded = "testpassword";
- DmaapConsumer consumer = new SDNOHealthCheckDmaapConsumer();
- assertEquals("decoded password", notEncoded, consumer.deobfuscatePassword(encodedBase64));
+ @Test
+ public void deobfuscateTest() throws FileNotFoundException, IOException {
+ String encodedBase64 = "dGVzdHBhc3N3b3Jk";
+ String notEncoded = "testpassword";
+ DmaapConsumer consumer = new SDNOHealthCheckDmaapConsumer();
+ assertEquals("decoded password", notEncoded, consumer.deobfuscatePassword(encodedBase64));
- }
+ }
}
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
index 0836ed23eb..4bfac38151 100644
--- a/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java
+++ b/common/src/test/java/org/onap/so/client/dmaap/DmaapPublisherTest.java
@@ -20,7 +20,6 @@
package org.onap.so.client.dmaap;
import org.junit.Test;
-
import javax.ws.rs.ProcessingException;
import java.io.IOException;
import java.util.Optional;
@@ -49,12 +48,11 @@ public class DmaapPublisherTest {
}
};
- public DmaapPublisherTest() throws IOException {
- }
+ public DmaapPublisherTest() throws IOException {}
@Test(expected = ProcessingException.class)
public void sendTest() throws Exception {
- dmaapPublisher.send("{'key': 'value'}");
+ dmaapPublisher.send("{'key': 'value'}");
}
-} \ No newline at end of file
+}
diff --git a/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java b/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java
index d24b3ff147..1f047b3b36 100644
--- a/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java
+++ b/common/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java
@@ -24,12 +24,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -37,7 +35,6 @@ 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;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -46,69 +43,76 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(MockitoJUnitRunner.class)
public class GraphInventoryPatchConverterTest {
- private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
+ private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
+
+ @Test
+ public void convertObjectToPatchFormatTest()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ GenericVnf vnf = new GenericVnf();
+ vnf.setIpv4Loopback0Address("");
+ String result = validator.marshallObjectToPatchFormat(vnf);
+ GenericVnf resultObj = mapper.readValue(result.toString(), GenericVnf.class);
+ assertTrue("expect object to become a String to prevent double marshalling", result instanceof String);
+ assertNull("expect null because of custom mapper", resultObj.getIpv4Loopback0Address());
+
+ }
+
+ @Test
+ public void convertStringToPatchFormatTest()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ String payload = "{\"ipv4-loopback0-address\":\"\"}";
+ String result = validator.marshallObjectToPatchFormat(payload);
+
+ assertEquals("expect no change", payload, result);
+ }
+
+ @Test
+ public void convertStringToPatchFormatNull_Test()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ String payload = "{\"ipv4-loopback0-address\": null}";
+ String result = validator.marshallObjectToPatchFormat(payload);
+ System.out.println(result);
+ assertEquals("expect no change", payload, result);
+ }
+
+ @Test
+ public void convertMapToPatchFormatTest()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ HashMap<String, String> map = new HashMap<>();
+ map.put("ipv4-loopback0-address", "");
+ map.put("ipv4-loopback1-address", "192.168.1.1");
+ String result = validator.marshallObjectToPatchFormat(map);
+
+ assertEquals("expect string", "{\"ipv4-loopback1-address\":\"192.168.1.1\"}", result);
+ }
+
+ @Test
+ public void hasComplexObjectTest() {
+ 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\"}]}";
+ String empty = "{}";
+ String arrayCaseSimpleOnly = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"]}";
+ String relationshipListCaseNesting =
+ "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}";
+ String relationshipListCase =
+ "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}]}";
+ String nothing = "";
+
+ assertTrue("expect has nesting", validator.hasComplexObject(hasNesting));
+ assertFalse("expect no nesting", validator.hasComplexObject(noNesting));
+ assertTrue("expect has nesting", validator.hasComplexObject(arrayCase));
+ assertFalse("expect no nesting", validator.hasComplexObject(empty));
+ assertFalse("expect no nesting", validator.hasComplexObject(arrayCaseSimpleOnly));
+ assertFalse("expect no nesting", validator.hasComplexObject(relationshipListCase));
+ assertTrue("expect has nesting", validator.hasComplexObject(relationshipListCaseNesting));
+ assertFalse("expect no nesting", validator.hasComplexObject(nothing));
+ }
- @Test
- public void convertObjectToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
- GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
- GenericVnf vnf = new GenericVnf();
- vnf.setIpv4Loopback0Address("");
- String result = validator.marshallObjectToPatchFormat(vnf);
- GenericVnf resultObj = mapper.readValue(result.toString(), GenericVnf.class);
- assertTrue("expect object to become a String to prevent double marshalling", result instanceof String);
- assertNull("expect null because of custom mapper", resultObj.getIpv4Loopback0Address());
-
- }
-
- @Test
- public void convertStringToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
- GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
- String payload = "{\"ipv4-loopback0-address\":\"\"}";
- String result = validator.marshallObjectToPatchFormat(payload);
-
- assertEquals("expect no change", payload, result);
- }
-
- @Test
- public void convertStringToPatchFormatNull_Test() throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
- GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
- String payload = "{\"ipv4-loopback0-address\": null}";
- String result = validator.marshallObjectToPatchFormat(payload);
- System.out.println(result);
- assertEquals("expect no change", payload, result);
- }
-
- @Test
- public void convertMapToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
- GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
- HashMap<String, String> map = new HashMap<>();
- map.put("ipv4-loopback0-address", "");
- map.put("ipv4-loopback1-address", "192.168.1.1");
- String result = validator.marshallObjectToPatchFormat(map);
-
- assertEquals("expect string", "{\"ipv4-loopback1-address\":\"192.168.1.1\"}", result);
- }
-
- @Test
- public void hasComplexObjectTest() {
- 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\"}]}";
- String empty = "{}";
- String arrayCaseSimpleOnly = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"]}";
- String relationshipListCaseNesting = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}";
- String relationshipListCase = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}]}";
- String nothing = "";
-
- assertTrue("expect has nesting", validator.hasComplexObject(hasNesting));
- assertFalse("expect no nesting", validator.hasComplexObject(noNesting));
- assertTrue("expect has nesting", validator.hasComplexObject(arrayCase));
- assertFalse("expect no nesting", validator.hasComplexObject(empty));
- assertFalse("expect no nesting", validator.hasComplexObject(arrayCaseSimpleOnly));
- assertFalse("expect no nesting", validator.hasComplexObject(relationshipListCase));
- assertTrue("expect has nesting", validator.hasComplexObject(relationshipListCaseNesting));
- assertFalse("expect no nesting", validator.hasComplexObject(nothing));
- }
-
}
diff --git a/common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java b/common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java
index be93f47585..fb26e1870e 100644
--- a/common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java
+++ b/common/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java
@@ -21,9 +21,7 @@
package org.onap.so.client.graphinventory.entities.uri.parsers;
import static org.junit.Assert.assertEquals;
-
import java.util.Map;
-
import org.junit.Test;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.graphinventory.entities.uri.parsers.UriParser;
@@ -31,19 +29,19 @@ import org.onap.so.client.graphinventory.entities.uri.parsers.UriParserSpringImp
public class UriParserSpringImplTest {
-
-
-
- @Test
- public void reverseTemplate() {
- final UriParser parser = new UriParserSpringImpl(AAIObjectType.SERVICE_INSTANCE.toString());
- final String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
-
- Map<String, String> result = parser.parse(uri);
-
- assertEquals("found customer-id", "key1", result.get("global-customer-id"));
- assertEquals("found service-type", "key2", result.get("service-type"));
- assertEquals("found service-instance-id", "key3", result.get("service-instance-id"));
-
- }
+
+
+ @Test
+ public void reverseTemplate() {
+ final UriParser parser = new UriParserSpringImpl(AAIObjectType.SERVICE_INSTANCE.toString());
+ final String uri =
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+
+ Map<String, String> result = parser.parse(uri);
+
+ assertEquals("found customer-id", "key1", result.get("global-customer-id"));
+ assertEquals("found service-type", "key2", result.get("service-type"));
+ assertEquals("found service-instance-id", "key3", result.get("service-instance-id"));
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java b/common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java
index 76b7369399..8ffb70665c 100644
--- a/common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java
+++ b/common/src/test/java/org/onap/so/client/grm/GRMBeansTest.java
@@ -21,9 +21,7 @@
package org.onap.so.client.grm;
import java.util.List;
-
import org.junit.Test;
-
import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.PojoClassFilter;
import com.openpojo.reflection.filters.FilterEnum;
@@ -38,25 +36,21 @@ import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
public class GRMBeansTest {
- private static final String POJO_PACKAGE = "org.onap.so.client.grm.beans";
- private PojoClassFilter filterTestClasses = new FilterTestClasses();
+ private static final String POJO_PACKAGE = "org.onap.so.client.grm.beans";
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ @Test
+ public void testPojoStructureAndBehavior() {
+ Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
+ .with(new SetterTester()).with(new GetterTester()).build();
+
+ validator.validate(POJO_PACKAGE, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
+ }
- @Test
- public void testPojoStructureAndBehavior() {
- Validator validator = ValidatorBuilder.create()
- .with(new GetterMustExistRule())
- .with(new SetterMustExistRule())
- .with(new SetterTester())
- .with(new GetterTester())
- .build();
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
- validator.validate(POJO_PACKAGE, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
- }
-
- private static class FilterTestClasses implements PojoClassFilter {
- public boolean include(PojoClass pojoClass) {
- return !pojoClass.getSourcePath().contains("/test-classes/");
- }
- }
-
}
diff --git a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java
index d0d0e6701b..65069899de 100644
--- a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java
+++ b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointListTest.java
@@ -27,73 +27,71 @@ import static org.junit.Assert.*;
import org.junit.Test;
import org.onap.so.client.grm.beans.ServiceEndPoint;
import org.onap.so.client.grm.beans.ServiceEndPointList;
-
import com.fasterxml.jackson.databind.ObjectMapper;
public class ServiceEndPointListTest {
-
- private ObjectMapper mapper = new ObjectMapper();
-
- @Test
- public void testUnmarshall() throws Exception {
- String endpointsJson = getFileContentsAsString("__files/grm/endpoints.json");
- ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
-
- List<ServiceEndPoint> list = sel.getServiceEndPointList();
- ServiceEndPoint se = list.get(0);
-
- assertEquals(3, list.size());
- assertEquals("dummy.pod.ns.dummy-pod3", se.getName());
- assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor()));
- assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor()));
- assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch()));
- assertEquals("192.168.120.218", se.getHostAddress());
- assertEquals("32004", se.getListenPort());
- assertEquals("37.7022", se.getLatitude());
- assertEquals("121.9358", se.getLongitude());
- assertEquals("/", se.getContextPath());
- assertEquals("edge", se.getOperationalInfo().getCreatedBy());
- assertEquals("edge", se.getOperationalInfo().getUpdatedBy());
- assertEquals("Environment", se.getProperties().get(0).getName());
- assertEquals("DEV", se.getProperties().get(0).getValue());
- }
-
- @Test
- public void testUnmarshallServiceEndpointListStartsWithUppercase() throws Exception {
- String endpointsJson = getFileContentsAsString("__files/grm/endpoints2.json");
- ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
-
- List<ServiceEndPoint> list = sel.getServiceEndPointList();
- ServiceEndPoint se = list.get(0);
-
- assertEquals(3, list.size());
- assertEquals("dummy.pod.ns.dummy-pod3", se.getName());
- assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor()));
- assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor()));
- assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch()));
- assertEquals("192.168.120.218", se.getHostAddress());
- assertEquals("32004", se.getListenPort());
- assertEquals("37.7022", se.getLatitude());
- assertEquals("121.9358", se.getLongitude());
- assertEquals("/", se.getContextPath());
- assertEquals("edge", se.getOperationalInfo().getCreatedBy());
- assertEquals("edge", se.getOperationalInfo().getUpdatedBy());
- assertEquals("Environment", se.getProperties().get(0).getName());
- assertEquals("DEV", se.getProperties().get(0).getValue());
- }
-
- protected String getFileContentsAsString(String fileName) {
- String content = "";
- try {
- ClassLoader classLoader = this.getClass().getClassLoader();
- File file = new File(classLoader.getResource(fileName).getFile());
- content = new String(Files.readAllBytes(file.toPath()));
- }
- catch(Exception e) {
- e.printStackTrace();
- System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());
- }
- return content;
- }
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ public void testUnmarshall() throws Exception {
+ String endpointsJson = getFileContentsAsString("__files/grm/endpoints.json");
+ ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
+
+ List<ServiceEndPoint> list = sel.getServiceEndPointList();
+ ServiceEndPoint se = list.get(0);
+
+ assertEquals(3, list.size());
+ assertEquals("dummy.pod.ns.dummy-pod3", se.getName());
+ assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor()));
+ assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor()));
+ assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch()));
+ assertEquals("192.168.120.218", se.getHostAddress());
+ assertEquals("32004", se.getListenPort());
+ assertEquals("37.7022", se.getLatitude());
+ assertEquals("121.9358", se.getLongitude());
+ assertEquals("/", se.getContextPath());
+ assertEquals("edge", se.getOperationalInfo().getCreatedBy());
+ assertEquals("edge", se.getOperationalInfo().getUpdatedBy());
+ assertEquals("Environment", se.getProperties().get(0).getName());
+ assertEquals("DEV", se.getProperties().get(0).getValue());
+ }
+
+ @Test
+ public void testUnmarshallServiceEndpointListStartsWithUppercase() throws Exception {
+ String endpointsJson = getFileContentsAsString("__files/grm/endpoints2.json");
+ ServiceEndPointList sel = mapper.readValue(endpointsJson, ServiceEndPointList.class);
+
+ List<ServiceEndPoint> list = sel.getServiceEndPointList();
+ ServiceEndPoint se = list.get(0);
+
+ assertEquals(3, list.size());
+ assertEquals("dummy.pod.ns.dummy-pod3", se.getName());
+ assertEquals(Integer.valueOf(1), Integer.valueOf(se.getVersion().getMajor()));
+ assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getMinor()));
+ assertEquals(Integer.valueOf(0), Integer.valueOf(se.getVersion().getPatch()));
+ assertEquals("192.168.120.218", se.getHostAddress());
+ assertEquals("32004", se.getListenPort());
+ assertEquals("37.7022", se.getLatitude());
+ assertEquals("121.9358", se.getLongitude());
+ assertEquals("/", se.getContextPath());
+ assertEquals("edge", se.getOperationalInfo().getCreatedBy());
+ assertEquals("edge", se.getOperationalInfo().getUpdatedBy());
+ assertEquals("Environment", se.getProperties().get(0).getName());
+ assertEquals("DEV", se.getProperties().get(0).getValue());
+ }
+
+ protected String getFileContentsAsString(String fileName) {
+
+ String content = "";
+ try {
+ ClassLoader classLoader = this.getClass().getClassLoader();
+ File file = new File(classLoader.getResource(fileName).getFile());
+ content = new String(Files.readAllBytes(file.toPath()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());
+ }
+ return content;
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java
index 4fe6bca05e..2c1a5ad5fa 100644
--- a/common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java
+++ b/common/src/test/java/org/onap/so/client/grm/ServiceEndPointRequestTest.java
@@ -29,62 +29,61 @@ import org.onap.so.client.grm.beans.Property;
import org.onap.so.client.grm.beans.ServiceEndPoint;
import org.onap.so.client.grm.beans.ServiceEndPointRequest;
import org.onap.so.client.grm.beans.Version;
-
import com.fasterxml.jackson.databind.ObjectMapper;
public class ServiceEndPointRequestTest {
- private ObjectMapper mapper = new ObjectMapper();
-
- @Test
- public void testMarshall() throws Exception {
-
- String expected =
- "{\"serviceEndPoint\":{\"name\":\"TEST.ECOMP_PSL.Inventory\",\"version\":{\"major\":1,\"minor\":0,\"patch\":\"0\"}," +
- "\"hostAddress\":\"127.0.0.1\",\"listenPort\":\"8080\",\"latitude\":\"37.7022\",\"longitude\":\"121.9358\"," +
- "\"contextPath\":\"/\",\"routeOffer\":\"TEST\",\"operationalInfo\":{\"createdBy\":\"edge\",\"updatedBy\":\"edge\"}," +
- "\"properties\":[{\"name\":\"Environment\",\"value\":\"TEST\"},{\"name\":\"cpfrun_cluster_name\"," +
- "\"value\":\"testcase_cluster_no_cluster\"}]},\"env\":\"DEV\"}";
-
- Version ver = new Version();
- ver.setMajor(1);
- ver.setMinor(0);
- ver.setPatch("0");
-
- ServiceEndPoint sep = new ServiceEndPoint();
- sep.setName("TEST.ECOMP_PSL.Inventory");
- sep.setVersion(ver);
- sep.setHostAddress("127.0.0.1");
- sep.setListenPort("8080");
- sep.setLatitude("37.7022");
- sep.setLongitude("121.9358");
- sep.setContextPath("/");
- sep.setRouteOffer("TEST");
-
- OperationalInfo operInfo = new OperationalInfo();
- operInfo.setCreatedBy("edge");
- operInfo.setUpdatedBy("edge");
-
- sep.setOperationalInfo(operInfo);
-
- Property prop1 = new Property();
- prop1.setName("Environment");
- prop1.setValue("TEST");
-
- Property prop2 = new Property();
- prop2.setName("cpfrun_cluster_name");
- prop2.setValue("testcase_cluster_no_cluster");
-
- List<Property> props = new ArrayList<Property>();
- props.add(prop1);
- props.add(prop2);
-
- sep.setProperties(props);
-
- ServiceEndPointRequest request = new ServiceEndPointRequest();
- request.setEnv("DEV");
- request.setServiceEndPoint(sep);
-
- assertEquals(expected, mapper.writeValueAsString(request));
- }
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ public void testMarshall() throws Exception {
+
+ String expected =
+ "{\"serviceEndPoint\":{\"name\":\"TEST.ECOMP_PSL.Inventory\",\"version\":{\"major\":1,\"minor\":0,\"patch\":\"0\"},"
+ + "\"hostAddress\":\"127.0.0.1\",\"listenPort\":\"8080\",\"latitude\":\"37.7022\",\"longitude\":\"121.9358\","
+ + "\"contextPath\":\"/\",\"routeOffer\":\"TEST\",\"operationalInfo\":{\"createdBy\":\"edge\",\"updatedBy\":\"edge\"},"
+ + "\"properties\":[{\"name\":\"Environment\",\"value\":\"TEST\"},{\"name\":\"cpfrun_cluster_name\","
+ + "\"value\":\"testcase_cluster_no_cluster\"}]},\"env\":\"DEV\"}";
+
+ Version ver = new Version();
+ ver.setMajor(1);
+ ver.setMinor(0);
+ ver.setPatch("0");
+
+ ServiceEndPoint sep = new ServiceEndPoint();
+ sep.setName("TEST.ECOMP_PSL.Inventory");
+ sep.setVersion(ver);
+ sep.setHostAddress("127.0.0.1");
+ sep.setListenPort("8080");
+ sep.setLatitude("37.7022");
+ sep.setLongitude("121.9358");
+ sep.setContextPath("/");
+ sep.setRouteOffer("TEST");
+
+ OperationalInfo operInfo = new OperationalInfo();
+ operInfo.setCreatedBy("edge");
+ operInfo.setUpdatedBy("edge");
+
+ sep.setOperationalInfo(operInfo);
+
+ Property prop1 = new Property();
+ prop1.setName("Environment");
+ prop1.setValue("TEST");
+
+ Property prop2 = new Property();
+ prop2.setName("cpfrun_cluster_name");
+ prop2.setValue("testcase_cluster_no_cluster");
+
+ List<Property> props = new ArrayList<Property>();
+ props.add(prop1);
+ props.add(prop2);
+
+ sep.setProperties(props);
+
+ ServiceEndPointRequest request = new ServiceEndPointRequest();
+ request.setEnv("DEV");
+ request.setServiceEndPoint(sep);
+
+ assertEquals(expected, mapper.writeValueAsString(request));
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/grm/exception/GRMClientCallFailedTest.java b/common/src/test/java/org/onap/so/client/grm/exception/GRMClientCallFailedTest.java
index 989a753800..0dfd55c0b4 100644
--- a/common/src/test/java/org/onap/so/client/grm/exception/GRMClientCallFailedTest.java
+++ b/common/src/test/java/org/onap/so/client/grm/exception/GRMClientCallFailedTest.java
@@ -20,7 +20,6 @@
package org.onap.so.client.grm.exception;
import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import org.onap.so.client.grm.exceptions.GRMClientCallFailed;
diff --git a/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
index 46f9de2268..ad22c65248 100644
--- a/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
+++ b/common/src/test/java/org/onap/so/client/policy/PolicyClientImplTest.java
@@ -26,12 +26,10 @@ import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doReturn;
import static org.mockito.ArgumentMatchers.any;
-
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -43,7 +41,6 @@ import org.onap.so.client.policy.entities.DictionaryData;
import org.onap.so.client.policy.entities.PolicyConfig;
import org.onap.so.client.policy.entities.PolicyDecision;
import org.onap.so.client.policy.entities.PolicyServiceType;
-
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -52,99 +49,101 @@ import com.fasterxml.jackson.databind.SerializationFeature;
public class PolicyClientImplTest {
- @BeforeClass
- public static void setUp() {
- System.setProperty("mso.config.path", "src/test/resources");
- }
-
- private static String RESOURCE_PATH = "src/test/resources/__files/Policy/";
-
- @Test
- public void successReadProperties() {
- PolicyRestClient client = new PolicyRestClient(new PolicyRestPropertiesImpl(), PolicyServiceType.GET_DECISION);
- Map<String, String> map = new HashMap<>();
- client.initializeHeaderMap(map);
- assertEquals("Found expected Client Auth", "Basic bTAzNzQzOnBvbGljeVIwY2sk", map.get("ClientAuth"));
- assertEquals("Found expected Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==", map.get("Authorization"));
- assertEquals("Found expected Environment", "TEST", map.get("Environment"));
- }
-
- @Test
- @Ignore
- public void getDecisionTest() {
- PolicyClient client = new PolicyClientImpl();
- PolicyDecision decision = client.getDecision("S", "V", "BB1", "1", "123");
- assertEquals("Decision is correct", decision.getDecision(), "PERMIT");
- assertEquals("Decision details is correct", decision.getDetails(), "Retry");
- }
-
- @Test
- @Ignore
- public void getAllowedTreatmentsTest() {
- PolicyClient client = new PolicyClientImpl();
- DictionaryData dictClient = client.getAllowedTreatments("BB1", "1");
- final String dictBbidString = dictClient.getBbid().getString();
- final String dictWorkStepString = dictClient.getWorkstep().getString();
- assertEquals("DictionaryData matches a response Bbid", dictBbidString, "BB1");
- assertEquals("DicitonaryData matches a response WorkStep", dictWorkStepString, "1");
- }
-
- @Test
- public void getDecisionMockTest() {
- String serviceType = "S";
- String vnfType = "V";
- String bbID = "BB1";
- String workStep = "1";
- String errorCode = "123";
-
- PolicyDecision expected = new PolicyDecision();
- expected.setDecision("PERMIT");
- expected.setDetails("Retry");
-
- DecisionAttributes decisionAttributes = new DecisionAttributes();
- decisionAttributes.setServiceType(serviceType);
- decisionAttributes.setVNFType(vnfType);
- decisionAttributes.setBBID(bbID);
- decisionAttributes.setWorkStep(workStep);
- decisionAttributes.setErrorCode(errorCode);
- PolicyClient client = Mockito.spy(PolicyClientImpl.class);
-
- doReturn(expected).when(client).getDecision(serviceType, vnfType, bbID, workStep, errorCode);
-
- PolicyDecision actual = client.getDecision(serviceType, vnfType, bbID, workStep, errorCode);
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void getConfigFromStringJsonTest() throws JsonParseException, JsonMappingException, IOException {
- PolicyClientImpl client = new PolicyClientImpl();
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
- mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
- Config expected = mapper.readValue(new File(RESOURCE_PATH + "configJson.json"), Config.class);
- PolicyConfig[] returnedPolicyConfigList = mapper.readValue(new File(RESOURCE_PATH + "policyConfig.json"), PolicyConfig[].class);
- String configJson = returnedPolicyConfigList[0].getConfig();
- Config actual = client.getConfigFromStringJson(configJson);
-
- assertThat(actual, sameBeanAs(expected));
- }
-
- @Test
- public void getConfigWithPolicyNameTest() throws JsonParseException, JsonMappingException, IOException {
- PolicyClientImpl client = Mockito.spy(PolicyClientImpl.class);
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
- mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
- PolicyConfig[] returnedPolicyConfigList = mapper.readValue(new File(RESOURCE_PATH + "policyConfig.json"), PolicyConfig[].class);
- Config expected = mapper.readValue(new File(RESOURCE_PATH + "configJson.json"), Config.class);
-
- PolicyRestClient mockedClient = Mockito.mock(PolicyRestClient.class);
- doReturn(mockedClient).when(client).getPolicyRestClient(PolicyServiceType.GET_CONFIG);
- doReturn(returnedPolicyConfigList).when(mockedClient).post(isA(ConfigRequestParameters.class), any());
-
- Config actual = client.getConfigWithPolicyName("policyName");
-
- assertThat(actual, sameBeanAs(expected));
-
- }
+ @BeforeClass
+ public static void setUp() {
+ System.setProperty("mso.config.path", "src/test/resources");
+ }
+
+ private static String RESOURCE_PATH = "src/test/resources/__files/Policy/";
+
+ @Test
+ public void successReadProperties() {
+ PolicyRestClient client = new PolicyRestClient(new PolicyRestPropertiesImpl(), PolicyServiceType.GET_DECISION);
+ Map<String, String> map = new HashMap<>();
+ client.initializeHeaderMap(map);
+ assertEquals("Found expected Client Auth", "Basic bTAzNzQzOnBvbGljeVIwY2sk", map.get("ClientAuth"));
+ assertEquals("Found expected Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==", map.get("Authorization"));
+ assertEquals("Found expected Environment", "TEST", map.get("Environment"));
+ }
+
+ @Test
+ @Ignore
+ public void getDecisionTest() {
+ PolicyClient client = new PolicyClientImpl();
+ PolicyDecision decision = client.getDecision("S", "V", "BB1", "1", "123");
+ assertEquals("Decision is correct", decision.getDecision(), "PERMIT");
+ assertEquals("Decision details is correct", decision.getDetails(), "Retry");
+ }
+
+ @Test
+ @Ignore
+ public void getAllowedTreatmentsTest() {
+ PolicyClient client = new PolicyClientImpl();
+ DictionaryData dictClient = client.getAllowedTreatments("BB1", "1");
+ final String dictBbidString = dictClient.getBbid().getString();
+ final String dictWorkStepString = dictClient.getWorkstep().getString();
+ assertEquals("DictionaryData matches a response Bbid", dictBbidString, "BB1");
+ assertEquals("DicitonaryData matches a response WorkStep", dictWorkStepString, "1");
+ }
+
+ @Test
+ public void getDecisionMockTest() {
+ String serviceType = "S";
+ String vnfType = "V";
+ String bbID = "BB1";
+ String workStep = "1";
+ String errorCode = "123";
+
+ PolicyDecision expected = new PolicyDecision();
+ expected.setDecision("PERMIT");
+ expected.setDetails("Retry");
+
+ DecisionAttributes decisionAttributes = new DecisionAttributes();
+ decisionAttributes.setServiceType(serviceType);
+ decisionAttributes.setVNFType(vnfType);
+ decisionAttributes.setBBID(bbID);
+ decisionAttributes.setWorkStep(workStep);
+ decisionAttributes.setErrorCode(errorCode);
+ PolicyClient client = Mockito.spy(PolicyClientImpl.class);
+
+ doReturn(expected).when(client).getDecision(serviceType, vnfType, bbID, workStep, errorCode);
+
+ PolicyDecision actual = client.getDecision(serviceType, vnfType, bbID, workStep, errorCode);
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void getConfigFromStringJsonTest() throws JsonParseException, JsonMappingException, IOException {
+ PolicyClientImpl client = new PolicyClientImpl();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
+ Config expected = mapper.readValue(new File(RESOURCE_PATH + "configJson.json"), Config.class);
+ PolicyConfig[] returnedPolicyConfigList =
+ mapper.readValue(new File(RESOURCE_PATH + "policyConfig.json"), PolicyConfig[].class);
+ String configJson = returnedPolicyConfigList[0].getConfig();
+ Config actual = client.getConfigFromStringJson(configJson);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void getConfigWithPolicyNameTest() throws JsonParseException, JsonMappingException, IOException {
+ PolicyClientImpl client = Mockito.spy(PolicyClientImpl.class);
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
+ PolicyConfig[] returnedPolicyConfigList =
+ mapper.readValue(new File(RESOURCE_PATH + "policyConfig.json"), PolicyConfig[].class);
+ Config expected = mapper.readValue(new File(RESOURCE_PATH + "configJson.json"), Config.class);
+
+ PolicyRestClient mockedClient = Mockito.mock(PolicyRestClient.class);
+ doReturn(mockedClient).when(client).getPolicyRestClient(PolicyServiceType.GET_CONFIG);
+ doReturn(returnedPolicyConfigList).when(mockedClient).post(isA(ConfigRequestParameters.class), any());
+
+ Config actual = client.getConfigWithPolicyName("policyName");
+
+ assertThat(actual, sameBeanAs(expected));
+
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java b/common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java
index 2796affa49..9d03fb9643 100644
--- a/common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java
+++ b/common/src/test/java/org/onap/so/client/policy/entities/PolicyEntitiesTest.java
@@ -21,7 +21,6 @@
package org.onap.so.client.policy.entities;
import org.junit.Test;
-
import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.PojoClassFilter;
import com.openpojo.reflection.filters.FilterEnum;
@@ -35,25 +34,22 @@ import com.openpojo.validation.test.impl.SetterTester;
public class PolicyEntitiesTest {
- private PojoClassFilter filterTestClasses = new FilterTestClasses();
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ @Test
+ public void pojoStructure() {
+ test("org.onap.so.client.policy.entities");
+ }
- @Test
- public void pojoStructure() {
- test("org.onap.so.client.policy.entities");
- }
+ private void test(String pojoPackage) {
+ Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
+ .with(new SetterTester()).with(new GetterTester()).build();
+ validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
+ }
- private void test(String pojoPackage) {
- Validator validator = ValidatorBuilder.create()
- .with(new GetterMustExistRule())
- .with(new SetterMustExistRule())
- .with(new SetterTester())
- .with(new GetterTester())
- .build();
- validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
- }
- private static class FilterTestClasses implements PojoClassFilter {
- public boolean include(PojoClass pojoClass) {
- return !pojoClass.getSourcePath().contains("/test-classes/");
- }
- }
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java b/common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java
index ba8772b05c..1ca8942ac1 100644
--- a/common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java
+++ b/common/src/test/java/org/onap/so/client/ruby/RubyCheckClientTest.java
@@ -24,83 +24,78 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
-
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.time.format.DateTimeFormatter;
-
import org.junit.Test;
import org.onap.so.client.ruby.beans.Ruby;
-
import static org.apache.commons.lang3.StringUtils.*;
import com.fasterxml.jackson.databind.ObjectMapper;
public class RubyCheckClientTest {
- private final String fileLocation = "src/test/resources/org/onap/so/client/ruby/create-ticket/";
- private static final String REQUEST_ID = "abc123";
- private static final String SOURCE_NAME = "source-name";
- private static final String TIME = "test-time";
- private static final String REASON = "reason";
- private static final String WORK_FLOW_ID = "work-flow-Id";
- private static final String NOTIFICATION = "notification";
-
+ private final String fileLocation = "src/test/resources/org/onap/so/client/ruby/create-ticket/";
+ private static final String REQUEST_ID = "abc123";
+ private static final String SOURCE_NAME = "source-name";
+ private static final String TIME = "test-time";
+ private static final String REASON = "reason";
+ private static final String WORK_FLOW_ID = "work-flow-Id";
+ private static final String NOTIFICATION = "notification";
+
+
+
+ @Test
+ public void verifyRubyCreateTicketRequest() throws IOException, ParseException {
+ String content = this.getJson("create-ticket-request.json");
+ ObjectMapper mapper = new ObjectMapper();
+ Ruby expected = mapper.readValue(content, Ruby.class);
+ RubyClient client = new RubyClient();
+ RubyClient spy = spy(client);
+ when(spy.getTime()).thenReturn(TIME);
+ String actual = spy.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, NOTIFICATION);
+ assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
+ }
+
+
+ @Test
+ public void verifyTimeFormat() {
+ RubyClient client = new RubyClient();
+ String time = client.getTime();
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z");
+ formatter.parse(time);
+ }
+
+
+ @Test
+ public void verifyReasonCharLimit() throws IOException {
+ final String reasonLong = repeat("*", 256);
+ RubyClient client = new RubyClient();
+ try {
+ client.buildRequest(REQUEST_ID, SOURCE_NAME, reasonLong, WORK_FLOW_ID, NOTIFICATION);
+ fail("Should have thrown IllegalArgumentException but did not!");
+ } catch (final IllegalArgumentException e) {
+ final String msg = "reason exceeds 255 characters";
+ assertEquals(msg, e.getMessage());
+ }
+ }
+
+ @Test
+ public void verifyNotificationCharLimit() throws IOException {
+ final String notificationLong = repeat("*", 1025);
+ RubyClient client = new RubyClient();
+ try {
+ client.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, notificationLong);
+ fail("Should have thrown IllegalArgumentException but did not!");
+ } catch (final IllegalArgumentException e) {
+ final String msg = "notification exceeds 1024 characters";
+ assertEquals(msg, e.getMessage());
+ }
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
+ }
-
- @Test
- public void verifyRubyCreateTicketRequest() throws IOException, ParseException{
- String content = this.getJson("create-ticket-request.json");
- ObjectMapper mapper = new ObjectMapper();
- Ruby expected = mapper.readValue(content, Ruby.class);
- RubyClient client = new RubyClient();
- RubyClient spy = spy(client);
- when(spy.getTime()).thenReturn(TIME);
- String actual = spy.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, NOTIFICATION);
- assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
- }
-
-
- @Test
- public void verifyTimeFormat() {
- RubyClient client = new RubyClient();
- String time = client.getTime();
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z");
- formatter.parse(time);
- }
-
-
- @Test
- public void verifyReasonCharLimit() throws IOException{
- final String reasonLong = repeat("*", 256);
- RubyClient client = new RubyClient();
- try{
- client.buildRequest(REQUEST_ID, SOURCE_NAME, reasonLong, WORK_FLOW_ID, NOTIFICATION);
- fail("Should have thrown IllegalArgumentException but did not!");
- }
- catch(final IllegalArgumentException e){
- final String msg = "reason exceeds 255 characters";
- assertEquals(msg, e.getMessage());
- }
- }
-
- @Test
- public void verifyNotificationCharLimit() throws IOException{
- final String notificationLong = repeat("*", 1025);
- RubyClient client = new RubyClient();
- try{
- client.buildRequest(REQUEST_ID, SOURCE_NAME, REASON, WORK_FLOW_ID, notificationLong);
- fail("Should have thrown IllegalArgumentException but did not!");
- }
- catch(final IllegalArgumentException e){
- final String msg = "notification exceeds 1024 characters";
- assertEquals(msg, e.getMessage());
- }
- }
-
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
- }
-
}
-
+
diff --git a/common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java b/common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java
index eb142be4c6..ca80930468 100644
--- a/common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java
+++ b/common/src/test/java/org/onap/so/client/ruby/beans/RubyBeansTest.java
@@ -21,7 +21,6 @@
package org.onap.so.client.ruby.beans;
import org.junit.Test;
-
import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.PojoClassFilter;
import com.openpojo.reflection.filters.FilterEnum;
@@ -35,25 +34,22 @@ import com.openpojo.validation.test.impl.SetterTester;
public class RubyBeansTest {
- private PojoClassFilter filterTestClasses = new FilterTestClasses();
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ @Test
+ public void pojoStructure() {
+ test("org.onap.so.client.ruby.beans");
+ }
- @Test
- public void pojoStructure() {
- test("org.onap.so.client.ruby.beans");
- }
+ private void test(String pojoPackage) {
+ Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
+ .with(new SetterTester()).with(new GetterTester()).build();
+ validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
+ }
- private void test(String pojoPackage) {
- Validator validator = ValidatorBuilder.create()
- .with(new GetterMustExistRule())
- .with(new SetterMustExistRule())
- .with(new SetterTester())
- .with(new GetterTester())
- .build();
- validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
- }
- private static class FilterTestClasses implements PojoClassFilter {
- public boolean include(PojoClass pojoClass) {
- return !pojoClass.getSourcePath().contains("/test-classes/");
- }
- }
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java b/common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java
index 4887aed522..750e578558 100644
--- a/common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java
+++ b/common/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java
@@ -21,74 +21,74 @@
package org.onap.so.client.sdno;
import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Optional;
-
import org.junit.Test;
import org.onap.so.client.sdno.beans.SDNO;
-
import com.fasterxml.jackson.databind.ObjectMapper;
public class SDNOHealthCheckClientTest {
-
-
- private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/health-check/";
- private static final String userId = "test-user";
- private static final Optional<String> clliCode = Optional.of("test-clli");
- private static final String requestId = "test-request-id";
- private static final String configurationId = "test-configuration-id";
- private static final String interfaceId = "test-interface-id";
-
- @Test
- public void verfyLPortMirrorPreCheckRequest() throws IOException{
- String content = this.getJson("custom-lport-mirror-pre-check-request.json");
- ObjectMapper mapper = new ObjectMapper();
- SDNO expected = mapper.readValue(content, SDNO.class);
- SDNOHealthCheckClient client = new SDNOHealthCheckClient();
- String actual = client.buildLPortMirrorCheckPreRequest(userId, requestId, clliCode, configurationId, interfaceId);
- assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
- }
-
- @Test
- public void verfyLPortMirrorPostCheckRequest() throws IOException{
- String content = this.getJson("custom-lport-mirror-post-check-request.json");
- ObjectMapper mapper = new ObjectMapper();
- SDNO expected = mapper.readValue(content, SDNO.class);
- SDNOHealthCheckClient client = new SDNOHealthCheckClient();
- String actual = client.buildLPortMirrorCheckPostRequest(userId, requestId, clliCode, configurationId, interfaceId);
- assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
- }
-
-
- @Test
- public void verifyPortMirrorPostCheckRequest() throws IOException{
- String content = this.getJson("custom-port-mirror-post-check-request.json");
- ObjectMapper mapper = new ObjectMapper();
- SDNO expected = mapper.readValue(content, SDNO.class);
- SDNOHealthCheckClient client = new SDNOHealthCheckClient();
- String actual = client.buildPortMirrorPostCheckRequest(userId, requestId, clliCode, configurationId);
-
- assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
-
- }
- @Test
- public void verifyPortMirrorPreCheckRequest() throws IOException {
- String content = this.getJson("custom-port-mirror-pre-check-request.json");
- ObjectMapper mapper = new ObjectMapper();
- SDNO expected = mapper.readValue(content, SDNO.class);
- SDNOHealthCheckClient client = new SDNOHealthCheckClient();
- String actual = client.buildPortMirrorPreCheckRequest(userId, requestId, clliCode, configurationId);
-
- assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
-
- }
-
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
- }
-
+
+
+ private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/health-check/";
+ private static final String userId = "test-user";
+ private static final Optional<String> clliCode = Optional.of("test-clli");
+ private static final String requestId = "test-request-id";
+ private static final String configurationId = "test-configuration-id";
+ private static final String interfaceId = "test-interface-id";
+
+ @Test
+ public void verfyLPortMirrorPreCheckRequest() throws IOException {
+ String content = this.getJson("custom-lport-mirror-pre-check-request.json");
+ ObjectMapper mapper = new ObjectMapper();
+ SDNO expected = mapper.readValue(content, SDNO.class);
+ SDNOHealthCheckClient client = new SDNOHealthCheckClient();
+ String actual =
+ client.buildLPortMirrorCheckPreRequest(userId, requestId, clliCode, configurationId, interfaceId);
+ assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
+ }
+
+ @Test
+ public void verfyLPortMirrorPostCheckRequest() throws IOException {
+ String content = this.getJson("custom-lport-mirror-post-check-request.json");
+ ObjectMapper mapper = new ObjectMapper();
+ SDNO expected = mapper.readValue(content, SDNO.class);
+ SDNOHealthCheckClient client = new SDNOHealthCheckClient();
+ String actual =
+ client.buildLPortMirrorCheckPostRequest(userId, requestId, clliCode, configurationId, interfaceId);
+ assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
+ }
+
+
+ @Test
+ public void verifyPortMirrorPostCheckRequest() throws IOException {
+ String content = this.getJson("custom-port-mirror-post-check-request.json");
+ ObjectMapper mapper = new ObjectMapper();
+ SDNO expected = mapper.readValue(content, SDNO.class);
+ SDNOHealthCheckClient client = new SDNOHealthCheckClient();
+ String actual = client.buildPortMirrorPostCheckRequest(userId, requestId, clliCode, configurationId);
+
+ assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
+
+ }
+
+ @Test
+ public void verifyPortMirrorPreCheckRequest() throws IOException {
+ String content = this.getJson("custom-port-mirror-pre-check-request.json");
+ ObjectMapper mapper = new ObjectMapper();
+ SDNO expected = mapper.readValue(content, SDNO.class);
+ SDNOHealthCheckClient client = new SDNOHealthCheckClient();
+ String actual = client.buildPortMirrorPreCheckRequest(userId, requestId, clliCode, configurationId);
+
+ assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
+
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
+ }
+
}
diff --git a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java
index 79ce196bd3..c2278c26f9 100644
--- a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java
+++ b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java
@@ -22,7 +22,6 @@ package org.onap.so.client.sdno;
import static org.junit.Assert.assertEquals;
import java.util.UUID;
-
import org.junit.Test;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.so.client.sdno.beans.RequestHealthDiagnostic;
@@ -30,28 +29,28 @@ import org.onap.so.client.sdno.beans.SDNO;
public class SDNOValidatorImplTest {
- @Test
- public void buildRequestDiagnosticTest() throws Exception {
- SDNOValidatorImpl validator = new SDNOValidatorImpl();
- UUID uuid = UUID.randomUUID();
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfName("VNFNAME");
- vnf.setVnfId("test");
- vnf.setIpv4OamAddress("1.2.3.4");
- vnf.setNfRole("VPE");
- SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid");
- assertEquals(request.getNodeType(), "VPE");
- assertEquals(request.getOperation(), "health-diagnostic");
-
- RequestHealthDiagnostic innerRequest = request.getBody().getInput().getRequestHealthDiagnostic();
- assertEquals(innerRequest.getRequestClientName(), "MSO");
- assertEquals(innerRequest.getRequestNodeName(), "VNFNAME");
- assertEquals(innerRequest.getRequestNodeUuid(), "test");
- assertEquals(innerRequest.getRequestNodeType(), "VPE");
- assertEquals(innerRequest.getRequestNodeIp(), "1.2.3.4");
- assertEquals(innerRequest.getRequestUserId(), "mechid");
- assertEquals(innerRequest.getRequestId(), uuid.toString());
- assertEquals(innerRequest.getHealthDiagnosticCode(), "default");
+ @Test
+ public void buildRequestDiagnosticTest() throws Exception {
+ SDNOValidatorImpl validator = new SDNOValidatorImpl();
+ UUID uuid = UUID.randomUUID();
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfName("VNFNAME");
+ vnf.setVnfId("test");
+ vnf.setIpv4OamAddress("1.2.3.4");
+ vnf.setNfRole("VPE");
+ SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid");
+ assertEquals(request.getNodeType(), "VPE");
+ assertEquals(request.getOperation(), "health-diagnostic");
+
+ RequestHealthDiagnostic innerRequest = request.getBody().getInput().getRequestHealthDiagnostic();
+ assertEquals(innerRequest.getRequestClientName(), "MSO");
+ assertEquals(innerRequest.getRequestNodeName(), "VNFNAME");
+ assertEquals(innerRequest.getRequestNodeUuid(), "test");
+ assertEquals(innerRequest.getRequestNodeType(), "VPE");
+ assertEquals(innerRequest.getRequestNodeIp(), "1.2.3.4");
+ assertEquals(innerRequest.getRequestUserId(), "mechid");
+ assertEquals(innerRequest.getRequestId(), uuid.toString());
+ assertEquals(innerRequest.getHealthDiagnosticCode(), "default");
- }
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java
index 9794c9b622..18b9be0983 100644
--- a/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java
+++ b/common/src/test/java/org/onap/so/client/sdno/SDNOValidatorTest.java
@@ -25,13 +25,11 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
-
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.UUID;
-
import org.hamcrest.core.StringContains;
import org.junit.Before;
import org.junit.Ignore;
@@ -47,70 +45,76 @@ import org.onap.so.client.dmaap.exceptions.DMaaPConsumerFailure;
import org.onap.so.client.exceptions.SDNOException;
import org.onap.so.client.sdno.beans.SDNO;
import org.onap.so.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer;
-
import com.fasterxml.jackson.databind.ObjectMapper;
public class SDNOValidatorTest {
-
- @Mock private Consumer mrConsumer;
- @Spy private SDNOHealthCheckDmaapConsumer dmaapConsumer;
- private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/";
- private final String uuid = "xyz123";
- @Rule public ExpectedException thrown = ExpectedException.none();
-
- @Before
- public void setUpTests() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void success() throws IOException, Exception {
- when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer);
- when(mrConsumer.fetch()).thenReturn(Arrays.asList(new String[]{getJson("response.json"), getJson("output-success.json")}));
-
- SDNOValidatorImpl validator = new SDNOValidatorImpl();
- SDNOValidatorImpl spy = spy(validator);
- when(dmaapConsumer.getRequestId()).thenReturn("xyz123");
- doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class));
- boolean result = spy.pollForResponse("xyz123");
- assertEquals("result is true", result, true);
- }
-
- @Test
- public void failure() throws IOException, Exception {
- when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer);
- when(mrConsumer.fetch()).thenReturn(Arrays.asList(new String[]{getJson("response.json"), getJson("output-failure.json")}));
-
- SDNOValidatorImpl validator = new SDNOValidatorImpl();
- SDNOValidatorImpl spy = spy(validator);
- when(dmaapConsumer.getRequestId()).thenReturn("xyz123");
- doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class));
- thrown.expect(SDNOException.class);
- thrown.expectMessage(new StringContains("my error message"));
- boolean result = spy.pollForResponse("xyz123");
-
- }
- @Ignore
- @Test
- public void run() throws Exception {
- SDNOValidatorImpl validator = new SDNOValidatorImpl();
- UUID uuid = UUID.randomUUID();
- GenericVnf vnf = new GenericVnf();
- vnf.setVnfId("test");
- vnf.setIpv4OamAddress("1.2.3.4");
- vnf.setNfRole("VPE");
- SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid");
- ObjectMapper mapper = new ObjectMapper();
- String json = mapper.writeValueAsString(request);
- validator.submitRequest(json);
- thrown.expect(DMaaPConsumerFailure.class);
- boolean result = validator.pollForResponse(uuid.toString());
- System.out.println(json);
- }
- private String getJson(String filename) throws IOException {
- return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
- }
+ @Mock
+ private Consumer mrConsumer;
+ @Spy
+ private SDNOHealthCheckDmaapConsumer dmaapConsumer;
+ private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/";
+ private final String uuid = "xyz123";
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Before
+ public void setUpTests() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void success() throws IOException, Exception {
+ when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer);
+ when(mrConsumer.fetch())
+ .thenReturn(Arrays.asList(new String[] {getJson("response.json"), getJson("output-success.json")}));
+
+ SDNOValidatorImpl validator = new SDNOValidatorImpl();
+ SDNOValidatorImpl spy = spy(validator);
+ when(dmaapConsumer.getRequestId()).thenReturn("xyz123");
+ doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class));
+ boolean result = spy.pollForResponse("xyz123");
+ assertEquals("result is true", result, true);
+ }
+
+ @Test
+ public void failure() throws IOException, Exception {
+ when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer);
+ when(mrConsumer.fetch())
+ .thenReturn(Arrays.asList(new String[] {getJson("response.json"), getJson("output-failure.json")}));
+
+ SDNOValidatorImpl validator = new SDNOValidatorImpl();
+ SDNOValidatorImpl spy = spy(validator);
+ when(dmaapConsumer.getRequestId()).thenReturn("xyz123");
+ doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class));
+ thrown.expect(SDNOException.class);
+ thrown.expectMessage(new StringContains("my error message"));
+ boolean result = spy.pollForResponse("xyz123");
+
+ }
+
+ @Ignore
+ @Test
+ public void run() throws Exception {
+ SDNOValidatorImpl validator = new SDNOValidatorImpl();
+ UUID uuid = UUID.randomUUID();
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("test");
+ vnf.setIpv4OamAddress("1.2.3.4");
+ vnf.setNfRole("VPE");
+ SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid");
+ ObjectMapper mapper = new ObjectMapper();
+ String json = mapper.writeValueAsString(request);
+ validator.submitRequest(json);
+ thrown.expect(DMaaPConsumerFailure.class);
+ boolean result = validator.pollForResponse(uuid.toString());
+ System.out.println(json);
+
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java b/common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java
index bdfefd028c..6f33c490f6 100644
--- a/common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java
+++ b/common/src/test/java/org/onap/so/client/sdno/beans/SdnoBeansTest.java
@@ -21,7 +21,6 @@
package org.onap.so.client.sdno.beans;
import org.junit.Test;
-
import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.PojoClassFilter;
import com.openpojo.reflection.filters.FilterEnum;
@@ -35,25 +34,22 @@ import com.openpojo.validation.test.impl.SetterTester;
public class SdnoBeansTest {
- private PojoClassFilter filterTestClasses = new FilterTestClasses();
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ @Test
+ public void pojoStructure() {
+ test("org.onap.so.client.sdno.beans");
+ }
- @Test
- public void pojoStructure() {
- test("org.onap.so.client.sdno.beans");
- }
+ private void test(String pojoPackage) {
+ Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
+ .with(new SetterTester()).with(new GetterTester()).build();
+ validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
+ }
- private void test(String pojoPackage) {
- Validator validator = ValidatorBuilder.create()
- .with(new GetterMustExistRule())
- .with(new SetterMustExistRule())
- .with(new SetterTester())
- .with(new GetterTester())
- .build();
- validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
- }
- private static class FilterTestClasses implements PojoClassFilter {
- public boolean include(PojoClass pojoClass) {
- return !pojoClass.getSourcePath().contains("/test-classes/");
- }
- }
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
}
diff --git a/common/src/test/java/org/onap/so/configuration/rest/BasicHttpHeadersProviderTest.java b/common/src/test/java/org/onap/so/configuration/rest/BasicHttpHeadersProviderTest.java
index 3e762cfbe7..cab39824b0 100644
--- a/common/src/test/java/org/onap/so/configuration/rest/BasicHttpHeadersProviderTest.java
+++ b/common/src/test/java/org/onap/so/configuration/rest/BasicHttpHeadersProviderTest.java
@@ -23,9 +23,7 @@ package org.onap.so.configuration.rest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.onap.so.configuration.rest.BasicHttpHeadersProvider.AUTHORIZATION_HEADER;
-
import java.util.Arrays;
-
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
diff --git a/common/src/test/java/org/onap/so/configuration/rest/HttpComponentsClientConfigurationTest.java b/common/src/test/java/org/onap/so/configuration/rest/HttpComponentsClientConfigurationTest.java
index 5084acc934..4b054ff7d1 100644
--- a/common/src/test/java/org/onap/so/configuration/rest/HttpComponentsClientConfigurationTest.java
+++ b/common/src/test/java/org/onap/so/configuration/rest/HttpComponentsClientConfigurationTest.java
@@ -21,7 +21,6 @@
package org.onap.so.configuration.rest;
import static org.junit.Assert.assertNotNull;
-
import org.junit.Test;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
diff --git a/common/src/test/java/org/onap/so/constants/DefaultsTest.java b/common/src/test/java/org/onap/so/constants/DefaultsTest.java
index 6383d0ea4c..11ecc96c36 100644
--- a/common/src/test/java/org/onap/so/constants/DefaultsTest.java
+++ b/common/src/test/java/org/onap/so/constants/DefaultsTest.java
@@ -21,7 +21,6 @@
package org.onap.so.constants;
import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -38,9 +37,9 @@ import org.springframework.test.context.junit4.SpringRunner;
@Category(SpringAware.class)
public class DefaultsTest {
- @Test
- public void checkValue() {
-
- assertEquals("my-custom-owner", Defaults.CLOUD_OWNER.toString());
- }
+ @Test
+ public void checkValue() {
+
+ assertEquals("my-custom-owner", Defaults.CLOUD_OWNER.toString());
+ }
}
diff --git a/common/src/test/java/org/onap/so/entity/MsoRequestTest.java b/common/src/test/java/org/onap/so/entity/MsoRequestTest.java
index 73b5c7ea2d..1561f67b3a 100644
--- a/common/src/test/java/org/onap/so/entity/MsoRequestTest.java
+++ b/common/src/test/java/org/onap/so/entity/MsoRequestTest.java
@@ -23,7 +23,6 @@ package org.onap.so.entity;
import org.junit.Test;
import org.onap.so.openpojo.rules.HasToStringRule;
import org.onap.so.openpojo.rules.ToStringTester;
-
import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.PojoClassFilter;
import com.openpojo.reflection.filters.FilterEnum;
@@ -46,14 +45,11 @@ public class MsoRequestTest {
}
private void test(String pojoPackage) {
- Validator validator = ValidatorBuilder.create()
- .with(new GetterMustExistRule())
- .with(new SetterMustExistRule())
- .with(new SetterTester())
- .with(new GetterTester())
- .build();
+ Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
+ .with(new SetterTester()).with(new GetterTester()).build();
validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
}
+
private static class FilterTestClasses implements PojoClassFilter {
public boolean include(PojoClass pojoClass) {
return !pojoClass.getSourcePath().contains("/test-classes/");
diff --git a/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java b/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java
index 27fb584b3b..c72f3f63f3 100644
--- a/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java
+++ b/common/src/test/java/org/onap/so/exceptions/ValidationExceptionTest.java
@@ -28,25 +28,25 @@ import org.junit.Test;
*/
public class ValidationExceptionTest {
@Test
- public void validationExceptionOverrideMessageFalse(){
+ public void validationExceptionOverrideMessageFalse() {
ValidationException e = new ValidationException("testMessage", false);
Assert.assertEquals("testMessage", e.getMessage());
}
@Test
- public void validationExceptionOverrideMessageTrue(){
+ public void validationExceptionOverrideMessageTrue() {
ValidationException e = new ValidationException("testMessage", true);
Assert.assertEquals("No valid testMessage is specified", e.getMessage());
}
@Test
- public void validationException(){
+ public void validationException() {
ValidationException e = new ValidationException("testMessage");
Assert.assertEquals("No valid testMessage is specified", e.getMessage());
}
@Test
- public void validationExceptionVersion(){
+ public void validationExceptionVersion() {
ValidationException e = new ValidationException("testMessage", "secondTestMessage");
Assert.assertEquals("testMessage does not match secondTestMessage", e.getMessage());
}
diff --git a/common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java b/common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java
index 06e25daa98..494d531090 100644
--- a/common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java
+++ b/common/src/test/java/org/onap/so/jsonpath/JsonPathUtilTest.java
@@ -21,35 +21,39 @@
package org.onap.so.jsonpath;
import static org.junit.Assert.assertEquals;
-
import java.util.Collections;
import java.util.Optional;
-
import org.junit.Test;
public class JsonPathUtilTest {
- private static final String json = "{\"test\" : \"hello\", \"test2\" : {\"nested\" : \"value\"}}";
- @Test
- public void pathExistsTest() {
- assertEquals("test is found", JsonPathUtil.getInstance().pathExists(json, "$.test"), true);
- assertEquals("nothing is not found", JsonPathUtil.getInstance().pathExists(json, "$.nothing"), false);
- }
-
- @Test
- public void locateResultTest() {
- assertEquals("value of hello is found", Optional.of("hello"), JsonPathUtil.getInstance().locateResult(json, "$.test"));
- assertEquals("nothing returns empty", Optional.empty(), JsonPathUtil.getInstance().locateResult(json, "$.nothing"));
- }
-
- @Test
- public void simpleAndComplexValues() {
- assertEquals("json doc found", Optional.of("{\"nested\":\"value\"}"), JsonPathUtil.getInstance().locateResult(json, "$.test2"));
- assertEquals("value found", Optional.of("value"), JsonPathUtil.getInstance().locateResult(json, "$.test2.nested"));
- }
-
- @Test
- public void pathListTest() {
- assertEquals(Collections.singletonList("$['test2']['nested']"), JsonPathUtil.getInstance().getPathList(json, "$.*.*"));
- }
+ private static final String json = "{\"test\" : \"hello\", \"test2\" : {\"nested\" : \"value\"}}";
+
+ @Test
+ public void pathExistsTest() {
+ assertEquals("test is found", JsonPathUtil.getInstance().pathExists(json, "$.test"), true);
+ assertEquals("nothing is not found", JsonPathUtil.getInstance().pathExists(json, "$.nothing"), false);
+ }
+
+ @Test
+ public void locateResultTest() {
+ assertEquals("value of hello is found", Optional.of("hello"),
+ JsonPathUtil.getInstance().locateResult(json, "$.test"));
+ assertEquals("nothing returns empty", Optional.empty(),
+ JsonPathUtil.getInstance().locateResult(json, "$.nothing"));
+ }
+
+ @Test
+ public void simpleAndComplexValues() {
+ assertEquals("json doc found", Optional.of("{\"nested\":\"value\"}"),
+ JsonPathUtil.getInstance().locateResult(json, "$.test2"));
+ assertEquals("value found", Optional.of("value"),
+ JsonPathUtil.getInstance().locateResult(json, "$.test2.nested"));
+ }
+
+ @Test
+ public void pathListTest() {
+ assertEquals(Collections.singletonList("$['test2']['nested']"),
+ JsonPathUtil.getInstance().getPathList(json, "$.*.*"));
+ }
}
diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/RequestStatusTest.java b/common/src/test/java/org/onap/so/serviceinstancebeans/RequestStatusTest.java
index fa4d2f772d..b9e389e2ec 100644
--- a/common/src/test/java/org/onap/so/serviceinstancebeans/RequestStatusTest.java
+++ b/common/src/test/java/org/onap/so/serviceinstancebeans/RequestStatusTest.java
@@ -26,18 +26,19 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class RequestStatusTest {
- @Test
- public void requestStatusDefaultValues() throws Exception {
- RequestStatus requestStatus = new RequestStatus();
- requestStatus.setRequestState("COMPLETE");
- requestStatus.setStatusMessage("STATUS: COMPLETED");
- requestStatus.setPercentProgress(100);
- requestStatus.setTimeStamp("Fri, 08 Mar 2019 04:41:42 GMT");
- String expectedResponse = "{\"requestState\":\"COMPLETE\",\"statusMessage\":\"STATUS: COMPLETED\",\"percentProgress\":100,\"timestamp\":\"Fri, 08 Mar 2019 04:41:42 GMT\"}";
+ @Test
+ public void requestStatusDefaultValues() throws Exception {
+ RequestStatus requestStatus = new RequestStatus();
+ requestStatus.setRequestState("COMPLETE");
+ requestStatus.setStatusMessage("STATUS: COMPLETED");
+ requestStatus.setPercentProgress(100);
+ requestStatus.setTimeStamp("Fri, 08 Mar 2019 04:41:42 GMT");
+ String expectedResponse =
+ "{\"requestState\":\"COMPLETE\",\"statusMessage\":\"STATUS: COMPLETED\",\"percentProgress\":100,\"timestamp\":\"Fri, 08 Mar 2019 04:41:42 GMT\"}";
- ObjectMapper mapper = new ObjectMapper();
- String realResponse = mapper.writeValueAsString(requestStatus);
-
- JSONAssert.assertEquals(expectedResponse, realResponse, false);
- }
+ ObjectMapper mapper = new ObjectMapper();
+ String realResponse = mapper.writeValueAsString(requestStatus);
+
+ JSONAssert.assertEquals(expectedResponse, realResponse, false);
+ }
}
diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java
index 946214efa4..1b20fc40ab 100644
--- a/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java
+++ b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstanceBeansTest.java
@@ -21,13 +21,10 @@
package org.onap.so.serviceinstancebeans;
import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
-
import org.junit.Test;
import org.onap.so.openpojo.rules.HasToStringRule;
import org.onap.so.openpojo.rules.ToStringTester;
-
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.openpojo.reflection.PojoClass;
@@ -42,40 +39,37 @@ import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
public class ServiceInstanceBeansTest {
-
- private PojoClassFilter filterTestClasses = new FilterTestClasses();
- @Test
- public void pojoStructure() {
- test("org.onap.so.serviceinstancebeans");
- }
-
- @Test
- public void cloudConfigurationkeepDefaultValues() throws IOException {
- CloudConfiguration cloudConfiguration = new CloudConfiguration();
- cloudConfiguration.setLcpCloudRegionId("myRegionId");
- ObjectMapper mapper = new ObjectMapper();
-
- assertEquals("{\"cloudOwner\":\"CloudOwner\",\"lcpCloudRegionId\":\"myRegionId\"}", mapper.writeValueAsString(cloudConfiguration));
-
-
- }
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ @Test
+ public void pojoStructure() {
+ test("org.onap.so.serviceinstancebeans");
+ }
+
+ @Test
+ public void cloudConfigurationkeepDefaultValues() throws IOException {
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setLcpCloudRegionId("myRegionId");
+ ObjectMapper mapper = new ObjectMapper();
+
+ assertEquals("{\"cloudOwner\":\"CloudOwner\",\"lcpCloudRegionId\":\"myRegionId\"}",
+ mapper.writeValueAsString(cloudConfiguration));
+
+
+ }
+
+ private void test(String pojoPackage) {
+ Validator validator = ValidatorBuilder.create().with(new GetterMustExistRule()).with(new SetterMustExistRule())
+ .with(new HasToStringRule()).with(new SetterTester()).with(new GetterTester())
+ .with(new ToStringTester()).build();
+ validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
+ }
+
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
- private void test(String pojoPackage) {
- Validator validator = ValidatorBuilder.create()
- .with(new GetterMustExistRule())
- .with(new SetterMustExistRule())
- .with(new HasToStringRule())
- .with(new SetterTester())
- .with(new GetterTester())
- .with(new ToStringTester())
- .build();
- validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
- }
- private static class FilterTestClasses implements PojoClassFilter {
- public boolean include(PojoClass pojoClass) {
- return !pojoClass.getSourcePath().contains("/test-classes/");
- }
- }
-
}
diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java
index 2e67ff4b2b..de197156bd 100644
--- a/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java
+++ b/common/src/test/java/org/onap/so/serviceinstancebeans/ServiceInstancesRequestTest.java
@@ -22,23 +22,23 @@ package org.onap.so.serviceinstancebeans;
import org.junit.Assert;
import org.junit.Test;
-
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class ServiceInstancesRequestTest {
- @Test
- public void serializeServiceInstance() {
- String incomingRequest = "{\"requestDetails\":{\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002672\",\"modelType\":\"configuration\",\"modelName\":\"MSO-Configuration\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444455\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002671\"},\"requestInfo\":{\"source\":\"VID\",\"instanceName\":\"port_mirror_config_m830-01\",\"suppressRollback\":false,\"requestorId\":\"mdg1215\"},\"relatedInstanceList\":[{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\",\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002671\",\"modelType\":\"service\",\"modelName\":\"MSOTADevInfra_vSAMP10a_Service\",\"modelVersion\":\"1.0\",\"modelUuid\":\"5df8b6de-2083-11e7-93ae-92361f002671\"}}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f11\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444456\",\"modelType\":\"vnf\",\"modelName\":\"testvnf\",\"modelVersion\":\"1.0\",\"modelUuid\":\"956121e0-542d-4b30-b8c7-be611e3c8f14\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002676\"},\"instanceDirection\":\"source\"}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f12\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444477\",\"modelType\":\"vnf\",\"modelName\":\"svProbe vnf model name\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444488\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002672\"},\"instanceDirection\":\"destination\"}}],\"cloudConfiguration\":{\"lcpCloudRegionId\":\"mdt1\"},\"requestParameters\":{\"subscriptionServiceType\":\"MSO-dev-service-type\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"}],\"aLaCarte\":false,\"autoBuildVfModules\":false,\"cascadeDelete\":false,\"usePreload\":true,\"rebuildVolumeGroups\":false}},\"serviceInstanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\"}";
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- try {
- ServiceInstancesRequest request = mapper.readValue(incomingRequest, ServiceInstancesRequest.class);
- System.out.println("Java Object: " + request);
- } catch (Exception e) {
- System.out.println("Caught Exception " + e.getMessage());
- Assert.fail("Caught error on object serialization");
- }
- }
+ @Test
+ public void serializeServiceInstance() {
+ String incomingRequest =
+ "{\"requestDetails\":{\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002672\",\"modelType\":\"configuration\",\"modelName\":\"MSO-Configuration\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444455\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002671\"},\"requestInfo\":{\"source\":\"VID\",\"instanceName\":\"port_mirror_config_m830-01\",\"suppressRollback\":false,\"requestorId\":\"mdg1215\"},\"relatedInstanceList\":[{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\",\"modelInfo\":{\"modelInvariantUuid\":\"9647dfc4-2083-11e7-93ae-92361f002671\",\"modelType\":\"service\",\"modelName\":\"MSOTADevInfra_vSAMP10a_Service\",\"modelVersion\":\"1.0\",\"modelUuid\":\"5df8b6de-2083-11e7-93ae-92361f002671\"}}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f11\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444456\",\"modelType\":\"vnf\",\"modelName\":\"testvnf\",\"modelVersion\":\"1.0\",\"modelUuid\":\"956121e0-542d-4b30-b8c7-be611e3c8f14\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002676\"},\"instanceDirection\":\"source\"}},{\"relatedInstance\":{\"instanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f12\",\"modelInfo\":{\"modelInvariantUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444477\",\"modelType\":\"vnf\",\"modelName\":\"svProbe vnf model name\",\"modelVersion\":\"1.0\",\"modelUuid\":\"36a3a8ea-49a6-4ac8-b06c-89a545444488\",\"modelCustomizationUuid\":\"68dc9a92-214c-11e7-93ae-92361f002672\"},\"instanceDirection\":\"destination\"}}],\"cloudConfiguration\":{\"lcpCloudRegionId\":\"mdt1\"},\"requestParameters\":{\"subscriptionServiceType\":\"MSO-dev-service-type\",\"userParams\":[{\"name\":\"someUserParam\",\"value\":\"someValue\"}],\"aLaCarte\":false,\"autoBuildVfModules\":false,\"cascadeDelete\":false,\"usePreload\":true,\"rebuildVolumeGroups\":false}},\"serviceInstanceId\":\"956121e0-542d-4b30-b8c7-be611e3c8f13\"}";
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ try {
+ ServiceInstancesRequest request = mapper.readValue(incomingRequest, ServiceInstancesRequest.class);
+ System.out.println("Java Object: " + request);
+ } catch (Exception e) {
+ System.out.println("Caught Exception " + e.getMessage());
+ Assert.fail("Caught error on object serialization");
+ }
+ }
}
diff --git a/common/src/test/java/org/onap/so/test/categories/SpringAware.java b/common/src/test/java/org/onap/so/test/categories/SpringAware.java
index 21035fcd4d..2462e678d9 100644
--- a/common/src/test/java/org/onap/so/test/categories/SpringAware.java
+++ b/common/src/test/java/org/onap/so/test/categories/SpringAware.java
@@ -21,5 +21,5 @@
package org.onap.so.test.categories;
public interface SpringAware {
- /* category marker */
+ /* category marker */
}
diff --git a/common/src/test/java/org/onap/so/utils/CheckResultsTest.java b/common/src/test/java/org/onap/so/utils/CheckResultsTest.java
index 0e1da16b9e..01de7167e8 100644
--- a/common/src/test/java/org/onap/so/utils/CheckResultsTest.java
+++ b/common/src/test/java/org/onap/so/utils/CheckResultsTest.java
@@ -21,11 +21,8 @@
package org.onap.so.utils;
import static org.junit.Assert.*;
-
import java.util.List;
-
import org.junit.Test;
-
import org.onap.so.utils.CheckResults.CheckResult;
public class CheckResultsTest {
@@ -34,25 +31,25 @@ public class CheckResultsTest {
* Test method for {@link org.onap.so.utils.CheckResults#getResults()}.
*/
@Test
- public final void testGetResults () {
- CheckResults cr = new CheckResults ();
- cr.addHostCheckResult ("host1", 0, "output");
- cr.addHostCheckResult ("host2", 2, "output2");
- cr.addServiceCheckResult ("host1", "service1", 0, "outputServ");
- cr.addServiceCheckResult ("host1", "service2", 2, "outputServ2");
- cr.addServiceCheckResult ("host2", "service1", 0, "output2Serv");
- cr.addServiceCheckResult ("host2", "service2", 2, "output2Serv2");
- List <CheckResult> res = cr.getResults ();
- assertEquals(res.size (), 6);
- assertEquals(res.get (0).getHostname (), "host1");
- assertEquals(res.get (1).getHostname (), "host2");
- assertEquals(res.get (2).getHostname (), "host1");
- assertEquals(res.get (3).getHostname (), "host1");
- assertEquals(res.get (4).getHostname (), "host2");
- assertEquals(res.get (5).getHostname (), "host2");
- assertEquals(res.get (0).getServicename (), null);
- assertEquals(res.get (3).getServicename (), "service2");
- assertEquals(res.get (5).getState (), 2);
+ public final void testGetResults() {
+ CheckResults cr = new CheckResults();
+ cr.addHostCheckResult("host1", 0, "output");
+ cr.addHostCheckResult("host2", 2, "output2");
+ cr.addServiceCheckResult("host1", "service1", 0, "outputServ");
+ cr.addServiceCheckResult("host1", "service2", 2, "outputServ2");
+ cr.addServiceCheckResult("host2", "service1", 0, "output2Serv");
+ cr.addServiceCheckResult("host2", "service2", 2, "output2Serv2");
+ List<CheckResult> res = cr.getResults();
+ assertEquals(res.size(), 6);
+ assertEquals(res.get(0).getHostname(), "host1");
+ assertEquals(res.get(1).getHostname(), "host2");
+ assertEquals(res.get(2).getHostname(), "host1");
+ assertEquals(res.get(3).getHostname(), "host1");
+ assertEquals(res.get(4).getHostname(), "host2");
+ assertEquals(res.get(5).getHostname(), "host2");
+ assertEquals(res.get(0).getServicename(), null);
+ assertEquals(res.get(3).getServicename(), "service2");
+ assertEquals(res.get(5).getState(), 2);
}
}
diff --git a/common/src/test/java/org/onap/so/utils/TestAppender.java b/common/src/test/java/org/onap/so/utils/TestAppender.java
index fba9c71c68..a1add63078 100644
--- a/common/src/test/java/org/onap/so/utils/TestAppender.java
+++ b/common/src/test/java/org/onap/so/utils/TestAppender.java
@@ -23,19 +23,18 @@ package org.onap.so.utils;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
-
import java.util.ArrayList;
import java.util.List;
public class TestAppender extends AppenderBase<ILoggingEvent> {
public static List<ILoggingEvent> events = new ArrayList<>();
-
- @Override
- protected void append(ILoggingEvent loggingEvent) {
- if (loggingEvent.getLevel() == Level.INFO) {
- events.add(loggingEvent);
+
+ @Override
+ protected void append(ILoggingEvent loggingEvent) {
+ if (loggingEvent.getLevel() == Level.INFO) {
+ events.add(loggingEvent);
}
- }
+ }
}
diff --git a/common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java b/common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java
index 9c9f58710e..433145f6f7 100644
--- a/common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java
+++ b/common/src/test/java/org/onap/so/utils/UUIDCheckerTest.java
@@ -23,18 +23,17 @@
package org.onap.so.utils;
import static org.junit.Assert.*;
-
import org.junit.Test;
public class UUIDCheckerTest {
- @Test
- public void isValidUUIDTest(){
- String nullID = null;
- String badID = "This is not a UUID";
- String id = UUIDChecker.getUUID();
- assertFalse(UUIDChecker.isValidUUID(nullID));
- assertFalse(UUIDChecker.isValidUUID(badID));
- assertTrue(UUIDChecker.isValidUUID(id));
- }
+ @Test
+ public void isValidUUIDTest() {
+ String nullID = null;
+ String badID = "This is not a UUID";
+ String id = UUIDChecker.getUUID();
+ assertFalse(UUIDChecker.isValidUUID(nullID));
+ assertFalse(UUIDChecker.isValidUUID(badID));
+ assertTrue(UUIDChecker.isValidUUID(id));
+ }
}
diff --git a/common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java b/common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java
index 148e1b452c..402b215ff9 100644
--- a/common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java
+++ b/common/src/test/java/org/onap/so/utils/XMLMarshallerTest.java
@@ -22,7 +22,6 @@ package org.onap.so.utils;
import org.junit.Assert;
import org.junit.Test;
-
import javax.xml.bind.annotation.XmlRootElement;
/**
@@ -57,8 +56,7 @@ public class XMLMarshallerTest {
String firstName;
String lastName;
- public TestPOJO() {
- }
+ public TestPOJO() {}
public String getFirstName() {
@@ -79,14 +77,18 @@ public class XMLMarshallerTest {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof TestPOJO)) return false;
+ if (this == o)
+ return true;
+ if (!(o instanceof TestPOJO))
+ return false;
TestPOJO testPOJO = (TestPOJO) o;
- if (getFirstName() != null ? !getFirstName().equals(testPOJO.getFirstName()) : testPOJO.getFirstName() != null)
+ if (getFirstName() != null ? !getFirstName().equals(testPOJO.getFirstName())
+ : testPOJO.getFirstName() != null)
return false;
- return getLastName() != null ? getLastName().equals(testPOJO.getLastName()) : testPOJO.getLastName() == null;
+ return getLastName() != null ? getLastName().equals(testPOJO.getLastName())
+ : testPOJO.getLastName() == null;
}
@Override
diff --git a/common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java b/common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java
index b49c5312e5..d1d3f2a5f0 100644
--- a/common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java
+++ b/common/src/test/java/org/onap/so/web/exceptions/RuntimeExceptionMapperTest.java
@@ -26,11 +26,9 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-
import org.junit.AfterClass;
import org.junit.Test;
@@ -38,29 +36,29 @@ import org.junit.Test;
public class RuntimeExceptionMapperTest {
-
- @Test
- public void testResponse() {
-
- RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
-
- Response r = mapper.toResponse(new RuntimeException("This is the run time exception message"));
-
- assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
- assertThat(r.getEntity(), instanceOf(ExceptionResponse.class));
- assertThat(((ExceptionResponse)r.getEntity()).getMessage(), equalTo("Unexpected Internal Exception"));
-
- }
-
- @Test
- public void preserve404ExceptionForForwarding() {
-
- RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
-
- Response r = mapper.toResponse(new NotFoundException("not found"));
-
- assertEquals(Status.NOT_FOUND.getStatusCode(), r.getStatus());
- assertThat(r.getEntity(), is(nullValue()));
- }
-
+
+ @Test
+ public void testResponse() {
+
+ RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
+
+ Response r = mapper.toResponse(new RuntimeException("This is the run time exception message"));
+
+ assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
+ assertThat(r.getEntity(), instanceOf(ExceptionResponse.class));
+ assertThat(((ExceptionResponse) r.getEntity()).getMessage(), equalTo("Unexpected Internal Exception"));
+
+ }
+
+ @Test
+ public void preserve404ExceptionForForwarding() {
+
+ RuntimeExceptionMapper mapper = new RuntimeExceptionMapper();
+
+ Response r = mapper.toResponse(new NotFoundException("not found"));
+
+ assertEquals(Status.NOT_FOUND.getStatusCode(), r.getStatus());
+ assertThat(r.getEntity(), is(nullValue()));
+ }
+
}