Remove dead code
[clamp.git] / src / test / java / org / onap / clamp / clds / client / req / tca / TcaRequestFormatterTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END============================================
22  * ===================================================================
23  *
24  */
25
26 package org.onap.clamp.clds.client.req.tca;
27
28 import static org.assertj.core.api.Assertions.assertThat;
29 import static org.mockito.Matchers.any;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
32
33 import com.google.gson.JsonObject;
34 import java.io.IOException;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.onap.clamp.clds.config.ClampProperties;
38 import org.onap.clamp.clds.exception.TcaRequestFormatterException;
39 import org.onap.clamp.clds.model.properties.ModelProperties;
40 import org.onap.clamp.clds.model.properties.Tca;
41 import org.onap.clamp.clds.model.properties.TcaItem;
42 import org.onap.clamp.clds.util.JsonUtils;
43
44 public class TcaRequestFormatterTest {
45
46     private static final String TCA_POLICY_PROPERTIES_TEMPLATE = "{"
47         + " \"domain\": \"measurementsForVfScaling\","
48         + " \"metricsPerEventName\": ["
49         + "  {"
50         + "   \"eventName\": \"???\","
51         + "   \"controlLoopSchemaType\": \"VNF\","
52         + "   \"policyScope\": \"DCAE\","
53         + "   \"policyName\": \"???\","
54         + "   \"policyVersion\": \"v0.0.1\","
55         + "   \"thresholds\": ["
56         + "   ]"
57         + "  }"
58         + " ]"
59         + "}";
60
61     @Test
62     public void shouldReturnFormattedTcaPolicyRequest() throws IOException {
63         //given
64         String service = "TestService";
65         String policy = "TestService_scope.PolicyName";
66         ClampProperties clampProperties = mock(ClampProperties.class);
67         String expectedRequestText = 
68             "{ "
69             + " \"domain\": \"measurementsForVfScaling\", "
70             + " \"metricsPerEventName\": [ "
71             + "  { "
72             + "   \"eventName\": \"vLoadBalancer\", "
73             + "   \"controlLoopSchemaType\": \"VNF\", "
74             + "   \"policyScope\": \"DCAE\", "
75             + "   \"policyName\": \"TestService_scope.PolicyName\", "
76             + "   \"policyVersion\": \"v0.0.1\", "
77             + "   \"thresholds\": [] "
78             + "  } "
79             + " ] "
80             + "}";
81     
82         JsonObject tcaPolicyPropertiesTemplate = JsonUtils.GSON
83             .fromJson(TCA_POLICY_PROPERTIES_TEMPLATE, JsonObject.class);
84
85         JsonObject expectedRequest = JsonUtils.GSON.fromJson(expectedRequestText, JsonObject.class);
86
87         ModelProperties modelProperties = mock(ModelProperties.class);
88         Tca tca = mock(Tca.class);
89         TcaItem tcaItem = mock(TcaItem.class);
90         when(clampProperties.getJsonTemplate(any(), any())).thenReturn(tcaPolicyPropertiesTemplate);
91         when(tca.getTcaItem()).thenReturn(tcaItem);
92         when(tcaItem.getEventName()).thenReturn("vLoadBalancer");
93         when(tcaItem.getControlLoopSchemaType()).thenReturn("VNF");
94
95         //when
96         JsonObject policyContent = TcaRequestFormatter
97             .createPolicyContent(clampProperties, modelProperties, service, policy, tca);
98
99         //then
100         assertThat(expectedRequest).isEqualTo(policyContent);
101     }
102
103     @Test(expected = TcaRequestFormatterException.class)
104     public void shouldThrowTcaRequestFormatterException() throws IOException {
105         //given
106         String service = "TestService";
107         String policy = "TestService_scope.PolicyName";
108         ClampProperties clampProperties =  mock(ClampProperties.class);
109         ModelProperties modelProperties = mock(ModelProperties.class);
110         Tca tca = mock(Tca.class);
111         //when
112         Mockito.when(clampProperties.getJsonTemplate(any(), any())).thenThrow(IOException.class);
113         //then
114         TcaRequestFormatter.createPolicyContent(clampProperties, modelProperties, service, policy, tca);
115     }
116 }