use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileMonitorTest method testUpdateFile.
@Test
public void testUpdateFile() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1a = new File(tempDir, "folder1/file1a.txt");
FileUtils.touch(file1a);
Thread.sleep(WAIT_INTERVAL);
assertEquals(1, changes.size());
assertChange(changes, "/fs-test/folder1/file1a.txt", ChangeType.CHANGED);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileMonitorTest method testRemoveContent.
@Test
public void testRemoveContent() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1a = new File(tempDir, "folder2/content.json");
file1a.delete();
Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
assertChange(changes, "/fs-test/folder2", ChangeType.CHANGED);
assertChange(changes, "/fs-test/folder2/content", ChangeType.REMOVED);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileVaultFileMonitorTest method testRemoveContentDotXmlOnly.
@Test
public void testRemoveContentDotXmlOnly() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file = new File(tempDir, "jcr_root/content/samples/en/.content.xml");
file.delete();
Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
assertChange(changes, "/content/samples/en", ChangeType.CHANGED);
// this second event is not fully correct, but this is a quite special case, accept it for now
assertChange(changes, "/content/samples/en", ChangeType.REMOVED);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileMonitorTest method testAddContent.
@Test
public void testAddContent() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file1c = new File(tempDir, "folder1/file1c.json");
FileUtils.write(file1c, "{\"prop1\":\"value1\",\"child1\":{\"prop2\":\"value1\"}}");
Thread.sleep(WAIT_INTERVAL);
assertEquals(3, changes.size());
assertChange(changes, "/fs-test/folder1", ChangeType.CHANGED);
assertChange(changes, "/fs-test/folder1/file1c", ChangeType.ADDED);
assertChange(changes, "/fs-test/folder1/file1c/child1", ChangeType.ADDED);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class ResourceBackedPojoChangeMonitor method onChange.
@Override
public void onChange(@Nonnull List<ResourceChange> changes) {
for (ResourceChange change : changes) {
String path = change.getPath();
ResourceChange.ChangeType changeType = change.getType();
switch(changeType) {
case CHANGED:
if (slyJavaUseMap.containsKey(path)) {
slyJavaUseMap.put(path, System.currentTimeMillis());
}
break;
case REMOVED:
if (slyJavaUseMap.containsKey(path)) {
slyJavaUseMap.remove(path);
}
break;
default:
break;
}
LOG.debug("Java Use Object {} was {}.", path, changeType.toString());
}
}
Aggregations