Search in sources :

Example 26 with ResourceChange

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);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange)

Example 27 with ResourceChange

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);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Example 28 with ResourceChange

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);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Example 29 with ResourceChange

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);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Example 30 with ResourceChange

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);
}
Also used : ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) File(java.io.File) Test(org.junit.Test)

Aggregations

ResourceChange (org.apache.sling.api.resource.observation.ResourceChange)38 Test (org.junit.Test)20 File (java.io.File)17 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 Event (org.osgi.service.event.Event)2 ImmutableList (com.google.common.collect.ImmutableList)1 SoftReference (java.lang.ref.SoftReference)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Event (javax.jcr.observation.Event)1 JackrabbitEvent (org.apache.jackrabbit.api.observation.JackrabbitEvent)1