2cb9002b25c4265174384973387cd310157432dc
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / utils / CDAPTCAUtilsTest.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\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
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.utils;\r
22 \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
30 \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
36 \r
37 /**\r
38  * @author Rajiv Singla . Creation Date: 11/9/2016.\r
39  */\r
40 public class CDAPTCAUtilsTest extends BaseAnalyticsCDAPTCAUnitTest {\r
41 \r
42     @Test\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
51     }\r
52 \r
53     @Test\r
54     public void testConvertRuntimeContextToTCAPolicy() throws Exception {\r
55 \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
62     }\r
63 \r
64     @Test\r
65     public void testConvertRuntimeContextToTCAPolicyFromJSON() throws Exception {\r
66 \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
73     }\r
74 \r
75 }\r