From 546117253dba6916c6d04e724a6d967c9093a6e5 Mon Sep 17 00:00:00 2001 From: andrea Date: Tue, 7 Apr 2015 07:51:44 +0200 Subject: [PATCH] Moved the default store path to project home (only for tests) --- .../moquette/server/IntegrationUtils.java | 40 +++++++++++++++++++ .../server/ServerIntegrationFuseTest.java | 2 +- .../server/ServerIntegrationPahoTest.java | 18 ++++++--- .../ServerIntegrationQoSValidationTest.java | 2 +- .../server/ServerIntegrationSSLTest.java | 6 ++- .../ServerIntegrationWebSocketTest.java | 2 +- ...erverLowlevelMessagesIntegrationTests.java | 2 +- .../server/ServerRestartIntegrationTest.java | 5 ++- 8 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 broker/src/test/java/org/eclipse/moquette/server/IntegrationUtils.java diff --git a/broker/src/test/java/org/eclipse/moquette/server/IntegrationUtils.java b/broker/src/test/java/org/eclipse/moquette/server/IntegrationUtils.java new file mode 100644 index 00000000..69c60ad2 --- /dev/null +++ b/broker/src/test/java/org/eclipse/moquette/server/IntegrationUtils.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012-2014 The original author or authors + * ------------------------------------------------------ + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * The Apache License v2.0 is available at + * http://www.opensource.org/licenses/apache2.0.php + * + * You may elect to redistribute this code under either of these licenses. + */ +package org.eclipse.moquette.server; + +import java.io.File; +import java.util.Properties; + +import static org.eclipse.moquette.commons.Constants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; +import static org.eclipse.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; + +/** + * Used to carry integration configurations. + * + * Created by andrea on 4/7/15. + */ +class IntegrationUtils { + static String localMapDBPath() { + String currentDir = System.getProperty("user.dir"); + return currentDir + File.separator + DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; + } + + public static Properties prepareTestPropeties() { + Properties testProperties = new Properties(); + testProperties.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath()); + return testProperties; + } +} diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java index ab3723c6..758040ce 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationFuseTest.java @@ -44,7 +44,7 @@ public class ServerIntegrationFuseTest { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(new Properties()); + m_server.startServer(IntegrationUtils.prepareTestPropeties()); } @Before diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java index 27e63452..eefafd05 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationPahoTest.java @@ -28,8 +28,9 @@ import java.io.File; import java.io.IOException; import java.util.Properties; -import static org.eclipse.moquette.commons.Constants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; -import static org.eclipse.moquette.commons.Constants.PERSISTENT_STORE_PROPERTY_NAME; +import static org.eclipse.moquette.commons.Constants.*; +import static org.eclipse.moquette.commons.Constants.KEY_MANAGER_PASSWORD_PROPERTY_NAME; +import static org.eclipse.moquette.commons.Constants.KEY_STORE_PASSWORD_PROPERTY_NAME; import static org.junit.Assert.*; public class ServerIntegrationPahoTest { @@ -52,13 +53,14 @@ public class ServerIntegrationPahoTest { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(new Properties()); + m_server.startServer(IntegrationUtils.prepareTestPropeties()); } @Before public void setUp() throws Exception { - File dbFile = new File(DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME); - assertFalse(String.format("The DB storagefile %s already exists", DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME), dbFile.exists()); + String dbPath = IntegrationUtils.localMapDBPath(); + File dbFile = new File(dbPath); + assertFalse(String.format("The DB storagefile %s already exists", dbPath), dbFile.exists()); startServer(); @@ -73,6 +75,10 @@ public class ServerIntegrationPahoTest { m_client.disconnect(); } + stopServer(); + } + + private void stopServer() { m_server.stopServer(); File dbFile = new File(m_server.getProperties().getProperty(PERSISTENT_STORE_PROPERTY_NAME)); if (dbFile.exists()) { @@ -164,7 +170,7 @@ public class ServerIntegrationPahoTest { m_server.stopServer(); - m_server.startServer(); + m_server.startServer(IntegrationUtils.prepareTestPropeties()); //reconnect and publish m_client.connect(options); diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java index 4f8dad60..6b4a76c0 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationQoSValidationTest.java @@ -60,7 +60,7 @@ public class ServerIntegrationQoSValidationTest { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(new Properties()); + m_server.startServer(IntegrationUtils.prepareTestPropeties()); } @Before diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationSSLTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationSSLTest.java index 5dcaca30..8cdf78eb 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationSSLTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationSSLTest.java @@ -68,13 +68,15 @@ public class ServerIntegrationSSLTest { sslProps.put(JKS_PATH_PROPERTY_NAME, "serverkeystore.jks"); sslProps.put(KEY_STORE_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); sslProps.put(KEY_MANAGER_PASSWORD_PROPERTY_NAME, "passw0rdsrv"); + sslProps.put(PERSISTENT_STORE_PROPERTY_NAME, IntegrationUtils.localMapDBPath()); m_server.startServer(sslProps); } @Before public void setUp() throws Exception { - File dbFile = new File(DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME); - assertFalse(String.format("The DB storage file %s already exists", DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME), dbFile.exists()); + String dbPath = IntegrationUtils.localMapDBPath(); + File dbFile = new File(dbPath); + assertFalse(String.format("The DB storagefile %s already exists", dbPath), dbFile.exists()); startServer(); diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java index fc91fdc6..4fc97eb7 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerIntegrationWebSocketTest.java @@ -47,7 +47,7 @@ public class ServerIntegrationWebSocketTest { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(new Properties()); + m_server.startServer(IntegrationUtils.prepareTestPropeties()); } @Before diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java b/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java index 7f677edd..dc708fe1 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerLowlevelMessagesIntegrationTests.java @@ -49,7 +49,7 @@ public class ServerLowlevelMessagesIntegrationTests { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(new Properties()); + m_server.startServer(IntegrationUtils.prepareTestPropeties()); } @Before diff --git a/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java b/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java index 113f5041..5b04fe0c 100644 --- a/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java +++ b/broker/src/test/java/org/eclipse/moquette/server/ServerRestartIntegrationTest.java @@ -19,6 +19,8 @@ import org.fusesource.mqtt.client.*; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -34,6 +36,7 @@ import static org.junit.Assert.assertNull; * @author andrea */ public class ServerRestartIntegrationTest { + private static Logger LOG = LoggerFactory.getLogger(ServerRestartIntegrationTest.class); Server m_server; MQTT m_mqtt; @@ -42,7 +45,7 @@ public class ServerRestartIntegrationTest { protected void startServer() throws IOException { m_server = new Server(); - m_server.startServer(new Properties()); + m_server.startServer(IntegrationUtils.prepareTestPropeties()); } @Before