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));
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations