use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class TestUtils method assertChange.
public static void assertChange(List<ResourceChange> changes, String path, ChangeType changeType) {
boolean found = false;
for (ResourceChange change : changes) {
if (StringUtils.equals(change.getPath(), path) && change.getType() == changeType) {
found = true;
break;
}
}
assertTrue("Change with path=" + path + ", changeType=" + changeType + " expected", found);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileVaultFileMonitorTest method testAddFolder.
@Test
public void testAddFolder() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File folder = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/newfolder");
folder.mkdir();
Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
assertChange(changes, "/content/dam/talk.png/jcr:content", ChangeType.CHANGED);
assertChange(changes, "/content/dam/talk.png/jcr:content/newfolder", ChangeType.ADDED);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileVaultFileMonitorTest method testRemoveFolder.
@Test
public void testRemoveFolder() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File folder = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/renditions");
FileUtils.deleteDirectory(folder);
Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
assertChange(changes, "/content/dam/talk.png/jcr:content", ChangeType.CHANGED);
assertChange(changes, "/content/dam/talk.png/jcr:content/renditions", ChangeType.REMOVED);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileVaultFileMonitorTest method testAddFile.
@Test
public void testAddFile() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file = new File(tempDir, "jcr_root/content/dam/talk.png/_jcr_content/renditions/text.txt");
FileUtils.write(file, "newcontent");
Thread.sleep(WAIT_INTERVAL);
assertEquals(2, changes.size());
assertChange(changes, "/content/dam/talk.png/jcr:content/renditions", ChangeType.CHANGED);
assertChange(changes, "/content/dam/talk.png/jcr:content/renditions/text.txt", ChangeType.ADDED);
}
use of org.apache.sling.api.resource.observation.ResourceChange in project sling by apache.
the class FileVaultFileMonitorTest method testAddContent.
@Test
public void testAddContent() throws Exception {
List<ResourceChange> changes = resourceListener.getChanges();
assertTrue(changes.isEmpty());
File file = new File(tempDir, "jcr_root/content/samples/fr/.content.xml");
file.getParentFile().mkdir();
FileUtils.write(file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:app=\"http://sample.com/jcr/app/1.0\" " + "xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\" jcr:primaryType=\"app:Page\">\n" + "<jcr:content jcr:primaryType=\"app:PageContent\"/>\n" + "</jcr:root>");
Thread.sleep(WAIT_INTERVAL);
assertChange(changes, "/content/samples", ChangeType.CHANGED);
assertChange(changes, "/content/samples/fr", ChangeType.ADDED);
assertChange(changes, "/content/samples/fr/jcr:content", ChangeType.ADDED);
}
Aggregations