2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.utils;
\r
23 import co.cask.cdap.api.RuntimeContext;
\r
24 import co.cask.cdap.api.app.ApplicationSpecification;
\r
25 import org.junit.Test;
\r
26 import org.mockito.Mockito;
\r
27 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
\r
28 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;
\r
29 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;
\r
31 import java.util.Map;
\r
33 import static org.hamcrest.CoreMatchers.is;
\r
34 import static org.junit.Assert.assertEquals;
\r
35 import static org.junit.Assert.assertThat;
\r
36 import static org.mockito.Mockito.mock;
\r
37 import static org.mockito.Mockito.when;
\r
40 * @author Rajiv Singla . Creation Date: 11/9/2016.
\r
42 public class CDAPTCAUtilsTest extends BaseAnalyticsCDAPTCAUnitTest {
\r
45 public void testGetValidatedTCAAppPreferences() throws Exception {
\r
46 RuntimeContext runtimeContext = mock(RuntimeContext.class);
\r
47 final Map<String, String> preferenceMap = getPreferenceMap();
\r
48 preferenceMap.remove("subscriberHostName");
\r
49 preferenceMap.remove("publisherHostName");
\r
50 when(runtimeContext.getRuntimeArguments()).thenReturn(preferenceMap);
\r
51 ApplicationSpecification mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class);
\r
52 when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION));
\r
53 when(runtimeContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification);
\r
54 TCAAppPreferences validatedTCAAppPreferences = CDAPTCAUtils.getValidatedTCAAppPreferences(runtimeContext);
\r
55 assertEquals(validatedTCAAppPreferences.getSubscriberHostName(), "HOSTNAME");
\r
59 public void testConvertRuntimeContextToTCAPolicy() throws Exception {
\r
61 final TCAPolicy tcaPolicy =
\r
62 CDAPTCAUtils.getValidatedTCAPolicyPreferences(getTestFlowletContextWithValidPolicy());
\r
63 assertThat("Policy Domain must be measurementsForVfScaling",
\r
64 tcaPolicy.getDomain(), is("measurementsForVfScaling"));
\r
65 assertThat("Policy must have 2 metrics per functional roles",
\r
66 tcaPolicy.getMetricsPerEventName().size(), is(2));
\r
70 public void testConvertRuntimeContextToTCAPolicyFromJSON() throws Exception {
\r
72 final TCAPolicy tcaPolicy =
\r
73 CDAPTCAUtils.getValidatedTCAPolicyPreferences(getTestFlowletContextWithValidPolicyFromJSON());
\r
74 assertThat("Policy Domain must be measurementsForVfScaling",
\r
75 tcaPolicy.getDomain(), is("measurementsForVfScaling"));
\r
76 assertThat("Policy must have 2 metrics per functional roles",
\r
77 tcaPolicy.getMetricsPerEventName().size(), is(2));
\r