From bb2a1d57c4e5a26576770895b97e754ac35a4b33 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 28 Sep 2017 17:52:30 +0200 Subject: Fix the Checkstyle issues Fix all checkstyle issues in all unit tests + rename all IT and remove useless tests Change-Id: I8d1244c26d4d2ca490ba8ffcf2236f484c783394 Issue-ID: CLAMP-54 Signed-off-by: Determe, Sebastien (sd378r) --- src/test/java/org/onap/clamp/clds/AbstractIT.java | 45 --- .../java/org/onap/clamp/clds/AbstractItCase.java | 45 +++ .../clds/client/req/OperationalPolicyReqTest.java | 6 +- .../org/onap/clamp/clds/client/req/SdcReqTest.java | 8 +- .../java/org/onap/clamp/clds/it/CldsDaoIT.java | 149 -------- .../java/org/onap/clamp/clds/it/CldsDaoItCase.java | 155 +++++++++ .../java/org/onap/clamp/clds/it/CldsServiceIT.java | 105 ------ .../org/onap/clamp/clds/it/CldsServiceItCase.java | 105 ++++++ src/test/java/org/onap/clamp/clds/it/HttpsIT.java | 142 -------- .../java/org/onap/clamp/clds/it/HttpsItCase.java | 145 ++++++++ .../onap/clamp/clds/it/OperationPolicyReqIT.java | 88 ----- .../clamp/clds/it/OperationPolicyReqItCase.java | 88 +++++ .../org/onap/clamp/clds/it/PolicyClientIT.java | 154 --------- .../org/onap/clamp/clds/it/PolicyClientItCase.java | 153 +++++++++ .../org/onap/clamp/clds/it/PropJsonBuilderIT.java | 378 --------------------- .../java/org/onap/clamp/clds/it/RefPropIT.java | 64 ---- .../java/org/onap/clamp/clds/it/RefPropItCase.java | 64 ++++ .../onap/clamp/clds/it/SdcCatalogServicesIT.java | 325 ------------------ .../clamp/clds/it/SdcCatalogServicesItCase.java | 325 ++++++++++++++++++ .../onap/clamp/clds/it/TcaRequestFormatterIT.java | 89 ----- .../clamp/clds/it/TcaRequestFormatterItCase.java | 89 +++++ 21 files changed, 1176 insertions(+), 1546 deletions(-) delete mode 100644 src/test/java/org/onap/clamp/clds/AbstractIT.java create mode 100644 src/test/java/org/onap/clamp/clds/AbstractItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/CldsDaoIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/CldsServiceIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/HttpsIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/HttpsItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/PropJsonBuilderIT.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/RefPropIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/RefPropItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java delete mode 100644 src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterIT.java create mode 100644 src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java (limited to 'src') diff --git a/src/test/java/org/onap/clamp/clds/AbstractIT.java b/src/test/java/org/onap/clamp/clds/AbstractIT.java deleted file mode 100644 index b705e38d..00000000 --- a/src/test/java/org/onap/clamp/clds/AbstractIT.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds; - -import org.junit.BeforeClass; -import org.onap.clamp.clds.client.PolicyClient; -import org.onap.clamp.clds.model.refprop.RefProp; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ActiveProfiles; - -@ActiveProfiles("clamp-default") -public abstract class AbstractIT { - - @Autowired - protected RefProp refProp; - @Autowired - protected PolicyClient policyClient; - - @BeforeClass - public static void oneTimeSetUp() { - System.setProperty("AJSC_CONF_HOME", System.getProperty("user.dir") + "/src/it/resources/"); - System.setProperty("CLDS_DCAE_URL", "http://localhost:13786/cl-dcae-services"); - } -} diff --git a/src/test/java/org/onap/clamp/clds/AbstractItCase.java b/src/test/java/org/onap/clamp/clds/AbstractItCase.java new file mode 100644 index 00000000..9be8a13b --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/AbstractItCase.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds; + +import org.junit.BeforeClass; +import org.onap.clamp.clds.client.PolicyClient; +import org.onap.clamp.clds.model.refprop.RefProp; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("clamp-default") +public abstract class AbstractItCase { + + @Autowired + protected RefProp refProp; + @Autowired + protected PolicyClient policyClient; + + @BeforeClass + public static void oneTimeSetUp() { + System.setProperty("AJSC_CONF_HOME", System.getProperty("user.dir") + "/src/it/resources/"); + System.setProperty("CLDS_DCAE_URL", "http://localhost:13786/cl-dcae-services"); + } +} 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 d4584436..734b6052 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,9 +31,9 @@ import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdc.Resource; import org.onap.policy.sdc.ResourceType; -import org.onap.policy.controlloop.policy.PolicyResult; public class OperationalPolicyReqTest { @@ -49,7 +49,7 @@ public class OperationalPolicyReqTest { stringList.add("test2"); stringList.add("test3"); stringList.add("test4"); - Resource resources[] = (Resource[]) method.invoke(null, stringList, ResourceType.VF); + Resource[] resources = (Resource[]) method.invoke(null, stringList, ResourceType.VF); assertTrue(resources.length == 4); assertTrue("test1".equals(resources[0].getResourceName())); @@ -69,7 +69,7 @@ public class OperationalPolicyReqTest { stringList.add("SUCCESS"); stringList.add("FAILURE_GUARD"); stringList.add("FAILURE_TIMEOUT"); - PolicyResult policyResult[] = (PolicyResult[]) method.invoke(null, stringList); + PolicyResult[] policyResult = (PolicyResult[]) method.invoke(null, stringList); assertTrue(policyResult.length == 4); assertTrue(policyResult[0].equals(PolicyResult.FAILURE)); diff --git a/src/test/java/org/onap/clamp/clds/client/req/SdcReqTest.java b/src/test/java/org/onap/clamp/clds/client/req/SdcReqTest.java index a283f43d..497abe0f 100644 --- a/src/test/java/org/onap/clamp/clds/client/req/SdcReqTest.java +++ b/src/test/java/org/onap/clamp/clds/client/req/SdcReqTest.java @@ -41,7 +41,7 @@ import org.onap.clamp.clds.model.prop.ModelProperties; public class SdcReqTest { String baseUrl = "AYBABTU"; - String serviceInvariantUUID = "serviceInvariantUUID"; + String serviceInvariantUuid = "serviceInvariantUUID"; @Test public void getSdcReqUrlsListNoGlobalPropTest() { @@ -52,7 +52,7 @@ public class SdcReqTest { List cldsSdcResources = new ArrayList<>(); cldsSdcResources.add(cldsSdcResource); List resourceVf = new ArrayList<>(); - resourceVf.add(serviceInvariantUUID); + resourceVf.add(serviceInvariantUuid); Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty()); @@ -60,7 +60,7 @@ public class SdcReqTest { when(prop.getGlobal()).thenReturn(global); Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty()); - when(global.getService()).thenReturn(serviceInvariantUUID); + when(global.getService()).thenReturn(serviceInvariantUuid); Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty()); CldsSdcServiceDetail cldsSdcServiceDetail = mock(CldsSdcServiceDetail.class); @@ -75,7 +75,7 @@ public class SdcReqTest { Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty()); when(global.getResourceVf()).thenReturn(resourceVf); - when(cldsSdcResource.getResourceInvariantUUID()).thenReturn(serviceInvariantUUID); + when(cldsSdcResource.getResourceInvariantUUID()).thenReturn(serviceInvariantUuid); when(cldsSdcResource.getResourceInstanceName()).thenReturn("Resource instance name"); List expected = new ArrayList<>(); expected.add("AYBABTU/null/resourceInstances/resourceinstancename/artifacts"); diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDaoIT.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoIT.java deleted file mode 100644 index bd419647..00000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsDaoIT.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import javax.ws.rs.NotFoundException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.AbstractIT; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsEvent; -import org.onap.clamp.clds.model.CldsModel; -import org.onap.clamp.clds.model.CldsTemplate; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test CldsDAO calls through CldsModel and CldsEvent. This really test the DB - * and stored procedures. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class CldsDaoIT extends AbstractIT { - - @Autowired - public CldsDao cldsDao; - - private String bpmnText; - private String imageText; - private String bpmnPropText; - - @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 testModelSave() throws IOException { - // Add the template first - CldsTemplate newTemplate = new CldsTemplate(); - newTemplate.setName("test-template"); - - 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"); - assertEquals(bpmnText, newTemplateRead.getBpmnText()); - assertEquals(imageText, newTemplateRead.getImageText()); - - // Save the model - CldsModel newModel = new CldsModel(); - newModel.setName("test-model"); - - 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()); - // Save the model in DB - cldsDao.setModel(newModel, "user"); - // Test if the model can be retrieved - CldsModel newCldsModel = cldsDao.getModelTemplate("test-model"); - assertEquals(bpmnText, newCldsModel.getBpmnText()); - assertEquals(imageText, newCldsModel.getImageText()); - assertEquals(bpmnPropText, newCldsModel.getPropText()); - - } - - @Test(expected = NotFoundException.class) - public void testGetModelNotFound() { - CldsModel.retrieve(cldsDao, "test-model-not-found", false); - } - - @Test(expected = NotFoundException.class) - public void testGetTemplateNotFound() { - CldsTemplate.retrieve(cldsDao, "test-template-not-found", false); - } - - @Test - public void testInsEvent() { - // 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); - newModel.setControlNamePrefix("ClosedLoop-"); - newModel.setTemplateName("test-template-for-event"); - 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/CldsDaoItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java new file mode 100644 index 00000000..1427c329 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import javax.ws.rs.NotFoundException; + +import org.junit.Before; +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.CldsEvent; +import org.onap.clamp.clds.model.CldsModel; +import org.onap.clamp.clds.model.CldsTemplate; +import org.onap.clamp.clds.util.ResourceFileUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Test CldsDAO calls through CldsModel and CldsEvent. This really test the DB + * and stored procedures. + */ +@RunWith(SpringRunner.class) +@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; + + /** + * 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 testModelSave() throws IOException { + // Add the template first + CldsTemplate newTemplate = new CldsTemplate(); + newTemplate.setName("test-template"); + + 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"); + assertEquals(bpmnText, newTemplateRead.getBpmnText()); + assertEquals(imageText, newTemplateRead.getImageText()); + + // Save the model + CldsModel newModel = new CldsModel(); + newModel.setName("test-model"); + + 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()); + // Save the model in DB + cldsDao.setModel(newModel, "user"); + // Test if the model can be retrieved + CldsModel newCldsModel = cldsDao.getModelTemplate("test-model"); + assertEquals(bpmnText, newCldsModel.getBpmnText()); + assertEquals(imageText, newCldsModel.getImageText()); + assertEquals(bpmnPropText, newCldsModel.getPropText()); + + } + + @Test(expected = NotFoundException.class) + public void testGetModelNotFound() { + CldsModel.retrieve(cldsDao, "test-model-not-found", false); + } + + @Test(expected = NotFoundException.class) + public void testGetTemplateNotFound() { + CldsTemplate.retrieve(cldsDao, "test-template-not-found", false); + } + + @Test + public void testInsEvent() { + // 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); + newModel.setControlNamePrefix("ClosedLoop-"); + newModel.setTemplateName("test-template-for-event"); + 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/CldsServiceIT.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceIT.java deleted file mode 100644 index f09c3577..00000000 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceIT.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.InputStream; -import java.security.Principal; -import java.util.Properties; - -import javax.ws.rs.core.SecurityContext; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.clamp.clds.AbstractIT; -import org.onap.clamp.clds.model.CldsInfo; -import org.onap.clamp.clds.service.CldsService; -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.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. - */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class CldsServiceIT extends AbstractIT { - - @Autowired - CldsService cldsService; - - @Test - public void testCldsInfoNotAuthorized() 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); - cldsService.setSecurityContext(securityContext); - - CldsInfo cldsInfo = cldsService.getCldsInfo(); - assertFalse(cldsInfo.isPermissionReadCl()); - assertFalse(cldsInfo.isPermissionReadTemplate()); - assertFalse(cldsInfo.isPermissionUpdateCl()); - assertFalse(cldsInfo.isPermissionUpdateTemplate()); - } - - @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"); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java new file mode 100644 index 00000000..a1882eaa --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.security.Principal; +import java.util.Properties; + +import javax.ws.rs.core.SecurityContext; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.clamp.clds.AbstractItCase; +import org.onap.clamp.clds.model.CldsInfo; +import org.onap.clamp.clds.service.CldsService; +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.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@TestPropertySource(locations = "classpath:application-no-camunda.properties") +public class CldsServiceItCase extends AbstractItCase { + + @Autowired + CldsService cldsService; + + @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()); + assertFalse(cldsInfo.isPermissionUpdateCl()); + assertFalse(cldsInfo.isPermissionUpdateTemplate()); + } + + @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"); + } +} diff --git a/src/test/java/org/onap/clamp/clds/it/HttpsIT.java b/src/test/java/org/onap/clamp/clds/it/HttpsIT.java deleted file mode 100644 index 98319b41..00000000 --- a/src/test/java/org/onap/clamp/clds/it/HttpsIT.java +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.net.HttpURLConnection; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.AbstractIT; -import org.springframework.beans.factory.annotation.Value; -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.http.client.SimpleClientHttpRequestFactory; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; - -/** - * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) -@TestPropertySource(locations = "classpath:https/https-test.properties") -public class HttpsIT extends AbstractIT { - - @Value("${server.port}") - private String httpsPort; - - @Value("${server.http-to-https-redirection.port}") - private String httpPort; - - @BeforeClass - public static void setUp() { - - try { - // setup ssl context to ignore certificate errors - SSLContext ctx = SSLContext.getInstance("TLS"); - X509TrustManager tm = new X509TrustManager() { - - @Override - public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) - throws java.security.cert.CertificateException { - } - - @Override - public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) - throws java.security.cert.CertificateException { - } - - @Override - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - }; - ctx.init(null, new TrustManager[] { tm }, null); - SSLContext.setDefault(ctx); - } catch (Exception ex) { - ex.printStackTrace(); - } - - } - - @Test - public void testDesignerIndex() throws Exception { - RestTemplate template = new RestTemplate(); - final MySimpleClientHttpRequestFactory factory = new MySimpleClientHttpRequestFactory(new HostnameVerifier() { - - @Override - public boolean verify(final String hostname, final SSLSession session) { - return true; - } - }); - template.setRequestFactory(factory); - - ResponseEntity entity = template - .getForEntity("http://localhost:" + this.httpPort + "/designer/index.html", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - - ResponseEntity httpsEntity = template - .getForEntity("https://localhost:" + this.httpsPort + "/designer/index.html", String.class); - assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(httpsEntity.getBody()).contains("CLDS"); - - } - - /** - * Http Request Factory for ignoring SSL hostname errors. Not for production - * use! - */ - class MySimpleClientHttpRequestFactory extends SimpleClientHttpRequestFactory { - - private final HostnameVerifier verifier; - - public MySimpleClientHttpRequestFactory(final HostnameVerifier verifier) { - this.verifier = verifier; - } - - @Override - protected void prepareConnection(final HttpURLConnection connection, final String httpMethod) - throws IOException { - if (connection instanceof HttpsURLConnection) { - ((HttpsURLConnection) connection).setHostnameVerifier(this.verifier); - } - super.prepareConnection(connection, httpMethod); - } - } - -} diff --git a/src/test/java/org/onap/clamp/clds/it/HttpsItCase.java b/src/test/java/org/onap/clamp/clds/it/HttpsItCase.java new file mode 100644 index 00000000..9befc40b --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/HttpsItCase.java @@ -0,0 +1,145 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.net.HttpURLConnection; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.clamp.clds.AbstractItCase; +import org.springframework.beans.factory.annotation.Value; +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.http.client.SimpleClientHttpRequestFactory; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +/** + * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS. + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) +@TestPropertySource(locations = "classpath:https/https-test.properties") +public class HttpsItCase extends AbstractItCase { + + @Value("${server.port}") + private String httpsPort; + + @Value("${server.http-to-https-redirection.port}") + private String httpPort; + + /** + * Setup the variable before tests execution. + */ + @BeforeClass + public static void setUp() { + + try { + // setup ssl context to ignore certificate errors + SSLContext ctx = SSLContext.getInstance("TLS"); + X509TrustManager tm = new X509TrustManager() { + + @Override + public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) + throws java.security.cert.CertificateException { + } + + @Override + public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) + throws java.security.cert.CertificateException { + } + + @Override + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + }; + ctx.init(null, new TrustManager[] { tm }, null); + SSLContext.setDefault(ctx); + } catch (Exception ex) { + ex.printStackTrace(); + } + + } + + @Test + public void testDesignerIndex() throws Exception { + RestTemplate template = new RestTemplate(); + final MySimpleClientHttpRequestFactory factory = new MySimpleClientHttpRequestFactory(new HostnameVerifier() { + + @Override + public boolean verify(final String hostname, final SSLSession session) { + return true; + } + }); + template.setRequestFactory(factory); + + ResponseEntity entity = template + .getForEntity("http://localhost:" + this.httpPort + "/designer/index.html", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + + ResponseEntity httpsEntity = template + .getForEntity("https://localhost:" + this.httpsPort + "/designer/index.html", String.class); + assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(httpsEntity.getBody()).contains("CLDS"); + + } + + /** + * Http Request Factory for ignoring SSL hostname errors. Not for production + * use! + */ + class MySimpleClientHttpRequestFactory extends SimpleClientHttpRequestFactory { + + private final HostnameVerifier verifier; + + public MySimpleClientHttpRequestFactory(final HostnameVerifier verifier) { + this.verifier = verifier; + } + + @Override + protected void prepareConnection(final HttpURLConnection connection, final String httpMethod) + throws IOException { + if (connection instanceof HttpsURLConnection) { + ((HttpsURLConnection) connection).setHostnameVerifier(this.verifier); + } + super.prepareConnection(connection, httpMethod); + } + } + +} diff --git a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java deleted file mode 100644 index 0f874e98..00000000 --- a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqIT.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.AbstractIT; -import org.onap.clamp.clds.client.req.OperationalPolicyReq; -import org.onap.clamp.clds.model.CldsEvent; -import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.model.prop.Policy; -import org.onap.clamp.clds.model.prop.PolicyChain; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.policy.api.AttributeType; -import org.onap.policy.controlloop.policy.builder.BuilderException; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class OperationPolicyReqIT extends AbstractIT { - - @Test - public void formatAttributesTest() throws IOException, BuilderException { - String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); - String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); - ModelProperties prop = new ModelProperties("testModel", "controlNameTest", CldsEvent.ACTION_SUBMIT, true, - modelBpmnProp, modelProp); - List>> attributes = new ArrayList<>(); - if (prop.getType(Policy.class).isFound()) { - for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) { - - attributes.add(OperationalPolicyReq.formatAttributes(refProp, prop, prop.getType(Policy.class).getId(), - policyChain)); - } - } - assertFalse(attributes.isEmpty()); - assertTrue(attributes.size() == 2); - // now validate the Yaml, to do so we replace the dynamic ID by a known - // key so that we can compare it - String yaml = URLDecoder.decode(attributes.get(0).get(AttributeType.RULE).get("ControlLoopYaml"), "UTF-8"); - yaml = yaml.replaceAll("trigger_policy: (.*)", "trigger_policy: "); - yaml = yaml.replaceAll("id: (.*)", "id: "); - yaml = yaml.replaceAll("success: (.*)", "success: "); - - assertEquals(ResourceFileUtil.getResourceAsString("example/operational-policy/yaml-policy-chain-1.yaml"), yaml); - - yaml = URLDecoder.decode(attributes.get(1).get(AttributeType.RULE).get("ControlLoopYaml"), "UTF-8"); - yaml = yaml.replaceAll("trigger_policy: (.*)", "trigger_policy: "); - yaml = yaml.replaceAll("id: (.*)", "id: "); - yaml = yaml.replaceAll("success: (.*)", "success: "); - - assertEquals(ResourceFileUtil.getResourceAsString("example/operational-policy/yaml-policy-chain-2.yaml"), yaml); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java new file mode 100644 index 00000000..c7084b64 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.List; +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.model.CldsEvent; +import org.onap.clamp.clds.model.prop.ModelProperties; +import org.onap.clamp.clds.model.prop.Policy; +import org.onap.clamp.clds.model.prop.PolicyChain; +import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.policy.api.AttributeType; +import org.onap.policy.controlloop.policy.builder.BuilderException; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@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"); + String modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); + ModelProperties prop = new ModelProperties("testModel", "controlNameTest", CldsEvent.ACTION_SUBMIT, true, + modelBpmnProp, modelProp); + List>> attributes = new ArrayList<>(); + if (prop.getType(Policy.class).isFound()) { + for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) { + + attributes.add(OperationalPolicyReq.formatAttributes(refProp, prop, prop.getType(Policy.class).getId(), + policyChain)); + } + } + assertFalse(attributes.isEmpty()); + assertTrue(attributes.size() == 2); + // now validate the Yaml, to do so we replace the dynamic ID by a known + // key so that we can compare it + String yaml = URLDecoder.decode(attributes.get(0).get(AttributeType.RULE).get("ControlLoopYaml"), "UTF-8"); + yaml = yaml.replaceAll("trigger_policy: (.*)", "trigger_policy: "); + yaml = yaml.replaceAll("id: (.*)", "id: "); + yaml = yaml.replaceAll("success: (.*)", "success: "); + + assertEquals(ResourceFileUtil.getResourceAsString("example/operational-policy/yaml-policy-chain-1.yaml"), yaml); + + yaml = URLDecoder.decode(attributes.get(1).get(AttributeType.RULE).get("ControlLoopYaml"), "UTF-8"); + yaml = yaml.replaceAll("trigger_policy: (.*)", "trigger_policy: "); + yaml = yaml.replaceAll("id: (.*)", "id: "); + yaml = yaml.replaceAll("success: (.*)", "success: "); + + assertEquals(ResourceFileUtil.getResourceAsString("example/operational-policy/yaml-policy-chain-2.yaml"), yaml); + } +} diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java deleted file mode 100644 index 7b631768..00000000 --- a/src/test/java/org/onap/clamp/clds/it/PolicyClientIT.java +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.AbstractIT; -import org.onap.clamp.clds.client.req.OperationalPolicyReq; -import org.onap.clamp.clds.client.req.TcaRequestFormatter; -import org.onap.clamp.clds.model.CldsEvent; -import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.model.prop.Policy; -import org.onap.clamp.clds.model.prop.PolicyChain; -import org.onap.clamp.clds.model.prop.Tca; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.policy.api.AttributeType; -import org.skyscreamer.jsonassert.JSONAssert; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test Policy API in org.onap.clamp.ClampDesigner.client package - replicate - * Policy Delegates in tests. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class PolicyClientIT extends AbstractIT { - String modelProp; - String modelBpmnProp; - String modelName; - String controlName; - - /** - * Initialize Test. - */ - @Before - public void setUp() throws IOException { - modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); - modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); - modelName = "example-model06"; - controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf"; - } - - private void createUpdateOperationalPolicy(String actionCd) throws Exception { - ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); - Policy policy = prop.getType(Policy.class); - if (policy.isFound()) { - for (PolicyChain policyChain : policy.getPolicyChains()) { - String operationalPolicyRequestUuid = UUID.randomUUID().toString(); - - Map> attributes = OperationalPolicyReq.formatAttributes(refProp, - prop, policy.getId(), policyChain); - String responseMessage = policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid); - } - } - } - - private void createUpdateTcaPolicy(String actionCd) throws Exception { - ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); - Tca tca = prop.getType(Tca.class); - if (tca.isFound()) { - String tcaPolicyRequestUuid = UUID.randomUUID().toString(); - String policyJson = TcaRequestFormatter.createPolicyJson(refProp, prop); - String responseMessage = ""; - try { - responseMessage = policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid); - } catch (Exception e) { - assertTrue(e.getMessage().contains("Exception while communicating with Policy")); - } - } - } - - 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()); - for (PolicyChain policyChain : policy.getPolicyChains()) { - prop.setPolicyUniqueId(policyChain.getPolicyId()); - String responseMessage = policyClient.deleteBrms(prop); - } - } - } - - 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()); - String responseMessage = ""; - try { - responseMessage = policyClient.deleteMicrosService(prop); - } catch (Exception e) { - assertTrue(e.getMessage().contains("Policy delete failed: PE500 ")); - } - } - } - - // @Test - /** - * 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/PolicyClientItCase.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java new file mode 100644 index 00000000..0c358948 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +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.model.CldsEvent; +import org.onap.clamp.clds.model.prop.ModelProperties; +import org.onap.clamp.clds.model.prop.Policy; +import org.onap.clamp.clds.model.prop.PolicyChain; +import org.onap.clamp.clds.model.prop.Tca; +import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.policy.api.AttributeType; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Test Policy API in org.onap.clamp.ClampDesigner.client package - replicate + * Policy Delegates in tests. + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations = "classpath:application-no-camunda.properties") +public class PolicyClientItCase extends AbstractItCase { + String modelProp; + String modelBpmnProp; + String modelName; + String controlName; + + /** + * Initialize Test. + */ + @Before + public void setUp() throws IOException { + modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json"); + modelBpmnProp = ResourceFileUtil.getResourceAsString("example/modelBpmnProp.json"); + modelName = "example-model06"; + controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf"; + } + + private void createUpdateOperationalPolicy(String actionCd) throws Exception { + ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); + Policy policy = prop.getType(Policy.class); + if (policy.isFound()) { + for (PolicyChain policyChain : policy.getPolicyChains()) { + String operationalPolicyRequestUuid = UUID.randomUUID().toString(); + + Map> attributes = OperationalPolicyReq.formatAttributes(refProp, + prop, policy.getId(), policyChain); + policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid); + } + } + } + + private void createUpdateTcaPolicy(String actionCd) throws Exception { + ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); + Tca tca = prop.getType(Tca.class); + if (tca.isFound()) { + String tcaPolicyRequestUuid = UUID.randomUUID().toString(); + String policyJson = TcaRequestFormatter.createPolicyJson(refProp, prop); + + try { + policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid); + } catch (Exception e) { + assertTrue(e.getMessage().contains("Exception while communicating with Policy")); + } + } + } + + 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()); + for (PolicyChain policyChain : policy.getPolicyChains()) { + prop.setPolicyUniqueId(policyChain.getPolicyId()); + policyClient.deleteBrms(prop); + } + } + } + + 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) { + assertTrue(e.getMessage().contains("Policy delete failed: PE500 ")); + } + } + } + + // @Test + /** + * 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/PropJsonBuilderIT.java b/src/test/java/org/onap/clamp/clds/it/PropJsonBuilderIT.java deleted file mode 100644 index cd626dd6..00000000 --- a/src/test/java/org/onap/clamp/clds/it/PropJsonBuilderIT.java +++ /dev/null @@ -1,378 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.AbstractIT; -import org.onap.clamp.clds.client.req.SdcReq; -import org.onap.clamp.clds.model.CldsSdcServiceDetail; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test SDC API - stand alone (except for some config). Replicates - * getSdcServices and getSdcServicesByUUID in the CldsService Adds test of - * putting putting an artifact to VF. TODO Also needs update and perhaps delete - * tests. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class PropJsonBuilderIT extends AbstractIT { - - private String globalPropsPartial; - private ObjectMapper mapper; - - /** - * Initial test setup. - */ - @Before - public void setUp() throws IOException { - String url = refProp.getStringValue("sdc.serviceUrl"); - String basicAuth = SdcReq.getSdcBasicAuth(refProp); - System.out.println("value of string and basicAuth:" + url + basicAuth); - // cldsservicedetail.set - globalPropsPartial = refProp.getStringValue("globalPropsPartialTest"); - mapper = new ObjectMapper(); - } - - /** - * List services from SDC. List meta data for a particular service from SDC. - * Test uploading artifact to a VF in SDC. - */ - @Test - public void testSdc() throws Exception { - // String createEmptySharedObject = createEmptySharedObject(); - // System.out.println("value of emptySharedObject:" + - // createEmptySharedObject); - sampleJsonObject(); - System.out.println(createTestEmptySharedObject()); - } - - private void sampleJsonObject() throws JsonProcessingException { - - /** - * Create three JSON Objects objectNode1, objectNode2, objectNode3. Add - * all these three objects in the array - */ - ObjectNode objectNode1 = mapper.createObjectNode(); - objectNode1.put("bookName", "Java"); - objectNode1.put("price", "100"); - - ObjectNode objectNode2 = mapper.createObjectNode(); - objectNode2.put("bookName", "Spring"); - objectNode2.put("price", "200"); - - ObjectNode objectNode3 = mapper.createObjectNode(); - objectNode3.put("bookName", "Liferay"); - objectNode3.put("price", "500"); - - /** - * Array contains JSON Objects. - */ - ArrayNode arrayNode = mapper.createArrayNode(); - arrayNode.add(objectNode1); - arrayNode.add(objectNode2); - arrayNode.add(objectNode3); - - /** - * We can directly write the JSON in the console. But it wont be pretty - * JSON String - */ - System.out.println(arrayNode.toString()); - - /** - * To make the JSON String pretty use the below code. - */ - System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(arrayNode)); - } - - private String createEmptySharedObject() throws JsonProcessingException { - - /** - * Empty Object initialization. "": { "vf": { "": "" }, "location": { - * "": "" }, "alarmCondition": { "": "" } } - */ - ObjectNode emptyObjectNode = mapper.createObjectNode(); - emptyObjectNode.put("", ""); - ObjectNode vfObjectNode = mapper.createObjectNode(); - vfObjectNode.putPOJO("vf", emptyObjectNode); - ObjectNode locationObjectNode = mapper.createObjectNode(); - locationObjectNode.putPOJO("location", emptyObjectNode); - ObjectNode alarmConditionObjectNode = mapper.createObjectNode(); - alarmConditionObjectNode.putPOJO("alarmCondition", emptyObjectNode); - ArrayNode samArrayNode = mapper.createArrayNode(); - samArrayNode.add(vfObjectNode); - samArrayNode.add(locationObjectNode); - samArrayNode.add(alarmConditionObjectNode); - ObjectNode emptyServiceObjectNode = mapper.createObjectNode(); - emptyServiceObjectNode.putPOJO("", samArrayNode); - - /** - * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1": - * "DCAE_CLAMP_DEMO3" } - * - */ - ObjectNode dcaeClampDemo3Node = mapper.createObjectNode(); - dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3"); - ArrayNode vfArrayNode = mapper.createArrayNode(); - vfArrayNode.add(emptyObjectNode); - vfArrayNode.add(dcaeClampDemo3Node); - ObjectNode vfObjectNode2 = mapper.createObjectNode(); - vfObjectNode2.putPOJO("vf", vfArrayNode); - - /** - * Object initialization. "location": { "SNDGCA64": "San Diego SAN3", - * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" }, - */ - ObjectNode sandiegoLocationNode = mapper.createObjectNode(); - sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3"); - ObjectNode alpharettaNode = mapper.createObjectNode(); - alpharettaNode.put("ALPRGAED", "Alpharetta PDK1"); - ArrayNode locationArrayNode = mapper.createArrayNode(); - locationArrayNode.add(emptyObjectNode); - locationArrayNode.add(sandiegoLocationNode); - locationArrayNode.add(alpharettaNode); - ObjectNode locationObjectNode2 = mapper.createObjectNode(); - locationObjectNode2.putPOJO("location", locationArrayNode); - - /** - * Object initialization. "alarmCondition": { - * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation - * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto - * Export Backup Failed", - */ - ObjectNode alamrCondition1 = mapper.createObjectNode(); - alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started"); - ObjectNode alarmConditon2 = mapper.createObjectNode(); - alarmConditon2.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed"); - ArrayNode alarmArrayNode = mapper.createArrayNode(); - alarmArrayNode.add(emptyObjectNode); - alarmArrayNode.add(alamrCondition1); - alarmArrayNode.add(alarmConditon2); - ObjectNode alarmConditionObjectNode2 = mapper.createObjectNode(); - alarmConditionObjectNode2.putPOJO("alarmCondition", alarmArrayNode); - - ArrayNode byServiceIdArrayNode = mapper.createArrayNode(); - byServiceIdArrayNode.add(vfObjectNode2); - byServiceIdArrayNode.add(locationObjectNode2); - byServiceIdArrayNode.add(alarmConditionObjectNode2); - - ObjectNode byServiceIdNode = mapper.createObjectNode(); - byServiceIdNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", byServiceIdArrayNode); - - ArrayNode byServiceBasicArrayNode = mapper.createArrayNode(); - byServiceBasicArrayNode.add(emptyServiceObjectNode); - byServiceBasicArrayNode.add(byServiceIdNode); - - ObjectNode byServiceBasicObjetNode = mapper.createObjectNode(); - - byServiceBasicObjetNode.putPOJO("byService", byServiceBasicArrayNode); - - /** - * Object initialization. "byVf": { "": { "vfc": { "": "" }, - * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } } - */ - ObjectNode vfCObjectNode = mapper.createObjectNode(); - vfCObjectNode.putPOJO("vfC", emptyObjectNode); - ObjectNode vfcIdObjectNode = mapper.createObjectNode(); - vfcIdObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", vfCObjectNode); - ArrayNode emptyvfcArrayNode = mapper.createArrayNode(); - emptyvfcArrayNode.add(vfCObjectNode); - emptyvfcArrayNode.add(vfcIdObjectNode); - ObjectNode emptyvfcobjectNode = mapper.createObjectNode(); - emptyvfcobjectNode.putPOJO("", emptyvfcArrayNode); - - ObjectNode byVfCBasicNode = mapper.createObjectNode(); - byVfCBasicNode.putPOJO("byVf", emptyvfcobjectNode); - - ArrayNode finalSharedArrayObject = mapper.createArrayNode(); - - finalSharedArrayObject.add(byServiceBasicObjetNode); - finalSharedArrayObject.add(byVfCBasicNode); - - ObjectNode finalSharedObjectNode = mapper.createObjectNode(); - finalSharedObjectNode.putPOJO("shared", finalSharedArrayObject); - - System.out.println("value :" + finalSharedObjectNode.toString()); - String testFinal = finalSharedObjectNode.toString(); - testFinal = testFinal.replaceFirst("\\{", ","); - return globalPropsPartial + testFinal; - } - - private String createTestEmptySharedObject() throws IOException { - - /** - * Object initialization. "": { "vf": { "": "" }, "location": { "": "" - * }, "alarmCondition": { "": "" } } - */ - ObjectNode emptyObjectNode = mapper.createObjectNode(); - emptyObjectNode.put("", ""); - ObjectNode vfObjectNode = mapper.createObjectNode(); - vfObjectNode.putPOJO("vf", emptyObjectNode); - vfObjectNode.putPOJO("location", emptyObjectNode); - vfObjectNode.putPOJO("alarmCondition", emptyObjectNode); - ObjectNode emptyServiceObjectNode = mapper.createObjectNode(); - emptyServiceObjectNode.putPOJO("", vfObjectNode); - - /** - * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1": - * "DCAE_CLAMP_DEMO3" } - * - */ - ObjectNode vfObjectNode2 = mapper.createObjectNode(); - ObjectNode dcaeClampDemo3Node = mapper.createObjectNode(); - dcaeClampDemo3Node.put("", ""); - dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3"); - vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node); - - /** - * Object initialization. "location": { "SNDGCA64": "San Diego SAN3", - * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" }, - */ - // ObjectNode sandiegoLocationNode = mapper.createObjectNode(); - // sandiegoLocationNode.put("SNDGCA64","San Diego SAN3"); - // sandiegoLocationNode.put("ALPRGAED","Alpharetta PDK1"); - String locationStringValue = refProp.getStringValue("ui.location.default"); - ObjectNode locationJsonNode = (ObjectNode) mapper.readValue(locationStringValue, JsonNode.class); - vfObjectNode2.putPOJO("location", locationJsonNode); - - /** - * Object initialization. "alarmCondition": { - * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation - * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto - * Export Backup Failed", - */ - // ObjectNode alamrCondition1 = mapper.createObjectNode(); - // alamrCondition1.put("A+Fallback+Operation+will+soon+be+started","A - // Fallback Operation will soon be started"); - // alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed","BRM, Scheduled - // Backup Failed"); - String alarmStringValue = refProp.getStringValue("ui.alarm.default"); - ObjectNode alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class); - vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode); - emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2); - ObjectNode byServiceBasicObjetNode = mapper.createObjectNode(); - byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode); - - /** - * Object initialization. "byVf": { "": { "vfc": { "": "" }, - * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } } - */ - ObjectNode vfCObjectNode = mapper.createObjectNode(); - vfCObjectNode.putPOJO("vfC", emptyObjectNode); - ObjectNode subVfCObjectNode = mapper.createObjectNode(); - subVfCObjectNode.putPOJO("vfc", emptyObjectNode); - vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode); - ObjectNode emptyvfcobjectNode = mapper.createObjectNode(); - emptyvfcobjectNode.putPOJO("", vfCObjectNode); - byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode); - - ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class); - readTree.putPOJO("shared", byServiceBasicObjetNode); - System.out.println("valuie of objNode:" + readTree); - return readTree.toString(); - } - - private String createCldsSharedObject(CldsSdcServiceDetail CldsSdcServiceDetail) throws IOException { - /** - * Object initialization. "": { "vf": { "": "" }, "location": { "": "" - * }, "alarmCondition": { "": "" } } - */ - ObjectNode emptyObjectNode = mapper.createObjectNode(); - emptyObjectNode.put("", ""); - ObjectNode vfObjectNode = mapper.createObjectNode(); - vfObjectNode.putPOJO("vf", emptyObjectNode); - vfObjectNode.putPOJO("location", emptyObjectNode); - vfObjectNode.putPOJO("alarmCondition", emptyObjectNode); - ObjectNode emptyServiceObjectNode = mapper.createObjectNode(); - emptyServiceObjectNode.putPOJO("", vfObjectNode); - - /** - * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1": - * "DCAE_CLAMP_DEMO3" } - * - */ - ObjectNode vfObjectNode2 = mapper.createObjectNode(); - ObjectNode dcaeClampDemo3Node = mapper.createObjectNode(); - dcaeClampDemo3Node.put("", ""); - dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3"); - vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node); - - /** - * Object initialization. "location": { "SNDGCA64": "San Diego SAN3", - * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" }, - */ - ObjectNode sandiegoLocationNode = mapper.createObjectNode(); - sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3"); - sandiegoLocationNode.put("ALPRGAED", "Alpharetta PDK1"); - vfObjectNode2.putPOJO("location", sandiegoLocationNode); - - /** - * Object initialization. "alarmCondition": { - * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation - * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto - * Export Backup Failed", - */ - ObjectNode alamrCondition1 = mapper.createObjectNode(); - alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started"); - alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed"); - vfObjectNode2.putPOJO("alarmCondition", alamrCondition1); - emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2); - ObjectNode byServiceBasicObjetNode = mapper.createObjectNode(); - byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode); - - /** - * Object initialization. "byVf": { "": { "vfc": { "": "" }, - * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } } - */ - - ObjectNode vfCObjectNode = mapper.createObjectNode(); - vfCObjectNode.putPOJO("vfC", emptyObjectNode); - ObjectNode subVfCObjectNode = mapper.createObjectNode(); - subVfCObjectNode.putPOJO("vfc", emptyObjectNode); - vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode); - ObjectNode emptyvfcobjectNode = mapper.createObjectNode(); - emptyvfcobjectNode.putPOJO("", vfCObjectNode); - byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode); - - ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class); - - readTree.putPOJO("shared", byServiceBasicObjetNode); - System.out.println("valuie of objNode:" + readTree); - return readTree.toString(); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/RefPropIT.java b/src/test/java/org/onap/clamp/clds/it/RefPropIT.java deleted file mode 100644 index 4617f5b4..00000000 --- a/src/test/java/org/onap/clamp/clds/it/RefPropIT.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import java.io.IOException; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.AbstractIT; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test corg.onap.clamp.ClampDesigner.model.refprop package using RefProp. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class RefPropIT extends AbstractIT { - - /** - * Test getting prop value as a JSON Node / template. - * - * @throws IOException - * when JSON parsing fails - */ - @Test - 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); - - // assertEquals(topicsJson, ref.getTopicsToJson()); - } - -} diff --git a/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java b/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java new file mode 100644 index 00000000..478a7b38 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import java.io.IOException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.clamp.clds.AbstractItCase; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Test corg.onap.clamp.ClampDesigner.model.refprop package using RefProp. + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations = "classpath:application-no-camunda.properties") +public class RefPropItCase extends AbstractItCase { + + /** + * Test getting prop value as a JSON Node / template. + * + * @throws IOException + * when JSON parsing fails + */ + @Test + 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); + + // assertEquals(topicsJson, ref.getTopicsToJson()); + } + +} diff --git a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesIT.java b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesIT.java deleted file mode 100644 index dce6c901..00000000 --- a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesIT.java +++ /dev/null @@ -1,325 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertTrue; - -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.onap.clamp.clds.AbstractIT; -import org.onap.clamp.clds.client.SdcCatalogServices; -import org.onap.clamp.clds.model.CldsAlarmCondition; -import org.onap.clamp.clds.model.CldsSdcResource; -import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo; -import org.onap.clamp.clds.model.CldsSdcServiceInfo; -import org.onap.clamp.clds.model.CldsServiceData; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test SDC Catalog Service class by mocking the SDC answers. - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class SdcCatalogServicesIT extends AbstractIT { - @Autowired - private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices(); - - @Test - public void removeDuplicateServicesTest() throws Exception { - - CldsSdcServiceInfo service1a = new CldsSdcServiceInfo(); - service1a.setName("service1"); - service1a.setVersion("1.0"); - service1a.setInvariantUUID("invariantUUID1.0"); - - List rawCldsSdcServiceList = new LinkedList(); - rawCldsSdcServiceList.add(service1a); - rawCldsSdcServiceList.add(service1a); - - CldsSdcServiceInfo service1b = new CldsSdcServiceInfo(); - service1b.setName("service1"); - service1b.setVersion("1.1"); - service1b.setInvariantUUID("invariantUUID1.1"); - rawCldsSdcServiceList.add(service1b); - - CldsSdcServiceInfo service1c = new CldsSdcServiceInfo(); - service1c.setName("service1"); - service1c.setVersion("1.2"); - service1c.setInvariantUUID("invariantUUID1.2"); - rawCldsSdcServiceList.add(service1c); - - CldsSdcServiceInfo service2 = new CldsSdcServiceInfo(); - service2.setName("service2"); - service2.setVersion("1.0"); - service2.setInvariantUUID("invariantUUID2.0"); - rawCldsSdcServiceList.add(service2); - - SdcCatalogServices catalogServices = new SdcCatalogServices(); - List resultList = catalogServices.removeDuplicateServices(rawCldsSdcServiceList); - - assertTrue(resultList.size() == 2); - - CldsSdcServiceInfo res1; - CldsSdcServiceInfo res2; - if ("service1".equals(resultList.get(0).getName())) { - res1 = resultList.get(0); - res2 = resultList.get(1); - } else { - res1 = resultList.get(1); - res2 = resultList.get(0); - } - - assertTrue("service1".equals(res1.getName())); - assertTrue("1.2".equals(res1.getVersion())); - - assertTrue("service2".equals(res2.getName())); - assertTrue("1.0".equals(res2.getVersion())); - - } - - @Test - public void removeDuplicateSdcResourceInstancesTest() { - - List rawCldsSdcResourceList = new LinkedList(); - - CldsSdcResource sdcResource1a = new CldsSdcResource(); - sdcResource1a.setResourceInstanceName("resource1"); - sdcResource1a.setResourceVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource1a); - - CldsSdcResource sdcResource1b = new CldsSdcResource(); - sdcResource1b.setResourceInstanceName("resource1"); - sdcResource1b.setResourceVersion("1.1"); - rawCldsSdcResourceList.add(sdcResource1b); - - CldsSdcResource sdcResource1c = new CldsSdcResource(); - sdcResource1c.setResourceInstanceName("resource1"); - sdcResource1c.setResourceVersion("1.2"); - rawCldsSdcResourceList.add(sdcResource1c); - - CldsSdcResource sdcResource2 = new CldsSdcResource(); - sdcResource2.setResourceInstanceName("resource2"); - sdcResource2.setResourceVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource2); - - SdcCatalogServices catalogServices = new SdcCatalogServices(); - List resultList = catalogServices.removeDuplicateSdcResourceInstances(rawCldsSdcResourceList); - - CldsSdcResource res1; - CldsSdcResource res2; - if ("resource1".equals(resultList.get(0).getResourceInstanceName())) { - res1 = resultList.get(0); - res2 = resultList.get(1); - } else { - res1 = resultList.get(1); - res2 = resultList.get(0); - } - - assertTrue("resource1".equals(res1.getResourceInstanceName())); - assertTrue("1.2".equals(res1.getResourceVersion())); - - assertTrue("resource2".equals(res2.getResourceInstanceName())); - assertTrue("1.0".equals(res2.getResourceVersion())); - - } - - @Test - public void removeDuplicateSdcResourceBasicInfoTest() { - - List rawCldsSdcResourceList = new LinkedList(); - - CldsSdcResourceBasicInfo sdcResource1a = new CldsSdcResourceBasicInfo(); - sdcResource1a.setName("resource1"); - sdcResource1a.setVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource1a); - - CldsSdcResourceBasicInfo sdcResource1b = new CldsSdcResourceBasicInfo(); - sdcResource1b.setName("resource1"); - sdcResource1b.setVersion("1.1"); - rawCldsSdcResourceList.add(sdcResource1b); - - CldsSdcResourceBasicInfo sdcResource1c = new CldsSdcResourceBasicInfo(); - sdcResource1c.setName("resource1"); - sdcResource1c.setVersion("1.2"); - rawCldsSdcResourceList.add(sdcResource1c); - - CldsSdcResourceBasicInfo sdcResource2 = new CldsSdcResourceBasicInfo(); - sdcResource2.setName("resource2"); - sdcResource2.setVersion("1.0"); - rawCldsSdcResourceList.add(sdcResource2); - - SdcCatalogServices catalogServices = new SdcCatalogServices(); - List resultList = catalogServices - .removeDuplicateSdcResourceBasicInfo(rawCldsSdcResourceList); - - CldsSdcResourceBasicInfo res1; - CldsSdcResourceBasicInfo res2; - if ("resource1".equals(resultList.get(0).getName())) { - res1 = resultList.get(0); - res2 = resultList.get(1); - } else { - res1 = resultList.get(1); - res2 = resultList.get(0); - } - - assertTrue("resource1".equals(res1.getName())); - assertTrue("1.2".equals(res1.getVersion())); - - assertTrue("resource2".equals(res2.getName())); - assertTrue("1.0".equals(res2.getVersion())); - - } - - @Test - public void getServiceUuidFromServiceInvariantIdTest() throws Exception { - SdcCatalogServices spy = Mockito.spy(sdcCatalogWired); - - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8")) - .when(spy).getSdcServicesInformation(null); - // Try the vcts4 version 1.0, this one should be replaced by 1.1 so it - // should not exist, returning empty string - String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b"); - assertTrue("".equals(resUuidVcts4Null)); - - // Try the vcts4 version 1.1, this one should be there as it replaces - // the vcts4 v1.0 - String resUuidVcts4Latest = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c"); - assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(resUuidVcts4Latest)); - - // Try the vcts5 version 1.0, this one should be there - String resUuidVcts5 = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c"); - assertTrue("29018914-966c-442d-9d08-251b9dc45b7f".equals(resUuidVcts5)); - - // try one that does not exist at all - String resUuidUnknown = spy.getServiceUuidFromServiceInvariantId("testuuid"); - assertTrue("".equals(resUuidUnknown)); - - } - - @Test - public void getCldsServiceDataWithAlarmConditionsTest() throws Exception { - SdcCatalogServices spy = Mockito.spy(sdcCatalogWired); - - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), "UTF-8")) - .when(spy).getSdcServicesInformation(null); - - // This invariant uuid is the one from vcts4 v1.1 - String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl") - + "/29018914-966c-442d-9d08-251b9dc45b8f/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl, false); - - String resourceDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/585822c7-4027-4f84-ba50-e9248606f136/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl, false); - - String securityRulesDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/d57e57d2-e3c6-470d-8d16-e6ea05f536c5/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl, false); - - String cinderVolumeDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/b4288e07-597a-44a2-aa98-ad36e551a39d/metadata"; - Mockito.doReturn(IOUtils - .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl, false); - - String vfcGenericDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl, false); - - String csvAlarmsDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392"; - Mockito.doReturn(IOUtils - .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, false); - - Mockito.doReturn(IOUtils - .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, true); - - String csvAlarmsDetailUrl2 = refProp.getStringValue("sdc.catalog.url") - + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392"; - Mockito.doReturn(IOUtils - .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl2, true); - - String allVfResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VF"; - Mockito.doReturn(IOUtils - .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl, false); - - String cVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") - + "resources/a0475018-1e7e-4ddd-8bee-33cbf958c2e6/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcCVFCResourceExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(cVfcResourcesDetailUrl, false); - - String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC"; - Mockito.doReturn(IOUtils - .toString(SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl, false); - - String allVfAlarms = refProp.getStringValue("sdc.catalog.url") - + "resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfAlarms, true); - - String vfcResourceExample = refProp.getStringValue("sdc.catalog.url") - + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/metadata"; - Mockito.doReturn(IOUtils.toString( - SdcCatalogServicesIT.class.getResourceAsStream("/example/sdc/sdcVFCResourceExample.json"), "UTF-8")) - .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourceExample, false); - - CldsServiceData cldsServiceData = spy - .getCldsServiceDataWithAlarmConditions("a33ed748-3477-4434-b3f3-b5560f5e7d9c"); - assertTrue("a33ed748-3477-4434-b3f3-b5560f5e7d9c".equals(cldsServiceData.getServiceInvariantUUID())); - assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID())); - assertTrue(cldsServiceData.getCldsVfs().size() == 1); - - List alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData, - "alarmCondition"); - assertTrue(alarmsList.size() == 12); - - } - -} diff --git a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java new file mode 100644 index 00000000..0deae6d3 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java @@ -0,0 +1,325 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertTrue; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.io.IOUtils; +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.model.CldsAlarmCondition; +import org.onap.clamp.clds.model.CldsSdcResource; +import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo; +import org.onap.clamp.clds.model.CldsSdcServiceInfo; +import org.onap.clamp.clds.model.CldsServiceData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Test SDC Catalog Service class by mocking the SDC answers. + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations = "classpath:application-no-camunda.properties") +public class SdcCatalogServicesItCase extends AbstractItCase { + @Autowired + private SdcCatalogServices sdcCatalogWired = new SdcCatalogServices(); + + @Test + public void removeDuplicateServicesTest() throws Exception { + + CldsSdcServiceInfo service1a = new CldsSdcServiceInfo(); + service1a.setName("service1"); + service1a.setVersion("1.0"); + service1a.setInvariantUUID("invariantUUID1.0"); + + List rawCldsSdcServiceList = new LinkedList(); + rawCldsSdcServiceList.add(service1a); + rawCldsSdcServiceList.add(service1a); + + CldsSdcServiceInfo service1b = new CldsSdcServiceInfo(); + service1b.setName("service1"); + service1b.setVersion("1.1"); + service1b.setInvariantUUID("invariantUUID1.1"); + rawCldsSdcServiceList.add(service1b); + + CldsSdcServiceInfo service1c = new CldsSdcServiceInfo(); + service1c.setName("service1"); + service1c.setVersion("1.2"); + service1c.setInvariantUUID("invariantUUID1.2"); + rawCldsSdcServiceList.add(service1c); + + CldsSdcServiceInfo service2 = new CldsSdcServiceInfo(); + service2.setName("service2"); + service2.setVersion("1.0"); + service2.setInvariantUUID("invariantUUID2.0"); + rawCldsSdcServiceList.add(service2); + + SdcCatalogServices catalogServices = new SdcCatalogServices(); + List resultList = catalogServices.removeDuplicateServices(rawCldsSdcServiceList); + + assertTrue(resultList.size() == 2); + + CldsSdcServiceInfo res1; + CldsSdcServiceInfo res2; + if ("service1".equals(resultList.get(0).getName())) { + res1 = resultList.get(0); + res2 = resultList.get(1); + } else { + res1 = resultList.get(1); + res2 = resultList.get(0); + } + + assertTrue("service1".equals(res1.getName())); + assertTrue("1.2".equals(res1.getVersion())); + + assertTrue("service2".equals(res2.getName())); + assertTrue("1.0".equals(res2.getVersion())); + + } + + @Test + public void removeDuplicateSdcResourceInstancesTest() { + + List rawCldsSdcResourceList = new LinkedList(); + + CldsSdcResource sdcResource1a = new CldsSdcResource(); + sdcResource1a.setResourceInstanceName("resource1"); + sdcResource1a.setResourceVersion("1.0"); + rawCldsSdcResourceList.add(sdcResource1a); + + CldsSdcResource sdcResource1b = new CldsSdcResource(); + sdcResource1b.setResourceInstanceName("resource1"); + sdcResource1b.setResourceVersion("1.1"); + rawCldsSdcResourceList.add(sdcResource1b); + + CldsSdcResource sdcResource1c = new CldsSdcResource(); + sdcResource1c.setResourceInstanceName("resource1"); + sdcResource1c.setResourceVersion("1.2"); + rawCldsSdcResourceList.add(sdcResource1c); + + CldsSdcResource sdcResource2 = new CldsSdcResource(); + sdcResource2.setResourceInstanceName("resource2"); + sdcResource2.setResourceVersion("1.0"); + rawCldsSdcResourceList.add(sdcResource2); + + SdcCatalogServices catalogServices = new SdcCatalogServices(); + List resultList = catalogServices.removeDuplicateSdcResourceInstances(rawCldsSdcResourceList); + + CldsSdcResource res1; + CldsSdcResource res2; + if ("resource1".equals(resultList.get(0).getResourceInstanceName())) { + res1 = resultList.get(0); + res2 = resultList.get(1); + } else { + res1 = resultList.get(1); + res2 = resultList.get(0); + } + + assertTrue("resource1".equals(res1.getResourceInstanceName())); + assertTrue("1.2".equals(res1.getResourceVersion())); + + assertTrue("resource2".equals(res2.getResourceInstanceName())); + assertTrue("1.0".equals(res2.getResourceVersion())); + + } + + @Test + public void removeDuplicateSdcResourceBasicInfoTest() { + + List rawCldsSdcResourceList = new LinkedList(); + + CldsSdcResourceBasicInfo sdcResource1a = new CldsSdcResourceBasicInfo(); + sdcResource1a.setName("resource1"); + sdcResource1a.setVersion("1.0"); + rawCldsSdcResourceList.add(sdcResource1a); + + CldsSdcResourceBasicInfo sdcResource1b = new CldsSdcResourceBasicInfo(); + sdcResource1b.setName("resource1"); + sdcResource1b.setVersion("1.1"); + rawCldsSdcResourceList.add(sdcResource1b); + + CldsSdcResourceBasicInfo sdcResource1c = new CldsSdcResourceBasicInfo(); + sdcResource1c.setName("resource1"); + sdcResource1c.setVersion("1.2"); + rawCldsSdcResourceList.add(sdcResource1c); + + CldsSdcResourceBasicInfo sdcResource2 = new CldsSdcResourceBasicInfo(); + sdcResource2.setName("resource2"); + sdcResource2.setVersion("1.0"); + rawCldsSdcResourceList.add(sdcResource2); + + SdcCatalogServices catalogServices = new SdcCatalogServices(); + List resultList = catalogServices + .removeDuplicateSdcResourceBasicInfo(rawCldsSdcResourceList); + + CldsSdcResourceBasicInfo res1; + CldsSdcResourceBasicInfo res2; + if ("resource1".equals(resultList.get(0).getName())) { + res1 = resultList.get(0); + res2 = resultList.get(1); + } else { + res1 = resultList.get(1); + res2 = resultList.get(0); + } + + assertTrue("resource1".equals(res1.getName())); + assertTrue("1.2".equals(res1.getVersion())); + + assertTrue("resource2".equals(res2.getName())); + assertTrue("1.0".equals(res2.getVersion())); + + } + + @Test + public void getServiceUuidFromServiceInvariantIdTest() throws Exception { + SdcCatalogServices spy = Mockito.spy(sdcCatalogWired); + + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), + "UTF-8")).when(spy).getSdcServicesInformation(null); + // Try the vcts4 version 1.0, this one should be replaced by 1.1 so it + // should not exist, returning empty string + String resUuidVcts4Null = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9b"); + assertTrue("".equals(resUuidVcts4Null)); + + // Try the vcts4 version 1.1, this one should be there as it replaces + // the vcts4 v1.0 + String resUuidVcts4Latest = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d9c"); + assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(resUuidVcts4Latest)); + + // Try the vcts5 version 1.0, this one should be there + String resUuidVcts5 = spy.getServiceUuidFromServiceInvariantId("a33ed748-3477-4434-b3f3-b5560f5e7d8c"); + assertTrue("29018914-966c-442d-9d08-251b9dc45b7f".equals(resUuidVcts5)); + + // try one that does not exist at all + String resUuidUnknown = spy.getServiceUuidFromServiceInvariantId("testuuid"); + assertTrue("".equals(resUuidUnknown)); + + } + + @Test + public void getCldsServiceDataWithAlarmConditionsTest() throws Exception { + SdcCatalogServices spy = Mockito.spy(sdcCatalogWired); + + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServicesListExample.json"), + "UTF-8")).when(spy).getSdcServicesInformation(null); + + // This invariant uuid is the one from vcts4 v1.1 + String serviceResourceDetailUrl = refProp.getStringValue("sdc.serviceUrl") + + "/29018914-966c-442d-9d08-251b9dc45b8f/metadata"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcServiceDetailsExample.json"), + "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(serviceResourceDetailUrl, false); + + String resourceDetailUrl = refProp.getStringValue("sdc.catalog.url") + + "resources/585822c7-4027-4f84-ba50-e9248606f136/metadata"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcResourceDetailsExample.json"), + "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(resourceDetailUrl, false); + + String securityRulesDetailUrl = refProp.getStringValue("sdc.catalog.url") + + "resources/d57e57d2-e3c6-470d-8d16-e6ea05f536c5/metadata"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcSecurityRules.json"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(securityRulesDetailUrl, false); + + String cinderVolumeDetailUrl = refProp.getStringValue("sdc.catalog.url") + + "resources/b4288e07-597a-44a2-aa98-ad36e551a39d/metadata"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCinderVolume.json"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(cinderVolumeDetailUrl, false); + + String vfcGenericDetailUrl = refProp.getStringValue("sdc.catalog.url") + + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/metadata"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCGenericWithAlarms.json"), + "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(vfcGenericDetailUrl, false); + + String csvAlarmsDetailUrl = refProp.getStringValue("sdc.catalog.url") + + "resources/2c8f1219-8000-4001-aa13-496a0396d40f/resourceInstances/virc_fe_be/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, false); + + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl, true); + + String csvAlarmsDetailUrl2 = refProp.getStringValue("sdc.catalog.url") + + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/artifacts/5138e316-0237-49aa-817a-b3d8eaf77392"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcAlarmsList.csv"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(csvAlarmsDetailUrl2, true); + + String allVfResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VF"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFResources.json"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfResourcesDetailUrl, false); + + String vfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + + "resources/a0475018-1e7e-4ddd-8bee-33cbf958c2e6/metadata"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcCVFCResourceExample.json"), + "UTF-8")).when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourcesDetailUrl, false); + + String allVfcResourcesDetailUrl = refProp.getStringValue("sdc.catalog.url") + "resources?resourceType=VFC"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResources.json"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfcResourcesDetailUrl, false); + + String allVfAlarms = refProp.getStringValue("sdc.catalog.url") + + "resources/84855843-5247-4e97-a2bd-5395a510253b/artifacts/d57ac7ec-f3c3-4793-983a-c75ac3a43153"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcMeasurementsList.csv"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(allVfAlarms, true); + + String vfcResourceExample = refProp.getStringValue("sdc.catalog.url") + + "resources/d7646638-2572-4a94-b497-c028ac15f9ca/metadata"; + Mockito.doReturn(IOUtils.toString( + SdcCatalogServicesItCase.class.getResourceAsStream("/example/sdc/sdcVFCResourceExample.json"), "UTF-8")) + .when(spy).getCldsServicesOrResourcesBasedOnURL(vfcResourceExample, false); + + CldsServiceData cldsServiceData = spy + .getCldsServiceDataWithAlarmConditions("a33ed748-3477-4434-b3f3-b5560f5e7d9c"); + assertTrue("a33ed748-3477-4434-b3f3-b5560f5e7d9c".equals(cldsServiceData.getServiceInvariantUUID())); + assertTrue("29018914-966c-442d-9d08-251b9dc45b8f".equals(cldsServiceData.getServiceUUID())); + assertTrue(cldsServiceData.getCldsVfs().size() == 1); + + List alarmsList = spy.getAllAlarmConditionsFromCldsServiceData(cldsServiceData, + "alarmCondition"); + assertTrue(alarmsList.size() == 12); + + } + +} diff --git a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterIT.java b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterIT.java deleted file mode 100644 index 89ff5792..00000000 --- a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterIT.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2017 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. - * 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 - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ - -package org.onap.clamp.clds.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.clamp.clds.AbstractIT; -import org.onap.clamp.clds.client.req.TcaRequestFormatter; -import org.onap.clamp.clds.model.CldsEvent; -import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.skyscreamer.jsonassert.JSONAssert; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * Test Onap TcaPolicyReq features - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(locations = "classpath:application-no-camunda.properties") -public class TcaRequestFormatterIT extends AbstractIT { - - String modelProp; - String modelBpmn; - String modelName; - String controlName; - String yamlInput; - - /** - * Initialize Test. - */ - @Before - public void setUp() throws IOException { - modelProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json"); - modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json"); - yamlInput = ResourceFileUtil.getResourceAsString("example/tca-policy-req/blueprint-input.yaml"); - modelName = "example-model01"; - controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf"; - } - - @Test - public void testCreatePolicyJson() throws IOException { - ModelProperties prop = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmn, - modelProp); - String result = TcaRequestFormatter.createPolicyJson(refProp, prop); - assertNotNull(result); - JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("example/tca-policy-req/tca-policy-expected.json"), - result, true); - } - - @Test - public void testUpdatedBlueprintWithConfiguration() throws IOException { - 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); - } -} diff --git a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java new file mode 100644 index 00000000..a32743a6 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +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.model.CldsEvent; +import org.onap.clamp.clds.model.prop.ModelProperties; +import org.onap.clamp.clds.util.ResourceFileUtil; +import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Test Onap TcaRequestFormatter features. + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations = "classpath:application-no-camunda.properties") +public class TcaRequestFormatterItCase extends AbstractItCase { + + String modelProp; + String modelBpmn; + String modelName; + String controlName; + String yamlInput; + + /** + * Initialize Test. + */ + @Before + public void setUp() throws IOException { + modelProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmnProperties.json"); + modelBpmn = ResourceFileUtil.getResourceAsString("example/model-properties/tca/modelBpmn.json"); + yamlInput = ResourceFileUtil.getResourceAsString("example/tca-policy-req/blueprint-input.yaml"); + modelName = "example-model01"; + controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf"; + } + + @Test + public void testCreatePolicyJson() throws IOException { + ModelProperties prop = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmn, + modelProp); + String result = TcaRequestFormatter.createPolicyJson(refProp, prop); + assertNotNull(result); + JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("example/tca-policy-req/tca-policy-expected.json"), + result, true); + } + + @Test + public void testUpdatedBlueprintWithConfiguration() throws IOException { + 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); + } +} -- cgit 1.2.3-korg