Add tests 91/67791/1
authorsebdet <sd378r@intl.att.com>
Wed, 19 Sep 2018 16:35:11 +0000 (18:35 +0200)
committersebdet <sd378r@intl.att.com>
Wed, 19 Sep 2018 16:35:11 +0000 (18:35 +0200)
Add some tests to cldsService

Issue-ID: CLAMP-217
Change-Id: I95f21306f3d807a283519604c1711dfd07466d4a
Signed-off-by: sebdet <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/config/SystemPropertiesLoader.java
src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
src/test/resources/application.properties
src/test/resources/example/sdc/expected-result/sdc-properties-global.json [new file with mode: 0644]

index bb2eb3a..093ad48 100644 (file)
@@ -5,24 +5,27 @@
  * Copyright (C) 2018 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. 
+ * 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 
+ *
+ * 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.clamp.clds.config;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
 import java.util.Properties;
 
 import javax.annotation.Resource;
@@ -33,12 +36,14 @@ import org.springframework.stereotype.Component;
 
 @Component
 public class SystemPropertiesLoader implements ApplicationListener<ContextRefreshedEvent> {
+    protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SystemPropertiesLoader.class);
 
     @Resource(name = "mapper")
     private Properties myTranslator;
 
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
+        logger.info("Loading additional JVM properties:"+myTranslator.toString());
         System.getProperties().putAll(myTranslator);
     }
 }
index 3c508bd..695aa2d 100644 (file)
@@ -50,6 +50,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.model.CldsEvent;
 import org.onap.clamp.clds.model.CldsInfo;
 import org.onap.clamp.clds.model.CldsModel;
 import org.onap.clamp.clds.model.CldsServiceData;
@@ -61,6 +62,8 @@ import org.skyscreamer.jsonassert.JSONAssert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
@@ -183,11 +186,37 @@ public class CldsServiceItCase {
         // Verify whether it has been added properly or not
         assertNotNull(cldsDao.getModel(randomNameModel));
 
+        CldsModel model= cldsService.getModel(randomNameModel);
         // Verify with GetModel
-        assertEquals(cldsService.getModel(randomNameModel).getTemplateName(),randomNameTemplate);
-        assertEquals(cldsService.getModel(randomNameModel).getName(),randomNameModel);
+        assertEquals(model.getTemplateName(),randomNameTemplate);
+        assertEquals(model.getName(),randomNameModel);
 
         assertTrue(cldsService.getModelNames().size() >= 1);
+
+        // Should fail
+        ResponseEntity<?> responseEntity = cldsService.putModelAndProcessAction(CldsEvent.ACTION_SUBMIT, randomNameModel, "true", model);
+        assertTrue(responseEntity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR));
+        model=(CldsModel)responseEntity.getBody();
+        assertNull(model);
+
+        responseEntity=cldsService.deployModel(randomNameModel, cldsService.getModel(randomNameModel));
+        assertNotNull(responseEntity);
+        assertNotNull(responseEntity.getStatusCode());
+        model=(CldsModel)responseEntity.getBody();
+        assertNotNull(model);
+
+        responseEntity=cldsService.unDeployModel(randomNameModel, cldsService.getModel(randomNameModel));
+        assertNotNull(responseEntity);
+        assertNotNull(responseEntity.getStatusCode());
+        model=(CldsModel)responseEntity.getBody();
+        assertNotNull(model);
+    }
+
+    @Test
+    public void testGetSdcProperties() throws IOException {
+        JSONAssert.assertEquals(
+            ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-global.json"), cldsService.getSdcProperties(),
+            true);
     }
 
     @Test
index 4268ce3..aa43ea2 100644 (file)
@@ -202,13 +202,13 @@ clamp.config.clds.service.cache.invalidate.after.seconds=120
 \r
 #DCAE Inventory Url Properties\r
 clamp.config.dcae.inventory.url=http://localhost:${docker.http-cache.port.host}\r
-clamp.config.dcae.intentory.retry.interval=10000\r
-clamp.config.dcae.intentory.retry.limit=3\r
+clamp.config.dcae.intentory.retry.interval=100\r
+clamp.config.dcae.intentory.retry.limit=1\r
 \r
 #DCAE Dispatcher Url Properties\r
 clamp.config.dcae.dispatcher.url=http://localhost:${docker.http-cache.port.host}\r
-clamp.config.dcae.dispatcher.retry.interval=10000\r
-clamp.config.dcae.dispatcher.retry.limit=10\r
+clamp.config.dcae.dispatcher.retry.interval=100\r
+clamp.config.dcae.dispatcher.retry.limit=1\r
 clamp.config.dcae.header.requestId = X-ECOMP-RequestID\r
 \r
 #Define user permission related parameters, the permission type can be changed but MUST be redefined in clds-users.properties in that case !\r
diff --git a/src/test/resources/example/sdc/expected-result/sdc-properties-global.json b/src/test/resources/example/sdc/expected-result/sdc-properties-global.json
new file mode 100644 (file)
index 0000000..f81784d
--- /dev/null
@@ -0,0 +1,102 @@
+{
+       "tca": {
+               "tname": "New_Set",
+               "tcaInt": "1",
+               "tcaVio": "1",
+               "eventName": {
+                       "vLoadBalancer": "vLoadBalancer",
+                       "vFirewallBroadcastPackets": "vFirewallBroadcastPackets",
+                       "Measurement_vGMUX": "Measurement_vGMUX"
+               },
+               "fieldPathM": {
+                       "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value": "Packet-loss-rate",
+                       "$.event.measurementsForVfScalingFields.vNicUsageArray[*].receivedTotalPacketsDelta": "receivedTotalPacketsDelta"
+               },
+               "operator": {
+                       ">": "GREATER",
+                       ">=": "GREATER_OR_EQUAL",
+                       "=": "EQUAL",
+                       "<=": "LESS_OR_EQUAL",
+                       "<": "LESS"
+               },
+               "opsPolicy": {
+                       "POLICY_test_X": "POLICY_test_X",
+                       "POLICY_test_Y": "POLICY_test_Y"
+               },
+               "controlLoopSchemaType": {
+                       "": "",
+                       "VM": "VM",
+                       "VNF": "VNF"
+               },
+               "closedLoopEventStatus": {
+                       "": "",
+                       "ONSET": "ONSET",
+                       "ABATED": "ABATED"
+               }
+       },
+       "global": {
+               "actionSet": {
+                       "vnfRecipe": "VNF"
+               },
+               "location": {
+                       "DC1": "Data Center 1",
+                       "DC2": "Data Center 2",
+                       "DC3": "Data Center 3"
+               }
+       },
+       "policy": {
+               "pname": "0",
+               "timeout": 345,
+               "vnfRecipe": {
+                       "": "",
+                       "restart": "Restart",
+                       "rebuild": "Rebuild",
+                       "migrate": "Migrate",
+                       "healthCheck": "Health Check",
+                       "modifyConfig": "ModifyConfig",
+                       "vfModuleCreate": "VF Module Create"
+               },
+               "maxRetries": "3",
+               "retryTimeLimit": 180,
+               "resource": {
+                       "vCTS": "vCTS",
+                       "v3CDB": "v3CDB",
+                       "vUDR": "vUDR",
+                       "vCOM": "vCOM",
+                       "vRAR": "vRAR",
+                       "vLCS": "vLCS",
+                       "vUDR-BE": "vUDR-BE",
+                       "vDBE": "vDBE"
+               },
+               "parentPolicyConditions": {
+                       "Failure_Retries": "Failure: Max Retries Exceeded",
+                       "Failure_Timeout": "Failure: Time Limit Exceeded",
+                       "Failure_Guard": "Failure: Guard",
+                       "Failure_Exception": "Failure: Exception",
+                       "Failure": "Failure: Other",
+                       "Success": "Success"
+               }
+       },
+       "shared": {
+               "byService": {
+                       "": {
+                               "vf": {
+                                       "": ""
+                               },
+                               "location": {
+                                       "": ""
+                               },
+                               "alarmCondition": {
+                                       "": ""
+                               }
+                       }
+               },
+               "byVf": {
+                       "": {
+                               "vfc": {
+                                       "": ""
+                               }
+                       }
+               }
+       }
+}
\ No newline at end of file