MR Java 11 Uplift
[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.core.classloader.annotations.PowerMockIgnore;
44 import org.powermock.modules.junit4.PowerMockRunner;
45
46 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
47 @RunWith(PowerMockRunner.class)
48 public class KafkaLiveLockAvoider2Test {
49         
50         @Mock
51         private CuratorFramework curatorFramework;
52         @Mock
53         private ExistsBuilder existsBuilder;
54         @Mock
55         private CreateBuilder createBuilder;
56         @Mock
57         private GetChildrenBuilder childrenBuilder;
58         @Mock
59         ProtectACLCreateModeStatPathAndBytesable<String> acl;
60         @InjectMocks
61         private KafkaLiveLockAvoider2 liveLockAvoider;
62         
63         public static final String ZNODE_ROOT = "/live-lock-avoid";
64         public static final String ZNODE_LOCKS = "/locks";
65         public static final String ZNODE_UNSTICK_TASKS ="/unstick-tasks";
66         
67         private static String locksPath = ZNODE_ROOT+ZNODE_LOCKS;
68         private static String tasksPath = ZNODE_ROOT+ZNODE_UNSTICK_TASKS;
69         
70
71         @Before
72         public void setUp() throws Exception {
73                 List<String> taskNodes= new ArrayList<String>();
74                 taskNodes.add("appId");
75                 MockitoAnnotations.initMocks(this);
76                 PowerMockito.when(acl.forPath(locksPath)).thenReturn(locksPath);
77                 PowerMockito.when(acl.forPath(tasksPath)).thenReturn(tasksPath);
78                 PowerMockito.when(createBuilder.creatingParentsIfNeeded()).thenReturn(acl);
79                 PowerMockito.when(curatorFramework.create()).thenReturn(createBuilder);
80                 PowerMockito.when(curatorFramework.checkExists()).thenReturn(existsBuilder);
81                 PowerMockito.when(childrenBuilder.forPath(tasksPath)).thenReturn(taskNodes);
82                 PowerMockito.when(curatorFramework.getChildren()).thenReturn(childrenBuilder);
83                 
84         }
85
86         @After
87         public void tearDown() throws Exception {
88         }
89
90         @Test
91         public void testUnlock(){
92                 liveLockAvoider.init();
93                 try {
94                         liveLockAvoider.unlockConsumerGroup("appId", "groupName");
95                 } catch (Exception e) {
96                         assertTrue(true);
97                 }
98         }
99         
100         @Test
101         public void testWatcher(){
102                 try {
103                         liveLockAvoider.startNewWatcherForServer("appId", null);
104                 } catch (Exception e) {
105                         assertTrue(true);
106                 }
107         }
108
109 }