aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-02-07 09:47:49 +0100
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-02-07 09:47:49 +0100
commiteca731806cfc887c05aca8b35277cee452f5c264 (patch)
tree06133d092a7c58af49c8a510ed77db8f55538021 /src/test/java
parent23001a5e8d48d8ab15309613fd0bfd30f5aeff96 (diff)
Improve Unit tests
Improve the unit tests on different cases. Issue-ID: CLAMP-74 Change-Id: If13558a540b22dc1156206111d1f33712249d1ac Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java22
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java77
-rw-r--r--src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java6
3 files changed, 59 insertions, 46 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
index f09fd9b19..c684d4455 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,10 +24,15 @@
package org.onap.clamp.clds.it;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import javax.ws.rs.NotFoundException;
@@ -36,6 +41,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.AbstractItCase;
import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.model.CLDSMonitoringDetails;
import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.CldsTemplate;
@@ -53,6 +59,8 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class CldsDaoItCase extends AbstractItCase {
+
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class);
@Autowired
public CldsDao cldsDao;
private String bpmnText;
@@ -141,4 +149,16 @@ public class CldsDaoItCase extends AbstractItCase {
CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED,
"process-instance-id");
}
+
+ @Test
+ public void testGetCLDSMonitoringDetails() {
+ List<CLDSMonitoringDetails> cldsMonitoringDetailsList = new ArrayList<CLDSMonitoringDetails>();
+ cldsMonitoringDetailsList = cldsDao.getCLDSMonitoringDetails();
+ cldsMonitoringDetailsList.forEach(clName -> {
+ logger.info(clName.getCloseloopName()); // Uncomment this line to
+ // view the result on
+ // console
+ assertNotNull(clName.getCloseloopName());
+ });
+ }
}
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java
index 259a2e3a8..b4415ed1a 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsTemplateServiceItCase.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,7 +37,7 @@ import java.util.List;
import javax.ws.rs.core.SecurityContext;
import javax.xml.transform.TransformerException;
-import org.junit.Before;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@@ -60,44 +60,42 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class CldsTemplateServiceItCase extends AbstractItCase {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsTemplateServiceItCase.class);
+
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsTemplateServiceItCase.class);
@Autowired
private CldsTemplateService cldsTemplateService;
- @Autowired
- private CldsDao cldsDao;
- private String bpmnText;
- private String imageText;
+ @Autowired
+ private CldsDao cldsDao;
+ private String bpmnText;
+ private String imageText;
private String bpmnPropText;
private CldsTemplate cldsTemplate;
- /**
- * Setup the variable before the tests execution.
+ /**
+ * Setup the variable before the tests execution.
*
- * @throws IOException
- * In case of issues when opening the files
- */
- @Before
- public void setupBefore() throws IOException {
- SecurityContext securityContext = Mockito.mock(SecurityContext.class);
- Principal principal = Mockito.mock(Principal.class);
- Mockito.when(principal.getName()).thenReturn("admin");
+ * @throws IOException
+ * In case of issues when opening the files
+ */
+ @Before
+ public void setupBefore() throws IOException {
+ SecurityContext securityContext = Mockito.mock(SecurityContext.class);
+ Principal principal = Mockito.mock(Principal.class);
+ Mockito.when(principal.getName()).thenReturn("admin");
Mockito.when(securityContext.getUserPrincipal()).thenReturn(principal);
- Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|read")).thenReturn(true);
- Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|update")).thenReturn(true);
- Mockito.when(securityContext.isUserInRole("permission-type-template|dev|read")).thenReturn(true);
- Mockito.when(securityContext.isUserInRole("permission-type-template|dev|update")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|read")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|update")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-template|dev|read")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-template|dev|update")).thenReturn(true);
cldsTemplateService.setSecurityContext(securityContext);
-
- bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml");
- imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
- bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
-
- cldsTemplate = new CldsTemplate();
- cldsTemplate.setName("testModel");
- cldsTemplate.setBpmnText(bpmnText);
+ bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml");
+ imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
+ bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
+ cldsTemplate = new CldsTemplate();
+ cldsTemplate.setName("testModel");
+ cldsTemplate.setBpmnText(bpmnText);
cldsTemplate.setImageText(imageText);
cldsTemplate.setPropText(bpmnPropText);
-
try {
cldsTemplateService.putTemplate("testModel", cldsTemplate);
} catch (IOException e) {
@@ -106,19 +104,16 @@ public class CldsTemplateServiceItCase extends AbstractItCase {
logger.error("Transforming exception while saving template.", ex);
}
}
-
+
@Test
public void testPutTemplate() throws Exception {
-
- CldsTemplate savedTemplate = cldsTemplate.retrieve(cldsDao, "testModel", false);
+ CldsTemplate savedTemplate = CldsTemplate.retrieve(cldsDao, "testModel", false);
assertNotNull(savedTemplate);
logger.info("saved template bpmn text is:" + savedTemplate.getBpmnText());
assertEquals(bpmnText, savedTemplate.getBpmnText());
-
assertEquals(imageText, savedTemplate.getImageText());
assertEquals(bpmnPropText, savedTemplate.getPropText());
assertEquals("testModel", savedTemplate.getName());
-
}
@Test
@@ -145,18 +140,16 @@ public class CldsTemplateServiceItCase extends AbstractItCase {
@Test
public void testGetTemplateNames() throws Exception {
- CldsTemplate cldsTemplateNew = new CldsTemplate();
-
- cldsTemplateNew.setName("testModelNew");
- cldsTemplateNew.setBpmnText(bpmnText);
+ CldsTemplate cldsTemplateNew = new CldsTemplate();
+ cldsTemplateNew.setName("testModelNew");
+ cldsTemplateNew.setBpmnText(bpmnText);
cldsTemplateNew.setImageText(imageText);
cldsTemplateNew.setPropText(bpmnPropText);
cldsTemplateService.putTemplate("testModelNew", cldsTemplateNew);
-
List<ValueItem> templateNames = cldsTemplateService.getTemplateNames();
- boolean testModel = false;
+ boolean testModel = false;
boolean testModelNew = false;
- for (ValueItem item: templateNames) {
+ for (ValueItem item : templateNames) {
if (item.getValue().equals("testModel")) {
testModel = true;
}
diff --git a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java
index ccbcb0ea0..c17ec0df8 100644
--- a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -68,7 +69,7 @@ public class TcaRequestFormatterItCase extends AbstractItCase {
}
@Test
- public void testCreatePolicyJson() throws IOException {
+ public void testCreatePolicyJson() throws IOException, JSONException {
ModelProperties prop = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmn,
modelProp);
String result = TcaRequestFormatter.createPolicyJson(refProp, prop);
@@ -82,7 +83,6 @@ public class TcaRequestFormatterItCase extends AbstractItCase {
ModelProperties prop = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmn,
modelProp);
String result = TcaRequestFormatter.updatedBlueprintWithConfiguration(refProp, prop, yamlInput);
-
assertNotNull(result);
assertEquals(ResourceFileUtil.getResourceAsString("example/tca-policy-req/blueprint-expected.yaml"), result);
}