Skip to content

Commit

Permalink
Upgrade all tests to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
mkjsix committed Apr 18, 2023
1 parent bb0c919 commit d859462
Show file tree
Hide file tree
Showing 69 changed files with 2,991 additions and 2,983 deletions.
14 changes: 7 additions & 7 deletions commons/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -68,17 +68,17 @@
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<!-- BEGIN Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
*/
package org.restheart.cache.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.restheart.cache.Cache;

/**
Expand Down Expand Up @@ -66,7 +67,7 @@ public void testPutNull() {
}

@Test
@Ignore // this is time dependant and can fail during CI
@Disabled // this is time dependant and can fail during CI
public void testRemoval() {
String key = "B";
Integer value = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
*/
package org.restheart.exchange;

import io.undertow.server.handlers.form.FormData;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.bson.BsonDocument;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import io.undertow.server.handlers.form.FormData;

/**
*
Expand All @@ -39,13 +41,15 @@ public BodyInjectorHandlerTest() {

/**
* If formData contains a PROPERTIES part, then must be valid JSON
*
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
@Test
public void test_extractProperties() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
public void test_extractProperties()
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
final String jsonString = "{\"key1\": \"value1\", \"key2\": \"value2\"}";
FormData formData = new FormData(1);

Expand Down
69 changes: 34 additions & 35 deletions commons/src/test/java/org/restheart/exchange/BsonRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@

package org.restheart.exchange;

import io.undertow.server.HttpServerExchange;
import io.undertow.util.HttpString;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.undertow.server.HttpServerExchange;
import io.undertow.util.HttpString;

/**
*
* @author Maurizio Turatti {@literal <maurizio@softinstigate.com>}
Expand All @@ -48,27 +46,28 @@ public class BsonRequestTest {
/**
*
*/
@BeforeClass
@BeforeAll
public static void setUpClass() {
}

/**
*
*/
@AfterClass
@AfterAll
public static void tearDownClass() {
}

/**
*
*
* public TestRule watcher = new TestWatcher() {
*
* @Override
* protected void starting(Description description) {
* LOG.info("executing test {}", description.toString());
* }
* };
*/
@Rule
public TestRule watcher = new TestWatcher() {
@Override
protected void starting(Description description) {
LOG.info("executing test {}", description.toString());
}
};

/**
*
Expand All @@ -79,14 +78,14 @@ public BsonRequestTest() {
/**
*
*/
@Before
@BeforeEach
public void setUp() {
}

/**
*
*/
@After
@AfterEach
public void tearDown() {
}

Expand Down Expand Up @@ -154,49 +153,49 @@ public void testGetMappedRequestUri() {
String whereUri = "/";

MongoRequest request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/mycollection", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/mycollection");

whatUri = "*";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/");

whatUri = "*";
whereUri = "/data";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/");

whatUri = "/data";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/data", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/data");

whatUri = "/db/coll";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/coll", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/coll");

whatUri = "/db/coll/doc";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/coll/doc", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/coll/doc");

whatUri = "/db/coll/";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/coll", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/coll");

whatUri = "/db/coll////";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/coll", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/coll");
}

/**
Expand All @@ -212,24 +211,24 @@ public void testGetMappedRequestUri2() {
String whereUri = "/";

MongoRequest request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/mycollection/x", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/mycollection/x");

whatUri = "*";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/x", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/x");

whatUri = "db";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/x", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/x");

whatUri = "db/coll";
whereUri = "/";

request = MongoRequest.init(ex, whereUri, whatUri);
assertEquals("/db/coll/x", request.getUnmappedRequestUri());
assertEquals( request.getUnmappedRequestUri(), "/db/coll/x");
}
}
35 changes: 9 additions & 26 deletions commons/src/test/java/org/restheart/exchange/RequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,16 @@

package org.restheart.exchange;

import io.undertow.server.HttpServerExchange;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RequestTest {
private static final Logger LOG = LoggerFactory.getLogger(RequestTest.class);
import org.junit.jupiter.api.Test;

/**
*
*/
@Rule
public TestRule watcher = new TestWatcher() {
@Override
protected void starting(Description description) {
LOG.info("executing test {}", description.toString());
}
};
import io.undertow.server.HttpServerExchange;

public class RequestTest {

@Test
public void testGetPath() {
Expand All @@ -59,11 +42,11 @@ public void testGetPath() {

assertEquals(path, req.getPath());
var params = req.getPathParams("/{one}/{two}");
assertEquals("foo", params.get("one"));
assertEquals("bar", params.get("two"));
assertEquals(params.get("one"), "foo");
assertEquals(params.get("two"), "bar");

var params2 = req.getPathParams("/{one}/*");
assertEquals("foo", params2.get("one"));
assertEquals(params2.get("one"), "foo");

var params3 = req.getPathParams("/{one}/{two}/*");
assertNull(params3.get("one"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
*/
package org.restheart.security;

import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -42,30 +39,22 @@ public class AclVarsInterpolatorTest {

private static final Logger LOG = LoggerFactory.getLogger(AclVarsInterpolatorTest.class);

@BeforeClass
@BeforeAll
public static void setUpClass() {
}

@AfterClass
@AfterAll
public static void tearDownClass() {
}

@Rule
public TestRule watcher = new TestWatcher() {
@Override
protected void starting(Description description) {
LOG.info("executing test {}", description.toString());
}
};

public AclVarsInterpolatorTest() {
}

@Before
@BeforeEach
public void setUp() {
}

@After
@AfterEach
public void tearDown() {
}

Expand Down
Loading

0 comments on commit d859462

Please sign in to comment.