This is an automated email from the ASF dual-hosted git repository. apelluru pushed a commit to branch SLING-11565 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcebuilder.git
commit 18d79dc18dd8f0ebdd96af4ce1690de484ee07ef Author: Ashok Pelluru <[email protected]> AuthorDate: Fri Sep 2 20:53:33 2022 +0200 SLING-11565: upgrade to 49 and IT's using paxexam --- pom.xml | 475 +++++++++------------ .../customizers/RBIT_TeleporterCustomizer.java | 46 -- .../sling/resourcebuilder/it/FileRetrievalIT.java | 64 +-- .../resourcebuilder/it/ResourceBuilderIT.java | 105 +++-- .../it/ResourceBuilderTestSupport.java | 135 ++++++ .../sling/resourcebuilder/it/TestEnvironment.java | 56 --- .../resourcebuilder/test/ResourceAssertions.java | 11 +- src/test/resources/files/models.js | 16 + src/test/resources/files/text.html | 16 + 9 files changed, 459 insertions(+), 465 deletions(-) diff --git a/pom.xml b/pom.xml index a1ed3ba..81000de 100644 --- a/pom.xml +++ b/pom.xml @@ -1,280 +1,195 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.sling</groupId> - <artifactId>sling</artifactId> - <version>34</version> - <relativePath /> - </parent> - - <artifactId>org.apache.sling.resourcebuilder</artifactId> - <version>1.0.5-SNAPSHOT</version> - <packaging>bundle</packaging> - - <name>Apache Sling Resource Builder</name> - <description>Utilities to create Sling content</description> - - <properties> - <!-- Set this to run the server on a specific port - <http.port></http.port> - --> - - <!-- Set this to run tests against an existing server instance --> - <keepJarRunning>false</keepJarRunning> - - <!-- - Options for the VM that executes our runnable jar. - Set debugging options here to debug teleported tests. - --> - <jar.executor.vm.options>-Xmx512m</jar.executor.vm.options> - - <!-- Options for the jar to execute. $JAREXEC_SERVER_PORT$ is replaced by the - selected port number --> - <jar.executor.jar.options>-p $JAREXEC_SERVER_PORT$</jar.executor.jar.options> - </properties> - <scm> - <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcebuilder.git</connection> - <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcebuilder.git</developerConnection> - <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-resourcebuilder.git</url> - <tag>HEAD</tag> - </scm> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - </plugin> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - <exclude>src/test/resources/**</exclude> - <exclude>sling/**</exclude> - <exclude>infinitest.filters</exclude> - </excludes> - </configuration> - </plugin> - <plugin> - <!-- Find free ports to run our server --> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>reserve-server-port</id> - <goals> - <goal>reserve-network-port</goal> - </goals> - <phase>process-resources</phase> - <configuration> - <portNames> - <portName>http.port</portName> - </portNames> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <artifactId>maven-clean-plugin</artifactId> - <configuration> - <filesets> - <fileset> - <directory>${basedir}</directory> - <includes> - <!-- sling folder is the workdir of the executable jar that we test --> - <include>sling/**</include> - </includes> - </fileset> - </filesets> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <executions> - <execution> - <id>integration-test</id> - <goals> - <goal>integration-test</goal> - </goals> - </execution> - <execution> - <id>verify</id> - <goals> - <goal>verify</goal> - </goals> - </execution> - </executions> - <configuration> - <systemPropertyVariables> - <!-- these are the minimal options required for the jar executor, see bundle-with-it module for more --> - <keepJarRunning>${keepJarRunning}</keepJarRunning> - <jar.executor.jar.options>${jar.executor.jar.options}</jar.executor.jar.options> - <jar.executor.vm.options>${jar.executor.vm.options}</jar.executor.vm.options> - <jar.executor.server.port>${http.port}</jar.executor.server.port> - <additional.bundles.path>${project.build.directory}</additional.bundles.path> - <server.ready.path.1>/:script src="system/sling.js"</server.ready.path.1> - <server.ready.path.2>/.explorer.html:href="/libs/sling/explorer/css/explorer.css"</server.ready.path.2> - <server.ready.path.3>/sling-test/sling/sling-test.html:Sling client library tests</server.ready.path.3> - - <!-- Additional bundles to install for testing --> - <sling.additional.bundle.1>org.apache.sling.junit.core</sling.additional.bundle.1> - <sling.additional.bundle.2>${project.artifactId}-${project.version}.jar</sling.additional.bundle.2> - </systemPropertyVariables> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <executions> - <execution> - <id>copy-runnable-jar</id> - <goals> - <goal>copy-dependencies</goal> - </goals> - <phase>process-resources</phase> - <configuration> - <includeArtifactIds>org.apache.sling.launchpad</includeArtifactIds> - <excludeTransitive>true</excludeTransitive> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - </configuration> - </execution> - <execution> - <!-- - Consider all dependencies as candidates to be installed - as additional bundles. We use system properties to define - which bundles to install in which order. - --> - <id>copy-additional-bundles</id> - <goals> - <goal>copy-dependencies</goal> - </goals> - <phase>process-resources</phase> - <configuration> - <outputDirectory>${project.build.directory}</outputDirectory> - <excludeTransitive>true</excludeTransitive> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <dependencies> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.annotation.versioning</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.service.component.annotations</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.api</artifactId> - <version>2.3.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.commons.mime</artifactId> - <version>2.1.2</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.4</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId> - <version>1.1.14</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.junit.core</artifactId> - <version>1.0.18</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.testing.tools</artifactId> - <version>1.0.14</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.junit.teleporter</artifactId> - <version>1.0.8</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>2.21.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.launchpad</artifactId> - <version>8</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.jetbrains</groupId> - <artifactId>annotations</artifactId> - <scope>provided</scope> - </dependency> - </dependencies> - -</project> +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling-bundle-parent</artifactId> + <version>49</version> + <relativePath /> + </parent> + + <artifactId>org.apache.sling.resourcebuilder</artifactId> + <version>1.0.5-SNAPSHOT</version> + + <name>Apache Sling Resource Builder</name> + <description>Utilities to create Sling content</description> + + <properties> + <org.ops4j.pax.exam.version>4.13.4</org.ops4j.pax.exam.version> + </properties> + <scm> + <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcebuilder.git</connection> + <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourcebuilder.git</developerConnection> + <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-resourcebuilder.git</url> + <tag>HEAD</tag> + </scm> + + <build> + <plugins> + <plugin> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + <configuration> + <redirectTestOutputToFile>true</redirectTestOutputToFile> + <systemPropertyVariables combine.children="append"> + <bundle.filename>${basedir}/target/${project.build.finalName}.jar</bundle.filename> + </systemPropertyVariables> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.servicemix.tooling</groupId> + <artifactId>depends-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.annotation.versioning</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.service.component.annotations</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.3.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.mime</artifactId> + <version>2.1.2</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.jetbrains</groupId> + <artifactId>annotations</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Test Dependencies --> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.paxexam</artifactId> + <scope>test</scope> + <version>4.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam</artifactId> + <scope>test</scope> + <version>${org.ops4j.pax.exam.version}</version> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-cm</artifactId> + <scope>test</scope> + <version>${org.ops4j.pax.exam.version}</version> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-forked</artifactId> + <scope>test</scope> + <version>${org.ops4j.pax.exam.version}</version> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-junit4</artifactId> + <scope>test</scope> + <version>${org.ops4j.pax.exam.version}</version> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-link-mvn</artifactId> + <scope>test</scope> + <version>${org.ops4j.pax.exam.version}</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + <scope>test</scope> + <version>7.0.5</version> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <version>4.2.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId> + <version>1.1.14</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>4.5.1</version> + <scope>test</scope> + </dependency> + </dependencies> + +</project> diff --git a/src/test/java/org/apache/sling/junit/teleporter/customizers/RBIT_TeleporterCustomizer.java b/src/test/java/org/apache/sling/junit/teleporter/customizers/RBIT_TeleporterCustomizer.java deleted file mode 100644 index 765923b..0000000 --- a/src/test/java/org/apache/sling/junit/teleporter/customizers/RBIT_TeleporterCustomizer.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.junit.teleporter.customizers; - -import org.apache.sling.junit.rules.TeleporterRule; -import org.apache.sling.resourcebuilder.api.ResourceBuilder; -import org.apache.sling.testing.teleporter.client.ClientSideTeleporter; -import org.apache.sling.testing.tools.sling.SlingTestBase; -import org.apache.sling.testing.tools.sling.TimeoutsProvider; - -import aQute.bnd.osgi.Constants; - -/** Setup the ClientSideTeleporter for our integration tests. - */ -public class RBIT_TeleporterCustomizer implements TeleporterRule.Customizer { - - private final static SlingTestBase S = new SlingTestBase(); - - @Override - public void customize(TeleporterRule t, String options) { - final ClientSideTeleporter cst = (ClientSideTeleporter)t; - cst.setBaseUrl(S.getServerBaseUrl()); - cst.setServerCredentials(S.getServerUsername(), S.getServerPassword()); - cst.setTestReadyTimeoutSeconds(TimeoutsProvider.getInstance().getTimeout(5)); - - // Make sure our bundle API is imported instead of embedded - final String apiPackage = ResourceBuilder.class.getPackage().getName(); - cst.includeDependencyPrefix("org.apache.sling.resourcebuilder"); - cst.excludeDependencyPrefix(apiPackage); - cst.getAdditionalBundleHeaders().put(Constants.IMPORT_PACKAGE, apiPackage); - } -} \ No newline at end of file diff --git a/src/test/java/org/apache/sling/resourcebuilder/it/FileRetrievalIT.java b/src/test/java/org/apache/sling/resourcebuilder/it/FileRetrievalIT.java index ea58168..eb25855 100644 --- a/src/test/java/org/apache/sling/resourcebuilder/it/FileRetrievalIT.java +++ b/src/test/java/org/apache/sling/resourcebuilder/it/FileRetrievalIT.java @@ -18,65 +18,69 @@ */ package org.apache.sling.resourcebuilder.it; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.io.InputStream; - -import javax.servlet.ServletException; - import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceMetadata; -import org.apache.sling.junit.rules.TeleporterRule; import org.apache.sling.resourcebuilder.test.ResourceAssertions; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.ops4j.pax.exam.CoreOptions.options; /** Verify that our file structure is correct, * by creating a file and retrieving it via * a Sling request. */ -@SuppressWarnings("null") -public class FileRetrievalIT { - - @Rule - public final TeleporterRule teleporter = - TeleporterRule - .forClass(getClass(), "RBIT_Teleporter") - .withResources("/files/"); - - private TestEnvironment E; - private ResourceAssertions A; +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerClass.class) +public class FileRetrievalIT extends ResourceBuilderTestSupport { + + private ResourceAssertions resourceAssertions; @Before public void setup() throws LoginException, PersistenceException { - E = new TestEnvironment(teleporter); - A = new ResourceAssertions(E.parent.getPath(), E.resolver); + initializeTestResources(); + resourceAssertions = new ResourceAssertions(parent.getPath(), resolver()); } @After - public void cleanup() throws PersistenceException { - E.cleanup(); + public void cleanup() throws PersistenceException, LoginException { + cleanupTestResources(); + } + + @Configuration + public Option[] configuration() { + return options( + baseConfiguration() + ); } @Test - public void createAndeRtrieveFile() throws IOException, ServletException { + public void createAndRetrieveFile() throws IOException { final String expected = "yes, it worked"; final long startTime = System.currentTimeMillis(); final String mimeType = "application/javascript"; - E.builder + builder .resource("somefolder") .file("the-model.js", getClass().getResourceAsStream("/files/models.js")) .commit(); - final Resource r = A.assertFile("somefolder/the-model.js", mimeType, expected, -1L); + final Resource r = resourceAssertions.assertFile("somefolder/the-model.js", mimeType, expected, -1L); final ResourceMetadata meta = r.getResourceMetadata(); assertTrue("Expecting a last modified time >= startTime", meta.getModificationTime() >= startTime); @@ -85,7 +89,7 @@ public class FileRetrievalIT { final InputStream is = r.adaptTo(InputStream.class); assertNotNull("Expecting InputStream for file resource " + r.getPath(), is); try { - final String content = A.readFully(is); + final String content = resourceAssertions.readFully(is); assertTrue("Expecting [" + expected + "] in content", content.contains(expected)); } finally { is.close(); diff --git a/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java b/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java index ace30df..00db39e 100644 --- a/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java +++ b/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderIT.java @@ -18,93 +18,106 @@ */ package org.apache.sling.resourcebuilder.it; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.Comparator; - import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.PersistenceException; -import org.apache.sling.junit.rules.TeleporterRule; +import org.apache.sling.resourcebuilder.impl.MapArgsConverter; import org.apache.sling.resourcebuilder.test.ResourceAssertions; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.ProbeBuilder; +import org.ops4j.pax.exam.TestProbeBuilder; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; +import org.osgi.framework.Constants; + +import java.io.IOException; +import java.util.Comparator; + +import static org.junit.Assert.fail; +import static org.ops4j.pax.exam.CoreOptions.options; /** Server-side integration test for the * ResourceBuilder, acquired via the ResourceBuilderProvider */ -@SuppressWarnings("null") -public class ResourceBuilderIT { - - @Rule - public final TeleporterRule teleporter = - TeleporterRule - .forClass(getClass(), "RBIT_Teleporter") - .withResources("/files/"); - - private TestEnvironment E; - private ResourceAssertions A; +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerClass.class) +public class ResourceBuilderIT extends ResourceBuilderTestSupport { + + private ResourceAssertions resourceAssertions; @Before public void setup() throws LoginException, PersistenceException { - E = new TestEnvironment(teleporter); - A = new ResourceAssertions(E.parent.getPath(), E.resolver); + initializeTestResources(); + resourceAssertions = new ResourceAssertions(parent.getPath(), resolver()); } @After - public void cleanup() throws PersistenceException { - E.cleanup(); + public void cleanup() throws PersistenceException, LoginException { + cleanupTestResources(); + } + + @Configuration + public Option[] configuration() { + return options( + baseConfiguration() + ); + } + + @ProbeBuilder + public TestProbeBuilder probeConfiguration(final TestProbeBuilder probeBuilder) { + probeBuilder.setHeader(Constants.EXPORT_PACKAGE, MapArgsConverter.class.getPackage().getName()); + + return probeBuilder; } - @Test public void simpleResource() { - E.builder - .resource("foo", "title", E.testRootPath) - .commit(); - A.assertProperties("foo", "title", E.testRootPath); + builder.resource("foo", "title", testRootPath).commit(); + + resourceAssertions.assertProperties("foo", "title", testRootPath); } @Test public void smallTreeWithFile() throws IOException { - E.builder + builder .resource("somefolder") .file("the-model.js", getClass().getResourceAsStream("/files/models.js"), "foo", 42L) .commit(); - - A.assertFile("somefolder/the-model.js", "foo", "yes, it worked", 42L); + + resourceAssertions.assertFile("somefolder/the-model.js", "foo", "yes, it worked", 42L); } @Test public void fileAutoValues() throws IOException { final long startTime = System.currentTimeMillis(); - E.builder + builder .resource("a/b/c") .file("model2.js", getClass().getResourceAsStream("/files/models.js")) .commit(); - final Comparator<Long> moreThanStartTime = new Comparator<Long>() { - @Override - public int compare(Long expected, Long fromResource) { - if(fromResource >= startTime) { - return 0; - } - fail("last-modified is not >= than current time:" + fromResource + " < " + startTime); - return -1; + final Comparator<Long> moreThanStartTime = (expected, fromResource) -> { + if(fromResource >= startTime) { + return 0; } + fail("last-modified is not >= than current time:" + fromResource + " < " + startTime); + return -1; }; - - A.assertFile("a/b/c/model2.js", "application/javascript", "yes, it worked", startTime, moreThanStartTime); + + resourceAssertions.assertFile("a/b/c/model2.js", "application/javascript", "yes, it worked", startTime, moreThanStartTime); } @Test - public void usingResolver() throws IOException { - E.builderService.forResolver(E.resolver).resource("foo/a/b").commit(); - E.builderService.forResolver(E.resolver).resource("foo/c/d").commit(); - A.assertResource("/foo/a/b"); - A.assertResource("/foo/c/d"); + public void usingResolver() throws LoginException { + builderService.forResolver(resolver()).resource("foo/a/b").commit(); + builderService.forResolver(resolver()).resource("foo/c/d").commit(); + + resourceAssertions.assertResource("/foo/a/b"); + resourceAssertions.assertResource("/foo/c/d"); } } diff --git a/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderTestSupport.java b/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderTestSupport.java new file mode 100644 index 0000000..ce5f734 --- /dev/null +++ b/src/test/java/org/apache/sling/resourcebuilder/it/ResourceBuilderTestSupport.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.resourcebuilder.it; +import org.apache.sling.resourcebuilder.impl.MapArgsConverter; +import org.ops4j.pax.exam.ProbeBuilder; +import org.ops4j.pax.exam.TestProbeBuilder; +import org.osgi.framework.BundleContext; + +import org.apache.sling.api.resource.LoginException; +import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.api.resource.ResourceResolverFactory; +import org.apache.sling.resourcebuilder.api.ResourceBuilder; +import org.apache.sling.resourcebuilder.api.ResourceBuilderFactory; +import org.apache.sling.testing.paxexam.TestSupport; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.options.ModifiableCompositeOption; +import org.ops4j.pax.exam.options.OptionalCompositeOption; +import org.ops4j.pax.exam.options.extra.VMOption; +import org.osgi.framework.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static org.apache.sling.testing.paxexam.SlingOptions.awaitility; +import static org.apache.sling.testing.paxexam.SlingOptions.logback; +import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar; +import static org.awaitility.Awaitility.await; +import static org.ops4j.pax.exam.CoreOptions.composite; +import static org.ops4j.pax.exam.CoreOptions.junitBundles; +import static org.ops4j.pax.exam.CoreOptions.vmOption; +import static org.ops4j.pax.exam.CoreOptions.when; +import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration; + +public class ResourceBuilderTestSupport extends TestSupport { + + private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBuilderTestSupport.class); + + @Inject + private BundleContext bundleContext; + + @Inject + protected ResourceResolverFactory resourceResolverFactory; + + @Inject + protected ResourceBuilderFactory builderService; + + protected ResourceBuilder builder; + protected String testRootPath; + protected Resource parent; + + public ModifiableCompositeOption baseConfiguration() { + return composite( + super.baseConfiguration(), + slingQuickstart(), + //Sling ResourceBuilder + testBundle("bundle.filename"), + logback(), + awaitility(), + junitBundles(), + newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist") + .put("whitelist.bundles.regexp", "PAXEXAM-PROBE-.*") + .asOption(), + + optionalRemoteDebug(), + jacoco() + ); + } + + protected Option slingQuickstart() { + final int httpPort = findFreePort(); + final String workingDirectory = workingDirectory(); + return slingQuickstartOakTar(workingDirectory, httpPort); + } + + /** + * Optionally configure remote debugging on the port supplied by the "debugPort" + * system property. + */ + protected ModifiableCompositeOption optionalRemoteDebug() { + VMOption option = null; + String property = System.getProperty("debugPort"); + if (property != null) { + option = vmOption(String.format("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%s", property)); + } + return composite(option); + } + + // remove with Testing PaxExam 4.0 + protected OptionalCompositeOption jacoco() { + final String jacocoCommand = System.getProperty("jacoco.command"); + final VMOption option = Objects.nonNull(jacocoCommand) && !jacocoCommand.trim().isEmpty() ? vmOption(jacocoCommand) : null; + return when(Objects.nonNull(option)).useOptions(option); + } + + ResourceResolver resolver() throws LoginException { + return resourceResolverFactory.getAdministrativeResourceResolver(null); + } + + void initializeTestResources() throws LoginException, PersistenceException { + testRootPath = getClass().getSimpleName() + "-" + UUID.randomUUID(); + + final Resource root = resolver().getResource("/"); + parent = resolver().create(root, testRootPath, null); + builder = builderService.forParent(parent); + } + + void cleanupTestResources() throws PersistenceException, LoginException { + if(resolver() != null && parent != null) { + resolver().delete(parent); + resolver().commit(); + } + } +} diff --git a/src/test/java/org/apache/sling/resourcebuilder/it/TestEnvironment.java b/src/test/java/org/apache/sling/resourcebuilder/it/TestEnvironment.java deleted file mode 100644 index 8b0334a..0000000 --- a/src/test/java/org/apache/sling/resourcebuilder/it/TestEnvironment.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sling.resourcebuilder.it; - -import java.util.UUID; - -import org.apache.sling.api.resource.LoginException; -import org.apache.sling.api.resource.PersistenceException; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; -import org.apache.sling.api.resource.ResourceResolverFactory; -import org.apache.sling.junit.rules.TeleporterRule; -import org.apache.sling.resourcebuilder.api.ResourceBuilder; -import org.apache.sling.resourcebuilder.api.ResourceBuilderFactory; - -@SuppressWarnings("null") -class TestEnvironment { - - final ResourceBuilder builder; - final ResourceBuilderFactory builderService; - final ResourceResolver resolver; - final String testRootPath; - final Resource parent; - - TestEnvironment(TeleporterRule teleporter) throws LoginException, PersistenceException { - testRootPath = getClass().getSimpleName() + "-" + UUID.randomUUID().toString(); - resolver = teleporter.getService(ResourceResolverFactory.class).getAdministrativeResourceResolver(null); - final Resource root = resolver.getResource("/"); - parent = resolver.create(root, testRootPath, null); - builderService = teleporter.getService(ResourceBuilderFactory.class); - builder = builderService.forParent(parent); - } - - void cleanup() throws PersistenceException { - if(resolver != null && parent != null) { - resolver.delete(parent); - resolver.commit(); - } - } -} \ No newline at end of file diff --git a/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java b/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java index 7abad01..5e522f2 100644 --- a/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java +++ b/src/test/java/org/apache/sling/resourcebuilder/test/ResourceAssertions.java @@ -60,14 +60,11 @@ public class ResourceAssertions { /** Assert that a file exists and verify its properties. */ public Resource assertFile(String path, String mimeType, String expectedContent, Long lastModified) throws IOException { - final Comparator<Long> defaultComparator = new Comparator<Long>() { - @Override - public int compare(Long expected, Long fromResource) { - if(expected == -1) { - return 0; - } - return expected.compareTo(fromResource); + final Comparator<Long> defaultComparator = (expected, fromResource) -> { + if(expected == -1) { + return 0; } + return expected.compareTo(fromResource); }; return assertFile(path, mimeType, expectedContent, lastModified, defaultComparator); } diff --git a/src/test/resources/files/models.js b/src/test/resources/files/models.js index 142f8d3..6a9a508 100644 --- a/src/test/resources/files/models.js +++ b/src/test/resources/files/models.js @@ -1 +1,17 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ function someJavascriptFunction() { return "yes, it worked." } \ No newline at end of file diff --git a/src/test/resources/files/text.html b/src/test/resources/files/text.html index 57dfc39..2994ef8 100644 --- a/src/test/resources/files/text.html +++ b/src/test/resources/files/text.html @@ -1,3 +1,19 @@ +<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> <html> This is an html file </html> \ No newline at end of file
