2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Samsung. 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============================================
19 * ===================================================================
23 package org.onap.clamp.clds.client;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Matchers.eq;
27 import static org.mockito.Mockito.never;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
31 import org.apache.camel.Exchange;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.runners.MockitoJUnitRunner;
37 import org.onap.clamp.clds.dao.CldsDao;
39 @RunWith(MockitoJUnitRunner.class)
40 public class CldsEventDelegateTest {
42 private static final String CONTROL_NAME_KEY = "controlName";
43 private static final String TEST_KEY = "isTest";
44 private static final String INSERT_TEST_EVENT_KEY = "isInsertTestEvent";
45 private static final String PREFIX = "abcdef-";
46 private static final String UUID = "ABCDEFGHIJKLMNOPQRSTUVWXYZ-123456789";
49 private Exchange exchange;
52 private CldsDao cldsDao;
55 private CldsEventDelegate cldsEventDelegate;
58 public void shouldExecuteSuccessfully() {
60 when(exchange.getProperty(eq(CONTROL_NAME_KEY))).thenReturn(PREFIX + UUID);
61 when(exchange.getProperty(eq(TEST_KEY))).thenReturn(false);
62 when(exchange.getProperty(eq(INSERT_TEST_EVENT_KEY))).thenReturn(false);
65 cldsEventDelegate.addEvent(exchange, null);
68 verify(cldsDao).insEvent(eq(null), eq(PREFIX), eq(UUID), any());
72 public void shouldExecuteWithoutInsertingEventIntoDatabase() {
74 when(exchange.getProperty(eq(TEST_KEY))).thenReturn(true);
75 when(exchange.getProperty(eq(INSERT_TEST_EVENT_KEY))).thenReturn(false);
78 cldsEventDelegate.addEvent(exchange, null);
81 verify(cldsDao, never()).insEvent(any(), any(), any(), any());