Adjust sparky parent pom
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / sync / SyncControllerImplTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.aai.sparky.sync;
23
24 import static org.junit.Assert.*;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mockito;
29 import org.onap.aai.sparky.sync.IndexCleaner;
30 import org.onap.aai.sparky.sync.IndexSynchronizer;
31 import org.onap.aai.sparky.sync.IndexValidator;
32 import org.onap.aai.sparky.sync.SyncControllerImpl;
33 import org.onap.aai.sparky.sync.SyncControllerImpl.SyncActions;
34 import org.onap.aai.sparky.sync.config.SyncControllerConfig;
35 import org.onap.aai.sparky.sync.enumeration.SynchronizerState;
36
37 public class SyncControllerImplTest {
38         
39         private SyncControllerConfig syncControllerConfig;
40         
41         private IndexSynchronizer mockSynchronizer = Mockito.mock(IndexSynchronizer.class);
42         private IndexValidator mockValidator = Mockito.mock(IndexValidator.class);
43         private IndexCleaner mockCleaner = Mockito.mock(IndexCleaner.class);
44         
45         @Before
46           public void init() throws Exception {
47                 
48                 syncControllerConfig = new SyncControllerConfig();
49                 
50                 syncControllerConfig.setSyncTaskDelayInMs(0);
51                 syncControllerConfig.setSyncTaskFrequencyInDays(2);
52                 syncControllerConfig.setTargetSyncStartTimeStamp("05:00:00 UTC+00:00");
53                 syncControllerConfig.setControllerName("Base-Sync-Controller-Impl");
54                 
55         syncControllerConfig.setPeriodicSyncEnabled(true);
56                 syncControllerConfig.setRunOnceSyncEnabled(true);
57               
58           }
59         
60         
61         @Test 
62         public void validateBasicConstruction() throws Exception {
63                 
64                 SyncControllerImpl syncController = new SyncControllerImpl(syncControllerConfig);
65                 
66                 assertTrue(syncController.isPeriodicSyncEnabled());
67                 assertTrue(syncController.isRunOnceSyncEnabled());
68                 assertEquals(0, syncController.getDelayInMs());
69                         
70         }
71         
72         @Test 
73         public void validateSmallSync() throws Exception {
74                 
75                 SyncControllerImpl syncController = new SyncControllerImpl(syncControllerConfig);
76
77                 Mockito.when( mockSynchronizer.getIndexName() ).thenReturn("mock-sync-index");
78                 Mockito.when( mockCleaner.getIndexName()).thenReturn("mock-sync-index");
79                 Mockito.when( mockValidator.getIndexName()).thenReturn("mock-sync-index");
80                 
81                 Mockito.when(mockSynchronizer.getStatReport(Boolean.TRUE)).thenReturn("mock-sync-index stat report");
82                 Mockito.when(mockValidator.exists()).thenReturn(false);
83                 Mockito.when(mockSynchronizer.getState()).thenReturn(SynchronizerState.PERFORMING_SYNCHRONIZATION,
84                                 SynchronizerState.PERFORMING_SYNCHRONIZATION, SynchronizerState.PERFORMING_SYNCHRONIZATION,
85                                 SynchronizerState.PERFORMING_SYNCHRONIZATION, SynchronizerState.PERFORMING_SYNCHRONIZATION,
86                                 SynchronizerState.IDLE);
87                 
88                 syncController.registerEntitySynchronizer(mockSynchronizer);
89                 syncController.registerIndexValidator(mockValidator);
90                 syncController.registerIndexCleaner(mockCleaner);
91                 
92                 
93                 
94                 
95                 syncController.performAction(SyncActions.SYNCHRONIZE);
96                 
97                         
98         }
99
100         
101         
102 }