Search in sources :

Example 1 with ServerAdapter

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

the class BundleDeploymentTest method deployBundleOnServer.

private void deployBundleOnServer(boolean installBundleLocally) throws Exception {
    wstServer.waitForServerToStart();
    // create faceted project
    IProject bundleProject = projectRule.getProject();
    ProjectAdapter project = new ProjectAdapter(bundleProject);
    project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
    // configure java project with dependencies
    MavenDependency slingApiDep = new MavenDependency().groupId("org.apache.sling").artifactId("org.apache.sling.api").version("2.2.0");
    MavenDependency servletApiDep = new MavenDependency().groupId("javax.servlet").artifactId("servlet-api").version("2.4");
    project.configureAsJavaProject(slingApiDep, servletApiDep);
    // create DS component class
    InputStream simpleServlet = getClass().getResourceAsStream("SimpleServlet.java.v1.txt");
    project.createOrUpdateFile(Path.fromPortableString("src/example/SimpleServlet.java"), simpleServlet);
    // create DS component descriptor
    InputStream servletDescriptor = getClass().getResourceAsStream("SimpleServlet.xml");
    project.createOrUpdateFile(Path.fromPortableString("src/OSGI-INF/SimpleServlet.xml"), servletDescriptor);
    // create manifest
    OsgiBundleManifest manifest = OsgiBundleManifest.symbolicName("test.bundle001").version("1.0.0.SNAPSHOT").name("Test bundle").serviceComponent("OSGI-INF/SimpleServlet.xml").importPackage("javax.servlet,org.apache.sling.api,org.apache.sling.api.servlets");
    project.createOsgiBundleManifest(manifest);
    // install bundle facet
    project.installFacet("sling.bundle", "1.0");
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.setAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, installBundleLocally);
    server.installModule(bundleProject);
    final RepositoryAccessor repo = new RepositoryAccessor(config);
    Poller poller = new Poller();
    poller.pollUntil(new Callable<Void>() {

        @Override
        public Void call() throws HttpException, IOException {
            repo.assertGetIsSuccessful("simple-servlet", "Version 1");
            return null;
        }
    }, nullValue(Void.class));
    // update DS component class
    InputStream simpleServlet2 = getClass().getResourceAsStream("SimpleServlet.java.v2.txt");
    project.createOrUpdateFile(Path.fromPortableString("src/example/SimpleServlet.java"), simpleServlet2);
    poller.pollUntil(new Callable<Void>() {

        @Override
        public Void call() throws HttpException, IOException {
            repo.assertGetIsSuccessful("simple-servlet", "Version 2");
            return null;
        }
    }, nullValue(Void.class));
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) InputStream(java.io.InputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) OsgiBundleManifest(org.apache.sling.ide.test.impl.helpers.OsgiBundleManifest) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) HttpException(org.apache.commons.httpclient.HttpException) Poller(org.apache.sling.ide.test.impl.helpers.Poller) MavenDependency(org.apache.sling.ide.test.impl.helpers.MavenDependency)

Example 2 with ServerAdapter

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

the class ContentDeploymentTest method deployFileWithAttachedMetadata.

@Test
public void deployFileWithAttachedMetadata() throws Exception {
    wstServer.waitForServerToStart();
    // 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");
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.installModule(contentProject);
    // create filter.xml
    project.createVltFilterWithRoots("/test");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/hello.esp"), new ByteArrayInputStream("// not really javascript".getBytes()));
    // verify that file is created
    final RepositoryAccessor repo = new RepositoryAccessor(config);
    Poller poller = new Poller();
    assertThatNode(repo, poller, "/test/hello.esp", hasPrimaryType("nt:file"));
    InputStream contentXml = getClass().getResourceAsStream("file-custom-mimetype.xml");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/hello.esp.dir/.content.xml"), contentXml);
    assertThatNode(repo, poller, "/test/hello.esp/jcr:content", hasPropertyValue("jcr:mimeType", "text/javascript"));
}
Also used : ServerAdapter(org.apache.sling.ide.test.impl.helpers.ServerAdapter) RepositoryAccessor(org.apache.sling.ide.test.impl.helpers.RepositoryAccessor) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) IProject(org.eclipse.core.resources.IProject) Poller(org.apache.sling.ide.test.impl.helpers.Poller) Test(org.junit.Test)

Example 3 with ServerAdapter

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

the class ContentImportTest method importFileWithNamespacedName.

@Test
public void importFileWithNamespacedName() throws Exception {
    RepositoryAccessor repo = new RepositoryAccessor(config);
    // 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.createVltFilterWithRoots("/content/test-root");
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/hello.txt"), new ByteArrayInputStream("hello, world".getBytes()));
    wstServer.waitForServerToStart();
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.installModule(contentProject);
    deh.clearUnexpectedEventsAfterSettling();
    repo.createFile("/content/test-root/sling:file", "some_content".getBytes());
    runImport(contentProject);
    assertThat(contentProject, hasFile("jcr_root/content/test-root/_sling_file"));
}
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 4 with ServerAdapter

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

the class ContentDeploymentTest method deployFileWithMissingParentFromRepository.

/**
     * This test validates that if the parent of a resource that does not exist in the repository the resource is
     * successfully created
     * 
     * @throws Exception
     */
@Test
public void deployFileWithMissingParentFromRepository() throws Exception {
    wstServer.waitForServerToStart();
    // 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");
    ServerAdapter server = new ServerAdapter(wstServer.getServer());
    server.installModule(contentProject);
    // create filter.xml
    project.createVltFilterWithRoots("/test");
    // create file
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/demo/nested/structure/hello.txt"), new ByteArrayInputStream("hello, world".getBytes()));
    // verify that file is created
    final RepositoryAccessor repo = new RepositoryAccessor(config);
    Poller poller = new Poller();
    poller.pollUntil(new Callable<Node>() {

        @Override
        public Node call() throws RepositoryException {
            return repo.getNode("/test/demo/nested/structure/hello.txt");
        }
    }, hasFileContent("hello, world"));
}
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 5 with ServerAdapter

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

Aggregations

ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)28 ServerAdapter (org.apache.sling.ide.test.impl.helpers.ServerAdapter)28 IProject (org.eclipse.core.resources.IProject)28 RepositoryAccessor (org.apache.sling.ide.test.impl.helpers.RepositoryAccessor)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)11 Session (javax.jcr.Session)3 IOException (java.io.IOException)2 HttpException (org.apache.commons.httpclient.HttpException)2 ValueFactory (javax.jcr.ValueFactory)1 SyncDir (org.apache.sling.ide.eclipse.ui.nav.model.SyncDir)1 MavenDependency (org.apache.sling.ide.test.impl.helpers.MavenDependency)1 OsgiBundleManifest (org.apache.sling.ide.test.impl.helpers.OsgiBundleManifest)1 IFolder (org.eclipse.core.resources.IFolder)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1