summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-02-05 11:13:31 -0500
committerJim Hahn <jrh3@att.com>2021-02-05 12:52:50 -0500
commit296a26edcc3102602b494d1be9c23e0265b09f66 (patch)
tree547b0aef999a7d51ca2d59dd860ce8b49504bb21 /models-interactions/model-actors/actor.so/src/test
parent23dec48efae039ff961ea68358ab69d80a81531b (diff)
Give better messages than NPE for missing data
When data is not available to actor operations, an NPE is generally thrown. Modified the code to provide more info about what is missing than simply NPE. Issue-ID: POLICY-2913 Change-Id: I37b6eadd966e0693508a6d552b7db4edf5410018 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/test')
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java13
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java36
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java25
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java25
-rw-r--r--models-interactions/model-actors/actor.so/src/test/resources/VfModuleDelete.json5
-rw-r--r--models-interactions/model-actors/actor.so/src/test/resources/vfModuleCreate.json5
6 files changed, 99 insertions, 10 deletions
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java
index 2ef9caac9..29a7d082a 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/ModifyNssiTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 Wipro Limited.
- * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,7 @@ package org.onap.policy.controlloop.actor.so;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -102,5 +103,15 @@ public class ModifyNssiTest extends BasicSoOperation {
return ResourceUtils.getResourceAsString("src/test/resources/ModifyNSSI.json");
}
+ /**
+ * Tests makeRequest() when a property is missing.
+ */
+ @Test
+ public void testMakeRequestMissingProperty() throws Exception {
+ oper = new ModifyNssi(params, config);
+
+ assertThatIllegalStateException().isThrownBy(() -> oper.makeRequest())
+ .withMessageContaining("missing event payload");
+ }
}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
index 6f4ac0ed3..50bbfee2b 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,6 +37,8 @@ import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
+import org.onap.aai.domain.yang.CloudRegion;
+import org.onap.aai.domain.yang.Tenant;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.ControlLoopOperation;
@@ -206,6 +208,38 @@ public class SoOperationTest extends BasicSoOperation {
}
@Test
+ public void testConstructCloudConfiguration() throws Exception {
+ Tenant tenantItem = new Tenant();
+ tenantItem.setTenantId("my-tenant-id");
+
+ CloudRegion cloudRegionItem = new CloudRegion();
+ cloudRegionItem.setCloudRegionId("my-cloud-id");
+
+ assertThatCode(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem)).doesNotThrowAnyException();
+
+ tenantItem.setTenantId(null);
+ assertThatIllegalArgumentException()
+ .isThrownBy(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem))
+ .withMessageContaining("missing tenant ID");
+ tenantItem.setTenantId("my-tenant-id");
+
+ cloudRegionItem.setCloudRegionId(null);
+ assertThatIllegalArgumentException()
+ .isThrownBy(() -> oper.constructCloudConfiguration(tenantItem, cloudRegionItem))
+ .withMessageContaining("missing cloud region ID");
+ cloudRegionItem.setCloudRegionId("my-cloud-id");
+ }
+
+ @Test
+ public void testGetRequiredText() throws Exception {
+
+ assertThatCode(() -> oper.getRequiredText("some value", "my value")).doesNotThrowAnyException();
+
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getRequiredText("some value", null))
+ .withMessageContaining("missing some value");
+ }
+
+ @Test
public void testGetCoder() throws CoderException {
Coder opcoder = oper.getCoder();
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
index dfd5c92f6..7168ec449 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -212,6 +212,20 @@ public class VfModuleCreateTest extends BasicSoOperation {
verifyRequest("vfModuleCreate.json", pair.getRight());
}
+ /**
+ * Tests makeRequest() when a property is missing.
+ */
+ @Test
+ public void testMakeRequestMissingProperty() throws Exception {
+ loadProperties();
+
+ ServiceInstance instance = new ServiceInstance();
+ oper.setProperty(OperationProperties.AAI_SERVICE, instance);
+
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest())
+ .withMessageContaining("missing service instance ID");
+ }
+
private void loadProperties() {
// set the properties
ServiceInstance instance = new ServiceInstance();
@@ -229,8 +243,13 @@ public class VfModuleCreateTest extends BasicSoOperation {
vnf.setVnfId(VNF_ID);
oper.setProperty(OperationProperties.AAI_VNF, vnf);
- oper.setProperty(OperationProperties.AAI_DEFAULT_CLOUD_REGION, new CloudRegion());
- oper.setProperty(OperationProperties.AAI_DEFAULT_TENANT, new Tenant());
+ CloudRegion cloudRegion = new CloudRegion();
+ cloudRegion.setCloudRegionId("my-cloud-id");
+ oper.setProperty(OperationProperties.AAI_DEFAULT_CLOUD_REGION, cloudRegion);
+
+ Tenant tenant = new Tenant();
+ tenant.setTenantId("my-tenant-id");
+ oper.setProperty(OperationProperties.AAI_DEFAULT_TENANT, tenant);
oper.setProperty(OperationProperties.DATA_VF_COUNT, VF_COUNT);
}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
index ce762011a..cc11f952d 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -351,6 +351,20 @@ public class VfModuleDeleteTest extends BasicSoOperation {
assertEquals("Basic " + encoded, valueCaptor.getValue());
}
+ /**
+ * Tests makeRequest() when a property is missing.
+ */
+ @Test
+ public void testMakeRequestMissingProperty() throws Exception {
+ loadProperties();
+
+ ServiceInstance instance = new ServiceInstance();
+ oper.setProperty(OperationProperties.AAI_SERVICE, instance);
+
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest())
+ .withMessageContaining("missing service instance ID");
+ }
+
@Test
public void testMakeHttpClient() {
// must use a real operation to invoke this method
@@ -393,8 +407,13 @@ public class VfModuleDeleteTest extends BasicSoOperation {
vnf.setVnfId(VNF_ID);
oper.setProperty(OperationProperties.AAI_VNF, vnf);
- oper.setProperty(OperationProperties.AAI_DEFAULT_CLOUD_REGION, new CloudRegion());
- oper.setProperty(OperationProperties.AAI_DEFAULT_TENANT, new Tenant());
+ CloudRegion cloudRegion = new CloudRegion();
+ cloudRegion.setCloudRegionId("my-cloud-id");
+ oper.setProperty(OperationProperties.AAI_DEFAULT_CLOUD_REGION, cloudRegion);
+
+ Tenant tenant = new Tenant();
+ tenant.setTenantId("my-tenant-id");
+ oper.setProperty(OperationProperties.AAI_DEFAULT_TENANT, tenant);
oper.setProperty(OperationProperties.DATA_VF_COUNT, VF_COUNT);
}
diff --git a/models-interactions/model-actors/actor.so/src/test/resources/VfModuleDelete.json b/models-interactions/model-actors/actor.so/src/test/resources/VfModuleDelete.json
index 5b7cce5f3..f83344dc3 100644
--- a/models-interactions/model-actors/actor.so/src/test/resources/VfModuleDelete.json
+++ b/models-interactions/model-actors/actor.so/src/test/resources/VfModuleDelete.json
@@ -8,7 +8,10 @@
"modelVersion": "my-model-version",
"modelCustomizationId": "my-model-customization-id"
},
- "cloudConfiguration": {},
+ "cloudConfiguration": {
+ "lcpCloudRegionId": "my-cloud-id",
+ "tenantId": "my-tenant-id"
+ },
"requestInfo": {
"source": "POLICY",
"suppressRollback": false,
diff --git a/models-interactions/model-actors/actor.so/src/test/resources/vfModuleCreate.json b/models-interactions/model-actors/actor.so/src/test/resources/vfModuleCreate.json
index 06258f3f3..c28d73efa 100644
--- a/models-interactions/model-actors/actor.so/src/test/resources/vfModuleCreate.json
+++ b/models-interactions/model-actors/actor.so/src/test/resources/vfModuleCreate.json
@@ -8,7 +8,10 @@
"modelVersion": "my-model-version",
"modelCustomizationId": "my-model-customization-id"
},
- "cloudConfiguration": {},
+ "cloudConfiguration": {
+ "lcpCloudRegionId": "my-cloud-id",
+ "tenantId": "my-tenant-id"
+ },
"requestInfo": {
"instanceName": "vfModuleName",
"source": "POLICY",