diff --git a/src/main/java/org/swisspush/reststorage/FileSystemRestStorageRunner.java b/src/main/java/org/swisspush/reststorage/FileSystemRestStorageRunner.java index 7c0cb31..94e9ef6 100644 --- a/src/main/java/org/swisspush/reststorage/FileSystemRestStorageRunner.java +++ b/src/main/java/org/swisspush/reststorage/FileSystemRestStorageRunner.java @@ -3,7 +3,6 @@ import io.vertx.core.AsyncResult; import io.vertx.core.Vertx; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import static org.slf4j.LoggerFactory.getLogger; diff --git a/src/main/java/org/swisspush/reststorage/MimeTypeResolver.java b/src/main/java/org/swisspush/reststorage/MimeTypeResolver.java index a87ea8d..928d721 100644 --- a/src/main/java/org/swisspush/reststorage/MimeTypeResolver.java +++ b/src/main/java/org/swisspush/reststorage/MimeTypeResolver.java @@ -1,7 +1,6 @@ package org.swisspush.reststorage; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; @@ -14,7 +13,7 @@ public class MimeTypeResolver { private static final Logger log = getLogger(MimeTypeResolver.class); - private Map mimeTypes = new HashMap<>(); + private final Map mimeTypes = new HashMap<>(); private final String defaultMimeType; diff --git a/src/main/java/org/swisspush/reststorage/ModuleConfigurationAuthentication.java b/src/main/java/org/swisspush/reststorage/ModuleConfigurationAuthentication.java index 167ca7c..f3cceb2 100644 --- a/src/main/java/org/swisspush/reststorage/ModuleConfigurationAuthentication.java +++ b/src/main/java/org/swisspush/reststorage/ModuleConfigurationAuthentication.java @@ -9,7 +9,6 @@ import io.vertx.ext.auth.authentication.Credentials; import io.vertx.ext.auth.authentication.UsernamePasswordCredentials; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.swisspush.reststorage.util.ModuleConfiguration; import java.util.Objects; diff --git a/src/main/java/org/swisspush/reststorage/RedisRestStorageRunner.java b/src/main/java/org/swisspush/reststorage/RedisRestStorageRunner.java index 8a95ed4..2a91874 100644 --- a/src/main/java/org/swisspush/reststorage/RedisRestStorageRunner.java +++ b/src/main/java/org/swisspush/reststorage/RedisRestStorageRunner.java @@ -4,7 +4,6 @@ import io.vertx.core.DeploymentOptions; import io.vertx.core.Vertx; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.swisspush.reststorage.util.ModuleConfiguration; import static org.slf4j.LoggerFactory.getLogger; diff --git a/src/main/java/org/swisspush/reststorage/RestStorageHandler.java b/src/main/java/org/swisspush/reststorage/RestStorageHandler.java index a91ec1d..209f0e7 100644 --- a/src/main/java/org/swisspush/reststorage/RestStorageHandler.java +++ b/src/main/java/org/swisspush/reststorage/RestStorageHandler.java @@ -16,7 +16,6 @@ import org.slf4j.Logger; import org.swisspush.reststorage.util.*; -import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.util.*; @@ -192,7 +191,7 @@ public void handle(Resource resource) { StringBuilder body = new StringBuilder(1024); String editor = null; - if (editors.size() > 0) { + if (!editors.isEmpty()) { editor = editors.values().iterator().next(); } body.append("\n"); @@ -277,12 +276,8 @@ public void handle(Resource resource) { documentResource.closeHandler.handle(null); rsp.end(); }); - documentResource.addErrorHandler(ex -> { - log.error("TODO error handling", new Exception(ex)); - }); - documentResource.readStream.exceptionHandler((Handler) ex -> { - log.error("TODO error handling", new Exception(ex)); - }); + documentResource.addErrorHandler(ex -> log.error("TODO error handling", new Exception(ex))); + documentResource.readStream.exceptionHandler(ex -> log.error("TODO error handling", new Exception(ex))); pump.start(); } } @@ -737,7 +732,7 @@ private void respondWith(HttpServerResponse response, StatusCode statusCode, Str } private String collectionName(String path) { - if (path.equals("/") || path.equals("")) { + if (path.equals("/") || path.isEmpty()) { return "root"; } else { return path.substring(path.lastIndexOf("/") + 1); diff --git a/src/main/java/org/swisspush/reststorage/redis/RedisStorage.java b/src/main/java/org/swisspush/reststorage/redis/RedisStorage.java index 94e67ed..e623fc4 100644 --- a/src/main/java/org/swisspush/reststorage/redis/RedisStorage.java +++ b/src/main/java/org/swisspush/reststorage/redis/RedisStorage.java @@ -51,6 +51,8 @@ import java.util.UUID; import java.util.stream.Stream; +import static org.swisspush.reststorage.redis.RedisUtils.toPayload; + public class RedisStorage implements Storage { private final Logger log = LoggerFactory.getLogger(RedisStorage.class); @@ -815,7 +817,7 @@ private void handleJsonArrayValues(Response values, Handler handler, b } } } - if (allowEmptyReturn && items.size() == 0) { + if (allowEmptyReturn && items.isEmpty()) { notFound(handler); } else { r.items = new ArrayList<>(items); @@ -1293,46 +1295,4 @@ public void cleanup(Handler handler, String cleanupResourcesAm private boolean isEmpty(CharSequence cs) { return cs == null || cs.length() == 0; } - - /** - * from https://github.com/vert-x3/vertx-redis-client/blob/3.9/src/main/java/io/vertx/redis/impl/RedisClientImpl.java#L94 - * - * @param parameters - * @return - */ - private static List toPayload(Object... parameters) { - List result = new ArrayList<>(parameters.length); - - for (Object param : parameters) { - // unwrap - if (param instanceof JsonArray) { - param = ((JsonArray) param).getList(); - } - // unwrap - if (param instanceof JsonObject) { - param = ((JsonObject) param).getMap(); - } - - if (param instanceof Collection) { - ((Collection) param).stream().filter(Objects::nonNull).forEach(o -> result.add(o.toString())); - } else if (param instanceof Map) { - for (Map.Entry pair : ((Map) param).entrySet()) { - result.add(pair.getKey().toString()); - result.add(pair.getValue().toString()); - } - } else if (param instanceof Stream) { - ((Stream) param).forEach(e -> { - if (e instanceof Object[]) { - Collections.addAll(result, (String[]) e); - } else { - result.add(e.toString()); - } - }); - } else if (param != null) { - result.add(param.toString()); - } - } - return result; - } - } diff --git a/src/main/java/org/swisspush/reststorage/util/ResourcesUtils.java b/src/main/java/org/swisspush/reststorage/util/ResourcesUtils.java index 853e02b..7727773 100644 --- a/src/main/java/org/swisspush/reststorage/util/ResourcesUtils.java +++ b/src/main/java/org/swisspush/reststorage/util/ResourcesUtils.java @@ -16,7 +16,7 @@ */ public class ResourcesUtils { - private static Logger log = LoggerFactory.getLogger(ResourcesUtils.class); + private static final Logger log = LoggerFactory.getLogger(ResourcesUtils.class); private ResourcesUtils() { // prevent instantiation diff --git a/src/main/resources/mime-types.properties b/src/main/resources/mime-types.properties index bafe6c9..71b4ac0 100644 --- a/src/main/resources/mime-types.properties +++ b/src/main/resources/mime-types.properties @@ -28,7 +28,7 @@ aso=application/vnd.accpac.simply.aso atc=application/vnd.acucorp atomcat=application/atomcat+xml atomsvc=application/atomsvc+xml -atom, xml=application/atom+xml +atomxml=application/atom+xml atx=application/vnd.antix.game-component au=audio/basic avi=video/x-msvideo diff --git a/src/test/java/org/swisspush/reststorage/EtagIntegrationTest.java b/src/test/java/org/swisspush/reststorage/EtagIntegrationTest.java index a98c3cc..182aa6b 100644 --- a/src/test/java/org/swisspush/reststorage/EtagIntegrationTest.java +++ b/src/test/java/org/swisspush/reststorage/EtagIntegrationTest.java @@ -26,7 +26,7 @@ public void testEtag(TestContext context) { String etag = get("resources/res1").getHeader(ETAG_HEADER); context.assertNotNull(etag, "Etag header should be available in response headers"); - context.assertTrue(etag.length() > 0, "Etag header should not be empty"); + context.assertFalse(etag.isEmpty(), "Etag header should not be empty"); // get requests with no if-none-match header should result in statuscode 200 when().get("resources/res1").then().assertThat() diff --git a/src/test/java/org/swisspush/reststorage/FilesystemStorageTest.java b/src/test/java/org/swisspush/reststorage/FilesystemStorageTest.java index 4f18fb9..491b01f 100644 --- a/src/test/java/org/swisspush/reststorage/FilesystemStorageTest.java +++ b/src/test/java/org/swisspush/reststorage/FilesystemStorageTest.java @@ -346,6 +346,6 @@ private void doAsserts() { * check if such a directory exists or someone has access to it. */ private static String createPseudoFileStorageRoot() { - return new File( "target/fileStorage-"+ UUID.randomUUID().toString() ).getAbsolutePath().replaceAll("\\\\","/"); // <-- Fix windows + return new File( "target/fileStorage-"+ UUID.randomUUID()).getAbsolutePath().replaceAll("\\\\","/"); // <-- Fix windows } } diff --git a/src/test/java/org/swisspush/reststorage/RestStorageHandlerTest.java b/src/test/java/org/swisspush/reststorage/RestStorageHandlerTest.java index 42d56fe..e45c1c4 100644 --- a/src/test/java/org/swisspush/reststorage/RestStorageHandlerTest.java +++ b/src/test/java/org/swisspush/reststorage/RestStorageHandlerTest.java @@ -312,7 +312,7 @@ public void notifiesResourceAboutExceptionsOnRequest(TestContext testContext) th @Override public void put(String path, String etag, boolean merge, long expire, String lockOwner, LockMode lockMode, long lockExpire, boolean storeCompressed, Handler handler) { final DocumentResource resource = new DocumentResource(); - resource.writeStream = new FailFastVertxWriteStream() { + resource.writeStream = new FailFastVertxWriteStream<>() { @Override public Future write(Buffer t) { log.debug("Somewhat irrelevant got written to the resource."); diff --git a/src/test/java/org/swisspush/reststorage/lua/RedisCleanupLuaScriptTests.java b/src/test/java/org/swisspush/reststorage/lua/RedisCleanupLuaScriptTests.java index cb9d1bf..14d9b5e 100644 --- a/src/test/java/org/swisspush/reststorage/lua/RedisCleanupLuaScriptTests.java +++ b/src/test/java/org/swisspush/reststorage/lua/RedisCleanupLuaScriptTests.java @@ -11,7 +11,7 @@ import java.util.UUID; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class RedisCleanupLuaScriptTests extends AbstractLuaScriptTest { diff --git a/src/test/java/org/swisspush/reststorage/lua/RedisDelLuaScriptTests.java b/src/test/java/org/swisspush/reststorage/lua/RedisDelLuaScriptTests.java index 5fae971..2bde3d4 100644 --- a/src/test/java/org/swisspush/reststorage/lua/RedisDelLuaScriptTests.java +++ b/src/test/java/org/swisspush/reststorage/lua/RedisDelLuaScriptTests.java @@ -9,7 +9,8 @@ import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + public class RedisDelLuaScriptTests extends AbstractLuaScriptTest { diff --git a/src/test/java/org/swisspush/reststorage/lua/RedisGetLuaScriptTests.java b/src/test/java/org/swisspush/reststorage/lua/RedisGetLuaScriptTests.java index 51310a0..5c53629 100644 --- a/src/test/java/org/swisspush/reststorage/lua/RedisGetLuaScriptTests.java +++ b/src/test/java/org/swisspush/reststorage/lua/RedisGetLuaScriptTests.java @@ -5,7 +5,7 @@ import java.util.List; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class RedisGetLuaScriptTests extends AbstractLuaScriptTest { diff --git a/src/test/java/org/swisspush/reststorage/lua/RedisPutLuaScriptTests.java b/src/test/java/org/swisspush/reststorage/lua/RedisPutLuaScriptTests.java index 625492a..b0e4bed 100644 --- a/src/test/java/org/swisspush/reststorage/lua/RedisPutLuaScriptTests.java +++ b/src/test/java/org/swisspush/reststorage/lua/RedisPutLuaScriptTests.java @@ -11,7 +11,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class RedisPutLuaScriptTests extends AbstractLuaScriptTest { diff --git a/src/test/java/org/swisspush/reststorage/lua/RedisStorageExpandLuaScriptTests.java b/src/test/java/org/swisspush/reststorage/lua/RedisStorageExpandLuaScriptTests.java index 2cc4096..c57bb5c 100644 --- a/src/test/java/org/swisspush/reststorage/lua/RedisStorageExpandLuaScriptTests.java +++ b/src/test/java/org/swisspush/reststorage/lua/RedisStorageExpandLuaScriptTests.java @@ -19,7 +19,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class RedisStorageExpandLuaScriptTests extends AbstractLuaScriptTest { diff --git a/src/test/java/org/swisspush/reststorage/mocks/FailFastVertxWebRoutingContext.java b/src/test/java/org/swisspush/reststorage/mocks/FailFastVertxWebRoutingContext.java index d454f4e..bd6f630 100644 --- a/src/test/java/org/swisspush/reststorage/mocks/FailFastVertxWebRoutingContext.java +++ b/src/test/java/org/swisspush/reststorage/mocks/FailFastVertxWebRoutingContext.java @@ -17,7 +17,6 @@ import java.nio.charset.Charset; import java.util.List; import java.util.Map; -import java.util.Set; public class FailFastVertxWebRoutingContext implements RoutingContext {