Skip to content

Commit

Permalink
Handling null value for expectedSyncTime (no sync once)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Henrique Alves Lima committed Mar 5, 2017
1 parent 735433c commit a3026ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.techdm.aem.vltsync.impl;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Hashtable;
import java.util.Map;

import org.apache.felix.scr.annotations.Component;
Expand Down Expand Up @@ -50,15 +50,22 @@ public class ServiceSettingsImpl {
* @param syncRoot
* directory to add
* @param expectedSyncTime
* the expected sync time as result of adding this directory
* the expected sync time as result of adding this directory or
* null if sync once won't occur.
*/
public void addSyncRoot(final File syncRoot, Long expectedSyncTime) throws IllegalStateException {
logger.debug("addSyncRoot(): syncRoot = {}", syncRoot);

final Map<String, Object> props = new LinkedHashMap<String, Object>();
/*
* Job manager doesn't like properties with null value, so we use
* Hashtable here to assure that only non-null values will pass along.
*/
final Map<String, Object> props = new Hashtable<String, Object>();
props.put(ServiceSettingsConsumerImpl.KEY_ACTION, ServiceSettingsConsumerImpl.ACTION_ADD);
props.put(ServiceSettingsConsumerImpl.KEY_SYNC_ROOT, syncRoot);
props.put(ServiceSettingsConsumerImpl.KEY_EXPECTED_SYNC_TIME, expectedSyncTime);
if (expectedSyncTime != null) {
props.put(ServiceSettingsConsumerImpl.KEY_EXPECTED_SYNC_TIME, expectedSyncTime);
}

jobManager.addJob(ServiceSettingsConsumerImpl.TOPIC_NAME, props);
}
Expand All @@ -73,7 +80,11 @@ public void addSyncRoot(final File syncRoot, Long expectedSyncTime) throws Illeg
public void removeSyncRoot(final File syncRoot) throws IllegalStateException {
logger.debug("removeSyncRoot(): syncRoot = {}", syncRoot);

final Map<String, Object> props = new LinkedHashMap<String, Object>();
/*
* Job manager doesn't like properties with null value, so we use
* Hashtable here to assure that only non-null values will pass along.
*/
final Map<String, Object> props = new Hashtable<String, Object>();
props.put(ServiceSettingsConsumerImpl.KEY_ACTION, ServiceSettingsConsumerImpl.ACTION_REMOVE);
props.put(ServiceSettingsConsumerImpl.KEY_SYNC_ROOT, syncRoot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ public void testAddSyncRoot() {
/* Check its results. */
verify(this.jobManager, times(1)).addJob(TOPIC_NAME, this.props);
}



@Test
public void testAddSyncRootNoSyncOnce() {
/* Prepare data. */
this.props.put(KEY_ACTION, ACTION_ADD);
this.props.put(KEY_SYNC_ROOT, new File("/virtual/root"));
this.props.put(KEY_EXPECTED_SYNC_TIME, null);
this.props.remove(KEY_EXPECTED_SYNC_TIME);

/* Invoke method. */
this.serviceSettings.addSyncRoot(new File("/virtual/root"), null);
Expand Down

0 comments on commit a3026ad

Please sign in to comment.