You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2022/09/09 06:32:44 UTC
[sling-org-apache-sling-jcr-oak-server] branch master updated: SLING-11474 Update Testing PaxExam to 4.0.0
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-oak-server.git
The following commit(s) were added to refs/heads/master by this push:
new 034ea0f SLING-11474 Update Testing PaxExam to 4.0.0
034ea0f is described below
commit 034ea0fac40a0d05e075fb52fbafe91cc2a34864
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Fri Sep 9 08:32:27 2022 +0200
SLING-11474 Update Testing PaxExam to 4.0.0
* use Testing PaxExam 4.0.0-SNAPSHOT
* update test dependencies
* use Hamcrest's assertThat
---
pom.xml | 10 ++++++--
.../sling/jcr/oak/server/it/OakServerIT.java | 30 +++++++++++-----------
.../jcr/oak/server/it/OakServerTestSupport.java | 29 +++++----------------
.../oak/server/it/ResourceTypeResolutionIT.java | 21 +++++++--------
.../sling/jcr/oak/server/it/Sling9719IT.java | 10 ++++----
.../sling/jcr/oak/server/it/Sling9826IT.java | 19 +++++++-------
6 files changed, 53 insertions(+), 66 deletions(-)
diff --git a/pom.xml b/pom.xml
index 16c330a..bfa8ce7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,7 +103,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
- <version>7.0.3</version>
+ <version>7.0.5</version>
<scope>test</scope>
</dependency>
<!-- Apache Jackrabbit -->
@@ -177,7 +177,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>3.1.0</version>
+ <version>4.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<!-- OSGi -->
@@ -223,6 +223,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>org.apache.servicemix.bundles.hamcrest</artifactId>
+ <version>1.3_1</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
diff --git a/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerIT.java b/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerIT.java
index 85611fe..be436d1 100644
--- a/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerIT.java
+++ b/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerIT.java
@@ -46,9 +46,9 @@ import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.fail;
@RunWith(PaxExam.class)
@@ -59,13 +59,13 @@ public class OakServerIT extends OakServerTestSupport {
@Test
public void testRepositoryPresent() {
- assertNotNull(repository);
+ assertThat(repository, notNullValue());
}
@Test
public void testLoginAdministrative() throws RepositoryException {
final Session s = repository.loginAdministrative(null);
- assertNotNull(s);
+ assertThat(s, notNullValue());
s.logout();
}
@@ -84,14 +84,14 @@ public class OakServerIT extends OakServerTestSupport {
@Test
public void testAnonymousLoginA() throws RepositoryException {
final Session s = repository.login();
- assertNotNull(s);
+ assertThat(s, notNullValue());
s.logout();
}
@Test
public void testAnonymousLoginB() throws RepositoryException {
final Session s = repository.login(null, null);
- assertNotNull(s);
+ assertThat(s, notNullValue());
s.logout();
}
@@ -110,9 +110,9 @@ public class OakServerIT extends OakServerTestSupport {
final String path = assertCreateRetrieveNode(null, "content/foo");
final Session s = repository.login();
try {
- assertTrue("Expecting anonymous to see " + path, s.itemExists(path));
+ assertThat("Expecting anonymous to see " + path, s.itemExists(path), is(true));
final Node n = s.getNode(path);
- assertEquals("Expecting anonymous to see the foo property", path, n.getProperty("foo").getString());
+ assertThat("Expecting anonymous to see the foo property", path, is(n.getProperty("foo").getString()));
} finally {
s.logout();
}
@@ -149,7 +149,7 @@ public class OakServerIT extends OakServerTestSupport {
it.next();
count++;
}
- assertEquals("Expected " + N_NODES + " result for query " + stmt, N_NODES, count);
+ assertThat("Expected " + N_NODES + " result for query " + stmt, count, is(N_NODES));
} finally {
s.logout();
}
@@ -169,7 +169,7 @@ public class OakServerIT extends OakServerTestSupport {
@SuppressWarnings("deprecation")
final Query q = s.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
final NodeIterator it = q.execute().getNodes();
- assertTrue("Expecting a non-empty result", it.hasNext());
+ assertThat("Expecting a non-empty result", it.hasNext(), is(true));
boolean found = false;
while(it.hasNext()) {
if(it.nextNode().getPath().equals(absPath)) {
@@ -177,7 +177,7 @@ public class OakServerIT extends OakServerTestSupport {
break;
}
}
- assertTrue("Expecting test node " + absPath + " to be found", found);
+ assertThat("Expecting test node " + absPath + " to be found", found, is(true));
} finally {
s.logout();
}
@@ -191,7 +191,7 @@ public class OakServerIT extends OakServerTestSupport {
final Node child = deleteAfterTests(s.getRootNode().addNode(path));
final Property p = child.setProperty("foo", "bar");
s.save();
- assertNotNull(p.getBinary().getStream());
+ assertThat(p.getBinary().getStream(), notNullValue());
} finally {
s.logout();
}
@@ -289,7 +289,7 @@ public class OakServerIT extends OakServerTestSupport {
new Retry(5000) {
@Override
protected void exec() throws Exception {
- assertTrue("Expecting JCR events after adding " + path, c.get() > 0);
+ assertThat("Expecting JCR events after adding " + path, c.get() > 0, is(true));
}
};
@@ -314,7 +314,7 @@ public class OakServerIT extends OakServerTestSupport {
new Retry(5000) {
@Override
protected void exec() throws Exception {
- assertTrue("Expecting JCR events after modifying " + path, c.get() > 0);
+ assertThat("Expecting JCR events after modifying " + path, c.get() > 0, is(true));
}
};
diff --git a/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerTestSupport.java b/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerTestSupport.java
index 66edd5c..9fcde4e 100644
--- a/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/oak/server/it/OakServerTestSupport.java
@@ -20,7 +20,6 @@ package org.apache.sling.jcr.oak.server.it;
import java.util.LinkedList;
import java.util.List;
-import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import javax.inject.Inject;
@@ -38,8 +37,6 @@ import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.testing.paxexam.TestSupport;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.options.OptionalCompositeOption;
-import org.ops4j.pax.exam.options.extra.VMOption;
import org.ops4j.pax.exam.util.PathUtils;
import org.osgi.framework.BundleContext;
@@ -47,13 +44,11 @@ import static org.apache.sling.testing.paxexam.SlingOptions.scr;
import static org.apache.sling.testing.paxexam.SlingOptions.slingJcr;
import static org.apache.sling.testing.paxexam.SlingOptions.slingJcrRepoinit;
import static org.apache.sling.testing.paxexam.SlingOptions.versionResolver;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
import static org.ops4j.pax.exam.CoreOptions.composite;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.vmOption;
-import static org.ops4j.pax.exam.CoreOptions.when;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
@@ -141,8 +136,8 @@ public abstract class OakServerTestSupport extends TestSupport {
session = repository.loginAdministrative(null);
final String path = relParentPath == null ? "/" + name : "/" + relParentPath + "/" + name;
final Node n = session.getNode(path);
- assertNotNull(n);
- assertEquals(propValue, n.getProperty(propName).getString());
+ assertThat(n, notNullValue());
+ assertThat(propValue, is(n.getProperty(propName).getString()));
return n.getPath();
} finally {
session.logout();
@@ -157,23 +152,13 @@ public abstract class OakServerTestSupport extends TestSupport {
public Option[] configuration() {
return new Option[]{
baseConfiguration(),
- launchpad(),
+ quickstart(),
// Sling JCR Oak Server
testBundle("bundle.filename"),
- // testing
- junitBundles(),
- jacoco() // remove with Testing PaxExam 4.0
};
}
- // 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);
- }
-
- protected Option launchpad() {
+ protected Option quickstart() {
final String repoinit = String.format("raw:file:%s/src/test/resources/repoinit.txt", PathUtils.getBaseDir());
final String slingHome = String.format("%s/sling", workingDirectory());
final String repositoryHome = String.format("%s/repository", slingHome);
diff --git a/src/test/java/org/apache/sling/jcr/oak/server/it/ResourceTypeResolutionIT.java b/src/test/java/org/apache/sling/jcr/oak/server/it/ResourceTypeResolutionIT.java
index f8c4ce4..a4eccb8 100644
--- a/src/test/java/org/apache/sling/jcr/oak/server/it/ResourceTypeResolutionIT.java
+++ b/src/test/java/org/apache/sling/jcr/oak/server/it/ResourceTypeResolutionIT.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.jcr.oak.server.it;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.util.HashMap;
import javax.jcr.Node;
@@ -36,6 +32,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
@RunWith(PaxExam.class)
public class ResourceTypeResolutionIT extends OakServerTestSupport {
@@ -60,19 +59,17 @@ public class ResourceTypeResolutionIT extends OakServerTestSupport {
authenticationInfo.put(ResourceResolverFactory.USER, "test-user");
authenticationInfo.put(ResourceResolverFactory.PASSWORD, "test".toCharArray());
- ResourceResolver testResolver = resourceResolverFactory.getResourceResolver(authenticationInfo);
- try {
+ try (ResourceResolver testResolver = resourceResolverFactory.getResourceResolver(authenticationInfo)) {
Resource resource = testResolver.getResource("/content/foo/bar");
- assertNotNull(resource);
- assertEquals("/content/foo/bar", resource.getPath());
- assertTrue(resource.isResourceType("types/foo/bar"));
+ assertThat(resource, notNullValue());
+ assertThat(resource.getPath(), is("/content/foo/bar"));
+ assertThat(resource.isResourceType("types/foo/bar"), is(true));
// this assertion causes the private ResourceResolverControl#getResourceTypeResourceResolver
// to be called, which needs to inject the resourceresolver bundle via the authenticationInfo
// see SLING-6329
- assertTrue(resource.isResourceType("types/foo/parent"));
- } finally {
- testResolver.close();
+ assertThat(resource.isResourceType("types/foo/parent"), is(true));
}
+
}
}
diff --git a/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9719IT.java b/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9719IT.java
index 12daffa..759a70d 100644
--- a/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9719IT.java
+++ b/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9719IT.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.jcr.oak.server.it;
-import static org.junit.Assert.assertEquals;
-
import javax.jcr.Node;
import org.apache.jackrabbit.api.JackrabbitSession;
@@ -28,6 +26,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
@RunWith(PaxExam.class)
public class Sling9719IT extends OakServerTestSupport {
@@ -52,7 +52,7 @@ public class Sling9719IT extends OakServerTestSupport {
adminSession.save();
// counter initial value is 0. the default value
- assertEquals(0, counter.getProperty("oak:counter").getLong());
+ assertThat(counter.getProperty("oak:counter").getLong(), is(0L));
// incrementing by 5 the counter
counter.setProperty("oak:increment", 5);
@@ -62,7 +62,7 @@ public class Sling9719IT extends OakServerTestSupport {
new Retry(5000) {
@Override
protected void exec() throws Exception {
- assertEquals(5, counter.getProperty("oak:counter").getLong());
+ assertThat(counter.getProperty("oak:counter").getLong(), is(5L));
}
};
@@ -74,7 +74,7 @@ public class Sling9719IT extends OakServerTestSupport {
new Retry(5000) {
@Override
protected void exec() throws Exception {
- assertEquals(4, counter.getProperty("oak:counter").getLong());
+ assertThat(counter.getProperty("oak:counter").getLong(), is(4L));
}
};
diff --git a/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9826IT.java b/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9826IT.java
index d3f8052..ee0d59b 100644
--- a/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9826IT.java
+++ b/src/test/java/org/apache/sling/jcr/oak/server/it/Sling9826IT.java
@@ -18,10 +18,6 @@
*/
package org.apache.sling.jcr.oak.server.it;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
@@ -39,6 +35,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
@RunWith(PaxExam.class)
public class Sling9826IT extends OakServerTestSupport {
@@ -97,7 +96,7 @@ public class Sling9826IT extends OakServerTestSupport {
// verify the id and lookup by id and query works
String id = child.getIdentifier();
- assertNotNull(adminSession.getNodeByIdentifier(id));
+ assertThat(adminSession.getNodeByIdentifier(id), notNullValue());
verifyLookupByIdentifier(id);
// move it
@@ -112,17 +111,17 @@ public class Sling9826IT extends OakServerTestSupport {
throws ItemNotFoundException, RepositoryException, InvalidQueryException {
// verify lookup by id
Node nodeByIdentifier = adminSession.getNodeByIdentifier(id);
- assertNotNull(nodeByIdentifier);
- assertEquals(id, nodeByIdentifier.getIdentifier());
+ assertThat(nodeByIdentifier, notNullValue());
+ assertThat(nodeByIdentifier.getIdentifier(), is(id));
// verify lookup by query
Query query = adminSession.getWorkspace().getQueryManager().createQuery(String.format("SELECT * FROM [nt:base] WHERE [jcr:uuid] = '%s'", id), Query.JCR_SQL2);
QueryResult execute = query.execute();
NodeIterator nodes = execute.getNodes();
- assertTrue(nodes.hasNext());
+ assertThat(nodes.hasNext(), is(true));
Node nextNode = nodes.nextNode();
- assertNotNull(nextNode);
- assertEquals(id, nextNode.getIdentifier());
+ assertThat(nextNode, notNullValue());
+ assertThat(nextNode.getIdentifier(), is(id));
}
}