add testcases
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / cambria / backends / kafka / KafkaLiveLockAvoider2Test.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
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  *        http://www.apache.org/licenses/LICENSE-2.0
11 *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *  
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.mr.cambria.backends.kafka;
23
24 import static org.junit.Assert.assertTrue;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.apache.curator.framework.CuratorFramework;
30 import org.apache.curator.framework.api.CreateBuilder;
31 import org.apache.curator.framework.api.ExistsBuilder;
32 import org.apache.curator.framework.api.GetChildrenBuilder;
33 import org.apache.curator.framework.api.ProtectACLCreateModeStatPathAndBytesable;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.MockitoAnnotations;
41 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaLiveLockAvoider2;
42 import org.powermock.api.mockito.PowerMockito;
43 import org.powermock.modules.junit4.PowerMockRunner;
44
45
46 @RunWith(PowerMockRunner.class)
47 public class KafkaLiveLockAvoider2Test {
48         
49         @Mock
50         private CuratorFramework curatorFramework;
51         @Mock
52         private ExistsBuilder existsBuilder;
53         @Mock
54         private CreateBuilder createBuilder;
55         @Mock
56         private GetChildrenBuilder childrenBuilder;
57         @Mock
58         ProtectACLCreateModeStatPathAndBytesable<String> acl;
59         @InjectMocks
60         private KafkaLiveLockAvoider2 liveLockAvoider;
61         
62         public static final String ZNODE_ROOT = "/live-lock-avoid";
63         public static final String ZNODE_LOCKS = "/locks";
64         public static final String ZNODE_UNSTICK_TASKS ="/unstick-tasks";
65         
66         private static String locksPath = ZNODE_ROOT+ZNODE_LOCKS;
67         private static String tasksPath = ZNODE_ROOT+ZNODE_UNSTICK_TASKS;
68         
69
70         @Before
71         public void setUp() throws Exception {
72                 List<String> taskNodes= new ArrayList<String>();
73                 taskNodes.add("appId");
74                 MockitoAnnotations.initMocks(this);
75                 PowerMockito.when(acl.forPath(locksPath)).thenReturn(locksPath);
76                 PowerMockito.when(acl.forPath(tasksPath)).thenReturn(tasksPath);
77                 PowerMockito.when(createBuilder.creatingParentsIfNeeded()).thenReturn(acl);
78                 PowerMockito.when(curatorFramework.create()).thenReturn(createBuilder);
79                 PowerMockito.when(curatorFramework.checkExists()).thenReturn(existsBuilder);
80                 PowerMockito.when(childrenBuilder.forPath(tasksPath)).thenReturn(taskNodes);
81                 PowerMockito.when(curatorFramework.getChildren()).thenReturn(childrenBuilder);
82                 
83         }
84
85         @After
86         public void tearDown() throws Exception {
87         }
88
89         @Test
90         public void testUnlock(){
91                 liveLockAvoider.init();
92                 try {
93                         liveLockAvoider.unlockConsumerGroup("appId", "groupName");
94                 } catch (Exception e) {
95                         assertTrue(true);
96                 }
97         }
98         
99         @Test
100         public void testWatcher(){
101                 try {
102                         liveLockAvoider.startNewWatcherForServer("appId", null);
103                 } catch (Exception e) {
104                         assertTrue(true);
105                 }
106         }
107
108 }