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));
}
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"));
}
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));
}
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));
}
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);
}
Aggregations