Search in sources :

Example 16 with ProjectAdapter

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

the class JcrPartialCoverageAggregatesDeploymentTest method deploySlingOrderedFolderWithJcrContentNode.

@Test
public void deploySlingOrderedFolderWithJcrContentNode() throws Exception {
    wstServer.waitForServerToStart();
    // create faceted project
    IProject contentProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(contentProject);
    project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    // install content facet
    project.installFacet("sling.content", "1.0");
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.installModule(contentProject);
    // create filter.xml
    project.createVltFilterWithRoots("/content");
    // create a nt:file at /content/test-root/file.txt
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/folder/file.txt"), new ByteArrayInputStream("hello, world".getBytes()));
    // 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"));
    Matcher<Node> postConditions = allOf(hasPath("/content/test-root"), hasPrimaryType("sling:OrderedFolder"), hasChildrenNames("folder", "jcr:content"));
    final RepositoryAccessor repo = new RepositoryAccessor(config);
    Poller poller = new Poller();
    poller.pollUntil(new Callable<Node>() {

        @Override
        public Node call() throws RepositoryException {
            return repo.getNode("/content/test-root");
        }
    }, postConditions);
    // reorder the children of the /content/test-root node
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass().getResourceAsStream("sling-ordered-folder-with-children-reordered.xml"));
    postConditions = allOf(hasPath("/content/test-root"), hasPrimaryType("sling:OrderedFolder"), hasChildrenNames("jcr:content", "folder"));
    poller.pollUntil(new Callable<Node>() {

        @Override
        public Node call() throws RepositoryException {
            return repo.getNode("/content/test-root");
        }
    }, postConditions);
}
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) Poller(org.apache.sling.ide.test.impl.helpers.Poller) Test(org.junit.Test)

Example 17 with ProjectAdapter

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

the class JcrPartialCoverageAggregatesDeploymentTest method deployNodeWithContentXmlInParentFolder_reverse.

@Test
public void deployNodeWithContentXmlInParentFolder_reverse() throws Exception {
    wstServer.waitForServerToStart();
    // create faceted project
    IProject contentProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(contentProject);
    project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    // install content facet
    project.installFacet("sling.content", "1.0");
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.installModule(contentProject);
    // create filter.xml
    project.createVltFilterWithRoots("/content");
    // the expected repository structure is
    // mapping [sling:Mapping]
    // \- jcr:content [nt:unstructured]
    //  \- par [nt:unstructured]
    //   \- folder [sling:Folder] 
    // first create the local structure where the content is completely serialized inside the .content.xml file
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/mapping/.content.xml"), getClass().getResourceAsStream("sling-mapping-with-folder-child.xml"));
    // now create the folder and its associated .content.xml file ; this will cause
    // intermediate folders to be created whose serialization data is present in the
    // parent's .content.xml file
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/mapping/_jcr_content/par/folder/.content.xml"), getClass().getResourceAsStream("sling-folder-nodetype.xml"));
    final RepositoryAccessor repo = new RepositoryAccessor(config);
    Poller poller = new Poller();
    // wait until the structure is published
    poller.pollUntil(new Callable<Node>() {

        @Override
        public Node call() throws RepositoryException {
            return repo.getNode("/content/test-root/mapping/jcr:content/par/folder");
        }
    }, hasPrimaryType("sling:Folder"));
    // change the folder's node type to nt:unstructured and make sure it's covered by the parent
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/mapping/.content.xml"), getClass().getResourceAsStream("sling-mapping-with-unstructured-child.xml"));
    // oh boy, where do I start ...
    // this test keeps failing with issues which suggest concurrency problems, e.g. InvalidStateException
    // I've tried to work around this issue by refreshing the session, serialising the executions with a
    // SingleThreadExecutor, inspecting the before/after repo state ... but in the end only this
    // 'harmless' sleep fixes the test. It will have to do for now, at least until SLING-4438 is fixed
    Thread.sleep(1000);
    // delete the sling folder node type since the serialization is now completely covered by
    // the parent node
    project.deleteMember(Path.fromPortableString("jcr_root/content/test-root/mapping/_jcr_content"));
    // validate that the primary type has changed
    poller.pollUntil(new Callable<Node>() {

        @Override
        public Node call() throws RepositoryException {
            return repo.getNode("/content/test-root/mapping/jcr:content/par/folder");
        }
    }, hasPrimaryType("nt:unstructured"));
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) Node(javax.jcr.Node) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) RepositoryException(javax.jcr.RepositoryException) IProject(org.eclipse.core.resources.IProject) Poller(org.apache.sling.ide.test.impl.helpers.Poller) Test(org.junit.Test)

Example 18 with ProjectAdapter

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

the class ProjectHelperTest method inferContentProjectContentMissingFilter.

@Test
public void inferContentProjectContentMissingFilter() throws CoreException, InterruptedException {
    // create faceted project
    IProject contentProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(contentProject);
    project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    // install content facet
    project.installFacet("sling.content", "1.0");
    // create files
    project.createOrUpdateFile(Path.fromPortableString("src/main/content/jcr_root/test/hello.txt"), new ByteArrayInputStream("goodbye, world".getBytes()));
    assertThat(ProjectHelper.getInferredContentProjectContentRoot(contentProject), CoreMatchers.nullValue());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 19 with ProjectAdapter

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

the class ProjectHelperTest method inferContentProjectContentRootNested.

@Test
public void inferContentProjectContentRootNested() throws CoreException, InterruptedException {
    // create faceted project
    IProject contentProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(contentProject);
    project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    // install content facet
    project.installFacet("sling.content", "1.0");
    // create files
    project.createOrUpdateFile(Path.fromPortableString("src/main/content/jcr_root/test/hello.txt"), new ByteArrayInputStream("goodbye, world".getBytes()));
    project.createOrUpdateFile(Path.fromPortableString("src/main/content/META-INF/vault/filter.xml"), new ByteArrayInputStream("<workspaceFilter version=\"1.0\"/>".getBytes()));
    assertThat(ProjectHelper.getInferredContentProjectContentRoot(contentProject), CoreMatchers.<IContainer>equalTo(contentProject.getFolder("src/main/content")));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 20 with ProjectAdapter

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

the class ProjectHelperTest method inferContentProjectContentRootAtTheTopLevel.

@Test
public void inferContentProjectContentRootAtTheTopLevel() throws CoreException, InterruptedException {
    // create faceted project
    IProject contentProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(contentProject);
    project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    // install content facet
    project.installFacet("sling.content", "1.0");
    // create files
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/hello.txt"), new ByteArrayInputStream("goodbye, world".getBytes()));
    project.createOrUpdateFile(Path.fromPortableString("META-INF/vault/filter.xml"), new ByteArrayInputStream("<workspaceFilter version=\"1.0\"/>".getBytes()));
    assertThat(ProjectHelper.getInferredContentProjectContentRoot(contentProject), CoreMatchers.<IContainer>equalTo(contentProject));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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