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 static org.hamcrest.CoreMatchers.is;
\r
32 import static org.junit.Assert.assertEquals;
\r
33 import static org.junit.Assert.assertThat;
\r
34 import static org.mockito.Mockito.mock;
\r
35 import static org.mockito.Mockito.when;
\r
38 * @author Rajiv Singla . Creation Date: 11/9/2016.
\r
40 public class CDAPTCAUtilsTest extends BaseAnalyticsCDAPTCAUnitTest {
\r
43 public void testGetValidatedTCAAppPreferences() throws Exception {
\r
44 RuntimeContext runtimeContext = mock(RuntimeContext.class);
\r
45 when(runtimeContext.getRuntimeArguments()).thenReturn(getPreferenceMap());
\r
46 ApplicationSpecification mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class);
\r
47 when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION));
\r
48 when(runtimeContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification);
\r
49 TCAAppPreferences validatedTCAAppPreferences = CDAPTCAUtils.getValidatedTCAAppPreferences(runtimeContext);
\r
50 assertEquals(validatedTCAAppPreferences.getSubscriberHostName(), "HOSTNAME");
\r
54 public void testConvertRuntimeContextToTCAPolicy() throws Exception {
\r
56 final TCAPolicy tcaPolicy =
\r
57 CDAPTCAUtils.getValidatedTCAPolicyPreferences(getTestFlowletContextWithValidPolicy());
\r
58 assertThat("Policy Domain must be measurementsForVfScaling",
\r
59 tcaPolicy.getDomain(), is("measurementsForVfScaling"));
\r
60 assertThat("Policy must have 2 metrics per functional roles",
\r
61 tcaPolicy.getMetricsPerEventName().size(), is(2));
\r
65 public void testConvertRuntimeContextToTCAPolicyFromJSON() throws Exception {
\r
67 final TCAPolicy tcaPolicy =
\r
68 CDAPTCAUtils.getValidatedTCAPolicyPreferences(getTestFlowletContextWithValidPolicyFromJSON());
\r
69 assertThat("Policy Domain must be measurementsForVfScaling",
\r
70 tcaPolicy.getDomain(), is("measurementsForVfScaling"));
\r
71 assertThat("Policy must have 2 metrics per functional roles",
\r
72 tcaPolicy.getMetricsPerEventName().size(), is(2));
\r