Moved the default store path to project home (only for tests)

This commit is contained in:
andrea
2015-04-07 07:51:44 +02:00
parent 1a2dade994
commit 546117253d
8 changed files with 64 additions and 13 deletions
@@ -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;
}
}
@@ -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
@@ -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);
@@ -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
@@ -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();
@@ -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
@@ -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
@@ -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