Give better messages than NPE for missing data
[policy/models.git] / models-interactions / model-actors / actor.so / src / test / java / org / onap / policy / controlloop / actor / so / SoOperationTest.java
index 6f4ac0e..50bbfee 100644 (file)
@@ -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;
@@ -205,6 +207,38 @@ public class SoOperationTest extends BasicSoOperation {
         assertTrue(oper.buildConfigurationParameters().isEmpty());
     }
 
+    @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();