2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia 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 * ===================================================================
24 package org.onap.clamp.clds.client.req.tca;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.mockito.Matchers.any;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.when;
31 import com.google.gson.JsonObject;
32 import java.io.IOException;
33 import org.junit.Test;
34 import org.onap.clamp.clds.config.ClampProperties;
35 import org.onap.clamp.clds.model.properties.ModelProperties;
36 import org.onap.clamp.clds.model.properties.Tca;
37 import org.onap.clamp.clds.model.properties.TcaItem;
38 import org.onap.clamp.clds.util.JsonUtils;
40 public class TcaRequestFormatterTest {
42 private static final String TCA_POLICY_PROPERTIES_TEMPLATE = "{"
43 + " \"domain\": \"measurementsForVfScaling\","
44 + " \"metricsPerEventName\": ["
46 + " \"eventName\": \"???\","
47 + " \"controlLoopSchemaType\": \"VNF\","
48 + " \"policyScope\": \"DCAE\","
49 + " \"policyName\": \"???\","
50 + " \"policyVersion\": \"v0.0.1\","
51 + " \"thresholds\": ["
58 public void shouldReturnFormattedTcaPolicyRequest() throws IOException {
60 String service = "TestService";
61 String policy = "TestService_scope.PolicyName";
62 ClampProperties clampProperties = mock(ClampProperties.class);
63 String expectedRequestText =
65 + " \"domain\": \"measurementsForVfScaling\", "
66 + " \"metricsPerEventName\": [ "
68 + " \"eventName\": \"vLoadBalancer\", "
69 + " \"controlLoopSchemaType\": \"VNF\", "
70 + " \"policyScope\": \"DCAE\", "
71 + " \"policyName\": \"TestService_scope.PolicyName\", "
72 + " \"policyVersion\": \"v0.0.1\", "
73 + " \"thresholds\": [] "
78 JsonObject tcaPolicyPropertiesTemplate = JsonUtils.GSON
79 .fromJson(TCA_POLICY_PROPERTIES_TEMPLATE, JsonObject.class);
81 JsonObject expectedRequest = JsonUtils.GSON.fromJson(expectedRequestText, JsonObject.class);
83 ModelProperties modelProperties = mock(ModelProperties.class);
84 Tca tca = mock(Tca.class);
85 TcaItem tcaItem = mock(TcaItem.class);
86 when(clampProperties.getJsonTemplate(any(), any())).thenReturn(tcaPolicyPropertiesTemplate);
87 when(tca.getTcaItem()).thenReturn(tcaItem);
88 when(tcaItem.getEventName()).thenReturn("vLoadBalancer");
89 when(tcaItem.getControlLoopSchemaType()).thenReturn("VNF");
92 JsonObject policyContent = TcaRequestFormatter
93 .createPolicyContent(clampProperties, modelProperties, service, policy, tca);
96 assertThat(expectedRequest).isEqualTo(policyContent);