Search in sources :

Example 31 with ProjectAdapter

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

the class SlingContentModuleAdapterTest method projectMembersContainDotDirFoldersLast.

@Test
public void projectMembersContainDotDirFoldersLast() 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");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/testproject/_jcr_content/image/file"), new ByteArrayInputStream(new byte[0]));
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/testproject/_jcr_content/image/file.dir/.content.xml"), new ByteArrayInputStream(new byte[0]));
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/testproject/_jcr_content/image/file.dir/_jcr_content/_dam_thumbnails/_dam_thumbnail_319.png"), new ByteArrayInputStream(new byte[0]));
    IModule module = ServerUtil.getModule(contentProject);
    SlingContentModuleFactory moduleFactory = new SlingContentModuleFactory();
    ModuleDelegate moduleDelegate = moduleFactory.getModuleDelegate(module);
    IModuleResource[] members = moduleDelegate.members();
    int fileIdx = -1;
    int fileDirIdx = -1;
    for (int i = 0; i < members.length; i++) {
        String memberName = members[i].getModuleRelativePath().lastSegment();
        if (memberName == null) {
            continue;
        } else if (memberName.equals("file.dir")) {
            fileDirIdx = i;
        } else if (memberName.equals("file")) {
            fileIdx = i;
        }
    }
    Assert.assertTrue("file not sorted before file.dir ; file index = " + fileIdx + ", file.dir index = " + fileDirIdx, fileIdx < fileDirIdx);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) ModuleDelegate(org.eclipse.wst.server.core.model.ModuleDelegate) IProject(org.eclipse.core.resources.IProject) SlingContentModuleFactory(org.apache.sling.ide.eclipse.core.internal.SlingContentModuleFactory) Test(org.junit.Test)

Example 32 with ProjectAdapter

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

the class JavaUtilsTest method inferPackageName.

@Test
public void inferPackageName() 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 facets
    project.installFacet("sling.content", "1.0");
    project.installFacet("sightly", "1.1");
    // create basic html file
    IPath path = Path.fromOSString("jcr_root/apps/components/app/forum");
    IPath fullPath = project.ensureDirectoryExists(path).getFullPath();
    String inferredPackage = JavaUtils.inferPackage(fullPath);
    assertThat(inferredPackage, CoreMatchers.equalTo("apps.components.app.forum"));
}
Also used : IPath(org.eclipse.core.runtime.IPath) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 33 with ProjectAdapter

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

the class ResourceChangeCommandFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    // create faceted project
    contentProject = projectRule.getProject();
    project = new ProjectAdapter(contentProject);
    project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    // install content facet
    project.installFacet("sling.content", "1.0");
    // create filter.xml
    project.createVltFilterWithRoots("/content");
    Set<String> ignoredFileNames = new HashSet<>();
    ignoredFileNames.add(".gitignore");
    factory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), ignoredFileNames);
    spyRepo = new SpyRepository();
}
Also used : SpyRepository(org.apache.sling.ide.test.impl.helpers.SpyRepository) ResourceChangeCommandFactory(org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 34 with ProjectAdapter

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

the class JcrPartialCoverageAggregatesDeploymentTest method deploySlingFolder.

@Test
public void deploySlingFolder() 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 sling:Folder at /content/test-root
    InputStream contentXml = getClass().getResourceAsStream("sling-folder-nodetype.xml");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), contentXml);
    // create a sling:Folder at /content/test-root/nested
    InputStream childContentXml = getClass().getResourceAsStream("sling-folder-nodetype.xml");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/nested/.content.xml"), childContentXml);
    Matcher<Node> postConditions = allOf(hasPath("/content/test-root"), hasPrimaryType("sling:Folder"), hasChildrenCount(1));
    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);
    // update jcr:title for /content/test-root
    InputStream updatedContentXml = getClass().getResourceAsStream("sling-folder-nodetype-with-title.xml");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), updatedContentXml);
    poller.pollUntil(new Callable<Node>() {

        @Override
        public Node call() throws RepositoryException {
            return repo.getNode("/content/test-root");
        }
    }, allOf(hasPath("/content/test-root"), hasChildrenCount(1), hasPropertyValue("jcr:title", "Some Folder")));
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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 35 with ProjectAdapter

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

the class JcrPartialCoverageAggregatesDeploymentTest method deployNodeWithContentXmlInParentFolder.

@Test
public void deployNodeWithContentXmlInParentFolder() 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"));
    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");
        }
    }, hasPrimaryType("nt:unstructured"));
    // 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"));
    // first wait until the sling:Folder child node is created, to ensure that all changes are processed
    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"));
    // then, verify that the nt:unstructured node is correctly written
    poller.pollUntil(new Callable<Node>() {

        @Override
        public Node call() throws RepositoryException {
            return repo.getNode("/content/test-root/mapping/jcr:content/par");
        }
    }, 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)

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