Skip to content

Commit

Permalink
Fix typo in method name
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaceccanti committed Nov 10, 2020
1 parent b4b5bc1 commit 15c915f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public Runnable buildSyncTask(HrDbProperties properties, HrDbApiService api, VOM
syncTask.setSyncHandler(handler);

return new DatabaseTransactionTaskWrapper(syncTask, true, true,
properties.getMembesrshipCheck().getPeriodInSeconds());
properties.getMembershipCheck().getPeriodInSeconds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,21 @@ private void scheduleSyncTask(HrDbProperties config, Runnable syncTask) {
final Runnable task = wrapTask(syncTask);
ZonedDateTime now = ZonedDateTime.now(clock);
ZonedDateTime nextRun =
now.withHour(config.getMembesrshipCheck().getStartHour()).withMinute(0).withSecond(0);
now.withHour(config.getMembershipCheck().getStartHour()).withMinute(0).withSecond(0);

if (now.compareTo(nextRun) > 0) {
nextRun = nextRun.plusDays(1);
}

LOG.info("Scheduling HR DB sync task to start on {} and run every {} seconds", nextRun,
config.getMembesrshipCheck().getPeriodInSeconds());
config.getMembershipCheck().getPeriodInSeconds());

Duration duration = Duration.between(now, nextRun);

executorService.scheduleAtFixedRate(task, duration.getSeconds(),
config.getMembesrshipCheck().getPeriodInSeconds(), TimeUnit.SECONDS);
config.getMembershipCheck().getPeriodInSeconds(), TimeUnit.SECONDS);

if (config.getMembesrshipCheck().isRunAtStartup()) {
if (config.getMembershipCheck().isRunAtStartup()) {

ZonedDateTime startupRun = now.plusMinutes(5);

Expand Down Expand Up @@ -179,7 +179,7 @@ public void configure() throws VOMSPluginConfigurationException {
LOG.info("HR DB request validator registered succesfully. Syncing against HR db experiment {}",
hrConfig.getExperimentName());

if (hrConfig.getMembesrshipCheck().isEnabled()) {
if (hrConfig.getMembershipCheck().isEnabled()) {
scheduleSyncTask(hrConfig,
syncTaskFactory.buildSyncTask(hrConfig, apiService, userDao, config));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public long getTimeoutInSeconds() {
}

HrDbApiProperties api = new HrDbApiProperties();
MembershipCheck membesrshipCheck = new MembershipCheck();
MembershipCheck membershipCheck = new MembershipCheck();

String experimentName = "experiment";

Expand All @@ -143,12 +143,12 @@ public void setExperimentName(String experimentName) {
this.experimentName = experimentName;
}

public void setMembesrshipCheck(MembershipCheck membesrshipCheck) {
this.membesrshipCheck = membesrshipCheck;
public void setMembershipCheck(MembershipCheck membershipCheck) {
this.membershipCheck = membershipCheck;
}

public MembershipCheck getMembesrshipCheck() {
return membesrshipCheck;
public MembershipCheck getMembershipCheck() {
return membershipCheck;
}

private static void requireProperty(String key, Properties properties) {
Expand All @@ -169,25 +169,25 @@ public static final HrDbProperties fromProperties(Properties properties) {
int startHour = Integer.parseInt(properties.getProperty(MEMBERSHIP_CHECK_START_HOUR_KEY));

if (startHour >= 0 && startHour < 24) {
config.getMembesrshipCheck()
config.getMembershipCheck()
.setStartHour(
(Integer.parseInt(properties.getProperty(MEMBERSHIP_CHECK_START_HOUR_KEY))));
}
}

if (properties.containsKey(MEMBERSHIP_CHECK_RUN_AT_STARTUP_KEY)) {
config.getMembesrshipCheck()
config.getMembershipCheck()
.setRunAtStartup(
Boolean.parseBoolean(properties.getProperty(MEMBERSHIP_CHECK_RUN_AT_STARTUP_KEY)));
}

if (properties.containsKey(MEMBERSHIP_CHECK_PERIOD_KEY)) {
config.getMembesrshipCheck()
config.getMembershipCheck()
.setPeriodInSeconds(Long.parseLong(properties.getProperty(MEMBERSHIP_CHECK_PERIOD_KEY)));
}

if (properties.containsKey(MEMBERSHIP_CHECK_ENABLED_KEY)) {
config.getMembesrshipCheck().setEnabled(Boolean.parseBoolean(MEMBERSHIP_CHECK_ENABLED_KEY));
config.getMembershipCheck().setEnabled(Boolean.parseBoolean(MEMBERSHIP_CHECK_ENABLED_KEY));
}

config.getApi().setEndpoint(properties.getProperty(API_ENDPOINT_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void testMembershipCheckTaskScheduling() throws VOMSPluginConfigurationEx
configurator.configure();

verify(executorService).scheduleAtFixedRate(isA(DatabaseTransactionTaskWrapper.class),
Mockito.anyLong(), Mockito.eq(props.getMembesrshipCheck().getPeriodInSeconds()),
Mockito.anyLong(), Mockito.eq(props.getMembershipCheck().getPeriodInSeconds()),
Mockito.eq(TimeUnit.SECONDS));

verify(executorService).schedule(Mockito.isA(DatabaseTransactionTaskWrapper.class),
Expand All @@ -148,13 +148,13 @@ public void testMembershipCheckTaskScheduling() throws VOMSPluginConfigurationEx
public void testNoStartupTaskScheduling() throws VOMSPluginConfigurationException {
HrDbProperties props = new HrDbProperties();

props.getMembesrshipCheck().setRunAtStartup(false);
props.getMembershipCheck().setRunAtStartup(false);

configurator.setHrConfig(props);
configurator.configure();

verify(executorService).scheduleAtFixedRate(isA(DatabaseTransactionTaskWrapper.class), anyLong(),
Mockito.eq(props.getMembesrshipCheck().getPeriodInSeconds()), eq(TimeUnit.SECONDS));
Mockito.eq(props.getMembershipCheck().getPeriodInSeconds()), eq(TimeUnit.SECONDS));

verify(executorService, never()).schedule(isA(DatabaseTransactionTaskWrapper.class), anyLong(), any());
}
Expand All @@ -163,15 +163,15 @@ public void testNoStartupTaskScheduling() throws VOMSPluginConfigurationExceptio
public void testStartupTaskSchedulingCanceled() throws VOMSPluginConfigurationException {
HrDbProperties props = new HrDbProperties();

props.getMembesrshipCheck().setRunAtStartup(true);
props.getMembershipCheck().setRunAtStartup(true);

configurator.setHrConfig(props);
configurator.setClock(fixed(Instant.parse("2019-01-01T21:45:00.00Z"), ZoneId.systemDefault()));
configurator.configure();


verify(executorService).scheduleAtFixedRate(isA(DatabaseTransactionTaskWrapper.class), anyLong(),
eq(props.getMembesrshipCheck().getPeriodInSeconds()), eq(TimeUnit.SECONDS));
eq(props.getMembershipCheck().getPeriodInSeconds()), eq(TimeUnit.SECONDS));

verify(executorService, never()).schedule(isA(DatabaseTransactionTaskWrapper.class), anyLong(), any());
}
Expand All @@ -180,16 +180,16 @@ public void testStartupTaskSchedulingCanceled() throws VOMSPluginConfigurationEx
public void testStartupTaskScheduledTheNextDay() throws VOMSPluginConfigurationException {
HrDbProperties props = new HrDbProperties();

props.getMembesrshipCheck().setRunAtStartup(false);
props.getMembesrshipCheck().setStartHour(22);
props.getMembershipCheck().setRunAtStartup(false);
props.getMembershipCheck().setStartHour(22);

configurator.setHrConfig(props);
configurator.setClock(fixed(Instant.parse("2019-01-01T21:01:00.00Z"), ZoneId.systemDefault()));
configurator.configure();


verify(executorService).scheduleAtFixedRate(isA(DatabaseTransactionTaskWrapper.class), anyLong(),
eq(props.getMembesrshipCheck().getPeriodInSeconds()), eq(TimeUnit.SECONDS));
eq(props.getMembershipCheck().getPeriodInSeconds()), eq(TimeUnit.SECONDS));

verify(executorService, never()).schedule(isA(DatabaseTransactionTaskWrapper.class), anyLong(), any());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void testValueParsing() {
assertThat(hrConfig.getApi().getEndpoint(), is("http://example"));
assertThat(hrConfig.getApi().getUsername(), is("test"));
assertThat(hrConfig.getApi().getPassword(), is("password"));
assertThat(hrConfig.getMembesrshipCheck().isEnabled(), is(false));
assertThat(hrConfig.getMembesrshipCheck().getPeriodInSeconds(), is(86400L));
assertThat(hrConfig.getMembershipCheck().isEnabled(), is(false));
assertThat(hrConfig.getMembershipCheck().getPeriodInSeconds(), is(86400L));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package integration.hr;


import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.verify;

import java.util.Date;
Expand Down Expand Up @@ -210,8 +211,6 @@ public void testRestoreSuspendedUserDueToValidationError() {
assertThat(user.getEmailAddress(), is("[email protected]".toLowerCase()));

verify(manager).restoreUser(Mockito.eq(user));


}

@Test
Expand All @@ -234,8 +233,34 @@ public void testRestoreSuspendedUserDueToMembershipExpiration() {
assertThat(user.getEmailAddress(), is("[email protected]".toLowerCase()));

verify(manager).restoreUser(Mockito.eq(user));
}

@Test
public void testInstituteChangeHandling() {


InstituteDTO firstInstitute = new InstituteDTO();
institute.setName("First institute");

InstituteDTO secondInstitute = new InstituteDTO();
institute.setName("Second institute");

oneParticipation.setExperiment("experiment");
oneParticipation.setInstitute(firstInstitute);
oneParticipation.setStartDate(Date.from(ONE_YEAR_AGO));
oneParticipation.setEndDate(Date.from(ONE_WEEK_AGO));

anotherParticipation.setExperiment("experiment");
anotherParticipation.setInstitute(secondInstitute);
anotherParticipation.setStartDate(Date.from(A_DAY_AGO));

voPerson.setParticipations(Sets.newHashSet(oneParticipation, anotherParticipation));

user.setSuspended(true);
user.setSuspensionReasonCode(SuspensionReason.MEMBERSHIP_EXPIRATION);
user.setSuspensionReason(SuspensionReason.MEMBERSHIP_EXPIRATION.getMessage());

handler.synchronizeMembershipInformation(user, voPerson);
verify(manager).restoreUser(Mockito.eq(user));
}


Expand Down

0 comments on commit 15c915f

Please sign in to comment.