2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017 Amdocs
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 package org.onap.aai.sparky.synchronizer;
\r
25 import static org.junit.Assert.assertEquals;
\r
27 import java.io.File;
\r
28 import java.io.IOException;
\r
29 import java.lang.reflect.Field;
\r
30 import java.lang.reflect.Modifier;
\r
31 import java.text.SimpleDateFormat;
\r
32 import java.util.Calendar;
\r
33 import java.util.TimeZone;
\r
35 import org.junit.BeforeClass;
\r
36 import org.junit.Test;
\r
37 import org.junit.runner.RunWith;
\r
38 import org.mockito.runners.MockitoJUnitRunner;
\r
39 import org.onap.aai.sparky.config.oxm.OxmModelLoader;
\r
40 import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
\r
41 import org.onap.aai.sparky.synchronizer.config.SynchronizerConfiguration;
\r
42 import org.onap.aai.sparky.synchronizer.config.SynchronizerConstants;
\r
43 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
\r
45 @RunWith(MockitoJUnitRunner.class)
\r
46 public class SyncHelperTest {
\r
48 private SyncHelper syncHelper;
\r
51 public static void initBeforeClass() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
\r
52 String configHomePath =
\r
53 (new File(".").getCanonicalPath() + "/src/test/resources/appconfig/").replace('\\', '/');
\r
54 TierSupportUiConstants.AJSC_HOME = configHomePath;
\r
55 TierSupportUiConstants.CONFIG_HOME = configHomePath;
\r
56 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = configHomePath;
\r
57 ElasticSearchConfig.setConfig(null);
\r
58 SynchronizerConfiguration.setInstance(null);
\r
60 System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));
\r
61 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/";
\r
66 public void testGetOxmModelLoader() throws Exception {
\r
67 syncHelper = new SyncHelper(new OxmModelLoader());
\r
68 OxmModelLoader oxmLoader = new OxmModelLoader();
\r
69 syncHelper.setOxmModelLoader(oxmLoader);
\r
70 assertEquals(oxmLoader, syncHelper.getOxmModelLoader());
\r
74 public void testGetFirstSyncTime(){
\r
75 SyncHelper syncHelper = new SyncHelper(new OxmModelLoader());
\r
76 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
\r
77 TimeZone tz = TimeZone.getTimeZone("05:00:00 GMT+00:00");
\r
78 Calendar calendar = Calendar.getInstance(tz);
\r
79 sdf.setTimeZone(tz);
\r
81 calendar.set(Calendar.HOUR_OF_DAY, 1);
\r
82 calendar.set(Calendar.MINUTE, 1);
\r
83 calendar.set(Calendar.SECOND, 1);
\r
85 long timeCurrent = calendar.getTimeInMillis();
\r
86 int taskFrequencyInDay = 2;
\r
88 assertEquals(calendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));
\r
89 taskFrequencyInDay = 0;
\r
90 assertEquals(SynchronizerConstants.DELAY_NO_PERIODIC_SYNC_IN_MS, syncHelper.getFirstSyncTime(calendar, timeCurrent, taskFrequencyInDay));
\r
91 timeCurrent = timeCurrent + 100;
\r
92 taskFrequencyInDay = 2;
\r
93 Calendar expCalendar = calendar;
\r
94 expCalendar.add(Calendar.DAY_OF_MONTH, taskFrequencyInDay);
\r
95 //assertEquals(expCalendar.getTimeInMillis(), syncHelper.getFirstSyncTime(calendar, calendar.getTimeInMillis() + 100, taskFrequencyInDay));
\r
99 static void setFinalStatic() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
\r
100 Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");
\r
101 configField.setAccessible(true);
\r
103 Field modifiersField = Field.class.getDeclaredField( "modifiers" );
\r
104 modifiersField.setAccessible( true );
\r
105 modifiersField.setInt( configField, configField.getModifiers() & ~Modifier.FINAL );
\r
107 configField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/elasticsearch.properties");
\r
109 Field syncField = SynchronizerConfiguration.class.getDeclaredField("CONFIG_FILE");
\r
110 syncField.setAccessible(true);
\r
112 Field syncModifiersField = Field.class.getDeclaredField( "modifiers" );
\r
113 syncModifiersField.setAccessible( true );
\r
114 syncModifiersField.setInt( syncField, syncField.getModifiers() & ~Modifier.FINAL );
\r
116 syncField.set(null, System.getProperty("AJSC_HOME")+"/src/test/resources/appconfig/synchronizer.properties");
\r