91ee211c2c0b4642fcd31f77056751ff57f9dc55
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / SyncDataManagerTest.java
1 /*******************************************************************************
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  ******************************************************************************/
14 package org.onap.msb.apiroute;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mockito;
20 import org.onap.msb.apiroute.wrapper.consulextend.async.ConsulResponseCallback;
21 import org.onap.msb.apiroute.wrapper.consulextend.util.Http;
22 import org.powermock.api.mockito.PowerMockito;
23 import org.powermock.core.classloader.annotations.PowerMockIgnore;
24 import org.powermock.core.classloader.annotations.PrepareForTest;
25 import org.powermock.modules.junit4.PowerMockRunner;
26
27 import com.fasterxml.jackson.core.type.TypeReference;
28
29 @RunWith(PowerMockRunner.class)
30 @PrepareForTest({Http.class})
31 @PowerMockIgnore({"javax.net.ssl.*"})
32 public class SyncDataManagerTest {
33
34     @SuppressWarnings("unchecked")
35     @Before
36     public void setUpBeforeTest() {
37         Http http = PowerMockito.mock(Http.class);
38
39         PowerMockito.doNothing().when(http).asyncGet(Mockito.anyString(), Mockito.any(TypeReference.class),
40                         Mockito.any(ConsulResponseCallback.class));
41
42         PowerMockito.doNothing().when(http).asyncGetDelayHandle(Mockito.anyString(), Mockito.any(TypeReference.class),
43                         Mockito.any(ConsulResponseCallback.class));
44
45         //
46         PowerMockito.spy(Http.class);
47         PowerMockito.when(Http.getInstance()).thenReturn(http);
48
49     }
50
51     @Test
52     public void testSyncDataManager() {
53         SyncDataManager.initSyncTask("127.0.0.1", 8500);
54         SyncDataManager.startWatchService("huangleibo");
55         SyncDataManager.resetIndex("huangleibo");
56         SyncDataManager.stopWatchService("huangleibo");
57         SyncDataManager.stopWatchServiceList();
58     }
59 }