Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / utils / CDAPTCAUtilsTest.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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===========================================
19  */
20
21 package org.openecomp.dcae.apod.analytics.cdap.tca.utils;
22
23 import co.cask.cdap.api.RuntimeContext;
24 import org.junit.Test;
25 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
26 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;
27 import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;
28
29 import static org.hamcrest.CoreMatchers.is;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertThat;
32 import static org.mockito.Mockito.mock;
33 import static org.mockito.Mockito.when;
34
35 /**
36  * @author Rajiv Singla . Creation Date: 11/9/2016.
37  */
38 public class CDAPTCAUtilsTest extends BaseAnalyticsCDAPTCAUnitTest {
39
40     @Test
41     public void testGetValidatedTCAAppPreferences() throws Exception {
42         RuntimeContext runtimeContext = mock(RuntimeContext.class);
43         when(runtimeContext.getRuntimeArguments()).thenReturn(getPreferenceMap());
44         TCAAppPreferences validatedTCAAppPreferences = CDAPTCAUtils.getValidatedTCAAppPreferences(runtimeContext);
45         assertEquals(validatedTCAAppPreferences.getSubscriberHostName(), "mrlocal-mtnjftle01.homer.com");
46     }
47
48     @Test
49     public void testConvertRuntimeContextToTCAPolicy() throws Exception {
50
51         final TCAPolicy tcaPolicy =
52                 CDAPTCAUtils.getValidatedTCAPolicyPreferences(getTestFlowletContextWithValidPolicy());
53         assertThat("Policy Domain must be measurementsForVfScaling",
54                 tcaPolicy.getDomain(), is("measurementsForVfScaling"));
55         assertThat("Policy must have 2 metrics per functional roles",
56                 tcaPolicy.getMetricsPerFunctionalRole().size(), is(2));
57     }
58
59     @Test
60     public void testConvertRuntimeContextToTCAPolicyFromJSON() throws Exception {
61
62         final TCAPolicy tcaPolicy =
63                 CDAPTCAUtils.getValidatedTCAPolicyPreferences(getTestFlowletContextWithValidPolicyFromJSON());
64         assertThat("Policy Domain must be measurementsForVfScaling",
65                 tcaPolicy.getDomain(), is("measurementsForVfScaling"));
66         assertThat("Policy must have 2 metrics per functional roles",
67                 tcaPolicy.getMetricsPerFunctionalRole().size(), is(2));
68     }
69
70 }