summaryrefslogtreecommitdiffstats
path: root/mso-catalog-db
diff options
context:
space:
mode:
authorMcblain, Thomas <tom.mcblain@att.com>2019-06-06 15:59:20 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-06-06 15:59:30 -0400
commit37b23b4d859eda7fab5af1366f9688d882b8427a (patch)
tree017c0445971aaf9662e4cea1f16d213e77c71698 /mso-catalog-db
parentc4b90365d5c117bc6fd64af421a1468539a8aec3 (diff)
Handle when model cust uuid is null from sdnc
Modify wording on null uuid exception and test for it Expand null handling to vfmc and cvnfc find in lists Modify to chain the filter of nulls then to match. Change to ExpectedException in junit; filter nulls. Handle better when model cust. uuid is null from sdnc Change-Id: I1f1edffa1db84509bd649803660a55510868b6eb Issue-ID: SO-1989 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-catalog-db')
-rw-r--r--mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java26
-rw-r--r--mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java173
2 files changed, 192 insertions, 7 deletions
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 f502c34e20..2bfa2856d2 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
@@ -823,9 +823,14 @@ public class CatalogDbClient {
public VnfResourceCustomization findVnfResourceCustomizationInList(String vnfCustomizationUUID,
List<VnfResourceCustomization> vnfResourceCusts) {
- List<VnfResourceCustomization> filtered = vnfResourceCusts.stream()
- .filter(vnfCustRes -> vnfCustomizationUUID.equals(vnfCustRes.getModelCustomizationUUID()))
- .collect(Collectors.toList());
+ if (vnfCustomizationUUID == null) {
+ throw new EntityNotFoundException(
+ "a NULL UUID was provided in query to search for VnfResourceCustomization");
+ }
+ List<VnfResourceCustomization> filtered =
+ vnfResourceCusts.stream().filter(v -> v.getModelCustomizationUUID() != null)
+ .filter(vnfCustRes -> vnfCustomizationUUID.equals(vnfCustRes.getModelCustomizationUUID()))
+ .collect(Collectors.toList());
if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
return filtered.get(0);
} else
@@ -833,9 +838,12 @@ public class CatalogDbClient {
"Unable to find VnfResourceCustomization ModelCustomizationUUID:" + vnfCustomizationUUID);
}
- private VfModuleCustomization findVfModuleCustomizationInList(String vfModuleCustomizationUUID,
+ protected VfModuleCustomization findVfModuleCustomizationInList(String vfModuleCustomizationUUID,
List<VfModuleCustomization> vfModuleList) {
- List<VfModuleCustomization> filtered = vfModuleList.stream()
+ if (vfModuleCustomizationUUID == null) {
+ throw new EntityNotFoundException("a NULL UUID was provided in query to search for VfModuleCustomization");
+ }
+ List<VfModuleCustomization> filtered = vfModuleList.stream().filter(v -> v.getModelCustomizationUUID() != null)
.filter(vfModuleCust -> vfModuleCustomizationUUID.equals(vfModuleCust.getModelCustomizationUUID()))
.collect(Collectors.toList());
if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
@@ -845,9 +853,13 @@ public class CatalogDbClient {
"Unable to find VfModuleCustomization ModelCustomizationUUID:" + vfModuleCustomizationUUID);
}
- private CvnfcCustomization findCvnfcCustomizationInAList(String cvnfcCustomizationUuid,
+ protected CvnfcCustomization findCvnfcCustomizationInAList(String cvnfcCustomizationUuid,
List<CvnfcCustomization> cvnfcCustomList) {
- List<CvnfcCustomization> filtered = cvnfcCustomList.stream()
+ if (cvnfcCustomizationUuid == null) {
+ throw new EntityNotFoundException(
+ "a NULL UUID was provided in query to search for CvnfcCustomization" + cvnfcCustomizationUuid);
+ }
+ List<CvnfcCustomization> filtered = cvnfcCustomList.stream().filter(c -> c.getModelCustomizationUUID() != null)
.filter(cvnfc -> cvnfcCustomizationUuid.equals(cvnfc.getModelCustomizationUUID()))
.collect(Collectors.toList());
if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
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
new file mode 100644
index 0000000000..9c257bdec3
--- /dev/null
+++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
@@ -0,0 +1,173 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.db.catalog.client;
+
+import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import javax.persistence.EntityNotFoundException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.db.catalog.beans.CvnfcCustomization;
+import org.onap.so.db.catalog.beans.VfModuleCustomization;
+import org.onap.so.db.catalog.beans.VnfResourceCustomization;
+
+public class CatalogDbClientTest {
+
+ private CatalogDbClient catalogDbClient;
+
+ @Before
+ public void init() {
+ catalogDbClient = new CatalogDbClient();
+ }
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public final void testFindVnfResourceCustomizationInListNullInList() {
+ thrown.expect(EntityNotFoundException.class);
+ String vnfCustomizationUUID = "a123";
+ VnfResourceCustomization vrc = new VnfResourceCustomization();
+ vrc.setModelCustomizationUUID("z789J");
+ VnfResourceCustomization vrc2 = new VnfResourceCustomization();
+ vrc2.setModelCustomizationUUID(null);
+ ArrayList<VnfResourceCustomization> vrcs = new ArrayList<VnfResourceCustomization>();
+ vrcs.add(vrc);
+ vrcs.add(vrc2);
+ catalogDbClient.findVnfResourceCustomizationInList(vnfCustomizationUUID, vrcs);
+ }
+
+ @Test
+ public final void testFindVnfResourceCustomizationInListNullString() {
+ thrown.expect(EntityNotFoundException.class);
+ thrown.expectMessage("a NULL UUID was provided in query to search for VnfResourceCustomization");
+ String vnfCustomizationUUID = null;
+ VnfResourceCustomization vrc = new VnfResourceCustomization();
+ vrc.setModelCustomizationUUID("z789J");
+ VnfResourceCustomization vrc2 = new VnfResourceCustomization();
+ vrc2.setModelCustomizationUUID("a123");
+ ArrayList<VnfResourceCustomization> vrcs = new ArrayList<VnfResourceCustomization>();
+ vrcs.add(vrc);
+ vrcs.add(vrc2);
+ catalogDbClient.findVnfResourceCustomizationInList(vnfCustomizationUUID, vrcs);
+ }
+
+ @Test
+ public final void testFindVnfResourceCustomizationInListNoNulls() {
+ String vnfCustomizationUUID = "a123";
+ VnfResourceCustomization vrc = new VnfResourceCustomization();
+ vrc.setModelCustomizationUUID("z789J");
+ VnfResourceCustomization vrc2 = new VnfResourceCustomization();
+ vrc2.setModelCustomizationUUID("a123");
+ ArrayList<VnfResourceCustomization> vrcs = new ArrayList<VnfResourceCustomization>();
+ vrcs.add(vrc);
+ vrcs.add(vrc2);
+ VnfResourceCustomization aVrc = catalogDbClient.findVnfResourceCustomizationInList(vnfCustomizationUUID, vrcs);
+ assertTrue(aVrc.getModelCustomizationUUID().equals("a123"));
+ }
+
+ @Test
+ public final void testFindVfModuleCustomizationInListNullInList() {
+ thrown.expect(EntityNotFoundException.class);
+ String vfModuleCustomizationUUID = "a123";
+ VfModuleCustomization vmc = new VfModuleCustomization();
+ vmc.setModelCustomizationUUID("z789J");
+ VfModuleCustomization vmc2 = new VfModuleCustomization();
+ vmc2.setModelCustomizationUUID(null);
+ ArrayList<VfModuleCustomization> vmcs = new ArrayList<VfModuleCustomization>();
+ vmcs.add(vmc);
+ vmcs.add(vmc2);
+ catalogDbClient.findVfModuleCustomizationInList(vfModuleCustomizationUUID, vmcs);
+ }
+
+ @Test
+ public final void testFindVfModuleCustomizationInListNullString() {
+ thrown.expect(EntityNotFoundException.class);
+ thrown.expectMessage("a NULL UUID was provided in query to search for VfModuleCustomization");
+ String vfModuleCustomizationUUID = null;
+ VfModuleCustomization vmc = new VfModuleCustomization();
+ vmc.setModelCustomizationUUID("z789J");
+ VfModuleCustomization vmc2 = new VfModuleCustomization();
+ vmc2.setModelCustomizationUUID("a123");
+ ArrayList<VfModuleCustomization> vmcs = new ArrayList<VfModuleCustomization>();
+ vmcs.add(vmc);
+ vmcs.add(vmc2);
+ catalogDbClient.findVfModuleCustomizationInList(vfModuleCustomizationUUID, vmcs);
+ }
+
+ @Test
+ public final void testFindVfModuleCustomizationInListNoNulls() {
+ String vfModuleCustomizationUUID = "a123";
+ VfModuleCustomization vmc = new VfModuleCustomization();
+ vmc.setModelCustomizationUUID("z789J");
+ VfModuleCustomization vmc2 = new VfModuleCustomization();
+ vmc2.setModelCustomizationUUID("a123");
+ ArrayList<VfModuleCustomization> vmcs = new ArrayList<VfModuleCustomization>();
+ vmcs.add(vmc);
+ vmcs.add(vmc2);
+ VfModuleCustomization aVmc = catalogDbClient.findVfModuleCustomizationInList(vfModuleCustomizationUUID, vmcs);
+ assertTrue(aVmc.getModelCustomizationUUID().equals("a123"));
+ }
+
+ @Test
+ public final void testFindCvnfcCustomizationInListNullInList() {
+ thrown.expect(EntityNotFoundException.class);
+ String cvnfcCustomizationUuid = "a123";
+ CvnfcCustomization cvnfc = new CvnfcCustomization();
+ cvnfc.setModelCustomizationUUID("z789J");
+ CvnfcCustomization cvnfc2 = new CvnfcCustomization();
+ cvnfc2.setModelCustomizationUUID(null);
+ ArrayList<CvnfcCustomization> cvnfcs = new ArrayList<CvnfcCustomization>();
+ cvnfcs.add(cvnfc);
+ cvnfcs.add(cvnfc2);
+ catalogDbClient.findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcs);
+ }
+
+ @Test
+ public final void testFindCvnfcCustomizationInListNullString() {
+ thrown.expect(EntityNotFoundException.class);
+ thrown.expectMessage("a NULL UUID was provided in query to search for CvnfcCustomization");
+ String cvnfcCustomizationUuid = null;
+ CvnfcCustomization cvnfc = new CvnfcCustomization();
+ cvnfc.setModelCustomizationUUID("z789J");
+ CvnfcCustomization cvnfc2 = new CvnfcCustomization();
+ cvnfc2.setModelCustomizationUUID("a123");
+ ArrayList<CvnfcCustomization> cvnfcs = new ArrayList<CvnfcCustomization>();
+ cvnfcs.add(cvnfc);
+ cvnfcs.add(cvnfc2);
+ catalogDbClient.findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcs);
+ }
+
+ @Test
+ public final void testFindCvnfcCustomizationInListNoNulls() {
+ String cvnfcCustomizationUuid = "a123";
+ CvnfcCustomization cvnfc = new CvnfcCustomization();
+ cvnfc.setModelCustomizationUUID("z789J");
+ CvnfcCustomization cvnfc2 = new CvnfcCustomization();
+ cvnfc2.setModelCustomizationUUID("a123");
+ ArrayList<CvnfcCustomization> cvnfcs = new ArrayList<CvnfcCustomization>();
+ cvnfcs.add(cvnfc);
+ cvnfcs.add(cvnfc2);
+ CvnfcCustomization aCvnfc = catalogDbClient.findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcs);
+ assertTrue(aCvnfc.getModelCustomizationUUID().equals("a123"));
+ }
+}