diff options
Diffstat (limited to 'src')
7 files changed, 387 insertions, 104 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java index 0b4cbeab..afef5919 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java @@ -38,6 +38,18 @@ import org.onap.policy.api.AttributeType; import org.onap.policy.api.RuleProvider; public class GuardPolicyAttributesConstructor { + public static final String ACTOR = "actor"; + public static final String RECIPE = "recipe"; + public static final String TARGETS = "targets"; + public static final String CLNAME = "clname"; + public static final String MIN = "min"; + public static final String MAX = "max"; + public static final String LIMIT = "limit"; + public static final String TIME_WINDOW = "timeWindow"; + public static final String TIME_UNITS = "timeUnits"; + public static final String GUARD_ACTIVE_START = "guardActiveStart"; + public static final String GUARD_ACTIVE_END = "guardActiveEnd"; + private static final EELFLogger logger = EELFManager.getInstance() .getLogger(GuardPolicyAttributesConstructor.class); @@ -63,20 +75,20 @@ public class GuardPolicyAttributesConstructor { private static Map<String, String> prepareMatchingAttributes(PolicyItem policyItem, ModelProperties modelProp) { logger.info("Preparing matching attributes for guard..."); Map<String, String> matchingAttributes = new HashMap<>(); - matchingAttributes.put("actor", policyItem.getActor()); - matchingAttributes.put("recipe", policyItem.getRecipe()); - matchingAttributes.put("targets", policyItem.getGuardTargets()); - matchingAttributes.put("clname", modelProp.getControlNameAndPolicyUniqueId()); + matchingAttributes.put(ACTOR, policyItem.getActor()); + matchingAttributes.put(RECIPE, policyItem.getRecipe()); + matchingAttributes.put(TARGETS, policyItem.getGuardTargets()); + matchingAttributes.put(CLNAME, modelProp.getControlNameAndPolicyUniqueId()); if (RuleProvider.GUARD_MIN_MAX.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) { - matchingAttributes.put("min", policyItem.getMinGuard()); - matchingAttributes.put("max", policyItem.getMaxGuard()); + matchingAttributes.put(MIN, policyItem.getMinGuard()); + matchingAttributes.put(MAX, policyItem.getMaxGuard()); } else if (RuleProvider.GUARD_YAML.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) { - matchingAttributes.put("limit", policyItem.getLimitGuard()); - matchingAttributes.put("timeWindow", policyItem.getTimeWindowGuard()); - matchingAttributes.put("timeUnits", policyItem.getTimeUnitsGuard()); + matchingAttributes.put(LIMIT, policyItem.getLimitGuard()); + matchingAttributes.put(TIME_WINDOW, policyItem.getTimeWindowGuard()); + matchingAttributes.put(TIME_UNITS, policyItem.getTimeUnitsGuard()); } - matchingAttributes.put("guardActiveStart", policyItem.getGuardActiveStart()); - matchingAttributes.put("guardActiveEnd", policyItem.getGuardActiveEnd()); + matchingAttributes.put(GUARD_ACTIVE_START, policyItem.getGuardActiveStart()); + matchingAttributes.put(GUARD_ACTIVE_END, policyItem.getGuardActiveEnd()); logger.info("Prepared: " + matchingAttributes); return matchingAttributes; diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java index 610bd4c1..9f25ba9f 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java @@ -534,6 +534,7 @@ public class PolicyClient { deletePolicyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName()); } logger.info("Policy Name in delete policy method - " + deletePolicyParameters.getPolicyName()); + logger.info("Deleting policy from PDP..."); deletePolicyParameters.setPolicyComponent("PDP"); deletePolicyParameters.setDeleteCondition(DeletePolicyCondition.ALL); deletePolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group")); diff --git a/src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java b/src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java new file mode 100644 index 00000000..f1634567 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructorTest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 Nokia 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============================================ + * =================================================================== + * + */ + +package org.onap.clamp.clds.client.req.policy; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.assertj.core.api.Assertions; +import org.junit.Before; +import org.junit.Test; +import org.onap.clamp.clds.model.properties.ModelProperties; +import org.onap.clamp.clds.model.properties.Policy; +import org.onap.clamp.clds.model.properties.PolicyChain; +import org.onap.clamp.clds.model.properties.PolicyItem; +import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.policy.api.AttributeType; +import org.onap.policy.controlloop.policy.builder.BuilderException; + +public class GuardPolicyAttributesConstructorTest { + + private static final String CONTROL_NAME = "ClosedLoop-d4629aee-970f-11e8-86c9-02552dda865e"; + private ModelProperties modelProperties; + private List<PolicyChain> policyChains; + + @Before + public void setUp() throws Exception { + String modelProp = ResourceFileUtil + .getResourceAsString("example/model-properties/tca_new/model-properties.json"); + String modelBpmnJson = ResourceFileUtil.getResourceAsString("example/model-properties/tca_new/model-bpmn.json"); + modelProperties = new ModelProperties("CLAMPDemoVFW_v1_0_3af8daec-6f10-4027-a3540", CONTROL_NAME, "PUT", false, + modelBpmnJson, modelProp); + + policyChains = modelProperties.getType(Policy.class).getPolicyChains(); + } + + @Test + public void testRequestAttributes() throws IOException, BuilderException { + List<PolicyItem> policyItemsList = GuardPolicyAttributesConstructor + .getAllPolicyGuardsFromPolicyChain(policyChains.get(0)); + + Assertions.assertThat(policyItemsList.size()).isEqualTo(1); + + // Test first entry + Map<AttributeType, Map<String, String>> requestAttributes = GuardPolicyAttributesConstructor + .formatAttributes(modelProperties, policyItemsList.get(0)); + + Assertions.assertThat(requestAttributes).containsKeys(AttributeType.MATCHING); + Map<String, String> ruleParameters = requestAttributes.get(AttributeType.MATCHING); + Assertions.assertThat(ruleParameters).contains(Assertions.entry(GuardPolicyAttributesConstructor.ACTOR, "APPC"), + Assertions.entry(GuardPolicyAttributesConstructor.RECIPE, "restart"), + Assertions.entry(GuardPolicyAttributesConstructor.TARGETS, ".*"), + Assertions.entry(GuardPolicyAttributesConstructor.CLNAME, + modelProperties.getControlNameAndPolicyUniqueId()), + Assertions.entry(GuardPolicyAttributesConstructor.LIMIT, "1"), + Assertions.entry(GuardPolicyAttributesConstructor.TIME_WINDOW, "10"), + Assertions.entry(GuardPolicyAttributesConstructor.TIME_UNITS, "minute"), + Assertions.entry(GuardPolicyAttributesConstructor.GUARD_ACTIVE_START, "00:00:01-05:00"), + Assertions.entry(GuardPolicyAttributesConstructor.GUARD_ACTIVE_END, "00:00:00-05:00")); + } +} diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java index 59fad9a6..f849a6c0 100644 --- a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java @@ -24,156 +24,242 @@ package org.onap.clamp.clds.it; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import java.io.IOException; +import java.util.List; import java.util.Map; -import java.util.UUID; -import java.util.concurrent.TimeUnit; +import javax.xml.transform.TransformerException; + +import org.assertj.core.api.Assertions; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.clamp.clds.client.req.policy.GuardPolicyAttributesConstructor; import org.onap.clamp.clds.client.req.policy.OperationalPolicyAttributesConstructor; import org.onap.clamp.clds.client.req.policy.PolicyClient; import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter; import org.onap.clamp.clds.config.ClampProperties; -import org.onap.clamp.clds.config.PolicyConfiguration; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.model.properties.Policy; -import org.onap.clamp.clds.model.properties.PolicyChain; +import org.onap.clamp.clds.model.properties.PolicyItem; import org.onap.clamp.clds.model.properties.Tca; +import org.onap.clamp.clds.transform.XslTransformer; +import org.onap.clamp.clds.util.JacksonUtils; +import org.onap.clamp.clds.util.LoggingUtils; import org.onap.clamp.clds.util.ResourceFileUtil; import org.onap.policy.api.AttributeType; +import org.onap.policy.api.PolicyConfigType; +import org.onap.policy.api.PolicyType; +import org.onap.policy.controlloop.policy.builder.BuilderException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; /** - * Test Policy API in org.onap.clamp.ClampDesigner.client package - replicate - * Policy Delegates in tests. + * Test Policy API, this uses the emulator written in python that is started + * during the tests, It returns the payload sent in the policy queries so that + * it can be validated here. */ @RunWith(SpringRunner.class) @SpringBootTest public class PolicyClientItCase { @Autowired - private PolicyConfiguration policyConfiguration; - @Autowired private ClampProperties refProp; @Autowired private PolicyClient policyClient; + @Autowired + XslTransformer cldsBpmnTransformer; String modelProp; - String modelBpmnProp; String modelName; String controlName; + String modelBpmnPropJson; + ModelProperties prop; /** * Initialize Test. + * + * @throws TransformerException */ @Before - public void setUp() throws IOException { - modelProp = ResourceFileUtil.getResourceAsString("example/model-properties/policy/modelBpmnProperties.json"); - modelBpmnProp = ResourceFileUtil.getResourceAsString("example/model-properties/policy/modelBpmn.json"); + public void setUp() throws IOException, TransformerException { + modelProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca_new/model-properties.json"); modelName = "example-model06"; controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf"; + modelBpmnPropJson = cldsBpmnTransformer.doXslTransformToString( + ResourceFileUtil.getResourceAsString("example/model-properties/tca_new/tca-template.xml")); + prop = new ModelProperties(modelName, controlName, CldsEvent.ACTION_SUBMIT, false, modelBpmnPropJson, + modelProp); } - 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<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor - .formatAttributes(refProp, prop, policy.getId(), policyChain); - policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid); - } - } + @Test + public void testSendGuardPolicy() throws TransformerException, IOException { + // Normally there is only one Guard + List<PolicyItem> policyItems = GuardPolicyAttributesConstructor + .getAllPolicyGuardsFromPolicyChain(prop.getType(Policy.class).getPolicyChains().get(0)); + PolicyItem policyItem = policyItems.get(0); + prop.setCurrentModelElementId(prop.getType(Policy.class).getId()); + prop.setPolicyUniqueId(prop.getType(Policy.class).getPolicyChains().get(0).getPolicyId()); + prop.setGuardUniqueId(policyItem.getId()); + String response = policyClient.sendGuardPolicy( + GuardPolicyAttributesConstructor.formatAttributes(prop, policyItem), prop, LoggingUtils.getRequestId(), + policyItem); + Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class); + Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Decision"), + Assertions.entry("policyName", + modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0_Guard_6TtHGPq"), + Assertions.entry("policyDescription", "from clds"), Assertions.entry("onapName", "PDPD"), + Assertions.entry("requestID", LoggingUtils.getRequestId()), Assertions.entry("ruleProvider", "GUARD_YAML")); + + // Check Guard attributes + Assertions.assertThat((Map<String, Object>) mapNodes.get("attributes")) + .containsKey(AttributeType.MATCHING.name()); + Assertions.assertThat( + (Map<String, Object>) ((Map<String, Object>) mapNodes.get("attributes")).get(AttributeType.MATCHING.name())) + .contains(Assertions.entry(GuardPolicyAttributesConstructor.ACTOR, "APPC"), + Assertions.entry(GuardPolicyAttributesConstructor.CLNAME, controlName + "_0"), + Assertions.entry(GuardPolicyAttributesConstructor.TIME_WINDOW, "10")); } - 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("Policy send failed: PE500 ")); - } - } + @Test + public void testSendBrmsPolicy() + throws TransformerException, BuilderException, IllegalArgumentException, IOException { + Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor.formatAttributes( + refProp, prop, prop.getType(Policy.class).getId(), prop.getType(Policy.class).getPolicyChains().get(0)); + String response = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId()); + + Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class); + Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"), + Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"), + Assertions.entry("policyConfigType", PolicyConfigType.BRMS_PARAM.name()), + Assertions.entry("requestID", LoggingUtils.getRequestId())); + + // Check BRMS attributes present + Assertions.assertThat((Map<String, Object>) mapNodes.get("attributes")) + .containsKeys(AttributeType.MATCHING.name(), AttributeType.RULE.name()); + } - 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); - } - } + @Test + public void testSendMicroServiceInJson() + throws TransformerException, BuilderException, IllegalArgumentException, IOException { + prop.setCurrentModelElementId(prop.getType(Policy.class).getId()); + String jsonToSend = "{\"test\":\"test\"}"; + String response = policyClient.sendMicroServiceInJson(jsonToSend, prop, LoggingUtils.getRequestId()); + + Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class); + Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"), + Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h"), + Assertions.entry("policyConfigType", PolicyConfigType.MicroService.name()), + Assertions.entry("requestID", LoggingUtils.getRequestId()), + Assertions.entry("configBodyType", PolicyType.JSON.name()), Assertions.entry("onapName", "DCAE"), + Assertions.entry("configBody", jsonToSend)); + } - private void deleteTcaPolicy(String actionCd) throws Exception { - ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp); + @Test + public void testSendBasePolicyInOther() throws IllegalArgumentException, IOException { + String body = "test"; + String response = policyClient.sendBasePolicyInOther(body, "myPolicy", prop, LoggingUtils.getRequestId()); + Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class); + Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"), + Assertions.entry("policyName", "myPolicy"), + Assertions.entry("policyConfigType", PolicyConfigType.Base.name()), + Assertions.entry("requestID", LoggingUtils.getRequestId()), + Assertions.entry("configBodyType", PolicyType.OTHER.name()), Assertions.entry("onapName", "DCAE"), + Assertions.entry("configBody", body)); + } + + @Test + public void testSendMicroServiceInOther() throws IllegalArgumentException, IOException { 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 ")); - } - } + String tcaJson = TcaRequestFormatter.createPolicyJson(refProp, prop); + String response = policyClient.sendMicroServiceInOther(tcaJson, prop); + + Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class); + Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"), + Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_TCA_1d13unw"), + Assertions.entry("policyConfigType", PolicyConfigType.MicroService.name()), + Assertions.entry("configBody", tcaJson), Assertions.entry("onapName", "DCAE")); } - // @Test - /** - * Temporarily disabled Test. - */ - public void testCreateUpdateDeleteOperationalPolicy() throws Exception { - createUpdateOperationalPolicy(CldsEvent.ACTION_SUBMIT); - TimeUnit.SECONDS.sleep(20); - deleteOperationalPolicy(CldsEvent.ACTION_DELETE); + @Test + public void testDeleteMicrosService() throws IllegalArgumentException, IOException { + Tca tca = prop.getType(Tca.class); + prop.setCurrentModelElementId(tca.getId()); + String[] responses = policyClient.deleteMicrosService(prop).split("\\}\\{"); + + // There are 2 responses appended to the result, one for PDP one for PAP ! + Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class); + Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class); + + Assertions.assertThat(mapNodesPdp).contains( + Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_TCA_1d13unw"), + Assertions.entry("policyType", PolicyConfigType.MicroService.name()), + Assertions.entry("policyComponent", "PDP"), Assertions.entry("deleteCondition", "ALL")); + + Assertions.assertThat(mapNodesPap).contains( + Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_TCA_1d13unw"), + Assertions.entry("policyType", PolicyConfigType.MicroService.name()), + Assertions.entry("policyComponent", "PAP"), Assertions.entry("deleteCondition", "ALL")); } @Test - public void testCreateUpdateDeleteTcaPolicy() throws Exception { - createUpdateTcaPolicy(CldsEvent.ACTION_SUBMIT); - TimeUnit.SECONDS.sleep(20); - deleteTcaPolicy(CldsEvent.ACTION_DELETE); + public void testDeleteGuard() throws IllegalArgumentException, IOException { + List<PolicyItem> policyItems = GuardPolicyAttributesConstructor + .getAllPolicyGuardsFromPolicyChain(prop.getType(Policy.class).getPolicyChains().get(0)); + prop.setCurrentModelElementId(prop.getType(Policy.class).getId()); + prop.setPolicyUniqueId(prop.getType(Policy.class).getPolicyChains().get(0).getPolicyId()); + prop.setGuardUniqueId(policyItems.get(0).getId()); + String[] responses = policyClient.deleteGuard(prop).split("\\}\\{"); + + // There are 2 responses appended to the result, one for PDP one for PAP ! + Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class); + Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class); + + Assertions.assertThat(mapNodesPdp).contains( + Assertions.entry("policyName", + modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0_Guard_6TtHGPq"), + Assertions.entry("policyType", "Decision"), Assertions.entry("policyComponent", "PDP"), + Assertions.entry("deleteCondition", "ALL")); + Assertions.assertThat(mapNodesPap).contains( + Assertions.entry("policyName", + modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0_Guard_6TtHGPq"), + Assertions.entry("policyType", "Decision"), Assertions.entry("policyComponent", "PAP"), + Assertions.entry("deleteCondition", "ALL")); } @Test - public void testPolicyConfiguration() { - assertNotNull(policyConfiguration.getPdpUrl1()); - assertNotNull(policyConfiguration.getPdpUrl2()); - assertNotNull(policyConfiguration.getPapUrl()); - assertNotNull(policyConfiguration.getPolicyEnvironment()); - assertNotNull(policyConfiguration.getClientId()); - assertNotNull(policyConfiguration.getClientKey()); - assertNotNull(policyConfiguration.getNotificationType()); - assertNotNull(policyConfiguration.getNotificationUebServers()); - assertEquals(8, policyConfiguration.getProperties().size()); - assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PDP_URL1)) - .contains("/pdp/ , testpdp, alpha123")); - assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PDP_URL2)) - .contains("/pdp/ , testpdp, alpha123")); - assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PAP_URL)) - .contains("/pap/ , testpap, alpha123")); - assertEquals("websocket", policyConfiguration.getProperties().get(PolicyConfiguration.NOTIFICATION_TYPE)); - assertEquals("localhost", - policyConfiguration.getProperties().get(PolicyConfiguration.NOTIFICATION_UEB_SERVERS)); - assertEquals("python", policyConfiguration.getProperties().get(PolicyConfiguration.CLIENT_ID)); - assertEquals("dGVzdA==", policyConfiguration.getProperties().get(PolicyConfiguration.CLIENT_KEY)); - assertEquals("DEVL", policyConfiguration.getProperties().get(PolicyConfiguration.ENVIRONMENT)); + public void testDeleteBrms() throws IllegalArgumentException, IOException { + prop.setPolicyUniqueId(prop.getType(Policy.class).getPolicyChains().get(0).getPolicyId()); + prop.setCurrentModelElementId(prop.getType(Policy.class).getId()); + String[] responses = policyClient.deleteBrms(prop).split("\\}\\{"); + + // There are 2 responses appended to the result, one for PDP one for PAP ! + Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class); + Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance() + .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class); + + Assertions.assertThat(mapNodesPdp).contains( + Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"), + Assertions.entry("policyType", "BRMS_Param"), Assertions.entry("policyComponent", "PDP"), + Assertions.entry("deleteCondition", "ALL")); + Assertions.assertThat(mapNodesPap).contains( + Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"), + Assertions.entry("policyType", "BRMS_Param"), Assertions.entry("policyComponent", "PAP"), + Assertions.entry("deleteCondition", "ALL")); + } } diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyConfigurationItCase.java b/src/test/java/org/onap/clamp/clds/it/PolicyConfigurationItCase.java new file mode 100644 index 00000000..fd20e360 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/PolicyConfigurationItCase.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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============================================ + * =================================================================== + * + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.clamp.clds.config.PolicyConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Test Config Policy read from application.properties. + */ +@RunWith(SpringRunner.class) +@SpringBootTest +public class PolicyConfigurationItCase { + + @Autowired + private PolicyConfiguration policyConfiguration; + + @Test + public void testPolicyConfiguration() { + assertNotNull(policyConfiguration.getPdpUrl1()); + assertNotNull(policyConfiguration.getPdpUrl2()); + assertNotNull(policyConfiguration.getPapUrl()); + assertNotNull(policyConfiguration.getPolicyEnvironment()); + assertNotNull(policyConfiguration.getClientId()); + assertNotNull(policyConfiguration.getClientKey()); + assertNotNull(policyConfiguration.getNotificationType()); + assertNotNull(policyConfiguration.getNotificationUebServers()); + assertEquals(8, policyConfiguration.getProperties().size()); + assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PDP_URL1)) + .contains("/pdp/ , testpdp, alpha123")); + assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PDP_URL2)) + .contains("/pdp/ , testpdp, alpha123")); + assertTrue(((String) policyConfiguration.getProperties().get(PolicyConfiguration.PAP_URL)) + .contains("/pap/ , testpap, alpha123")); + assertEquals("websocket", policyConfiguration.getProperties().get(PolicyConfiguration.NOTIFICATION_TYPE)); + assertEquals("localhost", + policyConfiguration.getProperties().get(PolicyConfiguration.NOTIFICATION_UEB_SERVERS)); + assertEquals("python", policyConfiguration.getProperties().get(PolicyConfiguration.CLIENT_ID)); + assertEquals("dGVzdA==", policyConfiguration.getProperties().get(PolicyConfiguration.CLIENT_KEY)); + assertEquals("DEVL", policyConfiguration.getProperties().get(PolicyConfiguration.ENVIRONMENT)); + } +} diff --git a/src/test/resources/example/model-properties/tca_new/model-bpmn.json b/src/test/resources/example/model-properties/tca_new/model-bpmn.json new file mode 100644 index 00000000..84964c55 --- /dev/null +++ b/src/test/resources/example/model-properties/tca_new/model-bpmn.json @@ -0,0 +1,21 @@ +{ + "policy": [ + { + "id": "Policy_12lup3h", + "from": "TCA_1d13unw" + } + ], + "tca": [ + { + "id": "TCA_1d13unw", + "from": "VesCollector_1g9cmz0" + } + ], + "holmes": [], + "vesCollector": [ + { + "id": "VesCollector_1g9cmz0", + "from": "StartEvent_1" + } + ] +}
\ No newline at end of file diff --git a/src/test/resources/http-cache/third_party_proxy.py b/src/test/resources/http-cache/third_party_proxy.py index a1092412..de40ca90 100755 --- a/src/test/resources/http-cache/third_party_proxy.py +++ b/src/test/resources/http-cache/third_party_proxy.py @@ -171,6 +171,15 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w') as f: f.write(jsonGenerated) return True + elif self.path.startswith("/pdp/api/") and http_type == "PUT" or http_type == "DELETE": + print "self.path start with /pdp/api/, copying body to response ..." + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len(self.data_string)) + "\", \"Content-Type\": \""+str(self.headers['Content-Type'])+"\"}") + with open(cached_file_content, 'w+') as f: + f.write(self.data_string) + return True else: return False @@ -328,6 +337,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): cached_file_header="" print("\n\n\nGot a DELETE for %s " % self.path) self.check_credentials() + self.data_string = self.rfile.read(int(self.headers['Content-Length'])) print("self.headers:\n %s" % self.headers) is_special = self._execute_content_generated_cases("DELETE") |