Search in sources :

Example 6 with ProjectAdapter

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"));
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) RepositoryException(javax.jcr.RepositoryException) IProject(org.eclipse.core.resources.IProject) Session(javax.jcr.Session) Test(org.junit.Test)

Example 7 with ProjectAdapter

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));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject)

Example 8 with ProjectAdapter

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());
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 9 with ProjectAdapter

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"));
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) RepositoryException(javax.jcr.RepositoryException) ValueFactory(javax.jcr.ValueFactory) IProject(org.eclipse.core.resources.IProject) Session(javax.jcr.Session) Test(org.junit.Test)

Example 10 with ProjectAdapter

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));
}
Also used : ContentResourceTester(org.apache.sling.ide.eclipse.core.internal.ContentResourceTester) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)48 IProject (org.eclipse.core.resources.IProject)45 Test (org.junit.Test)40 ByteArrayInputStream (java.io.ByteArrayInputStream)28 ServerAdapter (org.apache.sling.ide.test.impl.helpers.ServerAdapter)28 RepositoryAccessor (org.apache.sling.ide.test.impl.helpers.RepositoryAccessor)27 Poller (org.apache.sling.ide.test.impl.helpers.Poller)19 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)15 InputStream (java.io.InputStream)11 Before (org.junit.Before)5 ContentResourceTester (org.apache.sling.ide.eclipse.core.internal.ContentResourceTester)4 IOException (java.io.IOException)3 Session (javax.jcr.Session)3 HttpException (org.apache.commons.httpclient.HttpException)2 SlingContentModuleFactory (org.apache.sling.ide.eclipse.core.internal.SlingContentModuleFactory)2 OsgiBundleManifest (org.apache.sling.ide.test.impl.helpers.OsgiBundleManifest)2 IPath (org.eclipse.core.runtime.IPath)2 IModule (org.eclipse.wst.server.core.IModule)2 IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)2