aboutsummaryrefslogtreecommitdiffstats
path: root/mso-catalog-db
diff options
context:
space:
mode:
authorUbuntu <sunshine.wang@huawei.com>2020-01-07 22:08:38 +0800
committerUbuntu <sunshine.wang@huawei.com>2020-01-07 22:15:15 +0800
commit8c02dcc9057a300c08a7fc22265c45c3c771226e (patch)
treeaf0bde6ae3429aa0e1103ae79bfbd7efb148173e /mso-catalog-db
parent8f37667d999101c2e4e395d810376173a5714794 (diff)
find workflow by pnf model uuid with CatalogDbClient
Issue-ID: SO-2558 Signed-off-by: Yaoguang Wang <sunshine.wang@huawei.com> Change-Id: I62d9ae70befdd870d217de64cca36fe04a69e96e
Diffstat (limited to 'mso-catalog-db')
-rw-r--r--mso-catalog-db/pom.xml17
-rw-r--r--mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java8
-rw-r--r--mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java15
-rw-r--r--mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java34
4 files changed, 73 insertions, 1 deletions
diff --git a/mso-catalog-db/pom.xml b/mso-catalog-db/pom.xml
index 08e9719f50..610ed25096 100644
--- a/mso-catalog-db/pom.xml
+++ b/mso-catalog-db/pom.xml
@@ -102,5 +102,22 @@
<artifactId>asm-xml</artifactId>
<version>6.1</version>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.28.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <version>2.0.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java
index 8754673f40..7873d70bd4 100644
--- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java
+++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java
@@ -133,6 +133,7 @@ public class CatalogDbClient {
private static final String MODEL_VERSION = "modelVersion";
private static final String MODEL_INVARIANT_UUID = "modelInvariantUUID";
private static final String VNF_RESOURCE_MODEL_UUID = "vnfResourceModelUUID";
+ private static final String PNF_RESOURCE_MODEL_UUID = "pnfResourceModelUUID";
private static final String NF_ROLE = "nfRole";
private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
private static final String VNF_COMPONENT_TYPE = "vnfComponentType";
@@ -201,6 +202,7 @@ public class CatalogDbClient {
private String findPnfResourceCustomizationByModelUuid = "/findPnfResourceCustomizationByModelUuid";
private String findWorkflowByArtifactUUID = "/findByArtifactUUID";
private String findWorkflowByModelUUID = "/findWorkflowByModelUUID";
+ private String findWorkflowByPnfModelUUID = "/findWorkflowByPnfModelUUID";
private String findWorkflowBySource = "/findBySource";
private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid";
@@ -338,6 +340,7 @@ public class CatalogDbClient {
findWorkflowByArtifactUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByArtifactUUID;
findWorkflowByModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByModelUUID;
+ findWorkflowByPnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByPnfModelUUID;
findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource;
findVnfResourceCustomizationByModelUuid =
@@ -998,6 +1001,11 @@ public class CatalogDbClient {
.queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString()));
}
+ public List<Workflow> findWorkflowByPnfModelUUID(String pnfResourceModelUUID) {
+ return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByPnfModelUUID)
+ .queryParam(PNF_RESOURCE_MODEL_UUID, pnfResourceModelUUID).build().toString()));
+ }
+
public List<Workflow> findWorkflowBySource(String source) {
return this.getMultipleResources(workflowClient,
getUri(UriBuilder.fromUri(findWorkflowBySource).queryParam(SOURCE, source).build().toString()));
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
index 8bcc60c8be..f1b399325e 100644
--- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
+++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
@@ -39,10 +39,23 @@ public interface WorkflowRepository extends JpaRepository<Workflow, Integer> {
* This operation is required by {@link org.onap.so.db.catalog.client.CatalogDbClient} to provide Workflow based on
* model UUID without projection.
*
- * @param vnfResourceModelUUIDmodel UUID
+ * @param vnfResourceModelUUID UUID
* @return List of Workflow
*/
@Query(value = "select b.* from vnf_resource_to_workflow a join workflow b where a.WORKFLOW_ID = b.ID and a.VNF_RESOURCE_MODEL_UUID = ?1",
nativeQuery = true)
List<Workflow> findWorkflowByModelUUID(String vnfResourceModelUUID);
+
+ /**
+ * Used to fetch the @{link Workflow} by the Pnf Model UUID.
+ *
+ * This operation is required by {@link org.onap.so.db.catalog.client.CatalogDbClient} to provide Workflow based on
+ * pnf model UUID without projection.
+ *
+ * @param pnfResourceModelUUID UUID
+ * @return List of Workflow
+ */
+ @Query(value = "select b.* from pnf_resource_to_workflow a join workflow b where a.WORKFLOW_ID = b.ID and a.PNF_RESOURCE_MODEL_UUID = ?1",
+ nativeQuery = true)
+ List<Workflow> findWorkflowByPnfModelUUID(String pnfResourceModelUUID);
}
diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
index b82c17dc84..d87ed517f4 100644
--- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
+++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
@@ -20,23 +20,39 @@
package org.onap.so.db.catalog.client;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
+import java.util.List;
import javax.persistence.EntityNotFoundException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.ArgumentMatchers;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.onap.so.db.catalog.beans.CvnfcCustomization;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
+import uk.co.blackpepper.bowman.Client;
+import org.onap.so.db.catalog.beans.Workflow;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(CatalogDbClient.class)
public class CatalogDbClientTest {
private CatalogDbClient catalogDbClient;
+ private CatalogDbClient mockedCatalogDbClient;
+
@Before
public void init() {
catalogDbClient = new CatalogDbClient();
+ mockedCatalogDbClient = PowerMockito.spy(catalogDbClient);
}
@Rule
@@ -171,4 +187,22 @@ public class CatalogDbClientTest {
assertTrue(aCvnfc.getModelCustomizationUUID().equals("a123"));
}
+ @Test
+ public final void testFindWorkflowByPnfModelUUID() throws Exception {
+ String pnfResourceModelUUID = "f2d1f2b2-88bb-49da-b716-36ae420ccbff";
+ Workflow wf = new Workflow();
+ wf.setArtifactUUID("b2fd5627-55e4-4f4f-8064-9e6f443e9152");
+ wf.setArtifactName("DummyPnfWorkflow");
+ wf.setVersion(1.0);
+ List<Workflow> wfList = new ArrayList<Workflow>();
+ wfList.add(wf);
+
+ PowerMockito.doReturn(wfList).when(mockedCatalogDbClient, "getMultipleResources",
+ ArgumentMatchers.<Client<Workflow>>any(), ArgumentMatchers.anyObject());
+ List<Workflow> results = mockedCatalogDbClient.findWorkflowByPnfModelUUID(pnfResourceModelUUID);
+ assertEquals(wf.getArtifactUUID(), results.get(0).getArtifactUUID());
+ assertEquals(wf.getArtifactName(), results.get(0).getArtifactName());
+ assertEquals(wf.getVersion(), results.get(0).getVersion());
+ }
+
}