diff options
author | sebdet <sebastien.determe@intl.att.com> | 2018-12-07 17:48:10 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2018-12-07 17:48:10 +0100 |
commit | 9d1f89cff526052bd28a24d4ac33b1fd54d76983 (patch) | |
tree | 1e7f2598b46433953dd1ab13be88803b7df1860a /src/test/java | |
parent | d72d0d05d74f4125e8f36beea096aa7769d19eab (diff) |
Add unit tests
Add test to policyClient + guard policyAttributes
Issue-ID: CLAMP-252
Change-Id: I344a631cc1dfd38e87f61b34dcb1bb3dbb00625a
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/test/java')
3 files changed, 332 insertions, 93 deletions
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 000000000..f16345676 --- /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 59fad9a69..f849a6c06 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 000000000..fd20e360a --- /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)); + } +} |