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.onap.dcae.apod.analytics.cdap.tca.flowlet;
23 import co.cask.cdap.api.flow.flowlet.OutputEmitter;
24 import co.cask.cdap.api.flow.flowlet.StreamEvent;
25 import com.google.common.base.Charsets;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
29 import org.onap.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
30 import org.onap.dcae.apod.analytics.common.AnalyticsConstants;
32 import java.nio.ByteBuffer;
34 import static org.mockito.ArgumentMatchers.eq;
35 import static org.mockito.Mockito.doNothing;
36 import static org.mockito.Mockito.times;
37 import static org.mockito.Mockito.verify;
38 import static org.mockito.Mockito.when;
41 * @author Rajiv Singla . Creation Date: 12/19/2016.
43 public class TCAVESMessageRouterFlowletTest extends BaseAnalyticsCDAPTCAUnitTest {
45 private static final String TEST_MESSAGE = "test message";
46 private final OutputEmitter mockOutputEmitter = Mockito.mock(OutputEmitter.class);
48 private class TCATestVESMessageRouterFlowlet extends TCAVESMessageRouterFlowlet {
50 @SuppressWarnings("unchecked")
51 public TCATestVESMessageRouterFlowlet() {
52 this.vesMessageEmitter = mockOutputEmitter;
53 doNothing().when(mockOutputEmitter).emit(eq(TEST_MESSAGE),
54 eq(AnalyticsConstants.TCA_VES_MESSAGE_ROUTER_PARTITION_KEY),
55 eq(TEST_MESSAGE.hashCode()));
60 public void testConfigure() throws Exception {
61 final TCAVESMessageRouterFlowlet tcavesMessageRouterFlowlet = new TCAVESMessageRouterFlowlet();
62 assertFlowletNameAndDescription(CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_NAME_FLOWLET,
63 CDAPComponentsConstants.TCA_FIXED_VES_MESSAGE_ROUTER_DESCRIPTION_FLOWLET, tcavesMessageRouterFlowlet);
66 @SuppressWarnings("unchecked")
68 public void routeVESMessage() throws Exception {
69 final TCATestVESMessageRouterFlowlet tcavesMessageRouterFlowlet = new TCATestVESMessageRouterFlowlet();
70 final StreamEvent mockStreamEvent = Mockito.mock(StreamEvent.class);
71 final ByteBuffer testMessage = Charsets.UTF_8.encode(TEST_MESSAGE);
72 when(mockStreamEvent.getBody()).thenReturn(testMessage);
73 tcavesMessageRouterFlowlet.routeVESMessage(mockStreamEvent);
74 verify(mockOutputEmitter,
75 times(1)).emit(eq(TEST_MESSAGE),
76 eq(AnalyticsConstants.TCA_VES_MESSAGE_ROUTER_PARTITION_KEY),
77 eq(TEST_MESSAGE.hashCode()));