use of org.apache.sling.ide.test.impl.helpers.ProjectAdapter in project sling by apache.
the class ContentImportTest method importFromRepositoryWithNtUnstructuredNodeWithNoPropertiesCausesSpuriousLocalDeletion.
@Test
public void importFromRepositoryWithNtUnstructuredNodeWithNoPropertiesCausesSpuriousLocalDeletion() throws Exception {
RepositoryAccessor repo = new RepositoryAccessor(config);
repo.createNode("/content/test-root/en", "nt:folder");
// create faceted project
IProject contentProject = projectRule.getProject();
ProjectAdapter project = new ProjectAdapter(contentProject);
project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
// install bundle facet
project.installFacet("sling.content", "1.0");
wstServer.waitForServerToStart();
project.createVltFilterWithRoots("/content/test-root");
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/en/hello.txt"), new ByteArrayInputStream("hello, world".getBytes()));
ServerAdapter server = new ServerAdapter(wstServer.getServer());
server.installModule(contentProject);
deh.clearUnexpectedEventsAfterSettling();
repo.createNode("/content/test-root/folder", "sling:Folder");
repo.createNode("/content/test-root/folder/jcr:content", "nt:unstructured");
repo.createFile("/content/test-root/folder/jcr:content/some_file.txt", "dummy contents".getBytes());
repo.doWithSession(new SessionRunnable<Void>() {
@Override
public Void doWithSession(Session session) throws RepositoryException {
session.getRootNode().getNode("content/test-root/folder/jcr:content/some_file.txt/jcr:content").setProperty("jcr:mimeType", "x-vendor-reserved");
session.save();
return null;
}
});
// run initial import
runImport(contentProject);
assertThat(contentProject, hasFile("jcr_root/content/test-root/folder/_jcr_content/some_file.txt.dir/.content.xml"));
// run second import
runImport(contentProject);
assertThat(contentProject, hasFile("jcr_root/content/test-root/folder/_jcr_content/some_file.txt.dir/.content.xml"));
}
use of org.apache.sling.ide.test.impl.helpers.ProjectAdapter in project sling by apache.
the class SightlyNatureTest method testValidationMarkers.
private void testValidationMarkers(boolean invalidTag) throws Exception {
final IProject project = projectRule.getProject();
// create faceted project
ProjectAdapter projectAdapter = new ProjectAdapter(project);
projectAdapter.addNatures("org.eclipse.wst.common.project.facet.core.nature");
projectAdapter.installFacet("sling.content", "1.0");
projectAdapter.installFacet("sightly", "1.1");
final IPath sightlyTemplatePath = Path.fromPortableString("/jcr_root/libs/my/component/html.html");
String tagName = invalidTag ? "invalid-tag" : "sly";
projectAdapter.createOrUpdateFile(sightlyTemplatePath, new ByteArrayInputStream(("<" + tagName + " />").getBytes()));
ValidationFramework.getDefault().join(new NullProgressMonitor());
IMarker[] markers = project.findMember(sightlyTemplatePath).findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
if (invalidTag) {
assertThat("markers.length", markers.length, equalTo(1));
// might be overspecifying
assertThat(markers[0].getAttribute(IMarker.MESSAGE, ""), equalTo("Unknown tag (invalid-tag)."));
} else {
assertThat("markers.length", markers.length, equalTo(0));
}
}
use of org.apache.sling.ide.test.impl.helpers.ProjectAdapter in project sling by apache.
the class ContentImportTest method importFilesAndFoldersRespectsVltIgnoreNotUnderImportRoot.
@Test
public void importFilesAndFoldersRespectsVltIgnoreNotUnderImportRoot() throws Exception {
// create faceted project
IProject contentProject = projectRule.getProject();
ProjectAdapter project = new ProjectAdapter(contentProject);
project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
// install bundle facet
project.installFacet("sling.content", "1.0");
wstServer.waitForServerToStart();
project.createVltFilterWithRoots("/content/test-root/en");
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/hello.txt"), new ByteArrayInputStream("hello, world".getBytes()));
project.createOrUpdateFile(Path.fromPortableString("jcr_root/.vltignore"), new ByteArrayInputStream("content/test-root/en\n".getBytes()));
ServerAdapter server = new ServerAdapter(wstServer.getServer());
server.installModule(contentProject);
deh.clearUnexpectedEventsAfterSettling();
// create server-side content
RepositoryAccessor repo = new RepositoryAccessor(config);
repo.createNode("/content/test-root/en", "nt:folder");
repo.createNode("/content/test-root/en/files", "nt:folder");
repo.createFile("/content/test-root/en/files/first.txt", "first file".getBytes());
runImport(contentProject);
assertThat(contentProject.findMember("jcr_root/content/test-root/en"), nullValue());
}
use of org.apache.sling.ide.test.impl.helpers.ProjectAdapter in project sling by apache.
the class ContentImportTest method importFilesWithExtraNodesUnderJcrContent.
@Test
public void importFilesWithExtraNodesUnderJcrContent() throws Exception {
// create faceted project
IProject contentProject = projectRule.getProject();
ProjectAdapter project = new ProjectAdapter(contentProject);
project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
// install bundle facet
project.installFacet("sling.content", "1.0");
// create filter.xml
project.createVltFilterWithRoots("/content/test-root");
// create sling:Folder at /content/test-root
project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass().getResourceAsStream("sling-folder-nodetype.xml"));
wstServer.waitForServerToStart();
ServerAdapter server = new ServerAdapter(wstServer.getServer());
server.installModule(contentProject);
deh.clearUnexpectedEventsAfterSettling();
// create server-side content
RepositoryAccessor repo = new RepositoryAccessor(config);
repo.tryDeleteResource("/content/test-root");
repo.createNode("/content/test-root", "sling:Folder");
repo.createFile("/content/test-root/file.txt", "hello, world".getBytes());
repo.doWithSession(new SessionRunnable<Void>() {
@Override
public Void doWithSession(Session session) throws RepositoryException {
ValueFactory valueFactory = session.getValueFactory();
Node contentNode = session.getNode("/content/test-root/file.txt/jcr:content");
contentNode.addMixin("sling:chunks");
Node chunkNode = contentNode.addNode("firstChunk", "sling:chunk");
chunkNode.setProperty("sling:offset", valueFactory.createValue(0));
chunkNode.setProperty("jcr:data", valueFactory.createValue(valueFactory.createBinary(new ByteArrayInputStream("hello, world".getBytes()))));
session.save();
return null;
}
});
assertThat(repo.getNode("/content/test-root").getPrimaryNodeType().getName(), equalTo("sling:Folder"));
runImport(contentProject);
assertThat("File not properly imported", contentProject, hasFile("jcr_root/content/test-root/file.txt", "hello, world".getBytes()));
assertThat("File extra serialization dir not imported", contentProject, hasFolder("jcr_root/content/test-root/file.txt.dir"));
assertThat("File jcr:content data not serialized in .content.xml", contentProject, hasFile("jcr_root/content/test-root/file.txt.dir/.content.xml"));
assertThat("File jcr:content extra dir not serialized as _jcr_content", contentProject, hasFolder("jcr_root/content/test-root/file.txt.dir/_jcr_content"));
assertThat("First chunk dir not serialized", contentProject, hasFolder("jcr_root/content/test-root/file.txt.dir/_jcr_content/firstChunk"));
assertThat("First chunk properties not serialized", contentProject, hasFile("jcr_root/content/test-root/file.txt.dir/_jcr_content/firstChunk/.content.xml"));
assertThat("Sling folder serialization file was deleted after import", contentProject, hasFile("jcr_root/content/test-root/.content.xml"));
}
use of org.apache.sling.ide.test.impl.helpers.ProjectAdapter in project sling by apache.
the class ContentResourceTesterTest method simpleFacetedProjectIsNotExportable.
@Test
public void simpleFacetedProjectIsNotExportable() throws CoreException {
// create faceted project
IProject contentProject = projectRule.getProject();
ProjectAdapter project = new ProjectAdapter(contentProject);
project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
assertThat("Faceted project can not be exported", new ContentResourceTester().test(contentProject, "canBeExported", null, null), equalTo(false));
}
Aggregations