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