Search in sources :

Example 1 with SpyCommand

use of org.apache.sling.ide.test.impl.helpers.SpyCommand in project sling by apache.

the class ResourceChangeCommandFactoryTest method commandForAddedOrUpdatedSlingFolder.

@Test
public void commandForAddedOrUpdatedSlingFolder() throws CoreException {
    // create a sling:Folder at /content/test-root/nested
    InputStream childContentXml = getClass().getResourceAsStream("sling-folder-nodetype-with-title.xml");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/.content.xml"), childContentXml);
    SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo, contentProject.findMember("jcr_root/content/test-root/nested"));
    Map<String, Object> props = new HashMap<>();
    props.put("jcr:primaryType", "sling:Folder");
    props.put("jcr:title", "Some Folder");
    assertThat("command.path", command.getPath(), nullValue());
    assertThat("command.resource.path", command.getResourceProxy().getPath(), equalTo("/content/test-root/nested"));
    assertThat("command.resource.properties", command.getResourceProxy().getProperties(), equalTo(props));
    assertThat("command.fileinfo", command.getFileInfo(), nullValue());
    assertThat("command.kind", command.getSpyKind(), equalTo(SpyCommand.Kind.ADD_OR_UPDATE));
}
Also used : SpyCommand(org.apache.sling.ide.test.impl.helpers.SpyCommand) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with SpyCommand

use of org.apache.sling.ide.test.impl.helpers.SpyCommand in project sling by apache.

the class ResourceChangeCommandFactoryTest method commandForSlingOrderedFolder_extraChildrenInTheFilesystem.

@Test
public void commandForSlingOrderedFolder_extraChildrenInTheFilesystem() throws CoreException {
    // create a sling:OrderedFolder at /content/test-root
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass().getResourceAsStream("sling-ordered-folder-with-children.xml"));
    // create the child folder listed in the .content.xml file
    contentProject.getFolder("jcr_root/content/test-root/folder").create(true, true, new NullProgressMonitor());
    // create an extra folder not listed in the .content.xml file
    contentProject.getFolder("jcr_root/content/test-root/folder2").create(true, true, new NullProgressMonitor());
    SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo, contentProject.findMember("jcr_root/content/test-root"));
    List<ResourceProxy> children = command.getResourceProxy().getChildren();
    assertThat("command.resource.children.size", children.size(), equalTo(3));
    assertThat("command.resource.children[2].name", PathUtil.getName(children.get(2).getPath()), equalTo("folder2"));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SpyCommand(org.apache.sling.ide.test.impl.helpers.SpyCommand) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Test(org.junit.Test)

Example 3 with SpyCommand

use of org.apache.sling.ide.test.impl.helpers.SpyCommand in project sling by apache.

the class ResourceChangeCommandFactoryTest method commandsForNotIgnoredFile.

@Test
public void commandsForNotIgnoredFile() throws CoreException, IOException {
    byte[] buffer = new byte[0];
    try (InputStream inputStream = new ByteArrayInputStream(buffer)) {
        // create a file at at /content/test-root/nested/gitignore (the input stream does not matter here)
        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/gitignore"), inputStream);
    }
    SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo, contentProject.findMember("jcr_root/content/test-root/nested/gitignore"));
    assertThat("command.path", command.getPath(), nullValue());
    assertThat("command.resource.path", command.getResourceProxy().getPath(), equalTo("/content/test-root/nested/gitignore"));
    assertThat("command.resource.properties", command.getResourceProxy().getProperties(), equalTo(singletonMap("jcr:primaryType", (Object) "nt:file")));
    assertThat("command.kind", command.getSpyKind(), equalTo(SpyCommand.Kind.ADD_OR_UPDATE));
    command = (SpyCommand<?>) factory.newCommandForRemovedResources(spyRepo, contentProject.findMember("jcr_root/content/test-root/nested/gitignore"));
    assertThat("command.path", command.getPath(), equalTo("/content/test-root/nested/gitignore"));
    assertThat("command.kind", command.getSpyKind(), equalTo(SpyCommand.Kind.DELETE));
}
Also used : SpyCommand(org.apache.sling.ide.test.impl.helpers.SpyCommand) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with SpyCommand

use of org.apache.sling.ide.test.impl.helpers.SpyCommand in project sling by apache.

the class ResourceChangeCommandFactoryTest method commandForSlingOrderedFolder_children.

@Test
public void commandForSlingOrderedFolder_children() throws CoreException {
    // create a sling:OrderedFolder at /content/test-root
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass().getResourceAsStream("sling-ordered-folder-with-children.xml"));
    // create the child folder listed in the .content.xml file
    contentProject.getFolder("jcr_root/content/test-root/folder").create(true, true, new NullProgressMonitor());
    SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo, contentProject.findMember("jcr_root/content/test-root"));
    List<ResourceProxy> children = command.getResourceProxy().getChildren();
    assertThat("command.resource.children.size", children.size(), equalTo(2));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SpyCommand(org.apache.sling.ide.test.impl.helpers.SpyCommand) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Test(org.junit.Test)

Example 5 with SpyCommand

use of org.apache.sling.ide.test.impl.helpers.SpyCommand in project sling by apache.

the class ResourceChangeCommandFactoryTest method commandsForIgnoredFile.

@Test
public void commandsForIgnoredFile() throws CoreException, IOException {
    byte[] buffer = new byte[0];
    try (InputStream inputStream = new ByteArrayInputStream(buffer)) {
        // create a file at at /content/test-root/nested/.gitignore (the input stream does not matter here)
        project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/.gitignore"), inputStream);
    }
    SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo, contentProject.findMember("jcr_root/content/test-root/nested/.gitignore"));
    assertNull(command);
    command = (SpyCommand<?>) factory.newCommandForRemovedResources(spyRepo, contentProject.findMember("jcr_root/content/test-root/nested/.gitignore"));
    assertNull(command);
}
Also used : SpyCommand(org.apache.sling.ide.test.impl.helpers.SpyCommand) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

SpyCommand (org.apache.sling.ide.test.impl.helpers.SpyCommand)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 HashMap (java.util.HashMap)1