05444d7aa1159c31984e6d9b9e03e9ffcf265017
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / flow / TCAVESCollectorFlowTest.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.flow;
22
23 import co.cask.cdap.AllProgramsApp;
24 import co.cask.cdap.api.flow.FlowletConnection;
25 import co.cask.cdap.api.flow.FlowletDefinition;
26 import co.cask.cdap.internal.app.runtime.flow.DefaultFlowConfigurer;
27 import org.junit.Test;
28 import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
29 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
30
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 import static org.hamcrest.CoreMatchers.is;
37 import static org.hamcrest.Matchers.containsInAnyOrder;
38 import static org.junit.Assert.assertThat;
39
40 /**
41  * @author Rajiv Singla . Creation Date: 1/12/2017.
42  */
43 public class TCAVESCollectorFlowTest extends BaseAnalyticsCDAPTCAUnitTest {
44
45     @Test
46     public void testConfigure() throws Exception {
47
48         final TCAVESCollectorFlow tcavesCollectorFlow = new TCAVESCollectorFlow(getTCATestAppConfig());
49         final DefaultFlowConfigurer configurer = new DefaultFlowConfigurer(new AllProgramsApp.NoOpFlow());
50         tcavesCollectorFlow.configure(configurer);
51         final String flowName = getPrivateFiledValue(configurer, "name", String.class);
52         final String flowDescription = getPrivateFiledValue(configurer, "description", String.class);
53
54         assertThat("TCAVESCollectorFlow Name must match with what is defined in CDAPComponents Constants",
55                 flowName, is(CDAPComponentsConstants.TCA_FIXED_VES_COLLECTOR_NAME_FLOW));
56
57         assertThat("TCAVESCollectorFlow Description must match with what is defined in CDAPComponents Constants",
58                 flowDescription, is(CDAPComponentsConstants.TCA_FIXED_VES_COLLECTOR_DESCRIPTION_FLOW));
59
60         final Map<String, FlowletDefinition> flowlets =
61                 (Map<String, FlowletDefinition>) getPrivateFiledValue(configurer, "flowlets", HashMap.class);
62
63         assertThat("TCAVESCollector must contain all TCA VES flowlets", flowlets.keySet(),
64                 containsInAnyOrder(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_NAME_FLOWLET,
65                         CDAPComponentsConstants.TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_NAME_FLOWLET,
66                         CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_SINK_NAME_FLOWLET));
67
68         final List<FlowletConnection> connections =
69                 (List<FlowletConnection>) getPrivateFiledValue(configurer, "connections", ArrayList.class);
70
71         assertThat("There must be three connections in VES Collector Flow", connections.size(), is(3));
72
73     }
74
75
76 }