2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.aai.sparky.sync;
24 import static org.junit.Assert.*;
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;
37 public class SyncControllerImplTest {
39 private SyncControllerConfig syncControllerConfig;
41 private IndexSynchronizer mockSynchronizer = Mockito.mock(IndexSynchronizer.class);
42 private IndexValidator mockValidator = Mockito.mock(IndexValidator.class);
43 private IndexCleaner mockCleaner = Mockito.mock(IndexCleaner.class);
46 public void init() throws Exception {
48 syncControllerConfig = new SyncControllerConfig();
50 syncControllerConfig.setSyncTaskDelayInMs(0);
51 syncControllerConfig.setSyncTaskFrequencyInDays(2);
52 syncControllerConfig.setTargetSyncStartTimeStamp("05:00:00 UTC+00:00");
53 syncControllerConfig.setControllerName("Base-Sync-Controller-Impl");
55 syncControllerConfig.setPeriodicSyncEnabled(true);
56 syncControllerConfig.setRunOnceSyncEnabled(true);
62 public void validateBasicConstruction() throws Exception {
64 SyncControllerImpl syncController = new SyncControllerImpl(syncControllerConfig);
66 assertTrue(syncController.isPeriodicSyncEnabled());
67 assertTrue(syncController.isRunOnceSyncEnabled());
68 assertEquals(0, syncController.getDelayInMs());
73 public void validateSmallSync() throws Exception {
75 SyncControllerImpl syncController = new SyncControllerImpl(syncControllerConfig);
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");
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);
88 syncController.registerEntitySynchronizer(mockSynchronizer);
89 syncController.registerIndexValidator(mockValidator);
90 syncController.registerIndexCleaner(mockCleaner);
95 syncController.performAction(SyncActions.SYNCHRONIZE);