Skip to content

Commit

Permalink
Fix hr.properties parsing
Browse files Browse the repository at this point in the history
Fix buggy `membership_check.enabled` property parsing.

Issue: https://issues.infn.it/jira/browse/VOMS-883
  • Loading branch information
andreaceccanti committed Nov 10, 2020
1 parent c13d55c commit 850f9e3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public static final HrDbProperties fromProperties(Properties properties) {
}

if (properties.containsKey(MEMBERSHIP_CHECK_ENABLED_KEY)) {
config.getMembershipCheck().setEnabled(Boolean.parseBoolean(MEMBERSHIP_CHECK_ENABLED_KEY));
config.getMembershipCheck()
.setEnabled(Boolean.parseBoolean(properties.getProperty(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 @@ -99,19 +99,37 @@ public void setup() {
configurator.setUserDao(dao);
configurator.setClock(CLOCK);

when(vomsConfig.getConfigurationDirectoryPath()).thenReturn("src/test/resources/cern/config");
when(vomsConfig.getExternalValidatorProperty(eq("orgdb"), anyString(), anyString()))
.thenReturn("src/test/resources/cern/config/orgdb.properties");
when(vomsConfig.getConfigurationDirectoryPath())
.thenReturn("src/test/resources/cern/disabled-task");
when(vomsConfig.getExternalValidatorProperty(eq("orgdb"), eq("configFile"), anyString()))
.thenReturn("src/test/resources/cern/disabled-task/hr.properties");
when(apiFactory.newHrDbApiService(any())).thenReturn(api);
when(validatorFactory.newHrDbRequestValidator(any(), any())).thenReturn(validator);
when(syncTaskFactory.buildSyncTask(any(), any(), any(), any())).thenReturn(syncTask);
}

@Test
public void testConfigurationFileIsFoundAndParsed() throws VOMSPluginConfigurationException {
public void testDisabledConfigurationFileIsFoundAndParsed()
throws VOMSPluginConfigurationException {
configurator.configure();
verifyZeroInteractions(executorService);// no interactions as periodic sync is disabled
verifyZeroInteractions(syncTaskFactory);// no interactions as periodic sync is disabled
verify(manager).setRequestValidationContext(Mockito.eq(validator));
}

@Test
public void testEnabledConfigurationFileIsFoundAndParsed()
throws VOMSPluginConfigurationException {
when(vomsConfig.getConfigurationDirectoryPath())
.thenReturn("src/test/resources/cern/enabled-task");
when(vomsConfig.getExternalValidatorProperty(eq("orgdb"), eq("configFile"), anyString()))
.thenReturn("src/test/resources/cern/enabled-task/hr.properties");
configurator.configure();
verifyZeroInteractions(executorService);
verifyZeroInteractions(syncTaskFactory);

verify(executorService).scheduleAtFixedRate(isA(DatabaseTransactionTaskWrapper.class),
Mockito.anyLong(), Mockito.eq(TimeUnit.HOURS.toSeconds(12)),
Mockito.eq(TimeUnit.SECONDS));

verify(manager).setRequestValidationContext(Mockito.eq(validator));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public void testValueParsing() {
assertThat(hrConfig.getMembershipCheck().getPeriodInSeconds(), is(86400L));
}


@Test
public void testFileParsing() {

}

@Test
public void testApiTimeoutChecks() {
Properties props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
experiment=cms
membership_check.enabled=true
membership_check.start_hour=4
membership_check.run_at_startup=false
api.endpoint=http://localhost:8080
api.username=user
api.password=password
api.timeout_secs=2

0 comments on commit 850f9e3

Please sign in to comment.