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.assertEquals;
27 import static org.junit.Assert.assertTrue;
29 import java.io.IOException;
31 import java.util.UUID;
32 import java.util.concurrent.TimeUnit;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
38 import org.onap.clamp.clds.AbstractIT;
39 import org.onap.clamp.clds.client.req.OperationalPolicyReq;
40 import org.onap.clamp.clds.client.req.StringMatchPolicyReq;
41 import org.onap.clamp.clds.client.req.TcaMPolicyReq;
42 import org.onap.clamp.clds.model.CldsEvent;
43 import org.onap.clamp.clds.model.prop.*;
44 import org.onap.clamp.clds.transform.TransformUtil;
46 import org.onap.policy.api.AttributeType;
48 import org.skyscreamer.jsonassert.JSONAssert;
50 import org.springframework.boot.test.context.SpringBootTest;
51 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
52 import org.springframework.test.context.junit4.SpringRunner;
57 * Test Policy API in org.onap.clamp.ClampDesigner.client package - replicate
58 * Policy Delegates in tests.
60 @RunWith(SpringRunner.class)
61 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
62 public class PolicyClientIT extends AbstractIT {
73 public void setUp() throws IOException {
74 modelProp = TransformUtil.getResourceAsString("example/modelProp.json");
75 modelBpmnProp = TransformUtil.getResourceAsString("example/modelBpmnProp.json");
76 modelName = "example-model06";
77 controlName = "ClosedLoop_FRWL_SIG_fad4dcae_e498_11e6_852e_0050568c4ccf";
80 private void createUpdateStringMatch(String actionCd) throws Exception {
81 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
82 StringMatch stringMatch = prop.getType(StringMatch.class);
83 if (stringMatch.isFound()) {
84 String stringMatchPolicyRequestUuid = UUID.randomUUID().toString();
86 String policyJson = StringMatchPolicyReq.format(refProp, prop);
87 String correctValue = TransformUtil.getResourceAsString("expected/stringmatch.json");
88 JSONAssert.assertEquals(policyJson, correctValue, true);
89 String responseMessage = "";
91 responseMessage = policyClient.sendMicroService(policyJson, prop, stringMatchPolicyRequestUuid);
92 } catch (Exception e) {
93 assertTrue(e.getMessage().contains("Policy send failed: PE500 "));
95 System.out.println(responseMessage);
99 private void createUpdateOperationalPolicy(String actionCd) throws Exception {
100 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
101 Policy policy = prop.getType(Policy.class);
102 if (policy.isFound()) {
103 for (PolicyChain policyChain : policy.getPolicyChains()) {
104 String operationalPolicyRequestUuid = UUID.randomUUID().toString();
106 Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp,
107 prop, policy.getId(), policyChain);
108 String responseMessage = policyClient.sendBrms(attributes, prop, operationalPolicyRequestUuid);
109 System.out.println(responseMessage);
114 private void createUpdateTcaPolicy(String actionCd) throws Exception {
115 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
116 Tca tca = prop.getTca();
118 String tcaPolicyRequestUuid = UUID.randomUUID().toString();
119 String policyJson = TcaMPolicyReq.formatTca(refProp, prop);
120 String correctValue = TransformUtil.getResourceAsString("expected/tca.json");
121 JSONAssert.assertEquals(policyJson, correctValue, true);
122 String responseMessage = "";
124 responseMessage = policyClient.sendMicroService(policyJson, prop, tcaPolicyRequestUuid);
125 } catch (Exception e) {
126 assertTrue(e.getMessage().contains("Policy send failed: PE500 "));
128 System.out.println(responseMessage);
132 private void deleteStringMatchPolicy(String actionCd) throws Exception {
133 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
135 StringMatch stringMatch = prop.getType(StringMatch.class);
136 if (stringMatch.isFound()) {
137 prop.setCurrentModelElementId(stringMatch.getId());
138 String responseMessage = "";
140 responseMessage = policyClient.deleteMicrosService(prop);
141 } catch (Exception e) {
142 assertTrue(e.getMessage().contains("Policy delete failed: PE500 "));
144 System.out.println(responseMessage);
148 private void deleteOperationalPolicy(String actionCd) throws Exception {
149 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
151 Policy policy = prop.getType(Policy.class);
152 if (policy.isFound()) {
153 prop.setCurrentModelElementId(policy.getId());
154 for (PolicyChain policyChain : policy.getPolicyChains()) {
155 prop.setPolicyUniqueId(policyChain.getPolicyId());
156 String responseMessage = policyClient.deleteBrms(prop);
157 System.out.println(responseMessage);
162 private void deleteTcaPolicy(String actionCd) throws Exception {
163 ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
165 Tca tca = prop.getTca();
167 prop.setCurrentModelElementId(tca.getId());
168 String responseMessage = "";
170 responseMessage = policyClient.deleteMicrosService(prop);
171 } catch (Exception e) {
172 assertTrue(e.getMessage().contains("Policy delete failed: PE500 "));
175 System.out.println(responseMessage);
181 * Temporarily disabled Test.
183 public void testCreateUpdateDeleteStringMatchPolicy() throws Exception {
185 createUpdateStringMatch(CldsEvent.ACTION_SUBMIT);
187 TimeUnit.SECONDS.sleep(20);
189 deleteStringMatchPolicy(CldsEvent.ACTION_DELETE);
194 * Temporarily disabled Test.
196 public void testCreateUpdateDeleteOperationalPolicy() throws Exception {
198 createUpdateOperationalPolicy(CldsEvent.ACTION_SUBMIT);
200 TimeUnit.SECONDS.sleep(20);
202 deleteOperationalPolicy(CldsEvent.ACTION_DELETE);
206 public void testCreateUpdateDeleteTcaPolicy() throws Exception {
208 createUpdateTcaPolicy(CldsEvent.ACTION_SUBMIT);
210 TimeUnit.SECONDS.sleep(20);
212 deleteTcaPolicy(CldsEvent.ACTION_DELETE);