diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2017-11-16 13:40:22 +0100 |
---|---|---|
committer | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2017-11-16 14:00:03 +0100 |
commit | 98344de96ed80b839929be0bd272753675009a5d (patch) | |
tree | a8f8c8e42ecde5c2ef0558bd812dcfd4b3fa0b27 /src/test/java/org/onap | |
parent | 37677f517e384685ba9056a9e8d79f2fa734f192 (diff) |
Refactor the java packages
Refactor the java packages, moving classes to others packages
Change-Id: I5cd2a6477876ce187502afff37a862029a081ab3
Issue-ID: CLAMP-74
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/test/java/org/onap')
10 files changed, 103 insertions, 54 deletions
diff --git a/src/test/java/org/onap/clamp/clds/AbstractItCase.java b/src/test/java/org/onap/clamp/clds/AbstractItCase.java index 9be8a13b..d3f64240 100644 --- a/src/test/java/org/onap/clamp/clds/AbstractItCase.java +++ b/src/test/java/org/onap/clamp/clds/AbstractItCase.java @@ -24,7 +24,7 @@ package org.onap.clamp.clds; import org.junit.BeforeClass; -import org.onap.clamp.clds.client.PolicyClient; +import org.onap.clamp.clds.client.req.policy.PolicyClient; import org.onap.clamp.clds.model.refprop.RefProp; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ActiveProfiles; diff --git a/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java b/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java index 734b6052..9b8f4aad 100644 --- a/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java +++ b/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdc.Resource; import org.onap.policy.sdc.ResourceType; 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 1427c329..78b24013 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java @@ -25,6 +25,8 @@ package org.onap.clamp.clds.it; import static org.junit.Assert.assertEquals; +import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils; + import java.io.IOException; import javax.ws.rs.NotFoundException; @@ -51,10 +53,8 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest @TestPropertySource(locations = "classpath:application-no-camunda.properties") public class CldsDaoItCase extends AbstractItCase { - @Autowired public CldsDao cldsDao; - private String bpmnText; private String imageText; private String bpmnPropText; @@ -74,40 +74,37 @@ public class CldsDaoItCase extends AbstractItCase { @Test public void testModelSave() throws IOException { + String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5); + String randomNameModel = RandomStringUtils.randomAlphanumeric(5); // Add the template first CldsTemplate newTemplate = new CldsTemplate(); - newTemplate.setName("test-template"); - + newTemplate.setName(randomNameTemplate); newTemplate.setBpmnText(bpmnText); newTemplate.setImageText(imageText); - // Save the template in DB cldsDao.setTemplate(newTemplate, "user"); // Test if it's well there - CldsTemplate newTemplateRead = cldsDao.getTemplate("test-template"); + CldsTemplate newTemplateRead = cldsDao.getTemplate(randomNameTemplate); assertEquals(bpmnText, newTemplateRead.getBpmnText()); assertEquals(imageText, newTemplateRead.getImageText()); - // Save the model CldsModel newModel = new CldsModel(); - newModel.setName("test-model"); - + newModel.setName(randomNameModel); newModel.setBpmnText(bpmnText); newModel.setImageText(imageText); newModel.setPropText(bpmnPropText); newModel.setControlNamePrefix("ClosedLoop-"); - newModel.setTemplateName("test-template"); + newModel.setTemplateName(randomNameTemplate); newModel.setTemplateId(newTemplate.getId()); newModel.setDocText(newTemplate.getPropText()); newModel.setDocId(newTemplate.getPropId()); // Save the model in DB cldsDao.setModel(newModel, "user"); // Test if the model can be retrieved - CldsModel newCldsModel = cldsDao.getModelTemplate("test-model"); + CldsModel newCldsModel = cldsDao.getModelTemplate(randomNameModel); assertEquals(bpmnText, newCldsModel.getBpmnText()); assertEquals(imageText, newCldsModel.getImageText()); assertEquals(bpmnPropText, newCldsModel.getPropText()); - } @Test(expected = NotFoundException.class) @@ -125,21 +122,16 @@ public class CldsDaoItCase extends AbstractItCase { // Add the template first CldsTemplate newTemplate = new CldsTemplate(); newTemplate.setName("test-template-for-event"); - newTemplate.setBpmnText(bpmnText); newTemplate.setImageText(imageText); - newTemplate.save(cldsDao, "user"); - // Test if it's well there CldsTemplate newTemplateRead = CldsTemplate.retrieve(cldsDao, "test-template-for-event", false); assertEquals(bpmnText, newTemplateRead.getBpmnText()); assertEquals(imageText, newTemplateRead.getImageText()); - // Save the model CldsModel newModel = new CldsModel(); newModel.setName("test-model-for-event"); - newModel.setBpmnText(bpmnText); newModel.setImageText(imageText); newModel.setPropText(bpmnPropText); @@ -148,7 +140,6 @@ public class CldsDaoItCase extends AbstractItCase { newModel.setTemplateId(newTemplate.getId()); newModel.setDocText(newTemplate.getPropText()); newModel.setDocId(newTemplate.getPropId()); - CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED, "process-instance-id"); } diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java index a1882eaa..f6e9abdd 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -25,20 +25,30 @@ package org.onap.clamp.clds.it; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils; + +import java.io.IOException; import java.io.InputStream; import java.security.Principal; import java.util.Properties; import javax.ws.rs.core.SecurityContext; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.onap.clamp.clds.AbstractItCase; +import org.onap.clamp.clds.dao.CldsDao; +import org.onap.clamp.clds.model.CldsHealthCheck; import org.onap.clamp.clds.model.CldsInfo; +import org.onap.clamp.clds.model.CldsModel; +import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.service.CldsService; +import org.onap.clamp.clds.util.ResourceFileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -52,19 +62,34 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @TestPropertySource(locations = "classpath:application-no-camunda.properties") public class CldsServiceItCase extends AbstractItCase { - @Autowired - CldsService cldsService; + CldsService cldsService; + private String bpmnText; + private String imageText; + private String bpmnPropText; + @Autowired + public CldsDao cldsDao; + + /** + * Setup the variable before the tests execution. + * + * @throws IOException + * In case of issues when opening the files + */ + @Before + public void setupBefore() throws IOException { + bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml"); + imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml"); + bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json"); + } @Test public void testCldsInfoNotAuthorized() throws Exception { SecurityContext securityContext = Mockito.mock(SecurityContext.class); Principal principal = Mockito.mock(Principal.class); Mockito.when(principal.getName()).thenReturn("admin"); - Mockito.when(securityContext.getUserPrincipal()).thenReturn(principal); cldsService.setSecurityContext(securityContext); - CldsInfo cldsInfo = cldsService.getCldsInfo(); assertFalse(cldsInfo.isPermissionReadCl()); assertFalse(cldsInfo.isPermissionReadTemplate()); @@ -74,32 +99,75 @@ public class CldsServiceItCase extends AbstractItCase { @Test public void testCldsInfoAuthorized() throws Exception { - SecurityContext securityContext = Mockito.mock(SecurityContext.class); Principal p = Mockito.mock(Principal.class); Mockito.when(p.getName()).thenReturn("admin"); - Mockito.when(securityContext.getUserPrincipal()).thenReturn(p); 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); - cldsService.setSecurityContext(securityContext); - CldsInfo cldsInfo = cldsService.getCldsInfo(); assertTrue(cldsInfo.isPermissionReadCl()); assertTrue(cldsInfo.isPermissionReadTemplate()); assertTrue(cldsInfo.isPermissionUpdateCl()); assertTrue(cldsInfo.isPermissionUpdateTemplate()); - Properties prop = new Properties(); - InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("clds-version.properties"); prop.load(in); in.close(); - assertEquals(cldsInfo.getCldsVersion(), prop.getProperty("clds.version")); assertEquals(cldsInfo.getUserName(), "admin"); } + + @Test + public void testGetHealthCheck() throws Exception { + CldsHealthCheck cldsHealthCheck = cldsService.gethealthcheck(); + assertNotNull(cldsHealthCheck); + assertEquals("UP", cldsHealthCheck.getHealthCheckStatus()); + assertEquals("CLDS-APP", cldsHealthCheck.getHealthCheckComponent()); + assertEquals("OK", cldsHealthCheck.getDescription()); + } + + @Test + public void testPutModel() throws Exception { + String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5); + String randomNameModel = RandomStringUtils.randomAlphanumeric(5); + SecurityContext securityContext = Mockito.mock(SecurityContext.class); + Principal p = Mockito.mock(Principal.class); + Mockito.when(p.getName()).thenReturn("admin"); + Mockito.when(securityContext.getUserPrincipal()).thenReturn(p); + 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); + cldsService.setSecurityContext(securityContext); + // Add the template first + CldsTemplate newTemplate = new CldsTemplate(); + newTemplate.setName(randomNameTemplate); + newTemplate.setBpmnText(bpmnText); + newTemplate.setImageText(imageText); + // Save the template in DB + cldsDao.setTemplate(newTemplate, "user"); + // Test if it's well there + CldsTemplate newTemplateRead = cldsDao.getTemplate(randomNameTemplate); + assertEquals(bpmnText, newTemplateRead.getBpmnText()); + assertEquals(imageText, newTemplateRead.getImageText()); + // Save the model + CldsModel newModel = new CldsModel(); + newModel.setName(randomNameTemplate); + newModel.setBpmnText(bpmnText); + newModel.setImageText(imageText); + newModel.setPropText(bpmnPropText); + newModel.setControlNamePrefix("ClosedLoop-"); + newModel.setTemplateName("test-template"); + newModel.setTemplateId(newTemplate.getId()); + newModel.setDocText(newTemplate.getPropText()); + newModel.setDocId(newTemplate.getPropId()); + // Test the PutModel method + cldsService.putModel(randomNameModel, newModel); + // Verify whether it has been added properly or not + assertNotNull(cldsDao.getModel(randomNameModel)); + } } diff --git a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java index c87bbf62..30091995 100644 --- a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java @@ -36,7 +36,7 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.AbstractItCase; -import org.onap.clamp.clds.client.req.OperationalPolicyReq; +import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.prop.ModelProperties; import org.onap.clamp.clds.model.prop.Policy; @@ -52,7 +52,6 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest @TestPropertySource(locations = "classpath:application-no-camunda.properties") public class OperationPolicyReqItCase extends AbstractItCase { - @Test public void formatAttributesTest() throws IOException, BuilderException { String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java index c129800d..27573776 100644 --- a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java @@ -34,8 +34,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.AbstractItCase; -import org.onap.clamp.clds.client.req.OperationalPolicyReq; -import org.onap.clamp.clds.client.req.TcaRequestFormatter; +import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq; +import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.prop.ModelProperties; import org.onap.clamp.clds.model.prop.Policy; @@ -77,7 +77,6 @@ public class PolicyClientItCase extends AbstractItCase { if (policy.isFound()) { for (PolicyChain policyChain : policy.getPolicyChains()) { String operationalPolicyRequestUuid = UUID.randomUUID().toString(); - Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp, prop, policy.getId(), policyChain); policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid); @@ -91,7 +90,6 @@ public class PolicyClientItCase extends AbstractItCase { if (tca.isFound()) { String tcaPolicyRequestUuid = UUID.randomUUID().toString(); String policyJson = TcaRequestFormatter.createPolicyJson(refProp, prop); - try { policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid); } catch (Exception e) { @@ -102,7 +100,6 @@ public class PolicyClientItCase extends AbstractItCase { private void deleteOperationalPolicy(String actionCd) throws Exception { ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); - Policy policy = prop.getType(Policy.class); if (policy.isFound()) { prop.setCurrentModelElementId(policy.getId()); @@ -115,11 +112,9 @@ public class PolicyClientItCase extends AbstractItCase { private void deleteTcaPolicy(String actionCd) throws Exception { ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); - Tca tca = prop.getType(Tca.class); if (tca.isFound()) { prop.setCurrentModelElementId(tca.getId()); - try { policyClient.deleteMicrosService(prop); } catch (Exception e) { @@ -133,21 +128,15 @@ public class PolicyClientItCase extends AbstractItCase { * Temporarily disabled Test. */ public void testCreateUpdateDeleteOperationalPolicy() throws Exception { - createUpdateOperationalPolicy(CldsEvent.ACTION_SUBMIT); - TimeUnit.SECONDS.sleep(20); - deleteOperationalPolicy(CldsEvent.ACTION_DELETE); } @Test public void testCreateUpdateDeleteTcaPolicy() throws Exception { - createUpdateTcaPolicy(CldsEvent.ACTION_SUBMIT); - TimeUnit.SECONDS.sleep(20); - deleteTcaPolicy(CldsEvent.ACTION_DELETE); } } diff --git a/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java b/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java index 478a7b38..7ccda5a8 100644 --- a/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java @@ -23,6 +23,8 @@ package org.onap.clamp.clds.it; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -42,6 +44,7 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest @TestPropertySource(locations = "classpath:application-no-camunda.properties") public class RefPropItCase extends AbstractItCase { + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(RefPropItCase.class); /** * Test getting prop value as a JSON Node / template. @@ -53,12 +56,9 @@ public class RefPropItCase extends AbstractItCase { public void testJsonTemplate() throws IOException { ObjectNode root = (ObjectNode) refProp.getJsonTemplate("tca.template"); root.put("closedLoopControlName", "ClosedLoop-FRWL-SIG-1582f840-2881-11e6-b4ec-005056a9d756"); - ObjectMapper mapper = new ObjectMapper(); String jsonText = mapper.writeValueAsString(root); - System.out.println("jsonText=" + jsonText); - + logger.error("Exception caught IllegalArgumentException as expected"); // assertEquals(topicsJson, ref.getTopicsToJson()); } - } diff --git a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java index b684a506..5d3b7703 100644 --- a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java @@ -33,7 +33,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.onap.clamp.clds.AbstractItCase; -import org.onap.clamp.clds.client.SdcCatalogServices; +import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; import org.onap.clamp.clds.model.CldsAlarmCondition; import org.onap.clamp.clds.model.CldsSdcResource; import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo; diff --git a/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java index faff2846..757d85b5 100644 --- a/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java @@ -30,12 +30,13 @@ import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; +import org.apache.commons.codec.DecoderException; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.clamp.clds.client.SdcCatalogServices; -import org.onap.clamp.clds.client.req.SdcReq; +import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; +import org.onap.clamp.clds.client.req.sdc.SdcReq; import org.onap.clamp.clds.model.CldsSdcResource; import org.onap.clamp.clds.model.CldsSdcServiceDetail; import org.onap.clamp.clds.model.prop.Global; @@ -55,7 +56,7 @@ public class SdcReqItCase { private SdcReq sdcReq; @Test - public void getSdcReqUrlsListNoGlobalPropTest() throws GeneralSecurityException { + public void getSdcReqUrlsListNoGlobalPropTest() throws GeneralSecurityException, DecoderException { ModelProperties prop = mock(ModelProperties.class); SdcCatalogServices sdcCatalogServices = mock(SdcCatalogServices.class); DelegateExecution delegateExecution = mock(DelegateExecution.class); 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 a32743a6..ccbcb0ea 100644 --- a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java @@ -32,7 +32,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.clamp.clds.AbstractItCase; -import org.onap.clamp.clds.client.req.TcaRequestFormatter; +import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.prop.ModelProperties; import org.onap.clamp.clds.util.ResourceFileUtil; |