diff options
Diffstat (limited to 'common/src/test/java/org')
6 files changed, 190 insertions, 8 deletions
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 1c49c11382..b07d893adb 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 @@ -24,6 +24,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -32,12 +33,14 @@ import static org.mockito.Mockito.verify; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; +import javax.ws.rs.core.GenericType; import org.json.JSONException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Pserver; @@ -46,7 +49,6 @@ import org.onap.so.client.aai.entities.singletransaction.SingleTransactionReques import org.onap.so.client.aai.entities.singletransaction.SingleTransactionResponse; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; -import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; @@ -60,11 +62,13 @@ 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"); + AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex2"); ObjectMapper mapper; public AAIClient client = new AAIClient(); + @Spy public AAIResourcesClient aaiClient = new AAIResourcesClient(); @Before @@ -82,9 +86,11 @@ public class AAISingleTransactionClientTest { 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); - + Map<String, Object> map = new HashMap<>(); + map.put("resource-version", "1234"); + doReturn(Optional.of(map)).when(aaiClient).get(any(GenericType.class), eq(uriC)); + AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction().create(uriA, pserver) + .update(uriA, pserver2).create(uriB, complex).delete(uriC); SingleTransactionRequest actual = singleTransaction.getRequest(); 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 adbdbb419f..305cdf59cc 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 @@ -22,6 +22,7 @@ package org.onap.so.client.aai; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -31,19 +32,19 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import javax.ws.rs.core.GenericType; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Relationship; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; -import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; import org.onap.so.client.graphinventory.GraphInventoryPatchConverter; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; @@ -61,11 +62,13 @@ public class AAITransactionalClientTest { AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4"); AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5"); AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6"); + AAIResourceUri uriG = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test7"); ObjectMapper mapper; public AAIClient client = new AAIClient(); + @Spy public AAIResourcesClient aaiClient = new AAIResourcesClient(); @Before @@ -95,9 +98,12 @@ public class AAITransactionalClientTest { List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>(); uris.add(uriB); + Map<String, Object> map = new HashMap<>(); + map.put("resource-version", "1234"); + doReturn(Optional.of(map)).when(aaiClient).get(any(GenericType.class), eq(uriG)); AAIResourceUri uriAClone = uriA.clone(); AAITransactionalClient transactions = aaiClient.beginTransaction().connect(uriA, uris).connect(uriC, uriD) - .beginNewTransaction().connect(uriE, uriF); + .beginNewTransaction().connect(uriE, uriF).beginNewTransaction().delete(uriG); String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions()); Map<String, Object> actual = 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 5fa2ff0295..b91d0e705a 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 @@ -91,6 +91,13 @@ public class AAIValidatorTest { } @Test + public void test_IsPhysicalServerLocked_NoServers_False() throws IOException { + when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(null); + 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); 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 6e55fe17fa..fb45652d53 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 @@ -24,6 +24,7 @@ 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.DSLNodeKey; import org.onap.so.client.graphinventory.entities.DSLQueryBuilder; import org.onap.so.client.graphinventory.entities.__; @@ -108,4 +109,40 @@ public class DSLQueryBuilderTest { builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')")); assertTrue(builder.equals(builder)); } + + + @Test + public void mixedTypeTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.CLOUD_REGION, + __.key("cloud-owner", "owner"), __.key("cloud-region-id", "id"))); + builder.to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", 167), __.key("my-boolean", true)).output()); + assertTrue(builder.equals( + "cloud-region('cloud-owner', 'owner')('cloud-region-id', 'id') > vlan-tag*('vlan-id-outer', 167)('my-boolean', true)")); + } + + @Test + public void outputOnNodeLambdasTest() { + DSLQueryBuilder<DSLNode, DSLNode> builder = + new DSLQueryBuilder<>(new DSLNode(AAIObjectType.L_INTERFACE, new DSLNodeKey("interface-id", "myId"))); + + builder.to(AAIObjectType.VSERVER, __.key("vserver-name", "myName")).output().to(AAIObjectType.P_INTERFACE) + .output(); + assertEquals("l-interface('interface-id', 'myId') > vserver*('vserver-name', 'myName') > p-interface*", + builder.build()); + } + + @Test + public void skipOutputOnUnionTest() { + 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()))) + .output(); + + assertEquals( + "generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]", + builder.build()); + } } diff --git a/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java b/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java new file mode 100644 index 0000000000..b2db986d02 --- /dev/null +++ b/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java @@ -0,0 +1,61 @@ +package org.onap.so.utils; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import org.camunda.bpm.client.ExternalTaskClient; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.core.env.Environment; + +@RunWith(MockitoJUnitRunner.class) +public class ExternalTaskServiceUtilsTest { + + @Spy + @InjectMocks + private ExternalTaskServiceUtils utils = new ExternalTaskServiceUtils(); + + @Mock + private Environment mockEnv; + + @Mock + private ExternalTaskClient mockClient; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + doReturn("3").when(mockEnv).getProperty("workflow.topics.maxClients", "3"); + doReturn("07a7159d3bf51a0e53be7a8f89699be7").when(mockEnv).getRequiredProperty("mso.msoKey"); + doReturn("6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436").when(mockEnv) + .getRequiredProperty("mso.auth"); + doReturn("someid").when(mockEnv).getRequiredProperty("mso.config.cadi.aafId"); + doReturn("http://camunda.com").when(mockEnv).getRequiredProperty("mso.workflow.endpoint"); + } + + @Test + public void testCreateExternalTaskClient() throws Exception { + ExternalTaskClient actualClient = utils.createExternalTaskClient(); + Assert.assertNotNull(actualClient); + } + + @Test + public void testGetAuth() throws Exception { + String actual = utils.getAuth(); + String expected = "Att32054Life!@"; + assertEquals(expected, actual); + } + + @Test + public void testGetMaxClients() throws Exception { + int actual = utils.getMaxClients(); + int expected = 3; + assertEquals(expected, actual); + } + +} diff --git a/common/src/test/java/org/onap/so/utils/ExternalTaskUtilsTest.java b/common/src/test/java/org/onap/so/utils/ExternalTaskUtilsTest.java new file mode 100644 index 0000000000..f918781b39 --- /dev/null +++ b/common/src/test/java/org/onap/so/utils/ExternalTaskUtilsTest.java @@ -0,0 +1,65 @@ +package org.onap.so.utils; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.core.env.Environment; + +@RunWith(MockitoJUnitRunner.class) +public class ExternalTaskUtilsTest { + + @Mock + private Environment mockenv; + + @InjectMocks + private ExternalTaskUtils externalTaskUtilsAnony = new ExternalTaskUtils() { + + }; + + @Test + public void retry_sequence_calculation_Test() { + Mockito.when(mockenv.getProperty("mso.workflow.topics.retryMultiplier", "6000")).thenReturn("6000"); + long firstRetry = externalTaskUtilsAnony.calculateRetryDelay(8); + assertEquals(6000L, firstRetry); + long secondRetry = externalTaskUtilsAnony.calculateRetryDelay(7); + assertEquals(6000L, secondRetry); + long thirdRetry = externalTaskUtilsAnony.calculateRetryDelay(6); + assertEquals(12000L, thirdRetry); + long fourthRetry = externalTaskUtilsAnony.calculateRetryDelay(5); + assertEquals(18000L, fourthRetry); + long fifthRetry = externalTaskUtilsAnony.calculateRetryDelay(4); + assertEquals(30000L, fifthRetry); + long sixRetry = externalTaskUtilsAnony.calculateRetryDelay(3); + assertEquals(48000L, sixRetry); + long seventhRetry = externalTaskUtilsAnony.calculateRetryDelay(2); + assertEquals(78000L, seventhRetry); + long eigthRetry = externalTaskUtilsAnony.calculateRetryDelay(1); + assertEquals(120000L, eigthRetry); + } + + @Test + public void retry_sequence_Test() { + Mockito.when(mockenv.getProperty("mso.workflow.topics.retryMultiplier", "6000")).thenReturn("6000"); + long firstRetry = externalTaskUtilsAnony.calculateRetryDelay(8); + assertEquals(6000L, firstRetry); + long secondRetry = externalTaskUtilsAnony.calculateRetryDelay(7); + assertEquals(6000L, secondRetry); + long thirdRetry = externalTaskUtilsAnony.calculateRetryDelay(6); + assertEquals(12000L, thirdRetry); + long fourthRetry = externalTaskUtilsAnony.calculateRetryDelay(5); + assertEquals(18000L, fourthRetry); + long fifthRetry = externalTaskUtilsAnony.calculateRetryDelay(4); + assertEquals(30000L, fifthRetry); + long sixRetry = externalTaskUtilsAnony.calculateRetryDelay(3); + assertEquals(48000L, sixRetry); + long seventhRetry = externalTaskUtilsAnony.calculateRetryDelay(2); + assertEquals(78000L, seventhRetry); + long eigthRetry = externalTaskUtilsAnony.calculateRetryDelay(1); + assertEquals(120000L, eigthRetry); + } + +} |