Search in sources :

Example 6 with RepositoryAccessor

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

the class ContentImportTest method importFullCoverageNode.

@Test
public void importFullCoverageNode() 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");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/hello.txt"), new ByteArrayInputStream("hello, world".getBytes()));
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.installModule(contentProject);
    deh.clearUnexpectedEventsAfterSettling();
    // create server-side content
    RepositoryAccessor repo = new RepositoryAccessor(config);
    repo.doWithSession(new SessionRunnable<Void>() {

        @Override
        public Void doWithSession(Session session) throws RepositoryException {
            Node configNode = session.getRootNode().addNode("content/test-root/org.apache.sling.example.Component.config", "sling:OsgiConfig");
            configNode.setProperty("enabled", Boolean.TRUE.toString());
            session.save();
            return null;
        }
    });
    runImport(contentProject);
    assertThat(contentProject, hasFile("jcr_root/content/test-root/org.apache.sling.example.Component.config.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) IProject(org.eclipse.core.resources.IProject) Session(javax.jcr.Session) Test(org.junit.Test)

Example 7 with RepositoryAccessor

use of org.apache.sling.ide.test.impl.helpers.RepositoryAccessor 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 8 with RepositoryAccessor

use of org.apache.sling.ide.test.impl.helpers.RepositoryAccessor 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 RepositoryAccessor

use of org.apache.sling.ide.test.impl.helpers.RepositoryAccessor 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 RepositoryAccessor

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

the class ContentImportTest method importFilesAndFolders.

@Test
public void importFilesAndFolders() 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/test-root/en/hello.txt"), new ByteArrayInputStream("hello, world".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, hasFolder("jcr_root/content/test-root/en/files"));
    assertThat(contentProject, hasFile("jcr_root/content/test-root/en/files/first.txt", "first file".getBytes()));
}
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)

Aggregations

RepositoryAccessor (org.apache.sling.ide.test.impl.helpers.RepositoryAccessor)28 ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)27 ServerAdapter (org.apache.sling.ide.test.impl.helpers.ServerAdapter)27 IProject (org.eclipse.core.resources.IProject)27 Test (org.junit.Test)26 Poller (org.apache.sling.ide.test.impl.helpers.Poller)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)15 InputStream (java.io.InputStream)10 Session (javax.jcr.Session)3 IOException (java.io.IOException)2 HttpException (org.apache.commons.httpclient.HttpException)2 ValueFactory (javax.jcr.ValueFactory)1 MavenDependency (org.apache.sling.ide.test.impl.helpers.MavenDependency)1 OsgiBundleManifest (org.apache.sling.ide.test.impl.helpers.OsgiBundleManifest)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1