Added unit tests for CldsEventDelegate
[clamp.git] / src / test / java / org / onap / clamp / clds / client / CldsEventDelegateTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
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
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  */
22
23 package org.onap.clamp.clds.client;
24
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;
30
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;
38
39 @RunWith(MockitoJUnitRunner.class)
40 public class CldsEventDelegateTest {
41
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";
47
48     @Mock
49     private Exchange exchange;
50
51     @Mock
52     private CldsDao cldsDao;
53
54     @InjectMocks
55     private CldsEventDelegate cldsEventDelegate;
56
57     @Test
58     public void shouldExecuteSuccessfully() {
59         // given
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);
63
64         // when
65         cldsEventDelegate.addEvent(exchange, null);
66
67         // then
68         verify(cldsDao).insEvent(eq(null), eq(PREFIX), eq(UUID), any());
69     }
70
71     @Test
72     public void shouldExecuteWithoutInsertingEventIntoDatabase() {
73         // given
74         when(exchange.getProperty(eq(TEST_KEY))).thenReturn(true);
75         when(exchange.getProperty(eq(INSERT_TEST_EVENT_KEY))).thenReturn(false);
76
77         // when
78         cldsEventDelegate.addEvent(exchange, null);
79
80         // then
81         verify(cldsDao, never()).insEvent(any(), any(), any(), any());
82     }
83 }