2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.it;
26 import static org.junit.Assert.assertTrue;
28 import java.io.IOException;
30 import java.util.UUID;
31 import java.util.concurrent.TimeUnit;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.onap.clamp.clds.AbstractIT;
37 import org.onap.clamp.clds.model.CldsEvent;
38 import org.onap.clamp.clds.model.prop.ModelProperties;
39 import org.openecomp.policy.api.AttributeType;
40 import org.springframework.boot.test.context.SpringBootTest;
41 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
42 import org.springframework.test.context.junit4.SpringRunner;
43 import org.onap.clamp.clds.client.req.OperationalPolicyReq;
44 import org.onap.clamp.clds.client.req.StringMatchPolicyReq;
45 import org.onap.clamp.clds.model.prop.Policy;
46 import org.onap.clamp.clds.model.prop.StringMatch;
47 import org.onap.clamp.clds.transform.TransformUtil;
50 * Test Policy API in org.onap.clamp.ClampDesigner.client package - replicate
51 * Policy Delegates in tests.
53 @RunWith(SpringRunner.class)
54 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
55 public class PolicyClientIT extends AbstractIT {
62 public void setUp() throws IOException {
63 modelProp = TransformUtil.getResourceAsString("example/modelProp.json");
64 modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json");
65 modelName = "example-model06";
66 controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf";
69 private void createUpdateStringMatch(String actionCd) throws Exception {
70 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, modelBpmnProp, modelProp);
71 String stringMatchPolicyRequestUuid = UUID.randomUUID().toString();
72 String policyJson = StringMatchPolicyReq.format(refProp, prop);
73 System.out.println("String Match policyJson=" + policyJson);
74 String responseMessage = policyClient.sendMicroService(policyJson, prop, stringMatchPolicyRequestUuid);
75 System.out.println(responseMessage);
78 private void createUpdateOperationalPolicy(String actionCd) throws Exception {
79 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, modelBpmnProp, modelProp);
80 String operationalPolicyRequestUuid = UUID.randomUUID().toString();
81 Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp, prop);
82 String responseMessage = policyClient.sendBrms(attributes, prop, operationalPolicyRequestUuid);
83 System.out.println(responseMessage);
86 private void createUpdatePolicies(String actionCd) throws Exception {
87 createUpdateStringMatch(actionCd);
88 createUpdateOperationalPolicy(actionCd);
91 private void deleteStringMatchPolicy(String actionCd) throws Exception {
92 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, modelBpmnProp, modelProp);
93 StringMatch stringMatch = prop.getStringMatch();
94 prop.setCurrentModelElementId(stringMatch.getId());
95 String responseMessage = policyClient.deleteMicrosService(prop);
96 System.out.println(responseMessage);
99 private void deleteOperationalPolicy(String actionCd) throws Exception {
100 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, modelBpmnProp, modelProp);
101 Policy policy = prop.getPolicy();
102 prop.setCurrentModelElementId(policy.getId());
103 String responseMessage = policyClient.deleteBrms(prop);
104 System.out.println(responseMessage);
107 private void deletePolicies(String actionCd) throws Exception {
108 deleteStringMatchPolicy(actionCd);
109 deleteOperationalPolicy(actionCd);
113 * Delete policies so we can start with a clean state. But this is just a
114 * precaution - the policies might not already exists. So ignore errors in
115 * attempting to do this.
119 private void cleanUpPolicies(String actionCd) {
121 deleteStringMatchPolicy(actionCd);
122 } catch (Exception e) {
124 "TestPolicyClient: The following error is ok - attempting delete in case the policy exists - the goal is to start with clean slate");
127 deleteOperationalPolicy(actionCd);
128 } catch (Exception e) {
130 "TestPolicyClient: The following error is ok - attempting delete in case the policy exists - the goal is to start with clean slate");
135 public void testCreateUpdateDeletePolicy() throws Exception {
137 cleanUpPolicies(CldsEvent.ACTION_DELETE);
138 TimeUnit.SECONDS.sleep(5);
139 System.out.println("entered into update");
143 actionCd = CldsEvent.ACTION_SUBMIT;
144 createUpdatePolicies(actionCd);
145 } catch (Exception e) {
146 assertTrue(e.getMessage().contains("Policy send failed: PE500 "));
150 actionCd = CldsEvent.ACTION_RESUBMIT;
151 createUpdatePolicies(actionCd);
152 } catch (Exception e) {
153 assertTrue(e.getMessage().contains("Policy send failed: PE500 "));
157 actionCd = CldsEvent.ACTION_RESUBMIT;
158 createUpdatePolicies(actionCd);
159 } catch (Exception e) {
160 assertTrue(e.getMessage().contains("Policy send failed: PE500 "));
164 TimeUnit.SECONDS.sleep(20);
165 deletePolicies(CldsEvent.ACTION_DELETE);
166 } catch (Exception e) {
167 assertTrue(e.getMessage().contains("Unable to get valid Response from PDP"));