diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java
index b4887c40c..8c15e0a8c 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java
@@ -387,7 +387,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Ensures that single DS requested by ID is listed with expected payload.")
public void getDistributionSet() throws Exception {
- final DistributionSet set = testdataFactory.createTestDistributionSet();
+ final DistributionSet set = testdataFactory.createUpdatedDistributionSet();
// perform request
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON))
diff --git a/hawkbit-mgmt-resource/src/test/resources/logback.xml b/hawkbit-mgmt-resource/src/test/resources/logback.xml
index 49ea574f2..30060d1c6 100644
--- a/hawkbit-mgmt-resource/src/test/resources/logback.xml
+++ b/hawkbit-mgmt-resource/src/test/resources/logback.xml
@@ -23,7 +23,7 @@
-
+
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java
index 342e0792b..ecb7f2d37 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java
@@ -13,8 +13,6 @@ import javax.persistence.PersistenceContext;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.util.AbstractIntegrationTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
@@ -79,26 +77,4 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
@Autowired
protected TenantAwareCacheManager cacheManager;
-
- private static CIMySqlTestDatabase tesdatabase;
-
- @BeforeClass
- public static void beforeClass() {
- createTestdatabaseAndStart();
- }
-
- private static void createTestdatabaseAndStart() {
- if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
- tesdatabase = new CIMySqlTestDatabase();
- tesdatabase.before();
- }
- }
-
- @AfterClass
- public static void afterClass() {
- if (tesdatabase != null) {
- tesdatabase.after();
- }
- }
-
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java
index 38a02c213..6650d1e3c 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java
@@ -13,11 +13,8 @@ import javax.persistence.PersistenceContext;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
-import org.springframework.data.mongodb.gridfs.GridFsOperations;
@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class,
TestConfiguration.class })
@@ -68,9 +65,6 @@ public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractInte
@Autowired
protected TargetInfoRepository targetInfoRepository;
- @Autowired
- protected GridFsOperations operations;
-
@Autowired
protected RolloutGroupRepository rolloutGroupRepository;
@@ -80,25 +74,4 @@ public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractInte
@Autowired
protected TenantAwareCacheManager cacheManager;
- private static CIMySqlTestDatabase tesdatabase;
-
- @BeforeClass
- public static void beforeClass() {
- createTestdatabaseAndStart();
- }
-
- private static void createTestdatabaseAndStart() {
- if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
- tesdatabase = new CIMySqlTestDatabase();
- tesdatabase.before();
- }
- }
-
- @AfterClass
- public static void afterClass() {
- if (tesdatabase != null) {
- tesdatabase.after();
- }
- }
-
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java
deleted file mode 100644
index 7812527c8..000000000
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package org.eclipse.hawkbit.repository.jpa;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.UUID;
-
-import org.h2.tools.Server;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- *
- */
-public class LocalH2TestDatabase implements Testdatabase {
-
- private final static Logger LOG = LoggerFactory.getLogger(LocalH2TestDatabase.class);
- private final int port;
- private Server h2server;
- private boolean dbStarted;
- private String uri;
-
- public LocalH2TestDatabase(final int port) {
- super();
- this.port = port;
- createUri();
- initSystemProperties();
- }
-
- private final void initSystemProperties() {
- System.setProperty("spring.datasource.driverClassName", getDriverClassName());
- System.setProperty("spring.datasource.username", "");
- System.setProperty("spring.datasource.password", "");
- System.setProperty("hawkbit.server.database", "H2");
- }
-
- private void dropAllObjects() {
- try (Connection connection = DriverManager.getConnection(uri)) {
- connection.prepareCall("DROP ALL OBJECTS;").execute();
- } catch (final SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void before() {
- try {
- startDatabase();
- } catch (ClassNotFoundException | SQLException | IOException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void after() {
- try {
- stopDatabase();
- } catch (ClassNotFoundException | SQLException | IOException e) {
- e.printStackTrace();
- }
- }
-
- private void startDatabase() throws SQLException, ClassNotFoundException, IOException {
- if (dbStarted) {
- return;
- }
-
- // Start H2 database for OpenFire
- h2server = Server
- .createTcpServer(
- new String[] { "-tcpPort", String.valueOf(port), "-tcpAllowOthers", "-tcpShutdownForce" })
- .start();
- dbStarted = true;
- LOG.info("H2 Database started on port {} and uri {}", port, uri);
- dropAllObjects();
- }
-
- private final void createUri() {
- this.uri = "jdbc:h2:tcp://localhost:" + port + "/mem:SP" + UUID.randomUUID().toString() + ";MVCC=TRUE;"
- + "DB_CLOSE_DELAY=-1";
- System.setProperty("spring.datasource.url", uri);
- }
-
- private void stopDatabase() throws SQLException, ClassNotFoundException, IOException {
- if (!dbStarted) {
- return;
- }
-
- h2server.stop();
- h2server = null;
- dbStarted = false;
- try {
- Thread.sleep(1000);
- } catch (final InterruptedException e) {
- }
- }
-
- @Override
- public String getDriverClassName() {
- return "org.h2.Driver";
- }
-
- @Override
- public String getUri() {
- return uri;
- }
-
-}
diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java
index 29bf02fa0..901827d32 100644
--- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java
@@ -29,7 +29,9 @@ import org.eclipse.hawkbit.security.DosFilter;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.MethodRule;
import org.junit.rules.TestWatchman;
@@ -211,4 +213,25 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
}
}
};
+
+ private static CIMySqlTestDatabase tesdatabase;
+
+ @BeforeClass
+ public static void beforeClass() {
+ createTestdatabaseAndStart();
+ }
+
+ private static void createTestdatabaseAndStart() {
+ if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) {
+ tesdatabase = new CIMySqlTestDatabase();
+ tesdatabase.before();
+ }
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ if (tesdatabase != null) {
+ tesdatabase.after();
+ }
+ }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/CIMySqlTestDatabase.java
similarity index 70%
rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java
rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/CIMySqlTestDatabase.java
index c0a8b161c..e6bbe1f6a 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/CIMySqlTestDatabase.java
@@ -6,10 +6,11 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
-package org.eclipse.hawkbit.repository.jpa;
+package org.eclipse.hawkbit.repository.util;
import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.commons.lang3.RandomStringUtils;
@@ -17,17 +18,20 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- *
+ * {@link Testdatabase} implementation for MySQL.
*
*/
public class CIMySqlTestDatabase implements Testdatabase {
- private final static Logger LOG = LoggerFactory.getLogger(CIMySqlTestDatabase.class);
+ private static final Logger LOG = LoggerFactory.getLogger(CIMySqlTestDatabase.class);
private String schemaName;
private String uri;
private final String username;
private final String password;
+ /**
+ * Constructor.
+ */
public CIMySqlTestDatabase() {
this.username = System.getProperty("spring.datasource.username");
this.password = System.getProperty("spring.datasource.password");
@@ -43,7 +47,7 @@ public class CIMySqlTestDatabase implements Testdatabase {
private void createSchemaUri() {
schemaName = "SP" + RandomStringUtils.randomAlphanumeric(10);
- this.uri = this.uri.substring(0, uri.lastIndexOf("/") + 1);
+ this.uri = this.uri.substring(0, uri.lastIndexOf('/') + 1);
System.setProperty("spring.datasource.url", uri + schemaName);
}
@@ -55,10 +59,12 @@ public class CIMySqlTestDatabase implements Testdatabase {
private void createSchema() {
try (Connection connection = DriverManager.getConnection(uri, username, password)) {
- connection.prepareStatement("CREATE SCHEMA " + schemaName + ";").execute();
- LOG.info("Schema {} created on uri {}", schemaName, uri);
+ try (PreparedStatement statement = connection.prepareStatement("CREATE SCHEMA " + schemaName + ";")) {
+ statement.execute();
+ LOG.info("Schema {} created on uri {}", schemaName, uri);
+ }
} catch (final SQLException e) {
- e.printStackTrace();
+ LOG.error("Schema creation failed!", e);
}
}
@@ -70,10 +76,12 @@ public class CIMySqlTestDatabase implements Testdatabase {
private void dropSchema() {
try (Connection connection = DriverManager.getConnection(uri, username, password)) {
- connection.prepareStatement("DROP SCHEMA " + schemaName + ";").execute();
- LOG.info("Schema {} dropped on uri {}", schemaName, uri);
+ try (PreparedStatement statement = connection.prepareStatement("DROP SCHEMA " + schemaName + ";")) {
+ statement.execute();
+ LOG.info("Schema {} dropped on uri {}", schemaName, uri);
+ }
} catch (final SQLException e) {
- e.printStackTrace();
+ LOG.error("Schema drop failed!", e);
}
}
diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java
index 0597a30cb..1ed5679c8 100644
--- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java
@@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Artifact;
+import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -219,7 +220,7 @@ public class TestdataFactory {
* @param version
* {@link DistributionSet#getVersion()} and
* {@link SoftwareModule#getVersion()} extended by a random
- * number.
+ * number.updat
* @param tags
* {@link DistributionSet#getTags()}
*
@@ -352,9 +353,14 @@ public class TestdataFactory {
* iterative number and {@link DistributionSet#isRequiredMigrationStep()}
* false.
*
+ * In addition it updates the ccreated {@link DistributionSet}s and
+ * {@link SoftwareModule}s to ensure that
+ * {@link BaseEntity#getLastModifiedAt()} and
+ * {@link BaseEntity#getLastModifiedBy()} is filled.
+ *
* @return persisted {@link DistributionSet}.
*/
- public DistributionSet createTestDistributionSet() {
+ public DistributionSet createUpdatedDistributionSet() {
DistributionSet set = createDistributionSet("");
set.setVersion(DEFAULT_VERSION);
set = distributionSetManagement.updateDistributionSet(set);
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/Testdatabase.java
similarity index 91%
rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java
rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/Testdatabase.java
index 38133c800..b24d34533 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/Testdatabase.java
@@ -6,7 +6,7 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
-package org.eclipse.hawkbit.repository.jpa;
+package org.eclipse.hawkbit.repository.util;
/**
*