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