diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java
index abf2740fa..fdad8a999 100644
--- a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java
+++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java
@@ -8,11 +8,9 @@ package org.eclipse.hawkbit.app;
* http://www.eclipse.org/legal/epl-v10.html
*/
-import org.eclipse.hawkbit.RepositoryApplicationConfiguration;
import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Import;
/**
* A {@link SpringBootApplication} annotated class with a main method to start.
@@ -20,7 +18,6 @@ import org.springframework.context.annotation.Import;
*
*/
@SpringBootApplication
-@Import({ RepositoryApplicationConfiguration.class })
@EnableHawkbitManagedSecurityConfiguration
// Exception squid:S1118 - Spring boot standard behavior
@SuppressWarnings({ "squid:S1118" })
diff --git a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java
index 4a3e6028a..d22d6f4a1 100644
--- a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java
+++ b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java
@@ -8,13 +8,11 @@
*/
package org.eclipse.hawkbit.app;
-import org.eclipse.hawkbit.RepositoryApplicationConfiguration;
import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration;
import org.eclipse.hawkbit.ddi.EnableDdiApi;
import org.eclipse.hawkbit.mgmt.EnableMgmtApi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Import;
/**
* A {@link SpringBootApplication} annotated class with a main method to start.
@@ -22,7 +20,6 @@ import org.springframework.context.annotation.Import;
*
*/
@SpringBootApplication
-@Import({ RepositoryApplicationConfiguration.class })
@EnableHawkbitManagedSecurityConfiguration
@EnableMgmtApi
@EnableDdiApi
diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java
new file mode 100644
index 000000000..dd6ead86b
--- /dev/null
+++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java
@@ -0,0 +1,25 @@
+/**
+ * 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.autoconfigure.repository;
+
+import org.eclipse.hawkbit.EnableJpaRepository;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+/**
+ * Auto-Configuration for enabling the REST-Resources.
+ *
+ */
+@Configuration
+@ConditionalOnClass({ EnableJpaRepository.class })
+@Import({ EnableJpaRepository.class })
+public class JpaRepositoryAutoConfiguration {
+
+}
diff --git a/hawkbit-ddi-resource/pom.xml b/hawkbit-ddi-resource/pom.xml
index 177494912..35aff47f5 100644
--- a/hawkbit-ddi-resource/pom.xml
+++ b/hawkbit-ddi-resource/pom.xml
@@ -48,6 +48,12 @@
+
+ org.eclipse.hawkbit
+ hawkbit-repository-test
+ ${project.version}
+ test
+
org.eclipse.hawkbit
hawkbit-rest-core
diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java
index 859b4c156..9d690f9d2 100644
--- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java
+++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java
@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.ControllerManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
@@ -68,6 +69,9 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
@Autowired
private RequestResponseContextHolder requestResponseContextHolder;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity downloadArtifactByFilename(@PathVariable("fileName") final String fileName,
@AuthenticationPrincipal final String targetid) {
@@ -139,17 +143,16 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), artifact.getSoftwareModule());
final String range = request.getHeader("Range");
- final ActionStatus actionStatus = controllerManagement.generateActionStatus();
+ final ActionStatus actionStatus = entityFactory.generateActionStatus();
actionStatus.setAction(action);
actionStatus.setOccurredAt(System.currentTimeMillis());
actionStatus.setStatus(Status.DOWNLOAD);
if (range != null) {
- actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range
- + " of: " + request.getRequestURI());
+ actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: "
+ + request.getRequestURI());
} else {
- actionStatus.addMessage(
- Constants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI());
+ actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI());
}
controllerManagement.addInformationalActionStatus(actionStatus);
return action;
diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
index 881eee659..656835e95 100644
--- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
+++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
@@ -31,6 +31,7 @@ import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.ControllerManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify;
@@ -97,6 +98,9 @@ public class DdiRootController implements DdiRootControllerRestApi {
@Autowired
private RequestResponseContextHolder requestResponseContextHolder;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity> getSoftwareModulesArtifacts(
@PathVariable("targetid") final String targetid,
@@ -175,17 +179,16 @@ public class DdiRootController implements DdiRootControllerRestApi {
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module);
final String range = request.getHeader("Range");
- final ActionStatus statusMessage = controllerManagement.generateActionStatus();
+ final ActionStatus statusMessage = entityFactory.generateActionStatus();
statusMessage.setAction(action);
statusMessage.setOccurredAt(System.currentTimeMillis());
statusMessage.setStatus(Status.DOWNLOAD);
if (range != null) {
- statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range
- + " of: " + request.getRequestURI());
+ statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: "
+ + request.getRequestURI());
} else {
- statusMessage.addMessage(
- Constants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI());
+ statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI());
}
controllerManagement.addInformationalActionStatus(statusMessage);
return action;
@@ -294,7 +297,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
private ActionStatus generateUpdateStatus(final DdiActionFeedback feedback, final String targetid,
final Long actionid, final Action action) {
- final ActionStatus actionStatus = controllerManagement.generateActionStatus();
+ final ActionStatus actionStatus = entityFactory.generateActionStatus();
actionStatus.setAction(action);
actionStatus.setOccurredAt(System.currentTimeMillis());
@@ -336,8 +339,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
LOG.debug("Controller reported intermediate status (actionid: {}, targetid: {}) as we got {} report.", actionid,
targetid, feedback.getStatus().getExecution());
actionStatus.setStatus(Status.RUNNING);
- actionStatus.addMessage(
- Constants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution());
+ actionStatus
+ .addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution());
}
private static void handleClosedUpdateStatus(final DdiActionFeedback feedback, final String targetid,
@@ -420,14 +423,14 @@ public class DdiRootController implements DdiRootControllerRestApi {
}
controllerManagement.addCancelActionStatus(
- generateActionCancelStatus(feedback, target, feedback.getId(), action, controllerManagement));
+ generateActionCancelStatus(feedback, target, feedback.getId(), action, entityFactory));
return new ResponseEntity<>(HttpStatus.OK);
}
private static ActionStatus generateActionCancelStatus(final DdiActionFeedback feedback, final Target target,
- final Long actionid, final Action action, final ControllerManagement controllerManagement) {
+ final Long actionid, final Action action, final EntityFactory entityFactory) {
- final ActionStatus actionStatus = controllerManagement.generateActionStatus();
+ final ActionStatus actionStatus = entityFactory.generateActionStatus();
actionStatus.setAction(action);
actionStatus.setOccurredAt(System.currentTimeMillis());
diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java
index 2e56ed840..b3828582c 100644
--- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java
+++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java
@@ -27,14 +27,13 @@ import java.util.List;
import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB;
import org.junit.Test;
import org.slf4j.LoggerFactory;
@@ -73,14 +72,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
@Description("Tests non allowed requests on the artifact ressource, e.g. invalid URI, wrong if-match, wrong command.")
public void invalidRequestsOnArtifactResource() throws Exception {
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List targets = new ArrayList<>();
targets.add(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
deploymentManagement.assignDistributionSet(ds, targets);
// create artifact
@@ -158,14 +156,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
@Description("Tests non allowed requests on the artifact ressource, e.g. invalid URI, wrong if-match, wrong command.")
public void invalidRequestsOnArtifactResourceByName() throws Exception {
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List targets = new ArrayList<>();
targets.add(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
deploymentManagement.assignDistributionSet(ds, targets);
// create artifact
@@ -241,17 +238,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
downLoadProgress = 1;
eventBus.register(this);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
- assertThat(artifactRepository.findAll()).hasSize(0);
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List targets = new ArrayList();
targets.add(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024 * 1024);
@@ -287,12 +282,11 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
@Description("Tests valid MD5SUm file downloads through the artifact resource by identifying the artifact by ID.")
public void downloadMd5sumThroughControllerApi() throws Exception {
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
@@ -322,17 +316,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
eventBus.register(this);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
- assertThat(artifactRepository.findAll()).hasSize(0);
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List targets = new ArrayList();
targets.add(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
@@ -353,17 +345,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
eventBus.register(this);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
- assertThat(artifactRepository.findAll()).hasSize(0);
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List targets = new ArrayList<>();
targets.add(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024 * 1024);
@@ -393,7 +383,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
final Action action = deploymentManagement.findActionsByTarget(target).get(0);
// one status - download
- assertThat(actionStatusRepository.findAll()).hasSize(2);
assertThat(action.getActionStatus()).hasSize(2);
assertThat(deploymentManagement.findActionStatusByAction(new PageRequest(0, 400, Direction.DESC, "id"), action)
.getContent().get(0).getStatus()).isEqualTo(Status.DOWNLOAD);
@@ -407,14 +396,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
@Description("Test various HTTP range requests for artifact download, e.g. chunk download or download resume.")
public void rangeDownloadArtifactByName() throws Exception {
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List targets = new ArrayList<>();
targets.add(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
final int resultLength = 5 * 1000 * 1024;
@@ -512,17 +500,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
@Description("Ensures that the download fails if te controller is not authenticated.")
public void faildDownloadArtifactByNameIfAuthenticationMissing() throws Exception {
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
- assertThat(artifactRepository.findAll()).hasSize(0);
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List targets = new ArrayList<>();
targets.add(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
@@ -538,12 +524,11 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
@Description("Downloads an MD5SUM file by the related artifacts filename.")
public void downloadMd5sumFileByName() throws Exception {
// create target
- Target target = targetManagement.generateTarget("4712");
+ Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
// create ds
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
// create artifact
final byte random[] = RandomUtils.nextBytes(5 * 1024);
diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java
index 8fd832b95..821c8b8ad 100644
--- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java
+++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java
@@ -22,7 +22,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -49,9 +48,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
@Description("Test of the controller can continue a started update even after a cancel command if it so desires.")
public void rootRsCancelActionButContinueAnyway() throws Exception {
// prepare test data
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
final Target savedTarget = targetManagement.createTarget(target);
final List toAssign = new ArrayList();
@@ -106,9 +104,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
@Test
@Description("Test for cancel operation of a update action.")
public void rootRsCancelAction() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
final Target savedTarget = targetManagement.createTarget(target);
final List toAssign = new ArrayList();
@@ -224,9 +221,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
}
private Action createCancelAction(final String targetid) {
- final Target target = targetManagement.generateTarget(targetid);
- final DistributionSet ds = TestDataUtil.generateDistributionSet(targetid, softwareManagement,
- distributionSetManagement);
+ final Target target = entityFactory.generateTarget(targetid);
+ final DistributionSet ds = testdataFactory.createDistributionSet(targetid);
final Target savedTarget = targetManagement.createTarget(target);
final List toAssign = new ArrayList();
toAssign.add(savedTarget);
@@ -241,9 +237,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
@Description("Tests the feedback channel of the cancel operation.")
public void rootRsCancelActionFeedback() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
final Target savedTarget = targetManagement.createTarget(target);
@@ -253,7 +248,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
// cancel action manually
final Action cancelAction = deploymentManagement.cancelAction(updateAction,
targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
- assertThat(actionStatusRepository.findAll()).hasSize(2);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
long current = System.currentTimeMillis();
@@ -266,7 +261,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
- assertThat(actionStatusRepository.findAll()).hasSize(3);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction.getId() + "/feedback",
@@ -277,7 +272,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
- assertThat(actionStatusRepository.findAll()).hasSize(4);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction.getId() + "/feedback",
@@ -287,7 +282,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
- assertThat(actionStatusRepository.findAll()).hasSize(5);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
// cancelation canceled -> should remove the action from active
@@ -300,7 +295,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
- assertThat(actionStatusRepository.findAll()).hasSize(6);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
// cancelation rejected -> action still active until controller close it
@@ -315,7 +310,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
- assertThat(actionStatusRepository.findAll()).hasSize(7);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
// cancelaction closed -> should remove the action from active
@@ -327,20 +322,17 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
- assertThat(actionStatusRepository.findAll()).hasSize(8);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(0);
}
@Test
@Description("Tests the feeback chanel of for multiple open cancel operations on the same target.")
public void multipleCancelActionFeedback() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement, true);
- final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement, true);
- final DistributionSet ds3 = TestDataUtil.generateDistributionSet("3", softwareManagement,
- distributionSetManagement, true);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("", true);
+ final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
+ final DistributionSet ds3 = testdataFactory.createDistributionSet("3", true);
final Target savedTarget = targetManagement.createTarget(target);
@@ -351,7 +343,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
final Action updateAction3 = deploymentManagement.findActionWithDetails(
deploymentManagement.assignDistributionSet(ds3.getId(), new String[] { "4712" }).getActions().get(0));
- assertThat(actionStatusRepository.findAll()).hasSize(3);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3);
// 3 update actions, 0 cancel actions
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(3);
@@ -370,7 +362,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction.getId()))))
.andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction.getId()))));
- assertThat(actionStatusRepository.findAll()).hasSize(6);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6);
mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -386,7 +378,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
- assertThat(actionStatusRepository.findAll()).hasSize(7);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
// 1 update actions, 1 cancel actions
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
@@ -396,7 +388,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction2.getId()))))
.andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction2.getId()))));
- assertThat(actionStatusRepository.findAll()).hasSize(8);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8);
mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -412,17 +404,18 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.content(JsonBuilder.cancelActionFeedback(cancelAction2.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
- assertThat(actionStatusRepository.findAll()).hasSize(9);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9);
assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(ds3);
mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/" + updateAction3.getId(),
tenantAware.getCurrentTenant())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
- assertThat(actionStatusRepository.findAll()).hasSize(10);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10);
// 1 update actions, 0 cancel actions
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
- final Action cancelAction3 = deploymentManagement.cancelAction(actionRepository.findOne(updateAction3.getId()),
+ final Action cancelAction3 = deploymentManagement.cancelAction(
+ deploymentManagement.findAction(updateAction3.getId()),
targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
// action is in cancelling state
@@ -435,7 +428,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction3.getId()))))
.andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction3.getId()))));
- assertThat(actionStatusRepository.findAll()).hasSize(12);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(12);
// now lets return feedback for the third cancelation
mvc.perform(post("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction3.getId() + "/feedback",
@@ -443,7 +436,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
.content(JsonBuilder.cancelActionFeedback(cancelAction3.getId().toString(), "closed"))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
- assertThat(actionStatusRepository.findAll()).hasSize(13);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(13);
// final status
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(0);
@@ -453,9 +446,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest {
@Test
@Description("Tests the feeback channel closing for too many feedbacks, i.e. denial of service prevention.")
public void tooMuchCancelActionFeedback() throws Exception {
- final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712"));
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = targetManagement.createTarget(entityFactory.generateTarget("4712"));
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
final List toAssign = new ArrayList();
toAssign.add(target);
diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java
index a216ce501..395e2284c 100644
--- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java
+++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java
@@ -21,8 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
import org.junit.Test;
@@ -40,13 +40,13 @@ import ru.yandex.qatools.allure.annotations.Stories;
@ActiveProfiles({ "im", "test" })
@Features("Component Tests - Direct Device Integration API")
@Stories("Config Data Resource")
-public class DdiConfigDataTest extends AbstractIntegrationTest {
+public class DdiConfigDataTest extends AbstractRestIntegrationTest {
@Test
@Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) "
+ "are requested only once from the device.")
public void requestConfigDataIfEmpty() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
+ final Target target = entityFactory.generateTarget("4712");
final Target savedTarget = targetManagement.createTarget(target);
final long current = System.currentTimeMillis();
@@ -84,7 +84,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest {
@Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) "
+ "can be uploaded correctly by the controller.")
public void putConfigData() throws Exception {
- targetManagement.createTarget(targetManagement.generateTarget("4717"));
+ targetManagement.createTarget(entityFactory.generateTarget("4717"));
// initial
final Map attributes = new HashMap<>();
@@ -127,7 +127,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest {
@Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) "
+ "upload limitation is inplace which is meant to protect the server from malicious attempts.")
public void putToMuchConfigData() throws Exception {
- targetManagement.createTarget(targetManagement.generateTarget("4717"));
+ targetManagement.createTarget(entityFactory.generateTarget("4717"));
// initial
Map attributes = new HashMap<>();
@@ -150,7 +150,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest {
@Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) "
+ "resource behaves as exptected in cae of invalid request attempts.")
public void badConfigData() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
+ final Target target = entityFactory.generateTarget("4712");
final Target savedTarget = targetManagement.createTarget(target);
// not allowed methods
diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java
index cafe655e9..124d8e38d 100644
--- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java
+++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java
@@ -25,8 +25,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.RandomUtils;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.Action.Status;
@@ -63,7 +61,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Test()
@Description("Ensures that artifacts are not found, when softare module does not exists.")
public void artifactsNotFound() throws Exception {
- final Target target = TestDataUtil.createTarget(targetManagement);
+ final Target target = testdataFactory.createTarget();
final Long softwareModuleIdNotExist = 1l;
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts",
tenantAware.getCurrentTenant(), target.getName(), softwareModuleIdNotExist))
@@ -73,9 +71,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Test()
@Description("Ensures that artifacts are found, when software module exists.")
public void artifactsExists() throws Exception {
- final Target target = TestDataUtil.createTarget(targetManagement);
- final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = testdataFactory.createTarget();
+ final DistributionSet distributionSet = testdataFactory.createDistributionSet("");
deploymentManagement.assignDistributionSet(distributionSet.getId(), new String[] { target.getName() });
@@ -84,7 +81,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0)));
- TestDataUtil.generateArtifacts(artifactManagement, softwareModuleId);
+ testdataFactory.createLocalArtifacts(softwareModuleId);
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts",
tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print())
@@ -99,11 +96,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Description("Forced deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.")
public void deplomentForceAction() throws Exception {
// Prepare test data
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement, true);
- final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement, true);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("", true);
+ final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
@@ -114,18 +109,18 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
final Target savedTarget = targetManagement.createTarget(target);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty();
- assertThat(actionRepository.findAll()).isEmpty();
- assertThat(actionStatusRepository.findAll()).isEmpty();
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(0);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0);
List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.FORCED,
Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity();
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
- assertThat(actionRepository.findAll()).hasSize(1);
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(1);
saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity();
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
- assertThat(actionRepository.findAll()).hasSize(2);
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(2);
final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
assertThat(uaction.getDistributionSet()).isEqualTo(ds);
@@ -143,7 +138,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
.isGreaterThanOrEqualTo(current);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isLessThanOrEqualTo(System.currentTimeMillis());
- assertThat(actionStatusRepository.findAll()).hasSize(2);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
current = System.currentTimeMillis();
@@ -238,11 +233,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Description("Attempt/soft deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.")
public void deplomentAttemptAction() throws Exception {
// Prepare test data
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement, true);
- final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement, true);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("", true);
+ final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
@@ -253,19 +246,18 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
final Target savedTarget = targetManagement.createTarget(target);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty();
- assertThat(actionRepository.findAll()).isEmpty();
- assertThat(actionStatusRepository.findAll()).isEmpty();
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(0);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0);
- List saved = deploymentManagement
- .assignDistributionSet(ds.getId(), ActionType.SOFT, Constants.NO_FORCE_TIME, savedTarget.getControllerId())
- .getAssignedEntity();
+ List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.SOFT,
+ Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity();
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
- assertThat(actionRepository.findAll()).hasSize(1);
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(1);
saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity();
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
- assertThat(actionRepository.findAll()).hasSize(2);
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(2);
final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
assertThat(uaction.getDistributionSet()).isEqualTo(ds);
@@ -284,7 +276,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
.isGreaterThanOrEqualTo(current);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isLessThanOrEqualTo(System.currentTimeMillis());
- assertThat(actionStatusRepository.findAll()).hasSize(2);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
current = System.currentTimeMillis();
@@ -369,11 +361,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Description("Attempt/soft deployment to a controller including automated switch to hard. Checks if the resource reponse payload for a given deployment is as expected.")
public void deplomentAutoForceAction() throws Exception {
// Prepare test data
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement, true);
- final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement, true);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("", true);
+ final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
final byte random[] = RandomUtils.nextBytes(5 * 1024);
final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
@@ -384,18 +374,18 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
final Target savedTarget = targetManagement.createTarget(target);
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty();
- assertThat(actionRepository.findAll()).isEmpty();
- assertThat(actionStatusRepository.findAll()).isEmpty();
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(0);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0);
List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.TIMEFORCED,
System.currentTimeMillis(), savedTarget.getControllerId()).getAssignedEntity();
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
- assertThat(actionRepository.findAll()).hasSize(1);
+ assertThat(deploymentManagement.countActionsAll()).isEqualTo(1);
saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity();
assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
- assertThat(actionRepository.findAll()).hasSize(2);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
assertThat(uaction.getDistributionSet()).isEqualTo(ds);
@@ -414,7 +404,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
.isGreaterThanOrEqualTo(current);
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery())
.isLessThanOrEqualTo(System.currentTimeMillis());
- assertThat(actionStatusRepository.findAll()).hasSize(2);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
current = System.currentTimeMillis();
@@ -506,7 +496,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Test
@Description("Test various invalid access attempts to the deployment resource und the expected behaviour of the server.")
public void badDeploymentAction() throws Exception {
- final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712"));
+ final Target target = targetManagement.createTarget(entityFactory.generateTarget("4712"));
// not allowed methods
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/1", tenantAware.getCurrentTenant()))
@@ -529,8 +519,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
// wrong media type
final List toAssign = new ArrayList<>();
toAssign.add(target);
- final DistributionSet savedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet savedSet = testdataFactory.createDistributionSet("");
final Action action1 = deploymentManagement.findActionWithDetails(
deploymentManagement.assignDistributionSet(savedSet, toAssign).getActions().get(0));
@@ -547,9 +536,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Description("The server protects itself against to many feedback upload attempts. The test verfies that "
+ "it is not possible to exceed the configured maximum number of feedback uplods.")
public void toMuchDeplomentActionFeedback() throws Exception {
- final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712"));
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = targetManagement.createTarget(entityFactory.generateTarget("4712"));
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
final List toAssign = new ArrayList<>();
toAssign.add(target);
@@ -575,19 +563,16 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Test
@Description("Multiple uploads of deployment status feedback to the server.")
public void multipleDeplomentActionFeedback() throws Exception {
- final Target target1 = targetManagement.generateTarget("4712");
- final Target target2 = targetManagement.generateTarget("4713");
- final Target target3 = targetManagement.generateTarget("4714");
+ final Target target1 = entityFactory.generateTarget("4712");
+ final Target target2 = entityFactory.generateTarget("4713");
+ final Target target3 = entityFactory.generateTarget("4714");
final Target savedTarget1 = targetManagement.createTarget(target1);
targetManagement.createTarget(target2);
targetManagement.createTarget(target3);
- final DistributionSet ds1 = TestDataUtil.generateDistributionSet("1", softwareManagement,
- distributionSetManagement, true);
- final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement, true);
- final DistributionSet ds3 = TestDataUtil.generateDistributionSet("3", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet ds1 = testdataFactory.createDistributionSet("1", true);
+ final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true);
+ final DistributionSet ds3 = testdataFactory.createDistributionSet("3", true);
final List toAssign = new ArrayList<>();
toAssign.add(savedTarget1);
@@ -680,8 +665,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Test
@Description("Verfies that an update action is correctly set to error if the controller provides error feedback.")
public void rootRsSingleDeplomentActionWithErrorFeedback() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
- DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement);
+ final Target target = entityFactory.generateTarget("4712");
+ DistributionSet ds = testdataFactory.createDistributionSet("");
final Target savedTarget = targetManagement.createTarget(target);
@@ -691,8 +676,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.UNKNOWN);
deploymentManagement.assignDistributionSet(ds, toAssign);
- final Action action = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) ds).getContent()
- .get(0);
+ final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds).getContent().get(0);
long current = System.currentTimeMillis();
long lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
@@ -747,7 +731,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
.hasSize(1);
assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0);
assertThat(deploymentManagement.findInActiveActionsByTarget(myT)).hasSize(2);
- assertThat(actionStatusRepository.findAll()).hasSize(4);
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4);
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getContent()).haveAtLeast(1,
new ActionStatusCondition(Status.ERROR));
assertThat(deploymentManagement.findActionStatusByAction(pageReq, action2).getContent()).haveAtLeast(1,
@@ -758,9 +742,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
@Test
@Description("Verfies that the controller can provided as much feedback entries as necessry as long as it is in the configured limites.")
public void rootRsSingleDeplomentActionFeedback() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = entityFactory.generateTarget("4712");
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
final Target savedTarget = targetManagement.createTarget(target);
@@ -770,17 +753,12 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
Target myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
deploymentManagement.assignDistributionSet(ds, toAssign);
- final Action action = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) ds).getContent()
- .get(0);
+ final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds).getContent().get(0);
myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
- assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10),
- (JpaDistributionSet) ds)).hasSize(0);
- assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), (JpaDistributionSet) ds))
- .hasSize(1);
- assertThat(targetRepository.findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet(
- new PageRequest(0, 10), (JpaDistributionSet) ds, (JpaDistributionSet) ds)).hasSize(1);
+ assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), pageReq)).hasSize(0);
+ assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1);
// Now valid Feedback
@@ -804,8 +782,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
- assertThat(actionStatusRepository.findAll()).hasSize(5);
- assertThat(actionStatusRepository.findAll()).haveAtLeast(5, new ActionStatusCondition(Status.RUNNING));
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5);
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5,
+ new ActionStatusCondition(Status.RUNNING));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
@@ -823,8 +802,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
- assertThat(actionStatusRepository.findAll()).hasSize(6);
- assertThat(actionStatusRepository.findAll()).haveAtLeast(5, new ActionStatusCondition(Status.RUNNING));
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6);
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5,
+ new ActionStatusCondition(Status.RUNNING));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
@@ -842,8 +822,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
- assertThat(actionStatusRepository.findAll()).hasSize(7);
- assertThat(actionStatusRepository.findAll()).haveAtLeast(6, new ActionStatusCondition(Status.RUNNING));
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6,
+ new ActionStatusCondition(Status.RUNNING));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
@@ -862,9 +843,11 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
- assertThat(actionStatusRepository.findAll()).hasSize(8);
- assertThat(actionStatusRepository.findAll()).haveAtLeast(7, new ActionStatusCondition(Status.RUNNING));
- assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED));
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8);
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(7,
+ new ActionStatusCondition(Status.RUNNING));
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
+ new ActionStatusCondition(Status.CANCELED));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
@@ -876,10 +859,13 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
- assertThat(actionStatusRepository.findAll()).hasSize(9);
- assertThat(actionStatusRepository.findAll()).haveAtLeast(6, new ActionStatusCondition(Status.RUNNING));
- assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.WARNING));
- assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED));
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9);
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6,
+ new ActionStatusCondition(Status.RUNNING));
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
+ new ActionStatusCondition(Status.WARNING));
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
+ new ActionStatusCondition(Status.CANCELED));
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
@@ -896,29 +882,27 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(1);
- assertThat(actionStatusRepository.findAll()).hasSize(10);
- assertThat(actionStatusRepository.findAll()).haveAtLeast(7, new ActionStatusCondition(Status.RUNNING));
- assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.WARNING));
- assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED));
- assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED));
+ assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10);
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(7,
+ new ActionStatusCondition(Status.RUNNING));
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
+ new ActionStatusCondition(Status.WARNING));
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
+ new ActionStatusCondition(Status.CANCELED));
+ assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1,
+ new ActionStatusCondition(Status.FINISHED));
- assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10),
- (JpaDistributionSet) ds)).hasSize(1);
- assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), (JpaDistributionSet) ds))
- .hasSize(1);
- assertThat(targetRepository.findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet(
- new PageRequest(0, 10), (JpaDistributionSet) ds, (JpaDistributionSet) ds)).hasSize(1);
+ assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), pageReq)).hasSize(1);
+ assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1);
}
@Test
@Description("Various forbidden request appempts on the feedback resource. Ensures correct answering behaviour as expected to these kind of errors.")
public void badDeplomentActionFeedback() throws Exception {
- final Target target = targetManagement.generateTarget("4712");
- final Target target2 = targetManagement.generateTarget("4713");
- final DistributionSet savedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
- final DistributionSet savedSet2 = TestDataUtil.generateDistributionSet("1", softwareManagement,
- distributionSetManagement);
+ final Target target = entityFactory.generateTarget("4712");
+ final Target target2 = entityFactory.generateTarget("4713");
+ final DistributionSet savedSet = testdataFactory.createDistributionSet("");
+ final DistributionSet savedSet2 = testdataFactory.createDistributionSet("1");
// target does not exist
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/1234/feedback", tenantAware.getCurrentTenant())
diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java
index 490e76161..135754604 100644
--- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java
+++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java
@@ -24,13 +24,12 @@ import java.util.List;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.WithSpringAuthorityRule;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
+import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
@@ -80,7 +79,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD
// create target first with "knownPrincipal" user and audit data
final String knownTargetControllerId = "target1";
final String knownCreatedBy = "knownPrincipal";
- targetManagement.createTarget(targetManagement.generateTarget(knownTargetControllerId));
+ targetManagement.createTarget(entityFactory.generateTarget(knownTargetControllerId));
final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId);
assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy);
assertThat(findTargetByControllerID.getCreatedAt()).isNotNull();
@@ -121,7 +120,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
- assertThat(targetRepository.findByControllerId("4711").getTargetInfo().getUpdateStatus())
+ assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.REGISTERED);
// not allowed methods
@@ -169,9 +168,8 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD
mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()).header("If-None-Match", etag))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotModified());
- final Target target = targetRepository.findByControllerId("4711");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = targetManagement.findTargetByControllerID("4711");
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4711" });
@@ -204,8 +202,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotModified());
// Now another deployment
- final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds2 = testdataFactory.createDistributionSet("2");
deploymentManagement.assignDistributionSet(ds2.getId(), new String[] { "4711" });
@@ -226,10 +223,10 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD
@Description("Ensures that the target state machine of a precomissioned target switches from "
+ "UNKNOWN to REGISTERED when the target polls for the first time.")
public void rootRsPrecommissioned() throws Exception {
- final Target target = targetManagement.generateTarget("4711");
+ final Target target = entityFactory.generateTarget("4711");
targetManagement.createTarget(target);
- assertThat(targetRepository.findByControllerId("4711").getTargetInfo().getUpdateStatus())
+ assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.UNKNOWN);
final long current = System.currentTimeMillis();
@@ -242,7 +239,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD
assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery())
.isGreaterThanOrEqualTo(current);
- assertThat(targetRepository.findByControllerId("4711").getTargetInfo().getUpdateStatus())
+ assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.REGISTERED);
}
@@ -265,11 +262,10 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD
public void tryToFinishAnUpdateProcessAfterItHasBeenFinished() throws Exception {
// mock
- final Target target = targetManagement.generateTarget("911");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final Target target = entityFactory.generateTarget("911");
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
Target savedTarget = targetManagement.createTarget(target);
- final List toAssign = new ArrayList();
+ final List toAssign = new ArrayList<>();
toAssign.add(savedTarget);
savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next();
final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
diff --git a/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf-amqp/pom.xml
index d1cb0cb30..bcebc9628 100644
--- a/hawkbit-dmf-amqp/pom.xml
+++ b/hawkbit-dmf-amqp/pom.xml
@@ -73,6 +73,12 @@
+
+ org.eclipse.hawkbit
+ hawkbit-repository-test
+ ${project.version}
+ test
+
com.h2database
h2
diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java
index 90039d4ba..107850fc1 100644
--- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java
+++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java
@@ -34,6 +34,7 @@ import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
@@ -97,6 +98,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
@Autowired
private HostnameResolver hostnameResolver;
+ @Autowired
+ private EntityFactory entityFactory;
+
/**
* Constructor.
*
@@ -336,7 +340,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
final ActionUpdateStatus actionUpdateStatus = convertMessage(message, ActionUpdateStatus.class);
final Action action = checkActionExist(message, actionUpdateStatus);
- final ActionStatus actionStatus = controllerManagement.generateActionStatus();
+ final ActionStatus actionStatus = entityFactory.generateActionStatus();
actionUpdateStatus.getMessage().forEach(actionStatus::addMessage);
actionStatus.setAction(action);
@@ -449,4 +453,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
this.eventBus = eventBus;
}
+ void setEntityFactory(final EntityFactory entityFactory) {
+ this.entityFactory = entityFactory;
+ }
+
}
diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java
index a1dd54710..c9be9ffa6 100644
--- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java
+++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java
@@ -10,6 +10,8 @@ package org.eclipse.hawkbit;
import org.eclipse.hawkbit.amqp.AmqpSenderService;
import org.eclipse.hawkbit.amqp.DefaultAmqpSenderService;
+import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
+import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
@@ -22,6 +24,15 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
public class AmqpTestConfiguration {
+ /**
+ * @return the {@link SystemSecurityContext} singleton bean which make it
+ * accessible in beans which cannot access the service directly,
+ * e.g. JPA entities.
+ */
+ @Bean
+ public SystemSecurityContextHolder systemSecurityContextHolder() {
+ return SystemSecurityContextHolder.getInstance();
+ }
/**
* Method to set the Jackson2JsonMessageConverter.
diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java
index 132ddb650..480948683 100644
--- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java
+++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java
@@ -33,8 +33,7 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageType;
import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest;
import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
@@ -57,7 +56,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@ActiveProfiles({ "test" })
@Features("Component Tests - Device Management Federation API")
@Stories("AmqpMessage Dispatcher Service Test")
-public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWithMongoDB {
+public class AmqpMessageDispatcherServiceTest extends AbstractJpaIntegrationTestWithMongoDB {
private static final String TENANT = "default";
@@ -108,8 +107,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
@Test
@Description("Verfies that download and install event with 3 software moduls and no artifacts works")
public void testSendDownloadRequesWithSoftwareModulesAndNoArtifacts() {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent(
1L, TENANT, CONTROLLER_ID, 1L, dsA.getModules(), AMQP_URI, TEST_TOKEN);
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
@@ -139,11 +137,10 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
@Test
@Description("Verfies that download and install event with software moduls and artifacts works")
public void testSendDownloadRequest() {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
final SoftwareModule module = dsA.getModules().iterator().next();
final List receivedList = new ArrayList<>();
- for (final Artifact artifact : TestDataUtil.generateArtifacts(artifactManagement, module.getId())) {
+ for (final Artifact artifact : testdataFactory.createLocalArtifacts(module.getId())) {
module.addArtifact((LocalArtifact) artifact);
receivedList.add(new DbArtifact());
}
diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java
index 2ce6cd91c..283b08eed 100644
--- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java
+++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java
@@ -38,6 +38,7 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken;
import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.ControllerManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
@@ -85,6 +86,9 @@ public class AmqpMessageHandlerServiceTest {
@Mock
private ControllerManagement controllerManagementMock;
+ @Mock
+ private EntityFactory entityFactoryMock;
+
@Mock
private ArtifactManagement artifactManagementMock;
@@ -117,6 +121,7 @@ public class AmqpMessageHandlerServiceTest {
amqpMessageHandlerService.setCache(cacheMock);
amqpMessageHandlerService.setHostnameResolver(hostnameResolverMock);
amqpMessageHandlerService.setEventBus(eventBus);
+ amqpMessageHandlerService.setEntityFactory(entityFactoryMock);
}
@@ -350,7 +355,7 @@ public class AmqpMessageHandlerServiceTest {
final Action action = createActionWithTarget(22L, Status.FINISHED);
when(controllerManagementMock.findActionWithDetails(Matchers.any())).thenReturn(action);
when(controllerManagementMock.addUpdateActionStatus(Matchers.any())).thenReturn(action);
- when(controllerManagementMock.generateActionStatus()).thenReturn(new JpaActionStatus());
+ when(entityFactoryMock.generateActionStatus()).thenReturn(new JpaActionStatus());
// for the test the same action can be used
final List actionList = new ArrayList<>();
actionList.add(action);
diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java
index 3d83fed69..8f855da68 100644
--- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java
+++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java
@@ -14,12 +14,11 @@ import org.eclipse.hawkbit.AmqpTestConfiguration;
import org.eclipse.hawkbit.RepositoryApplicationConfiguration;
import org.eclipse.hawkbit.api.ArtifactUrlHandler;
import org.eclipse.hawkbit.api.UrlProtocol;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.repository.jpa.TestConfiguration;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
+import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.junit.Before;
import org.junit.Test;
@@ -53,11 +52,9 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest
@Before
public void setup() {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
final SoftwareModule module = dsA.getModules().iterator().next();
- localArtifact = (LocalArtifact) TestDataUtil.generateArtifacts(artifactManagement, module.getId()).stream()
- .findAny().get();
+ localArtifact = testdataFactory.createLocalArtifacts(module.getId()).stream().findAny().get();
softwareModuleId = localArtifact.getSoftwareModule().getId();
fileName = localArtifact.getFilename();
sha1Hash = localArtifact.getSha1Hash();
diff --git a/hawkbit-mgmt-resource/pom.xml b/hawkbit-mgmt-resource/pom.xml
index 2279172e9..fb0167793 100644
--- a/hawkbit-mgmt-resource/pom.xml
+++ b/hawkbit-mgmt-resource/pom.xml
@@ -47,6 +47,12 @@
+
+ org.eclipse.hawkbit
+ hawkbit-repository-test
+ ${project.version}
+ test
+
org.eclipse.hawkbit
hawkbit-rest-core
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java
index d4780f71c..4a0f8d90e 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java
@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -75,11 +76,12 @@ public final class MgmtDistributionSetMapper {
* @return converted list of {@link DistributionSet}s
*/
static List dsFromRequest(final Iterable sets,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
+ final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
+ final EntityFactory entityFactory) {
final List mappedList = new ArrayList<>();
for (final MgmtDistributionSetRequestBodyPost dsRest : sets) {
- mappedList.add(fromRequest(dsRest, softwareManagement, distributionSetManagement));
+ mappedList.add(fromRequest(dsRest, softwareManagement, distributionSetManagement, entityFactory));
}
return mappedList;
@@ -95,9 +97,10 @@ public final class MgmtDistributionSetMapper {
* @return converted {@link DistributionSet}
*/
static DistributionSet fromRequest(final MgmtDistributionSetRequestBodyPost dsRest,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
+ final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
+ final EntityFactory entityFactory) {
- final DistributionSet result = distributionSetManagement.generateDistributionSet();
+ final DistributionSet result = entityFactory.generateDistributionSet();
result.setDescription(dsRest.getDescription());
result.setName(dsRest.getName());
result.setType(findDistributionSetTypeWithExceptionIfNotFound(dsRest.getType(), distributionSetManagement));
@@ -135,14 +138,14 @@ public final class MgmtDistributionSetMapper {
* @return
*/
static List fromRequestDsMetadata(final DistributionSet ds,
- final List metadata, final DistributionSetManagement distributionSetManagement) {
+ final List metadata, final EntityFactory entityFactory) {
final List mappedList = new ArrayList<>(metadata.size());
for (final MgmtMetadata metadataRest : metadata) {
if (metadataRest.getKey() == null) {
throw new IllegalArgumentException("the key of the metadata must be present");
}
- mappedList.add(distributionSetManagement.generateDistributionSetMetadata(ds, metadataRest.getKey(),
- metadataRest.getValue()));
+ mappedList.add(
+ entityFactory.generateDistributionSetMetadata(ds, metadataRest.getKey(), metadataRest.getValue()));
}
return mappedList;
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
index e9249f551..e99a33c5f 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
@@ -28,6 +28,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
@@ -74,6 +75,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@Autowired
private TenantAware currentTenant;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Autowired
private DistributionSetManagement distributionSetManagement;
@@ -118,8 +122,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(this.systemManagement
.getTenantMetadata(this.currentTenant.getCurrentTenant()).getDefaultDsType().getKey()));
- final Iterable createdDSets = this.distributionSetManagement.createDistributionSets(
- MgmtDistributionSetMapper.dsFromRequest(sets, this.softwareManagement, this.distributionSetManagement));
+ final Iterable createdDSets = this.distributionSetManagement
+ .createDistributionSets(MgmtDistributionSetMapper.dsFromRequest(sets, this.softwareManagement,
+ this.distributionSetManagement, entityFactory));
LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED);
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets),
@@ -284,7 +289,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
// immediately
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
final DistributionSetMetadata updated = this.distributionSetManagement.updateDistributionSetMetadata(
- distributionSetManagement.generateDistributionSetMetadata(ds, metadataKey, metadata.getValue()));
+ entityFactory.generateDistributionSetMetadata(ds, metadataKey, metadata.getValue()));
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated));
}
@@ -307,7 +312,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
final List created = this.distributionSetManagement.createDistributionSetMetadata(
- MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, distributionSetManagement));
+ MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, entityFactory));
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED);
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java
index 69f6e044c..18ec162ca 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -54,6 +55,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@Autowired
private DistributionSetManagement distributionSetManagement;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity> getDistributionSetTags(
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@@ -97,7 +101,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
LOG.debug("creating {} ds tags", tags.size());
final List createdTags = this.tagManagement
- .createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(tagManagement, tags));
+ .createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(entityFactory, tags));
return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java
index a6dd6f32b..5c139027c 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionS
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
-import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -36,21 +36,21 @@ final class MgmtDistributionSetTypeMapper {
}
- static List smFromRequest(final DistributionSetManagement distributionSetManagement,
+ static List smFromRequest(final EntityFactory entityFactory,
final SoftwareManagement softwareManagement,
final Iterable smTypesRest) {
final List mappedList = new ArrayList<>();
for (final MgmtDistributionSetTypeRequestBodyPost smRest : smTypesRest) {
- mappedList.add(fromRequest(distributionSetManagement, softwareManagement, smRest));
+ mappedList.add(fromRequest(entityFactory, softwareManagement, smRest));
}
return mappedList;
}
- static DistributionSetType fromRequest(final DistributionSetManagement distributionSetManagement,
+ static DistributionSetType fromRequest(final EntityFactory entityFactory,
final SoftwareManagement softwareManagement, final MgmtDistributionSetTypeRequestBodyPost smsRest) {
- final DistributionSetType result = distributionSetManagement.generateDistributionSetType(smsRest.getKey(),
+ final DistributionSetType result = entityFactory.generateDistributionSetType(smsRest.getKey(),
smsRest.getName(), smsRest.getDescription());
// Add mandatory
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
index 16cba384b..d69e4d8d4 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModule
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -53,6 +54,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@Autowired
private DistributionSetManagement distributionSetManagement;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity> getDistributionSetTypes(
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@@ -121,9 +125,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
public ResponseEntity> createDistributionSetTypes(
@RequestBody final List distributionSetTypes) {
- final List createdSoftwareModules = distributionSetManagement
- .createDistributionSetTypes(MgmtDistributionSetTypeMapper.smFromRequest(distributionSetManagement,
- softwareManagement, distributionSetTypes));
+ final List createdSoftwareModules = distributionSetManagement.createDistributionSetTypes(
+ MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, softwareManagement, distributionSetTypes));
return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toTypesResponse(createdSoftwareModules),
HttpStatus.CREATED);
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java
index e80889508..7467a45b0 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java
@@ -22,7 +22,7 @@ import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutSuccessAction.Succ
import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
-import org.eclipse.hawkbit.repository.RolloutManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Rollout;
@@ -84,9 +84,9 @@ final class MgmtRolloutMapper {
return body;
}
- static Rollout fromRequest(final RolloutManagement rolloutManagement, final MgmtRolloutRestRequestBody restRequest,
+ static Rollout fromRequest(final EntityFactory entityFactory, final MgmtRolloutRestRequestBody restRequest,
final DistributionSet distributionSet, final String filterQuery) {
- final Rollout rollout = rolloutManagement.generateRollout();
+ final Rollout rollout = entityFactory.generateRollout();
rollout.setName(restRequest.getName());
rollout.setDescription(restRequest.getDescription());
rollout.setDistributionSet(distributionSet);
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
index 0b3a77101..623241981 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
@@ -18,6 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
@@ -63,6 +64,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
@Autowired
private DistributionSetManagement distributionSetManagement;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity> getRollouts(
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@@ -138,7 +142,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
.successAction(successAction, successActionExpr).errorCondition(errorCondition, errorConditionExpr)
.errorAction(errorAction, errorActionExpr).build();
final Rollout rollout = this.rolloutManagement.createRollout(
- MgmtRolloutMapper.fromRequest(rolloutManagement, rolloutRequestBody, distributionSet,
+ MgmtRolloutMapper.fromRequest(entityFactory, rolloutRequestBody, distributionSet,
rolloutRequestBody.getTargetFilterQuery()),
rolloutRequestBody.getAmountGroups(), rolloutGroupConditions);
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java
index ff721dfbc..adc19df0a 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java
@@ -22,6 +22,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequ
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
@@ -52,31 +53,31 @@ public final class MgmtSoftwareModuleMapper {
return smType;
}
- static SoftwareModule fromRequest(final MgmtSoftwareModuleRequestBodyPost smsRest,
- final SoftwareManagement softwareManagement) {
- return softwareManagement.generateSoftwareModule(
+ static SoftwareModule fromRequest(final EntityFactory entityFactory,
+ final MgmtSoftwareModuleRequestBodyPost smsRest, final SoftwareManagement softwareManagement) {
+ return entityFactory.generateSoftwareModule(
getSoftwareModuleTypeFromKeyString(smsRest.getType(), softwareManagement), smsRest.getName(),
smsRest.getVersion(), smsRest.getDescription(), smsRest.getVendor());
}
- static List fromRequestSwMetadata(final SoftwareManagement softwareManagement,
+ static List fromRequestSwMetadata(final EntityFactory entityFactory,
final SoftwareModule sw, final List metadata) {
final List mappedList = new ArrayList<>(metadata.size());
for (final MgmtMetadata metadataRest : metadata) {
if (metadataRest.getKey() == null) {
throw new IllegalArgumentException("the key of the metadata must be present");
}
- mappedList.add(softwareManagement.generateSoftwareModuleMetadata(sw, metadataRest.getKey(),
- metadataRest.getValue()));
+ mappedList.add(
+ entityFactory.generateSoftwareModuleMetadata(sw, metadataRest.getKey(), metadataRest.getValue()));
}
return mappedList;
}
- static List smFromRequest(final Iterable smsRest,
- final SoftwareManagement softwareManagement) {
+ static List smFromRequest(final EntityFactory entityFactory,
+ final Iterable smsRest, final SoftwareManagement softwareManagement) {
final List mappedList = new ArrayList<>();
for (final MgmtSoftwareModuleRequestBodyPost smRest : smsRest) {
- mappedList.add(fromRequest(smRest, softwareManagement));
+ mappedList.add(fromRequest(entityFactory, smRest, softwareManagement));
}
return mappedList;
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java
index aeaffa013..b4f1e8adb 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequ
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi;
import org.eclipse.hawkbit.repository.ArtifactManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -57,6 +58,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@Autowired
private SoftwareManagement softwareManagement;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
@RequestParam("file") final MultipartFile file,
@@ -158,8 +162,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
public ResponseEntity> createSoftwareModules(
@RequestBody final List softwareModules) {
LOG.debug("creating {} softwareModules", softwareModules.size());
- final Iterable createdSoftwareModules = softwareManagement
- .createSoftwareModule(MgmtSoftwareModuleMapper.smFromRequest(softwareModules, softwareManagement));
+ final Iterable createdSoftwareModules = softwareManagement.createSoftwareModule(
+ MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules, softwareManagement));
LOG.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED);
return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSoftwareModules(createdSoftwareModules),
@@ -237,7 +241,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) {
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata(
- softwareManagement.generateSoftwareModuleMetadata(sw, metadataKey, metadata.getValue()));
+ entityFactory.generateSoftwareModuleMetadata(sw, metadataKey, metadata.getValue()));
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated));
}
@@ -256,7 +260,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
final List created = softwareManagement.createSoftwareModuleMetadata(
- MgmtSoftwareModuleMapper.fromRequestSwMetadata(softwareManagement, sw, metadataRest));
+ MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, sw, metadataRest));
return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(created), HttpStatus.CREATED);
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java
index f52ea7f2a..565af7eb8 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java
@@ -18,7 +18,7 @@ import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
-import org.eclipse.hawkbit.repository.SoftwareManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
/**
@@ -36,19 +36,19 @@ final class MgmtSoftwareModuleTypeMapper {
}
- static List smFromRequest(final SoftwareManagement softwareManagement,
+ static List smFromRequest(final EntityFactory entityFactory,
final Iterable smTypesRest) {
final List mappedList = new ArrayList<>();
for (final MgmtSoftwareModuleTypeRequestBodyPost smRest : smTypesRest) {
- mappedList.add(fromRequest(softwareManagement, smRest));
+ mappedList.add(fromRequest(entityFactory, smRest));
}
return mappedList;
}
- static SoftwareModuleType fromRequest(final SoftwareManagement softwareManagement,
+ static SoftwareModuleType fromRequest(final EntityFactory entityFactory,
final MgmtSoftwareModuleTypeRequestBodyPost smsRest) {
- final SoftwareModuleType result = softwareManagement.generateSoftwareModuleType();
+ final SoftwareModuleType result = entityFactory.generateSoftwareModuleType();
result.setName(smsRest.getName());
result.setKey(smsRest.getKey());
result.setDescription(smsRest.getDescription());
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
index bbb61571c..353cf16e5 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModule
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -44,6 +45,9 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@Autowired
private SoftwareManagement softwareManagement;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity> getTypes(
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@@ -110,7 +114,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@RequestBody final List softwareModuleTypes) {
final List createdSoftwareModules = this.softwareManagement.createSoftwareModuleType(
- MgmtSoftwareModuleTypeMapper.smFromRequest(softwareManagement, softwareModuleTypes));
+ MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes));
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules),
HttpStatus.CREATED);
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java
index 7ede69658..bac21c2a5 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
-import org.eclipse.hawkbit.repository.TagManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.TargetTag;
@@ -96,21 +96,21 @@ final class MgmtTagMapper {
return response;
}
- static List mapTargeTagFromRequest(final TagManagement tagManagement,
+ static List mapTargeTagFromRequest(final EntityFactory entityFactory,
final Iterable tags) {
final List mappedList = new ArrayList<>();
for (final MgmtTagRequestBodyPut targetTagRest : tags) {
- mappedList.add(tagManagement.generateTargetTag(targetTagRest.getName(), targetTagRest.getDescription(),
+ mappedList.add(entityFactory.generateTargetTag(targetTagRest.getName(), targetTagRest.getDescription(),
targetTagRest.getColour()));
}
return mappedList;
}
- static List mapDistributionSetTagFromRequest(final TagManagement tagManagement,
+ static List mapDistributionSetTagFromRequest(final EntityFactory entityFactory,
final Iterable tags) {
final List mappedList = new ArrayList<>();
for (final MgmtTagRequestBodyPut targetTagRest : tags) {
- mappedList.add(tagManagement.generateDistributionSetTag(targetTagRest.getName(),
+ mappedList.add(entityFactory.generateDistributionSetTag(targetTagRest.getName(),
targetTagRest.getDescription(), targetTagRest.getColour()));
}
return mappedList;
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java
index b377e95f7..f00998d29 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java
@@ -25,7 +25,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.eclipse.hawkbit.repository.ActionFields;
-import org.eclipse.hawkbit.repository.TargetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.PollStatus;
@@ -169,17 +169,17 @@ public final class MgmtTargetMapper {
return targetRest;
}
- static List fromRequest(final TargetManagement targetManagement,
+ static List fromRequest(final EntityFactory entityFactory,
final Iterable targetsRest) {
final List mappedList = new ArrayList<>();
for (final MgmtTargetRequestBody targetRest : targetsRest) {
- mappedList.add(fromRequest(targetManagement, targetRest));
+ mappedList.add(fromRequest(entityFactory, targetRest));
}
return mappedList;
}
- static Target fromRequest(final TargetManagement targetManagement, final MgmtTargetRequestBody targetRest) {
- final Target target = targetManagement.generateTarget(targetRest.getControllerId());
+ static Target fromRequest(final EntityFactory entityFactory, final MgmtTargetRequestBody targetRest) {
+ final Target target = entityFactory.generateTarget(targetRest.getControllerId());
target.setDescription(targetRest.getDescription());
target.setName(targetRest.getName());
return target;
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
index e02072238..cc7bbcde6 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
@@ -28,6 +28,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.DeploymentManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -63,6 +64,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Autowired
private DeploymentManagement deploymentManagement;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity getTarget(@PathVariable("targetId") final String targetId) {
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
@@ -105,7 +109,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity> createTargets(@RequestBody final List targets) {
LOG.debug("creating {} targets", targets.size());
final Iterable createdTargets = this.targetManagement
- .createTargets(MgmtTargetMapper.fromRequest(targetManagement, targets));
+ .createTargets(MgmtTargetMapper.fromRequest(entityFactory, targets));
LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED);
return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets), HttpStatus.CREATED);
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java
index 7d1ba3f7f..c765c18cd 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java
@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTargetTagAssigmentResult;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
@@ -54,6 +55,9 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@Autowired
private TargetManagement targetManagement;
+ @Autowired
+ private EntityFactory entityFactory;
+
@Override
public ResponseEntity> getTargetTags(
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@@ -93,7 +97,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
public ResponseEntity> createTargetTags(@RequestBody final List tags) {
LOG.debug("creating {} target tags", tags.size());
final List createdTargetTags = this.tagManagement
- .createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(tagManagement, tags));
+ .createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(entityFactory, tags));
return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED);
}
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 700a2735c..b4887c40c 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
@@ -28,13 +28,13 @@ import java.util.Set;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.repository.util.TestdataFactory;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
@@ -60,8 +60,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
@Description("This test verifies the call of all Software Modules that are assiged to a Distribution Set through the RESTful API.")
public void getSoftwaremodules() throws Exception {
// Create DistributionSet with three software modules
- final DistributionSet set = TestDataUtil.generateDistributionSet("SMTest", softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createDistributionSet("SMTest");
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(set.getModules().size())));
@@ -72,10 +71,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
public void deleteFailureWhenDistributionSetInUse() throws Exception {
// create DisSet
- final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Eris", "560a",
- distributionSetManagement);
- final List smIDs = new ArrayList();
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Dysnomia ", "15,772", null, null);
+ final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Eris", "560a");
+ final List smIDs = new ArrayList<>();
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Dysnomia ", "15,772", null, null);
sm = softwareManagement.createSoftwareModule(sm);
smIDs.add(sm.getId());
final JSONArray smList = new JSONArray();
@@ -91,7 +89,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String[] knownTargetIds = new String[] { "1", "2" };
final JSONArray list = new JSONArray();
for (final String targetId : knownTargetIds) {
- targetManagement.createTarget(targetManagement.generateTarget(targetId));
+ targetManagement.createTarget(entityFactory.generateTarget(targetId));
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
}
deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]);
@@ -116,10 +114,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
public void assignmentFailureWhenAssigningToUsedDistributionSet() throws Exception {
// create DisSet
- final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Mars", "686,980",
- distributionSetManagement);
+ final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Mars", "686,980");
final List smIDs = new ArrayList<>();
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Phobos", "0,3189", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Phobos", "0,3189", null, null);
sm = softwareManagement.createSoftwareModule(sm);
smIDs.add(sm.getId());
final JSONArray smList = new JSONArray();
@@ -135,7 +132,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String[] knownTargetIds = new String[] { "1", "2" };
final JSONArray list = new JSONArray();
for (final String targetId : knownTargetIds) {
- targetManagement.createTarget(targetManagement.generateTarget(targetId));
+ targetManagement.createTarget(entityFactory.generateTarget(targetId));
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
}
// assign DisSet to target and test assignment
@@ -150,7 +147,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
// Create another SM and post assignment
final List smID2s = new ArrayList<>();
- SoftwareModule sm2 = softwareManagement.generateSoftwareModule(appType, "Deimos", "1,262", null, null);
+ SoftwareModule sm2 = entityFactory.generateSoftwareModule(appType, "Deimos", "1,262", null, null);
sm2 = softwareManagement.createSoftwareModule(sm2);
smID2s.add(sm2.getId());
final JSONArray smList2 = new JSONArray();
@@ -169,21 +166,20 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
public void assignSoftwaremoduleToDistributionSet() throws Exception {
// create DisSet
- final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Jupiter", "398,88",
- distributionSetManagement);
+ final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Jupiter", "398,88");
// Test if size is 0
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(disSet.getModules().size())));
// create Software Modules
- final List smIDs = new ArrayList();
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Europa", "3,551", null, null);
+ final List smIDs = new ArrayList<>();
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Europa", "3,551", null, null);
sm = softwareManagement.createSoftwareModule(sm);
smIDs.add(sm.getId());
- SoftwareModule sm2 = softwareManagement.generateSoftwareModule(appType, "Ganymed", "7,155", null, null);
+ SoftwareModule sm2 = entityFactory.generateSoftwareModule(appType, "Ganymed", "7,155", null, null);
sm2 = softwareManagement.createSoftwareModule(sm2);
smIDs.add(sm2.getId());
- SoftwareModule sm3 = softwareManagement.generateSoftwareModule(runtimeType, "Kallisto", "16,689", null, null);
+ SoftwareModule sm3 = entityFactory.generateSoftwareModule(runtimeType, "Kallisto", "16,689", null, null);
sm3 = softwareManagement.createSoftwareModule(sm3);
smIDs.add(sm3.getId());
final JSONArray list = new JSONArray();
@@ -205,8 +201,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
public void unassignSoftwaremoduleFromDistributionSet() throws Exception {
// Create DistributionSet with three software modules
- final DistributionSet set = TestDataUtil.generateDistributionSet("Venus", softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createDistributionSet("Venus");
int amountOfSM = set.getModules().size();
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -233,7 +228,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" };
final JSONArray list = new JSONArray();
for (final String targetId : knownTargetIds) {
- targetManagement.createTarget(targetManagement.generateTarget(targetId));
+ targetManagement.createTarget(entityFactory.generateTarget(targetId));
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
}
// assign already one target to DS
@@ -257,7 +252,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String knownTargetId = "knownTargetId1";
final Set createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1);
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
- targetManagement.createTarget(targetManagement.generateTarget(knownTargetId));
+ targetManagement.createTarget(entityFactory.generateTarget(knownTargetId));
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId);
mvc.perform(get(
@@ -284,15 +279,15 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String knownTargetId = "knownTargetId1";
final Set createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1);
final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next();
- final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget(knownTargetId));
+ final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownTargetId));
// create some dummy targets which are not assigned or installed
- targetManagement.createTarget(targetManagement.generateTarget("dummy1"));
- targetManagement.createTarget(targetManagement.generateTarget("dummy2"));
+ targetManagement.createTarget(entityFactory.generateTarget("dummy1"));
+ targetManagement.createTarget(entityFactory.generateTarget("dummy2"));
// assign knownTargetId to distribution set
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId);
// make it in install state
- TestDataUtil.sendUpdateActionStatusToTargets(controllerManagament, targetManagement, actionRepository,
- createdDs, Lists.newArrayList(createTarget), Status.FINISHED, "some message");
+ testdataFactory.sendUpdateActionStatusToTargets(Lists.newArrayList(createTarget), Status.FINISHED,
+ "some message");
mvc.perform(get(
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets"))
@@ -350,8 +345,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(0);
- DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ DistributionSet set = testdataFactory.createDistributionSet("one");
set.setRequiredMigrationStep(set.isRequiredMigrationStep());
set = distributionSetManagement.updateDistributionSet(set);
@@ -393,8 +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 = TestDataUtil.createTestDistributionSet(softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createTestDistributionSet();
// perform request
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON))
@@ -429,16 +422,16 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(0);
- final SoftwareModule ah = softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
- final SoftwareModule jvm = softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
- final SoftwareModule os = softwareManagement
- .createSoftwareModule(softwareManagement.generateSoftwareModule(osType, "poky", "3.0.2", null, ""));
+ final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
+ final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
+ final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
- DistributionSet one = TestDataUtil.buildDistributionSet("one", "one", standardDsType, os, jvm, ah);
- DistributionSet two = TestDataUtil.buildDistributionSet("two", "two", standardDsType, os, jvm, ah);
- DistributionSet three = TestDataUtil.buildDistributionSet("three", "three", standardDsType, os, jvm, ah);
+ DistributionSet one = testdataFactory.generateDistributionSet("one", "one", standardDsType,
+ Lists.newArrayList(os, jvm, ah));
+ DistributionSet two = testdataFactory.generateDistributionSet("two", "two", standardDsType,
+ Lists.newArrayList(os, jvm, ah));
+ DistributionSet three = testdataFactory.generateDistributionSet("three", "three", standardDsType,
+ Lists.newArrayList(os, jvm, ah));
three.setRequiredMigrationStep(true);
final List sets = new ArrayList<>();
@@ -547,8 +540,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(0);
- final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(1);
@@ -560,7 +552,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
// check repository content
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.isEmpty();
- assertThat(distributionSetRepository.findAll()).isEmpty();
+ assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(0);
}
@Test
@@ -570,9 +562,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(0);
- final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
- targetManagement.createTarget(targetManagement.generateTarget("test"));
+ final DistributionSet set = testdataFactory.createDistributionSet("one");
+ targetManagement.createTarget(entityFactory.generateTarget("test"));
deploymentManagement.assignDistributionSet(set.getId(), "test");
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
@@ -597,13 +588,12 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(0);
- final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(1);
- final DistributionSet update = distributionSetManagement.generateDistributionSet();
+ final DistributionSet update = entityFactory.generateDistributionSet();
update.setVersion("anotherVersion");
update.setName(null);
update.setType(standardDsType);
@@ -621,8 +611,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
@Test
@Description("Ensures that the server reacts properly to invalid requests (URI, Media Type, Methods) with correct reponses.")
public void invalidRequestsOnDistributionSetsResource() throws Exception {
- final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createDistributionSet("one");
final List sets = new ArrayList<>();
sets.add(set);
@@ -663,8 +652,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
@Test
@Description("Ensures that the metadata creation through API is reflected by the repository.")
public void createMetadata() throws Exception {
- final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet testDS = testdataFactory.createDistributionSet("one");
final String knownKey1 = "knownKey1";
final String knownKey2 = "knownKey2";
@@ -699,10 +687,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String knownValue = "knownValue";
final String updateValue = "valueForUpdate";
- final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet testDS = testdataFactory.createDistributionSet("one");
distributionSetManagement.createDistributionSetMetadata(
- distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue));
+ entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue));
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
@@ -724,10 +711,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String knownKey = "knownKey";
final String knownValue = "knownValue";
- final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet testDS = testdataFactory.createDistributionSet("one");
distributionSetManagement.createDistributionSetMetadata(
- distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue));
+ entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue));
mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
@@ -746,10 +732,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
// prepare and create metadata
final String knownKey = "knownKey";
final String knownValue = "knownValue";
- final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet testDS = testdataFactory.createDistributionSet("one");
distributionSetManagement.createDistributionSetMetadata(
- distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue));
+ entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue));
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -765,12 +750,11 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String offsetParam = "0";
final String knownKeyPrefix = "knownKey";
final String knownValuePrefix = "knownValue";
- final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet testDS = testdataFactory.createDistributionSet("one");
for (int index = 0; index < totalMetadata; index++) {
- distributionSetManagement.createDistributionSetMetadata(distributionSetManagement
- .generateDistributionSetMetadata(distributionSetManagement.findDistributionSetById(testDS.getId()),
- knownKeyPrefix + index, knownValuePrefix + index));
+ distributionSetManagement.createDistributionSetMetadata(entityFactory.generateDistributionSetMetadata(
+ distributionSetManagement.findDistributionSetById(testDS.getId()), knownKeyPrefix + index,
+ knownValuePrefix + index));
}
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam,
@@ -786,9 +770,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
public void searchDistributionSetRsql() throws Exception {
final String dsSuffix = "test";
final int amount = 10;
- TestDataUtil.generateDistributionSets(dsSuffix, amount, softwareManagement, distributionSetManagement);
- TestDataUtil.generateDistributionSet("DS1test", softwareManagement, distributionSetManagement);
- TestDataUtil.generateDistributionSet("DS2test", softwareManagement, distributionSetManagement);
+ testdataFactory.createDistributionSets(dsSuffix, amount);
+ testdataFactory.createDistributionSet("DS1test");
+ testdataFactory.createDistributionSet("DS2test");
final String rsqlFindLikeDs1OrDs2 = "name==DS1test,name==DS2test";
@@ -803,9 +787,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
@Description("Ensures that a DS search with complete==true parameter returns only DS that are actually completely filled with mandatory modules.")
public void filterDistributionSetComplete() throws Exception {
final int amount = 10;
- TestDataUtil.generateDistributionSets(amount, softwareManagement, distributionSetManagement);
- distributionSetManagement.createDistributionSet(distributionSetManagement.generateDistributionSet("incomplete",
- "2", "incomplete", distributionSetManagement.findDistributionSetTypeByKey("ecl_os"), null));
+ testdataFactory.createDistributionSets(amount);
+ distributionSetManagement.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2",
+ "incomplete", distributionSetManagement.findDistributionSetTypeByKey("ecl_os"), null));
final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE;
@@ -824,7 +808,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" };
final JSONArray list = new JSONArray();
for (final String targetId : knownTargetIds) {
- targetManagement.createTarget(targetManagement.generateTarget(targetId));
+ targetManagement.createTarget(entityFactory.generateTarget(targetId));
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
}
@@ -846,12 +830,11 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final int totalMetadata = 10;
final String knownKeyPrefix = "knownKey";
final String knownValuePrefix = "knownValue";
- final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet testDS = testdataFactory.createDistributionSet("one");
for (int index = 0; index < totalMetadata; index++) {
- distributionSetManagement.createDistributionSetMetadata(distributionSetManagement
- .generateDistributionSetMetadata(distributionSetManagement.findDistributionSetById(testDS.getId()),
- knownKeyPrefix + index, knownValuePrefix + index));
+ distributionSetManagement.createDistributionSetMetadata(entityFactory.generateDistributionSetMetadata(
+ distributionSetManagement.findDistributionSetById(testDS.getId()), knownKeyPrefix + index,
+ knownValuePrefix + index));
}
final String rsqlSearchValue1 = "value==knownValue1";
@@ -867,7 +850,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final Set created = new HashSet<>();
for (int index = 0; index < amount; index++) {
final String str = String.valueOf(character);
- created.add(TestDataUtil.generateDistributionSet(str, softwareManagement, distributionSetManagement));
+ created.add(testdataFactory.createDistributionSet(str));
character++;
}
return created;
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
index d4596bde7..ad6be0854 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
@@ -24,10 +24,10 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
@@ -58,10 +58,12 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
public void getDistributionSetTypes() throws Exception {
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
testType.setDescription("Desc1234");
testType = distributionSetManagement.updateDistributionSetType(testType);
+ // 4 types overall (2 hawkbit tenant default, 1 test default and 1
+ // generated in this test)
mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
@@ -96,7 +98,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
public void getDistributionSetTypesSortedByKey() throws Exception {
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("zzzzz", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("zzzzz", "TestName123", "Desc123"));
testType.setDescription("Desc1234");
testType = distributionSetManagement.updateDistributionSetType(testType);
@@ -111,7 +113,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
.andExpect(jsonPath("$content.[0].createdAt", equalTo(testType.getCreatedAt())))
.andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo("uploadTester")))
.andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
- .andExpect(jsonPath("$content.[0].key", equalTo("zzzzz"))).andExpect(jsonPath("$total", equalTo(4)));
+ .andExpect(jsonPath("$content.[0].key", equalTo("zzzzz")))
+ .andExpect(jsonPath("$total", equalTo(DEFAULT_DS_TYPES + 1)));
// ascending
mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)
@@ -124,7 +127,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
.andExpect(jsonPath("$content.[3].createdAt", equalTo(testType.getCreatedAt())))
.andExpect(jsonPath("$content.[3].lastModifiedBy", equalTo("uploadTester")))
.andExpect(jsonPath("$content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
- .andExpect(jsonPath("$content.[3].key", equalTo("zzzzz"))).andExpect(jsonPath("$total", equalTo(4)));
+ .andExpect(jsonPath("$content.[3].key", equalTo("zzzzz")))
+ .andExpect(jsonPath("$total", equalTo(DEFAULT_DS_TYPES + 1)));
}
@Test
@@ -132,14 +136,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes POST requests.")
public void createDistributionSetTypes() throws JSONException, Exception {
- assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(3);
+ assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES);
final List types = new ArrayList<>();
- types.add(distributionSetManagement.generateDistributionSetType("test1", "TestName1", "Desc1")
+ types.add(entityFactory.generateDistributionSetType("test1", "TestName1", "Desc1")
.addMandatoryModuleType(osType).addOptionalModuleType(runtimeType));
- types.add(distributionSetManagement.generateDistributionSetType("test2", "TestName2", "Desc2")
+ types.add(entityFactory.generateDistributionSetType("test2", "TestName2", "Desc2")
.addOptionalModuleType(osType).addOptionalModuleType(runtimeType).addOptionalModuleType(appType));
- types.add(distributionSetManagement.generateDistributionSetType("test3", "TestName3", "Desc3")
+ types.add(entityFactory.generateDistributionSetType("test3", "TestName3", "Desc3")
.addMandatoryModuleType(osType).addMandatoryModuleType(runtimeType));
final MvcResult mvcResult = mvc
@@ -205,7 +209,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.")
public void addMandatoryModuleToDistributionSetType() throws JSONException, Exception {
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId())
@@ -224,7 +228,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.")
public void addOptionalModuleToDistributionSetType() throws JSONException, Exception {
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId())
@@ -244,7 +248,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes GET requests.")
public void getMandatoryModulesOfDistributionSetType() throws JSONException, Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
@@ -263,7 +267,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes GET requests.")
public void getOptionalModulesOfDistributionSetType() throws JSONException, Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
@@ -274,7 +278,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("[0].name", equalTo(appType.getName())))
.andExpect(jsonPath("[0].description", equalTo(appType.getDescription())))
- .andExpect(jsonPath("[0].maxAssignments", equalTo(1)))
+ .andExpect(jsonPath("[0].maxAssignments", equalTo(Integer.MAX_VALUE)))
.andExpect(jsonPath("[0].key", equalTo("application")));
}
@@ -283,7 +287,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} GET requests.")
public void getMandatoryModuleOfDistributionSetType() throws JSONException, Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
@@ -305,7 +309,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} GET requests.")
public void getOptionalModuleOfDistributionSetType() throws JSONException, Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
@@ -327,7 +331,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} DELETE requests.")
public void removeMandatoryModuleToDistributionSetType() throws JSONException, Exception {
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
@@ -349,7 +353,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} DELETE requests.")
public void removeOptionalModuleToDistributionSetType() throws JSONException, Exception {
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")
.addMandatoryModuleType(osType).addOptionalModuleType(appType));
assertThat(testType.getOptLockRevision()).isEqualTo(1);
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
@@ -372,7 +376,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
public void getDistributionSetType() throws Exception {
DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
testType.setDescription("Desc1234");
testType = distributionSetManagement.updateDistributionSetType(testType);
@@ -391,14 +395,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).")
public void deleteDistributionSetTypeUnused() throws Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
- assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(4);
+ assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1);
mvc.perform(delete("/rest/v1/distributionsettypes/{dsId}", testType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
- assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(3);
+ assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES);
}
@Test
@@ -406,25 +410,25 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).")
public void deleteDistributionSetTypeUsed() throws Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
distributionSetManagement.createDistributionSet(
- distributionSetManagement.generateDistributionSet("sdfsd", "dsfsdf", "sdfsdf", testType, null));
+ entityFactory.generateDistributionSet("sdfsd", "dsfsdf", "sdfsdf", testType, null));
- assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(4);
- assertThat(distributionSetTypeRepository.count()).isEqualTo(4);
+ assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1);
+ assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1);
mvc.perform(delete("/rest/v1/distributionsettypes/{smId}", testType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
- assertThat(distributionSetTypeRepository.count()).isEqualTo(4);
- assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(3);
+ assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1);
+ assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES);
}
@Test
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} PUT requests.")
public void updateDistributionSetTypeOnlyDescriptionAndNameUntouched() throws Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc")
.put("name", "nameShouldNotBeChanged").toString();
@@ -439,6 +443,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Test
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.")
public void getDistributionSetTypesWithoutAddtionalRequestParameters() throws Exception {
+
+ // 3 types overall (2 hawkbit tenant default, 1 test default
final int types = 3;
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk())
@@ -450,7 +456,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Test
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.")
public void getDistributionSetTypesWithPagingLimitRequestParameter() throws Exception {
- final int types = 3;
+
+ final int types = DEFAULT_DS_TYPES;
final int limitSize = 1;
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
@@ -463,7 +470,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Test
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.")
public void getDistributionSetTypesWithPagingLimitAndOffsetRequestParameter() throws Exception {
- final int types = 3;
+
+ final int types = DEFAULT_DS_TYPES;
final int offsetParam = 2;
final int expectedSize = types - offsetParam;
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
@@ -479,10 +487,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).")
public void invalidRequestsOnDistributionSetTypesResource() throws Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
final SoftwareModuleType testSmType = softwareManagement.createSoftwareModuleType(
- softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
final List types = new ArrayList<>();
types.add(testType);
@@ -525,10 +533,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
// Modules types at creation time invalid
- final DistributionSetType testNewType = distributionSetManagement.generateDistributionSetType("test123",
+ final DistributionSetType testNewType = entityFactory.generateDistributionSetType("test123",
"TestName123", "Desc123");
testNewType.addMandatoryModuleType(
- softwareManagement.generateSoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE));
+ entityFactory.generateSoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE));
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Lists.newArrayList(testNewType)))
@@ -562,9 +570,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
@Description("Search erquest of software module types.")
public void searchDistributionSetTypeRsql() throws Exception {
final DistributionSetType testType = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123"));
+ entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"));
final DistributionSetType testType2 = distributionSetManagement.createDistributionSetType(
- distributionSetManagement.generateDistributionSetType("test1234", "TestName1234", "Desc123"));
+ entityFactory.generateDistributionSetType("test1234", "TestName1234", "Desc123"));
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
@@ -578,7 +586,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
char character = 'a';
for (int index = 0; index < amount; index++) {
final String str = String.valueOf(character);
- final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str);
+ final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str);
softwareManagement.createSoftwareModule(softwareModule);
character++;
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java
index fcdbfa918..16cc82e75 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java
@@ -15,7 +15,6 @@ import org.eclipse.hawkbit.cache.CacheConstants;
import org.eclipse.hawkbit.cache.DownloadArtifactCache;
import org.eclipse.hawkbit.cache.DownloadType;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -46,11 +45,9 @@ public class MgmtDownloadResourceTest extends AbstractRestIntegrationTestWithMon
@Before
public void setupCache() {
- final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("Test", softwareManagement,
- distributionSetManagement);
+ final DistributionSet distributionSet = testdataFactory.createDistributionSet("Test");
final SoftwareModule softwareModule = distributionSet.getModules().stream().findFirst().get();
- final Artifact artifact = TestDataUtil.generateArtifacts(artifactManagement, softwareModule.getId()).stream()
- .findFirst().get();
+ final Artifact artifact = testdataFactory.createLocalArtifacts(softwareModule.getId()).stream().findFirst().get();
downloadIdCache.put(downloadIdSha1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash()));
}
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java
index fd171b7da..ff49542ce 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java
@@ -24,13 +24,12 @@ import java.util.concurrent.Callable;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
@@ -73,8 +72,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
@Description("Testing that creating rollout with insufficient permission returns forbidden")
@WithUser(allSpPermissions = true, removeFromAllPermission = "ROLLOUT_MANAGEMENT")
public void createRolloutWithInsufficientPermissionReturnsForbidden() throws Exception {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
mvc.perform(post("/rest/v1/rollouts")
.content(JsonBuilder.rollout("name", "desc", 10, dsA.getId(), "name==test", null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
@@ -92,8 +90,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
@Test
@Description("Testing that creating rollout with not valid formed target filter query returns bad request")
public void createRolloutWithNotWellFormedFilterReturnsBadRequest() throws Exception {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
mvc.perform(post("/rest/v1/rollouts")
.content(JsonBuilder.rollout("name", "desc", 10, dsA.getId(), "name=test", null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
@@ -107,8 +104,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
final String targetFilterQuery = null;
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
mvc.perform(post("/rest/v1/rollouts")
.content(JsonBuilder.rollout("rollout1", "desc", 10, dsA.getId(), targetFilterQuery, null))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
@@ -121,8 +117,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
@Test
@Description("Testing that rollout can be created")
public void createRollout() throws Exception {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
postRollout("rollout1", 10, dsA.getId(), "name==target1");
}
@@ -137,8 +132,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
@Test
@Description("Testing that rollout paged list contains rollouts")
public void rolloutPagedListContainsAllRollouts() throws Exception {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// setup - create 2 rollouts
postRollout("rollout1", 10, dsA.getId(), "name==target1");
postRollout("rollout2", 5, dsA.getId(), "name==target2");
@@ -159,8 +153,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
@Test
@Description("Testing that rollout paged list is limited by the query param limit")
public void rolloutPagedListIsLimitedToQueryParam() throws Exception {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// setup - create 2 rollouts
postRollout("rollout1", 10, dsA.getId(), "name==target1");
postRollout("rollout2", 5, dsA.getId(), "name==target2");
@@ -175,9 +168,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void retrieveRolloutGroupsForSpecificRollout() throws Exception {
// setup
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -198,9 +190,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void startingRolloutSwitchesIntoRunningState() throws Exception {
// setup
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -221,9 +212,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void pausingRolloutSwitchesIntoPausedState() throws Exception {
// setup
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -248,9 +238,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void resumingRolloutSwitchesIntoRunningState() throws Exception {
// setup
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -279,9 +268,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void startingAlreadyStartedRolloutReturnsBadRequest() throws Exception {
// setup
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -301,9 +289,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void resumingNotStartedRolloutReturnsBadRequest() throws Exception {
// setup
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -319,9 +306,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void startingRolloutFirstRolloutGroupIsInRunningState() throws Exception {
// setup
final int amountTargets = 10;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
@@ -345,9 +331,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void retrieveSingleRolloutGroup() throws Exception {
// setup
final int amountTargets = 10;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -369,9 +354,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void retrieveTargetsFromRolloutGroup() throws Exception {
// setup
final int amountTargets = 10;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
@@ -393,9 +377,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
// setup
final int amountTargets = 10;
final List targets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ .createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
@@ -418,9 +401,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void retrieveTargetsFromRolloutGroupAfterRolloutIsStarted() throws Exception {
// setup
final int amountTargets = 10;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
@@ -443,9 +425,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void startingRolloutSwitchesIntoRunningStateAsync() throws Exception {
final int amountTargets = 1000;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -468,12 +449,14 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
final int amountTargetsRollout2 = 25;
final int amountTargetsRollout3 = 25;
final int amountTargetsOther = 25;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsRollout1, "rollout1", "rollout1"));
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsRollout2, "rollout2", "rollout2"));
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsRollout3, "rollout3", "rollout3"));
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsOther, "other1", "other1"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement
+ .createTargets(testdataFactory.generateTargets(amountTargetsRollout1, "rollout1", "rollout1"));
+ targetManagement
+ .createTargets(testdataFactory.generateTargets(amountTargetsRollout2, "rollout2", "rollout2"));
+ targetManagement
+ .createTargets(testdataFactory.generateTargets(amountTargetsRollout3, "rollout3", "rollout3"));
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsOther, "other1", "other1"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
createRollout("rollout1", 5, dsA.getId(), "controllerId==rollout1*");
final Rollout rollout2 = createRollout("rollout2", 5, dsA.getId(), "controllerId==rollout2*");
@@ -503,9 +486,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
public void retrieveRolloutGroupsForSpecificRolloutWithRSQLParam() throws Exception {
// setup
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
// create rollout including the created targets with prefix 'rollout'
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
@@ -577,7 +559,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest {
private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId,
final String targetFilterQuery) {
- final Rollout rollout = rolloutManagement.generateRollout();
+ final Rollout rollout = entityFactory.generateRollout();
rollout.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetId));
rollout.setName(name);
rollout.setTargetFilterQuery(targetFilterQuery);
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
index 2e9f1a47b..a0bf416c9 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
@@ -37,13 +37,12 @@ import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.HashGeneratorUtils;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
@@ -76,7 +75,6 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
public void assertPreparationOfRepo() {
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("no softwaremodule should be founded")
.hasSize(0);
- assertThat(artifactRepository.findAll()).as("no artifacts should be founded").hasSize(0);
}
@Test
@@ -92,13 +90,13 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final String updateDescription = "newDescription1";
softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
+ entityFactory.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
+ entityFactory.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
softwareManagement
- .createSoftwareModule(softwareManagement.generateSoftwareModule(osType, "poky", "3.0.2", null, ""));
+ .createSoftwareModule(entityFactory.generateSoftwareModule(osType, "poky", "3.0.2", null, ""));
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, knownSWName, knownSWVersion,
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, knownSWName, knownSWVersion,
knownSWDescription, knownSWVendor);
sm = softwareManagement.createSoftwareModule(sm);
@@ -125,9 +123,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.")
public void uploadArtifact() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
- assertThat(artifactRepository.findAll()).hasSize(0);
// create test file
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -166,7 +163,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException {
// check result in db...
// repo
- assertThat(artifactRepository.findAll()).as("Wrong artifact size").hasSize(1);
+ assertThat(artifactManagement.countLocalArtifactsAll()).as("Wrong artifact size").isEqualTo(1);
// binary
assertTrue("Wrong artifact content",
@@ -192,9 +189,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST")
public void emptyUploadArtifact() throws Exception {
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
- assertThat(artifactRepository.findAll()).hasSize(0);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, new byte[0]);
@@ -207,7 +204,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT")
public void duplicateUploadArtifact() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -229,9 +226,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.")
public void uploadArtifactWithCustomName() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
- assertThat(artifactRepository.findAll()).hasSize(0);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
// create test file
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -246,7 +243,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
// check result in db...
// repo
- assertThat(artifactRepository.findAll()).as("Artifact size is wring").hasSize(1);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
// hashes
assertThat(artifactManagement.findLocalArtifactByFilename("customFilename")).as("Local artifact is wrong")
@@ -256,9 +253,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST")
public void uploadArtifactWithHashCheck() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
- assertThat(artifactRepository.findAll()).hasSize(0);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
// create test file
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -300,7 +297,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("Tests binary download of an artifact including verfication that the downloaded binary is consistent and that the etag header is as expected identical to the SHA1 hash of the file.")
public void downloadArtifact() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -328,14 +325,14 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
Arrays.equals(result2.getResponse().getContentAsByteArray(), random));
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1);
- assertThat(artifactRepository.findAll()).as("Wrong artifact repostiory").hasSize(2);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2);
}
@Test
@Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.")
public void getArtifact() throws Exception {
// prepare data for test
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -361,7 +358,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.")
public void getArtifacts() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -404,7 +401,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random);
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
// no artifact available
@@ -437,7 +434,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.")
public void invalidRequestsOnSoftwaremodulesResource() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final List modules = new ArrayList<>();
@@ -519,15 +516,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Test retrieval of all software modules the user has access to.")
public void getSoftwareModules() throws Exception {
- SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1",
+ SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1",
"vendor1");
os = softwareManagement.createSoftwareModule(os);
- SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name1", "version1", "description1",
+ SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name1", "version1", "description1",
"vendor1");
jvm = softwareManagement.createSoftwareModule(jvm);
- SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name1", "version1", "description1",
+ SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name1", "version1", "description1",
"vendor1");
ah = softwareManagement.createSoftwareModule(ah);
@@ -590,27 +587,27 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Test
@Description("Test the various filter parameters, e.g. filter by name or type of the module.")
public void getSoftwareModulesWithFilterParameters() throws Exception {
- SoftwareModule os1 = softwareManagement.generateSoftwareModule(osType, "osName1", "1.0.0", "description1",
+ SoftwareModule os1 = entityFactory.generateSoftwareModule(osType, "osName1", "1.0.0", "description1",
"vendor1");
os1 = softwareManagement.createSoftwareModule(os1);
- SoftwareModule jvm1 = softwareManagement.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0",
+ SoftwareModule jvm1 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0",
"description1", "vendor1");
jvm1 = softwareManagement.createSoftwareModule(jvm1);
- SoftwareModule ah1 = softwareManagement.generateSoftwareModule(appType, "appName1", "3.0.0", "description1",
+ SoftwareModule ah1 = entityFactory.generateSoftwareModule(appType, "appName1", "3.0.0", "description1",
"vendor1");
ah1 = softwareManagement.createSoftwareModule(ah1);
- SoftwareModule os2 = softwareManagement.generateSoftwareModule(osType, "osName2", "1.0.1", "description2",
+ SoftwareModule os2 = entityFactory.generateSoftwareModule(osType, "osName2", "1.0.1", "description2",
"vendor2");
os2 = softwareManagement.createSoftwareModule(os2);
- SoftwareModule jvm2 = softwareManagement.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1",
+ SoftwareModule jvm2 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1",
"description2", "vendor2");
jvm2 = softwareManagement.createSoftwareModule(jvm2);
- SoftwareModule ah2 = softwareManagement.generateSoftwareModule(appType, "appName2", "3.0.1", "description2",
+ SoftwareModule ah2 = entityFactory.generateSoftwareModule(appType, "appName2", "3.0.1", "description2",
"vendor2");
ah2 = softwareManagement.createSoftwareModule(ah2);
@@ -688,7 +685,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Tests GET request on /rest/v1/softwaremodules/{smId}.")
public void getSoftareModule() throws Exception {
- SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1",
+ SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1",
"vendor1");
os = softwareManagement.createSoftwareModule(os);
@@ -708,7 +705,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.andExpect(jsonPath("$_links.artifacts.href",
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts")));
- SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name1", "version1", "description1",
+ SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name1", "version1", "description1",
"vendor1");
jvm = softwareManagement.createSoftwareModule(jvm);
@@ -728,7 +725,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.andExpect(jsonPath("$_links.artifacts.href",
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts")));
- SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name1", "version1", "description1",
+ SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name1", "version1", "description1",
"vendor1");
ah = softwareManagement.createSoftwareModule(ah);
@@ -755,11 +752,11 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Verfies that the create request actually results in the creation of the modules in the repository.")
public void createSoftwareModules() throws JSONException, Exception {
- final SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1",
+ final SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1",
"vendor1");
- final SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name2", "version1",
+ final SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name2", "version1",
"description1", "vendor1");
- final SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name3", "version1",
+ final SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name3", "version1",
"description1", "vendor1");
final List modules = new ArrayList<>();
@@ -841,7 +838,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
@Description("Verifies successfull deletion of software modules that are not in use, i.e. assigned to a DS.")
public void deleteUnassignedSoftwareModule() throws Exception {
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -849,24 +846,20 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremoudle size is wrong").hasSize(1);
- assertThat(artifactRepository.findAll()).as("artifact site is wrong").hasSize(1);
- assertThat(softwareModuleRepository.findAll()).as("Softwaremoudle size is wrong").hasSize(1);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(softwareManagement.findSoftwareModulesAll(pageReq))
.as("After delete no softwarmodule should be available").isEmpty();
- assertThat(softwareModuleRepository.findAll()).as("After delete no softwarmodule should be available")
- .isEmpty();
- assertThat(artifactRepository.findAll()).as("After delete no artifact should be available").isEmpty();
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
}
@Test
@Description("Verifies successfull deletion of software modules that are in use, i.e. assigned to a DS which should result in movinf the module to the archive.")
public void deleteAssignedSoftwareModule() throws Exception {
- final DistributionSet ds1 = TestDataUtil.generateDistributionSet("a", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds1 = testdataFactory.createDistributionSet("a");
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -874,8 +867,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
ds1.findFirstModuleByType(appType).getId(), "file1", false);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3);
- assertThat(artifactRepository.findAll()).hasSize(1);
- assertThat(softwareModuleRepository.findAll()).hasSize(3);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
@@ -887,17 +879,14 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
// all 3 are now marked as deleted
assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber())
.as("After delete no softwarmodule should be available").isEqualTo(0);
- assertThat(softwareModuleRepository.findAll()).as("After delete no softwarmodule should marked as deleted")
- .hasSize(3);
- assertThat(artifactRepository.findAll()).as("After delete artifact should available for marked as deleted sm's")
- .hasSize(1);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
}
@Test
@Description("Tests the deletion of an artifact including verfication that the artifact is actually erased in the repository and removed from the software module.")
public void deleteArtifact() throws Exception {
// Create 1 SM
- SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -911,7 +900,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1);
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(2);
- assertThat(artifactRepository.findAll()).hasSize(2);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2);
// delete
mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()))
@@ -920,8 +909,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
// check that only one artifact is still alive and still assigned
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted")
.hasSize(1);
- assertThat(artifactRepository.findAll()).as("After delete artifact should available for marked as deleted sm's")
- .hasSize(1);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1);
assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts())
.as("After delete artifact should available for marked as deleted sm's").hasSize(1);
@@ -937,7 +925,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final String knownValue2 = "knownValue1";
final SoftwareModule sm = softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null));
+ entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
final JSONArray jsonArray = new JSONArray();
jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1));
@@ -966,9 +954,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final String updateValue = "valueForUpdate";
final SoftwareModule sm = softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null));
+ entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
softwareManagement.createSoftwareModuleMetadata(
- softwareManagement.generateSoftwareModuleMetadata(sm, knownKey, knownValue));
+ entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue));
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
@@ -990,9 +978,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final String knownValue = "knownValue";
final SoftwareModule sm = softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null));
+ entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
softwareManagement.createSoftwareModuleMetadata(
- softwareManagement.generateSoftwareModuleMetadata(sm, knownKey, knownValue));
+ entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue));
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
@@ -1012,10 +1000,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
final String knownKeyPrefix = "knownKey";
final String knownValuePrefix = "knownValue";
final SoftwareModule sm = softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null));
+ entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null));
for (int index = 0; index < totalMetadata; index++) {
- softwareManagement.createSoftwareModuleMetadata(softwareManagement.generateSoftwareModuleMetadata(
+ softwareManagement.createSoftwareModuleMetadata(entityFactory.generateSoftwareModuleMetadata(
softwareManagement.findSoftwareModuleById(sm.getId()), knownKeyPrefix + index,
knownValuePrefix + index));
}
@@ -1032,7 +1020,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
char character = 'a';
for (int index = 0; index < amount; index++) {
final String str = String.valueOf(character);
- final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str);
+ final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str);
softwareManagement.createSoftwareModule(softwareModule);
character++;
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
index ae137e125..363b12cde 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
@@ -24,9 +24,9 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
@@ -55,7 +55,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests.")
public void getSoftwareModuleTypes() throws Exception {
SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
- softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
testType.setDescription("Desc1234");
testType = softwareManagement.updateSoftwareModuleType(testType);
@@ -77,7 +77,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].name", equalTo(appType.getName())))
.andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].description",
equalTo(appType.getDescription())))
- .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].maxAssignments", equalTo(1)))
+ .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].maxAssignments",
+ equalTo(Integer.MAX_VALUE)))
.andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].key", equalTo("application")))
.andExpect(jsonPath("$content.[?(@.key==test123)][0].id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$content.[?(@.key==test123)][0].name", equalTo("TestName123")))
@@ -96,8 +97,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with sorting by MAXASSIGNMENTS field.")
public void getSoftwareModuleTypesSortedByMaxAssignments() throws Exception {
- SoftwareModuleType testType = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
testType.setDescription("Desc1234");
testType = softwareManagement.updateSoftwareModuleType(testType);
@@ -106,30 +107,30 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:DESC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath("$content.[0].id", equalTo(testType.getId().intValue())))
- .andExpect(jsonPath("$content.[0].name", equalTo("TestName123")))
- .andExpect(jsonPath("$content.[0].description", equalTo("Desc1234")))
- .andExpect(jsonPath("$content.[0].createdBy", equalTo("uploadTester")))
- .andExpect(jsonPath("$content.[0].createdAt", equalTo(testType.getCreatedAt())))
- .andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo("uploadTester")))
- .andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
- .andExpect(jsonPath("$content.[0].maxAssignments", equalTo(5)))
- .andExpect(jsonPath("$content.[0].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4)));
+ .andExpect(jsonPath("$content.[1].id", equalTo(testType.getId().intValue())))
+ .andExpect(jsonPath("$content.[1].name", equalTo("TestName123")))
+ .andExpect(jsonPath("$content.[1].description", equalTo("Desc1234")))
+ .andExpect(jsonPath("$content.[1].createdBy", equalTo("uploadTester")))
+ .andExpect(jsonPath("$content.[1].createdAt", equalTo(testType.getCreatedAt())))
+ .andExpect(jsonPath("$content.[1].lastModifiedBy", equalTo("uploadTester")))
+ .andExpect(jsonPath("$content.[1].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
+ .andExpect(jsonPath("$content.[1].maxAssignments", equalTo(5)))
+ .andExpect(jsonPath("$content.[1].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4)));
// ascending
mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:ASC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
- .andExpect(jsonPath("$content.[3].id", equalTo(testType.getId().intValue())))
- .andExpect(jsonPath("$content.[3].name", equalTo("TestName123")))
- .andExpect(jsonPath("$content.[3].description", equalTo("Desc1234")))
- .andExpect(jsonPath("$content.[3].createdBy", equalTo("uploadTester")))
- .andExpect(jsonPath("$content.[3].createdAt", equalTo(testType.getCreatedAt())))
- .andExpect(jsonPath("$content.[3].lastModifiedBy", equalTo("uploadTester")))
- .andExpect(jsonPath("$content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
- .andExpect(jsonPath("$content.[3].maxAssignments", equalTo(5)))
- .andExpect(jsonPath("$content.[3].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4)));
+ .andExpect(jsonPath("$content.[2].id", equalTo(testType.getId().intValue())))
+ .andExpect(jsonPath("$content.[2].name", equalTo("TestName123")))
+ .andExpect(jsonPath("$content.[2].description", equalTo("Desc1234")))
+ .andExpect(jsonPath("$content.[2].createdBy", equalTo("uploadTester")))
+ .andExpect(jsonPath("$content.[2].createdAt", equalTo(testType.getCreatedAt())))
+ .andExpect(jsonPath("$content.[2].lastModifiedBy", equalTo("uploadTester")))
+ .andExpect(jsonPath("$content.[2].lastModifiedAt", equalTo(testType.getLastModifiedAt())))
+ .andExpect(jsonPath("$content.[2].maxAssignments", equalTo(5)))
+ .andExpect(jsonPath("$content.[2].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4)));
}
@Test
@@ -138,9 +139,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
public void createSoftwareModuleTypes() throws JSONException, Exception {
final List types = new ArrayList<>();
- types.add(softwareManagement.generateSoftwareModuleType("test1", "TestName1", "Desc1", 1));
- types.add(softwareManagement.generateSoftwareModuleType("test2", "TestName2", "Desc2", 2));
- types.add(softwareManagement.generateSoftwareModuleType("test3", "TestName3", "Desc3", 3));
+ types.add(entityFactory.generateSoftwareModuleType("test1", "TestName1", "Desc1", 1));
+ types.add(entityFactory.generateSoftwareModuleType("test2", "TestName2", "Desc2", 2));
+ types.add(entityFactory.generateSoftwareModuleType("test3", "TestName3", "Desc3", 3));
final MvcResult mvcResult = mvc
.perform(post("/rest/v1/softwaremoduletypes/").content(JsonBuilder.softwareModuleTypes(types))
@@ -182,8 +183,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} GET requests.")
public void getSoftwareModuleType() throws Exception {
- SoftwareModuleType testType = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
testType.setDescription("Desc1234");
testType = softwareManagement.updateSoftwareModuleType(testType);
@@ -203,8 +204,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (hard delete scenario).")
public void deleteSoftwareModuleTypeUnused() throws Exception {
- final SoftwareModuleType testType = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4);
@@ -218,26 +219,24 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (soft delete scenario).")
public void deleteSoftwareModuleTypeUsed() throws Exception {
- final SoftwareModuleType testType = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
softwareManagement.createSoftwareModule(
- softwareManagement.generateSoftwareModule(testType, "name", "version", "description", "vendor"));
+ entityFactory.generateSoftwareModule(testType, "name", "version", "description", "vendor"));
assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4);
- assertThat(softwareModuleTypeRepository.count()).isEqualTo(4);
mvc.perform(delete("/rest/v1/softwaremoduletypes/{smId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- assertThat(softwareModuleTypeRepository.count()).isEqualTo(4);
assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(3);
}
@Test
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} PUT requests.")
public void updateSoftwareModuleTypeOnlyDescriptionAndNameUntouched() throws Exception {
- final SoftwareModuleType testType = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc")
.put("name", "nameShouldNotBeChanged").toString();
@@ -292,8 +291,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
@Test
@Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).")
public void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception {
- final SoftwareModuleType testType = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
final List types = new ArrayList<>();
types.add(testType);
@@ -331,10 +330,10 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
@Test
@Description("Search erquest of software module types.")
public void searchSoftwareModuleTypeRsql() throws Exception {
- final SoftwareModuleType testType = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
- final SoftwareModuleType testType2 = softwareManagement
- .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test1234", "TestName1234", "Desc123", 5));
+ final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5));
+ final SoftwareModuleType testType2 = softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType("test1234", "TestName1234", "Desc123", 5));
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
@@ -349,7 +348,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
char character = 'a';
for (int index = 0; index < amount; index++) {
final String str = String.valueOf(character);
- final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str);
+ final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str);
softwareManagement.createSoftwareModule(softwareModule);
character++;
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java
index b1ed0eb26..6e50d1103 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java
@@ -35,14 +35,12 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.ActionFields;
import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
-import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.Action.Status;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -111,7 +109,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
final String knownTargetId = "targetId";
final List actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
actions.get(0).setStatus(Status.FINISHED);
- controllerManagament.addUpdateActionStatus(controllerManagament.generateActionStatus(actions.get(0),
+ controllerManagament.addUpdateActionStatus(entityFactory.generateActionStatus(actions.get(0),
Status.FINISHED, System.currentTimeMillis(), "testmessage"));
final PageRequest pageRequest = new PageRequest(0, 1000, Direction.ASC, ActionFields.ID.getFieldName());
@@ -141,7 +139,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
public void securityTokenIsNotInResponseIfMissingPermission() throws Exception {
final String knownControllerId = "knownControllerId";
- targetManagement.createTarget(targetManagement.generateTarget(knownControllerId));
+ targetManagement.createTarget(entityFactory.generateTarget(knownControllerId));
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("securityToken").doesNotExist());
@@ -154,7 +152,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
public void securityTokenIsInResponseWithCorrectPermission() throws Exception {
final String knownControllerId = "knownControllerId";
- final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget(knownControllerId));
+ final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownControllerId));
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("securityToken", equalTo(createTarget.getSecurityToken())));
@@ -185,7 +183,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
}
private void createTarget(final String controllerId) {
- final JpaTarget target = (JpaTarget) targetManagement.generateTarget(controllerId);
+ final JpaTarget target = (JpaTarget) entityFactory.generateTarget(controllerId);
final JpaTargetInfo targetInfo = new JpaTargetInfo(target);
targetInfo.setAddress(IpUtil.createHttpUri("127.0.0.1").toString());
target.setTargetInfo(targetInfo);
@@ -197,9 +195,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
public void searchActionsRsql() throws Exception {
// prepare test
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
- final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget("knownTargetId"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
+ final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget("knownTargetId"));
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(createTarget));
@@ -306,7 +303,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
@Description("Ensures that deletion is executed if permitted.")
public void deleteTargetReturnsOK() throws Exception {
final String knownControllerId = "knownControllerIdDelete";
- targetManagement.createTarget(targetManagement.generateTarget(knownControllerId));
+ targetManagement.createTarget(entityFactory.generateTarget(knownControllerId));
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId))
.andExpect(status().isOk());
@@ -342,7 +339,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
final String body = new JSONObject().put("description", knownNewDescription).toString();
// prepare
- final Target t = targetManagement.generateTarget(knownControllerId);
+ final Target t = entityFactory.generateTarget(knownControllerId);
t.setDescription("old description");
t.setName(knownNameNotModiy);
targetManagement.createTarget(t);
@@ -525,8 +522,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
final String knownControllerId = "1";
final String knownName = "someName";
createSingleTarget(knownControllerId, knownName);
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
deploymentManagement.assignDistributionSet(ds.getId(), knownControllerId);
// test
@@ -596,8 +592,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
final String knownControllerId = "1";
final String knownName = "someName";
createSingleTarget(knownControllerId, knownName);
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
// assign ds to target
final Long actionId = deploymentManagement.assignDistributionSet(ds.getId(), knownControllerId).getActions()
.get(0);
@@ -684,13 +679,13 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
@Test
public void createTargetsListReturnsSuccessful() throws Exception {
- final Target test1 = targetManagement.generateTarget("id1");
+ final Target test1 = entityFactory.generateTarget("id1");
test1.setDescription("testid1");
test1.setName("testname1");
- final Target test2 = targetManagement.generateTarget("id2");
+ final Target test2 = entityFactory.generateTarget("id2");
test2.setDescription("testid2");
test2.setName("testname2");
- final Target test3 = targetManagement.generateTarget("id3");
+ final Target test3 = entityFactory.generateTarget("id3");
test3.setName("testname3");
test3.setDescription("testid3");
@@ -813,7 +808,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
@Test
public void getActionWithEmptyResult() throws Exception {
final String knownTargetId = "targetId";
- final Target target = targetManagement.generateTarget(knownTargetId);
+ final Target target = entityFactory.generateTarget(knownTargetId);
targetManagement.createTarget(target);
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
@@ -1028,13 +1023,12 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
final PageRequest pageRequest = new PageRequest(0, 100, Direction.ASC, ActionStatusFields.ID.getFieldName());
- Target target = targetManagement.generateTarget(knownTargetId);
+ Target target = entityFactory.generateTarget(knownTargetId);
target = targetManagement.createTarget(target);
final List targets = new ArrayList<>();
targets.add(target);
- final Iterator sets = TestDataUtil
- .generateDistributionSets(2, softwareManagement, distributionSetManagement).iterator();
+ final Iterator sets = testdataFactory.createDistributionSets(2).iterator();
final DistributionSet one = sets.next();
final DistributionSet two = sets.next();
@@ -1074,9 +1068,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
@Test
public void assignDistributionSetToTarget() throws Exception {
- final Target target = targetManagement.createTarget(targetManagement.generateTarget("fsdfsd"));
- final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final Target target = targetManagement.createTarget(entityFactory.generateTarget("fsdfsd"));
+ final DistributionSet set = testdataFactory.createDistributionSet("one");
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS")
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
@@ -1088,9 +1081,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
@Test
public void assignDistributionSetToTargetWithActionTimeForcedAndTime() throws Exception {
- final Target target = targetManagement.createTarget(targetManagement.generateTarget("fsdfsd"));
- final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final Target target = targetManagement.createTarget(entityFactory.generateTarget("fsdfsd"));
+ final DistributionSet set = testdataFactory.createDistributionSet("one");
final long forceTime = System.currentTimeMillis();
final String body = new JSONObject().put("id", set.getId()).put("type", "timeforced")
@@ -1110,14 +1102,13 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
@Test
public void invalidRequestsOnAssignDistributionSetToTarget() throws Exception {
- final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createDistributionSet("one");
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS")
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
- targetManagement.createTarget(targetManagement.generateTarget("fsdfsd"));
+ targetManagement.createTarget(entityFactory.generateTarget("fsdfsd"));
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS")
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))
@@ -1207,7 +1198,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
final Map knownControllerAttrs = new HashMap<>();
knownControllerAttrs.put("a", "1");
knownControllerAttrs.put("b", "2");
- final Target target = targetManagement.generateTarget(knownTargetId);
+ final Target target = entityFactory.generateTarget(knownTargetId);
targetManagement.createTarget(target);
controllerManagament.updateControllerAttributes(knownTargetId, knownControllerAttrs);
@@ -1221,7 +1212,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
public void getControllerEmptyAttributesReturnsNoContent() throws Exception {
// create target with attributes
final String knownTargetId = "targetIdWithAttributes";
- final Target target = targetManagement.generateTarget(knownTargetId);
+ final Target target = entityFactory.generateTarget(knownTargetId);
targetManagement.createTarget(target);
// test query target over rest resource
@@ -1255,7 +1246,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
}
private void createSingleTarget(final String controllerId, final String name) {
- final Target target = targetManagement.generateTarget(controllerId);
+ final Target target = entityFactory.generateTarget(controllerId);
target.setName(name);
target.setDescription(TARGET_DESCRIPTION_TEST);
targetManagement.createTarget(target);
@@ -1272,7 +1263,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
char character = 'a';
for (int index = 0; index < amount; index++) {
final String str = String.valueOf(character);
- final Target target = targetManagement.generateTarget(str);
+ final Target target = entityFactory.generateTarget(str);
target.setName(str);
target.setDescription(str);
final Target savedTarget = targetManagement.createTarget(target);
@@ -1288,7 +1279,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
private void feedbackToByInSync(final Long actionId) {
final Action action = deploymentManagement.findAction(actionId);
- final ActionStatus actionStatus = controllerManagement.generateActionStatus(action, Status.FINISHED, 0L);
+ final ActionStatus actionStatus = entityFactory.generateActionStatus(action, Status.FINISHED, 0L);
controllerManagement.addUpdateActionStatus(actionStatus);
}
@@ -1299,10 +1290,9 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
*/
private Target createTargetAndStartAction() {
// prepare test
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
final Target tA = targetManagement
- .createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
+ .createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
// assign a distribution set so we get an active update action
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
// verify active action
diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java
index 9e698e0af..de0411006 100644
--- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java
+++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java
@@ -14,8 +14,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.exception.SpServerError;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
+import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
import org.junit.BeforeClass;
@@ -34,7 +34,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Management API")
@Stories("Download Resource")
-public class SMRessourceMisingMongoDbConnectionTest extends AbstractIntegrationTest {
+public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrationTest {
@BeforeClass
public static void initialize() {
@@ -48,11 +48,11 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractIntegrationT
public void missingMongoDbConnectionResultsInErrorAtUpload() throws Exception {
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
- assertThat(artifactRepository.findAll()).hasSize(0);
- SoftwareModule sm = softwareManagement.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
- "version 1", null, null);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
+ SoftwareModule sm = entityFactory.generateSoftwareModule(
+ softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null);
sm = softwareManagement.createSoftwareModule(sm);
- assertThat(artifactRepository.findAll()).hasSize(0);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
// create test file
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
@@ -70,7 +70,7 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractIntegrationT
assertThat(exceptionInfo.getMessage()).isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED.getMessage());
// ensure that the JPA transaction was rolled back
- assertThat(artifactRepository.findAll()).hasSize(0);
+ assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0);
}
diff --git a/hawkbit-mgmt-resource/src/test/resources/log4j2.xml b/hawkbit-mgmt-resource/src/test/resources/log4j2.xml
deleted file mode 100644
index 98ea99ac9..000000000
--- a/hawkbit-mgmt-resource/src/test/resources/log4j2.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/hawkbit-mgmt-resource/src/test/resources/logback.xml b/hawkbit-mgmt-resource/src/test/resources/logback.xml
new file mode 100644
index 000000000..49ea574f2
--- /dev/null
+++ b/hawkbit-mgmt-resource/src/test/resources/logback.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
index 7854640da..ee73a1354 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
@@ -60,6 +60,12 @@ public interface ArtifactManagement {
ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix,
@NotNull Long moduleId);
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
+ Long countLocalArtifactsAll();
+
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
+ Long countExternalArtifactsAll();
+
/**
* Persists {@link ExternalArtifactProvider} based on given properties.
*
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java
index 114997fca..0e3f74730 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java
@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.repository;
import org.eclipse.hawkbit.repository.model.ActionStatus;
+import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.Target;
/**
@@ -24,6 +25,12 @@ public final class Constants {
*/
public static final String SERVER_MESSAGE_PREFIX = "Update Server: ";
+ /**
+ * Number of {@link DistributionSetType}s that are generated as part of
+ * default tenant setup.
+ */
+ public static final int DEFAULT_DS_TYPES_IN_TENANT = 2;
+
private Constants() {
// Utility class.
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
index cb325cbc9..90bb7068b 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
@@ -9,10 +9,8 @@
package org.eclipse.hawkbit.repository;
import java.net.URI;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import javax.validation.constraints.NotNull;
@@ -268,61 +266,4 @@ public interface ControllerManagement {
TargetInfo updateTargetStatus(@NotNull TargetInfo targetInfo, TargetUpdateStatus status, Long lastTargetQuery,
URI address);
- /**
- * Generates an empty {@link ActionStatus} object without persisting it.
- *
- * @return {@link ActionStatus} object
- */
- ActionStatus generateActionStatus();
-
- /**
- * Generates an {@link ActionStatus} object without persisting it.
- *
- * @param action
- * the {@link ActionStatus} belongs to.
- * @param status
- * as reflected by this {@link ActionStatus}.
- * @param occurredAt
- * time in {@link TimeUnit#MILLISECONDS} GMT when the status
- * change happened.
- * @param message
- * optional comment
- *
- * @return {@link ActionStatus} object
- */
- ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message);
-
- /**
- * Generates an {@link ActionStatus} object without persisting it.
- *
- * @param action
- * the {@link ActionStatus} belongs to.
- * @param status
- * as reflected by this {@link ActionStatus}.
- * @param occurredAt
- * time in {@link TimeUnit#MILLISECONDS} GMT when the status
- * change happened.
- * @param messages
- * optional comments
- *
- * @return {@link ActionStatus} object
- */
- ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt,
- final Collection messages);
-
- /**
- * Generates an {@link ActionStatus} object without persisting it.
- *
- * @param action
- * the {@link ActionStatus} belongs to.
- * @param status
- * as reflected by this {@link ActionStatus}.
- * @param occurredAt
- * time in {@link TimeUnit#MILLISECONDS} GMT when the status
- * change happened.
- *
- * @return {@link ActionStatus} object
- */
- ActionStatus generateActionStatus(Action action, Status status, Long occurredAt);
-
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java
index 6a6c7851d..59518f854 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java
@@ -187,6 +187,12 @@ public interface DeploymentManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Long countActionsByTarget(@NotNull String rsqlParam, @NotNull Target target);
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
+ Long countActionStatusAll();
+
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
+ Long countActionsAll();
+
/**
* counts all actions associated to a specific target.
*
@@ -274,6 +280,9 @@ public interface DeploymentManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target);
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
+ Slice findActionsByDistributionSet(@NotNull Pageable pageable, @NotNull DistributionSet ds);
+
/**
* Retrieves all {@link Action}s assigned to a specific {@link Target} and a
* given specification.
@@ -453,13 +462,6 @@ public interface DeploymentManagement {
+ SpringEvalExpressions.IS_SYSTEM_CODE)
Action startScheduledAction(@NotNull Action action);
- /**
- * Generates an empty {@link Action} without persisting it.
- *
- * @return {@link Action} object
- */
- Action generateAction();
-
/**
* All {@link ActionStatus} entries in the repository.
*
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java
index 3e31a5a9c..a2e7e5213 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java
@@ -473,26 +473,6 @@ public interface DistributionSetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
DistributionSetMetadata findOne(@NotNull DistributionSet distributionSet, @NotNull String key);
- /**
- * Generates an empty {@link DistributionSet} without persisting it.
- *
- * @return {@link DistributionSet} object
- */
- DistributionSet generateDistributionSet();
-
- DistributionSetMetadata generateDistributionSetMetadata();
-
- DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value);
-
- /**
- * Generates an empty {@link DistributionSetType} without persisting it.
- *
- * @return {@link DistributionSetType} object
- */
- DistributionSetType generateDistributionSetType();
-
- DistributionSetType generateDistributionSetType(String key, String name, String description);
-
/**
* Checks if a {@link DistributionSet} is currently in use by a target in
* the repository.
@@ -615,7 +595,4 @@ public interface DistributionSetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
DistributionSetType updateDistributionSetType(@NotNull DistributionSetType dsType);
- DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type,
- Collection moduleList);
-
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java
new file mode 100644
index 000000000..85a2f5e76
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java
@@ -0,0 +1,333 @@
+/**
+ * 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;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+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.BaseEntity;
+import org.eclipse.hawkbit.repository.model.DistributionSet;
+import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
+import org.eclipse.hawkbit.repository.model.DistributionSetTag;
+import org.eclipse.hawkbit.repository.model.DistributionSetType;
+import org.eclipse.hawkbit.repository.model.Rollout;
+import org.eclipse.hawkbit.repository.model.RolloutGroup;
+import org.eclipse.hawkbit.repository.model.SoftwareModule;
+import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
+import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
+import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
+import org.eclipse.hawkbit.repository.model.TargetTag;
+import org.hibernate.validator.constraints.NotEmpty;
+
+/**
+ * central {@link BaseEntity} generation service. Objects are created but not
+ * persisted.
+ *
+ */
+public interface EntityFactory {
+
+ /**
+ * Generates an empty {@link Action} without persisting it.
+ *
+ * @return {@link Action} object
+ */
+ Action generateAction();
+
+ /**
+ * Generates an empty {@link ActionStatus} object without persisting it.
+ *
+ * @return {@link ActionStatus} object
+ */
+ ActionStatus generateActionStatus();
+
+ /**
+ * Generates an {@link ActionStatus} object without persisting it.
+ *
+ * @param action
+ * the {@link ActionStatus} belongs to.
+ * @param status
+ * as reflected by this {@link ActionStatus}.
+ * @param occurredAt
+ * time in {@link TimeUnit#MILLISECONDS} GMT when the status
+ * change happened.
+ *
+ * @return {@link ActionStatus} object
+ */
+ ActionStatus generateActionStatus(Action action, Status status, Long occurredAt);
+
+ /**
+ * Generates an {@link ActionStatus} object without persisting it.
+ *
+ * @param action
+ * the {@link ActionStatus} belongs to.
+ * @param status
+ * as reflected by this {@link ActionStatus}.
+ * @param occurredAt
+ * time in {@link TimeUnit#MILLISECONDS} GMT when the status
+ * change happened.
+ * @param messages
+ * optional comments
+ *
+ * @return {@link ActionStatus} object
+ */
+ ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt,
+ final Collection messages);
+
+ /**
+ * Generates an {@link ActionStatus} object without persisting it.
+ *
+ * @param action
+ * the {@link ActionStatus} belongs to.
+ * @param status
+ * as reflected by this {@link ActionStatus}.
+ * @param occurredAt
+ * time in {@link TimeUnit#MILLISECONDS} GMT when the status
+ * change happened.
+ * @param message
+ * optional comment
+ *
+ * @return {@link ActionStatus} object
+ */
+ ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message);
+
+ /**
+ * Generates an empty {@link DistributionSet} without persisting it.
+ *
+ * @return {@link DistributionSet} object
+ */
+ DistributionSet generateDistributionSet();
+
+ /**
+ * Generates an {@link DistributionSet} without persisting it.
+ *
+ * @param name
+ * {@link DistributionSet#getName()}
+ * @param version
+ * {@link DistributionSet#getVersion()}
+ * @param description
+ * {@link DistributionSet#getDescription()}
+ * @param type
+ * {@link DistributionSet#getType()}
+ * @param moduleList
+ * {@link DistributionSet#getModules()}
+ *
+ * @return {@link DistributionSet} object
+ */
+ DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type,
+ Collection moduleList);
+
+ /**
+ * Generates an empty {@link DistributionSetMetadata} element without
+ * persisting it.
+ *
+ * @return {@link DistributionSetMetadata} object
+ */
+ DistributionSetMetadata generateDistributionSetMetadata();
+
+ /**
+ * Generates an {@link DistributionSetMetadata} element without persisting
+ * it.
+ *
+ * @param distributionSet
+ * {@link DistributionSetMetadata#getDistributionSet()}
+ * @param key
+ * {@link DistributionSetMetadata#getKey()}
+ * @param value
+ * {@link DistributionSetMetadata#getValue()}
+ *
+ * @return {@link DistributionSetMetadata} object
+ */
+ DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value);
+
+ /**
+ * Generates an empty {@link DistributionSetTag} without persisting it.
+ *
+ * @return {@link DistributionSetTag} object
+ */
+ DistributionSetTag generateDistributionSetTag();
+
+ /**
+ * Generates a {@link DistributionSetTag} without persisting it.
+ *
+ * @param name
+ * of the tag
+ * @return {@link DistributionSetTag} object
+ */
+ DistributionSetTag generateDistributionSetTag(String name);
+
+ /**
+ * Generates a {@link DistributionSetTag} without persisting it.
+ *
+ * @param name
+ * of the tag
+ * @param description
+ * of the tag
+ * @param colour
+ * of the tag
+ * @return {@link DistributionSetTag} object
+ */
+ DistributionSetTag generateDistributionSetTag(String name, String description, String colour);
+
+ /**
+ * Generates an empty {@link DistributionSetType} without persisting it.
+ *
+ * @return {@link DistributionSetType} object
+ */
+ DistributionSetType generateDistributionSetType();
+
+ /**
+ * Generates a {@link DistributionSetType} without persisting it.
+ *
+ * @param key
+ * {@link DistributionSetType#getKey()}
+ * @param name
+ * {@link DistributionSetType#getName()}
+ * @param description
+ * {@link DistributionSetType#getDescription()}
+ *
+ * @return {@link DistributionSetType} object
+ */
+ DistributionSetType generateDistributionSetType(String key, String name, String description);
+
+ /**
+ * Generates an empty {@link Rollout} without persisting it.
+ *
+ * @return {@link Rollout} object
+ */
+ Rollout generateRollout();
+
+ /**
+ * Generates an empty {@link RolloutGroup} without persisting it.
+ *
+ * @return {@link RolloutGroup} object
+ */
+ RolloutGroup generateRolloutGroup();
+
+ /**
+ * Generates an empty {@link SoftwareModule} without persisting it.
+ *
+ * @return {@link SoftwareModule} object
+ */
+ SoftwareModule generateSoftwareModule();
+
+ /**
+ * Generates a {@link SoftwareModule} without persisting it.
+ *
+ * @param type
+ * of the {@link SoftwareModule}
+ * @param name
+ * abstract name of the {@link SoftwareModule}
+ * @param version
+ * of the {@link SoftwareModule}
+ * @param description
+ * of the {@link SoftwareModule}
+ * @param vendor
+ * of the {@link SoftwareModule}
+ *
+ * @return {@link SoftwareModule} object
+ */
+ SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description,
+ String vendor);
+
+ /**
+ * Generates an empty {@link SoftwareModuleMetadata} pair without persisting
+ * it.
+ *
+ * @return {@link SoftwareModuleMetadata} object
+ */
+ SoftwareModuleMetadata generateSoftwareModuleMetadata();
+
+ /**
+ * Generates a {@link SoftwareModuleMetadata} pair without persisting it.
+ *
+ * @param softwareModule
+ * {@link SoftwareModuleMetadata#getSoftwareModule()}
+ * @param key
+ * {@link SoftwareModuleMetadata#getKey()}
+ * @param value
+ * {@link SoftwareModuleMetadata#getValue()}
+ *
+ * @return {@link SoftwareModuleMetadata} object
+ */
+ SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value);
+
+ /**
+ * Generates an empty {@link SoftwareModuleType} without persisting it.
+ *
+ * @return {@link SoftwareModuleType} object
+ */
+ SoftwareModuleType generateSoftwareModuleType();
+
+ /**
+ * Generates a {@link SoftwareModuleType} without persisting it.
+ *
+ * @param key
+ * {@link SoftwareModuleType#getKey()}
+ * @param name
+ * {@link SoftwareModuleType#getName()}
+ * @param description
+ * {@link SoftwareModuleType#getDescription()}
+ * @param maxAssignments
+ * {@link SoftwareModuleType#getMaxAssignments()}
+ *
+ * @return {@link SoftwareModuleType} object
+ */
+ SoftwareModuleType generateSoftwareModuleType(String key, String name, String description, int maxAssignments);
+
+ /**
+ * Generates an empty {@link Target} without persisting it.
+ *
+ * @param controllerID
+ * of the {@link Target}
+ *
+ * @return {@link Target} object
+ */
+ Target generateTarget(@NotEmpty String controllerID);
+
+ /**
+ * Generates an empty {@link TargetFilterQuery} without persisting it.
+ *
+ * @return {@link TargetFilterQuery} object
+ */
+ TargetFilterQuery generateTargetFilterQuery();
+
+ /**
+ * Generates an empty {@link TargetTag} without persisting it.
+ *
+ * @return {@link TargetTag} object
+ */
+ TargetTag generateTargetTag();
+
+ /**
+ * Generates a {@link TargetTag} without persisting it.
+ *
+ * @param name
+ * of the tag
+ * @return {@link TargetTag} object
+ */
+ TargetTag generateTargetTag(String name);
+
+ /**
+ * Generates a {@link TargetTag} without persisting it.
+ *
+ * @param name
+ * of the tag
+ * @param description
+ * of the tag
+ * @param colour
+ * of the tag
+ * @return {@link TargetTag} object
+ */
+ TargetTag generateTargetTag(String name, String description, String colour);
+
+}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java
index f28047666..bf7807db0 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java
@@ -62,4 +62,31 @@ public final class OffsetBasedPageRequest extends PageRequest {
return "OffsetBasedPageRequest [offset=" + offset + ", getPageSize()=" + getPageSize() + ", getPageNumber()="
+ getPageNumber() + "]";
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + offset;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (!(obj instanceof OffsetBasedPageRequest)) {
+ return false;
+ }
+ final OffsetBasedPageRequest other = (OffsetBasedPageRequest) obj;
+ if (offset != other.offset) {
+ return false;
+ }
+ return true;
+ }
+
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java
index d1d3678f5..512b9af3c 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java
@@ -150,11 +150,4 @@ public interface RolloutGroupManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId);
-
- /**
- * Generates an empty {@link RolloutGroup} without persisting it.
- *
- * @return {@link RolloutGroup} object
- */
- RolloutGroup generateRolloutGroup();
}
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
index 4753e70ef..2c6e85dda 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
@@ -341,11 +341,4 @@ public interface RolloutManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
Rollout updateRollout(@NotNull Rollout rollout);
- /**
- * Generates an empty {@link Rollout} without persisting it.
- *
- * @return {@link Rollout} object
- */
- Rollout generateRollout();
-
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java
index 9723dfd73..0934e871e 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java
@@ -483,50 +483,4 @@ public interface SoftwareManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm);
- /**
- * Generates an empty {@link SoftwareModuleType} without persisting it.
- *
- * @return {@link SoftwareModuleType} object
- */
- SoftwareModuleType generateSoftwareModuleType();
-
- /**
- * Generates an empty {@link SoftwareModule} without persisting it.
- *
- * @return {@link SoftwareModule} object
- */
- SoftwareModule generateSoftwareModule();
-
- /**
- * Generates a {@link SoftwareModule} without persisting it.
- *
- * @param type
- * of the {@link SoftwareModule}
- * @param name
- * abstract name of the {@link SoftwareModule}
- * @param version
- * of the {@link SoftwareModule}
- * @param description
- * of the {@link SoftwareModule}
- * @param vendor
- * of the {@link SoftwareModule}
- *
- * @return {@link SoftwareModule} object
- */
- SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description,
- String vendor);
-
- /**
- * Generates an empty {@link SoftwareModuleMetadata} pair without persisting
- * it.
- *
- * @return {@link SoftwareModuleMetadata} object
- */
- SoftwareModuleMetadata generateSoftwareModuleMetadata();
-
- SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value);
-
- SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description,
- final int maxAssignments);
-
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java
index 19138ae9b..5cc17e09b 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java
@@ -13,6 +13,8 @@ import java.util.List;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
+import org.eclipse.hawkbit.repository.model.DistributionSetType;
+import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
import org.eclipse.hawkbit.repository.report.model.SystemUsageReport;
import org.eclipse.hawkbit.tenancy.TenantAware;
@@ -39,7 +41,8 @@ public interface SystemManagement {
* @param tenant
* to delete
*/
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR
+ + SpringEvalExpressions.IS_SYSTEM_CODE)
void deleteTenant(@NotNull String tenant);
/**
@@ -69,7 +72,10 @@ public interface SystemManagement {
KeyGenerator currentTenantKeyGenerator();
/**
- * Returns {@link TenantMetaData} of given and current tenant.
+ * Returns {@link TenantMetaData} of given and current tenant. Creates for
+ * new tenants also two {@link SoftwareModuleType} (os and app) and
+ * {@link Constants#DEFAULT_DS_TYPES_IN_TENANT} {@link DistributionSetType}s
+ * (os and os_app).
*
* DISCLAIMER: this variant is used during initial login (where the tenant
* is not yet in the session). Please user {@link #getTenantMetadata()} for
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java
index 85e5d0273..1b80444b5 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java
@@ -245,62 +245,4 @@ public interface TagManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTag updateTargetTag(@NotNull TargetTag targetTag);
- /**
- * Generates an empty {@link TargetTag} without persisting it.
- *
- * @return {@link TargetTag} object
- */
- TargetTag generateTargetTag();
-
- /**
- * Generates an empty {@link DistributionSetTag} without persisting it.
- *
- * @return {@link DistributionSetTag} object
- */
- DistributionSetTag generateDistributionSetTag();
-
- /**
- * Generates a {@link TargetTag} without persisting it.
- *
- * @param name
- * of the tag
- * @param description
- * of the tag
- * @param colour
- * of the tag
- * @return {@link TargetTag} object
- */
- TargetTag generateTargetTag(String name, String description, String colour);
-
- /**
- * Generates a {@link TargetTag} without persisting it.
- *
- * @param name
- * of the tag
- * @return {@link TargetTag} object
- */
- TargetTag generateTargetTag(String name);
-
- /**
- * Generates a {@link DistributionSetTag} without persisting it.
- *
- * @param name
- * of the tag
- * @param description
- * of the tag
- * @param colour
- * of the tag
- * @return {@link DistributionSetTag} object
- */
- DistributionSetTag generateDistributionSetTag(String name, String description, String colour);
-
- /**
- * Generates a {@link DistributionSetTag} without persisting it.
- *
- * @param name
- * of the tag
- * @return {@link DistributionSetTag} object
- */
- DistributionSetTag generateDistributionSetTag(String name);
-
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java
index 127e22e63..48018b9ec 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java
@@ -95,11 +95,4 @@ public interface TargetFilterQueryManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery);
-
- /**
- * Generates an empty {@link TargetFilterQuery} without persisting it.
- *
- * @return {@link TargetFilterQuery} object
- */
- TargetFilterQuery generateTargetFilterQuery();
}
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java
index 7ebb3e4b4..9280e065d 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java
@@ -601,14 +601,4 @@ public interface TargetManagement {
+ SpringEvalExpressions.IS_CONTROLLER)
List updateTargets(@NotNull Collection targets);
- /**
- * Generates an empty {@link Target} without persisting it.
- *
- * @param controllerID
- * of the {@link Target}
- *
- * @return {@link Target} object
- */
- Target generateTarget(@NotEmpty String controllerID);
-
}
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java
index 32ecdcce4..6d390c03c 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java
@@ -16,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
* Management service for statistics of a single tenant.
*
*/
+@FunctionalInterface
public interface TenantStatsManagement {
/**
diff --git a/hawkbit-repository/hawkbit-repository-core/pom.xml b/hawkbit-repository/hawkbit-repository-core/pom.xml
new file mode 100644
index 000000000..77e20cf3c
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-core/pom.xml
@@ -0,0 +1,29 @@
+
+
+ 4.0.0
+
+ org.eclipse.hawkbit
+ hawkbit-repository
+ 0.2.0-SNAPSHOT
+
+ hawkbit-repository-core
+ hawkBit :: Repository Core Implementation Support
+
+
+
+ org.eclipse.hawkbit
+ hawkbit-repository-api
+ ${project.version}
+
+
+
+
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java
similarity index 100%
rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java
rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java
diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml
index e61ad8325..49a19530f 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml
+++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml
@@ -52,19 +52,20 @@
hawkbit-repository-api
${project.version}
+
+ org.eclipse.hawkbit
+ hawkbit-repository-core
+ ${project.version}
+
org.eclipse.hawkbit
hawkbit-artifact-repository-mongo
${project.version}
-
+
com.google.guava
guava
-
- net._01001111
- jlorem
-
org.springframework.boot
spring-boot
@@ -96,6 +97,12 @@
+
+ org.eclipse.hawkbit
+ hawkbit-repository-test
+ ${project.version}
+ test
+
com.h2database
h2
@@ -121,21 +128,11 @@
allure-junit-adaptor
test
-
-
-
-
-
org.springframework.security
spring-security-aspects
test
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
+
org.springframework
spring-test
@@ -150,12 +147,7 @@
org.easytesting
fest-assert
test
-
-
- de.flapdoodle.embed
- de.flapdoodle.embed.mongo
- test
-
+
org.springframework.security
spring-security-config
@@ -170,7 +162,6 @@
cz.jirutka.rsql
rsql-parser
-
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml b/hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml
deleted file mode 100644
index bd85e5e73..000000000
--- a/hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java
new file mode 100644
index 000000000..f15ec8c82
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java
@@ -0,0 +1,33 @@
+/**
+ * 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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.stereotype.Controller;
+
+/**
+ * Annotation to enable {@link ComponentScan} in the resource package to setup
+ * all {@link Controller} annotated classes and setup the REST-Resources for the
+ * Management API.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Configuration
+@ComponentScan
+@Import(RepositoryApplicationConfiguration.class)
+public @interface EnableJpaRepository {
+
+}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java
index afb6f4245..5f5a46c0b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java
@@ -47,11 +47,10 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess
@EnableTransactionManagement
@EnableJpaAuditing
@EnableAspectJAutoProxy
-@Configuration
@ComponentScan
+@Configuration
@EnableAutoConfiguration
public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
-
/**
* @return the {@link SystemSecurityContext} singleton bean which make it
* accessible in beans which cannot access the service directly,
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java
index 93e0afc00..ea0e5c34f 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java
@@ -288,4 +288,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
final boolean overrideExisting, final String contentType) {
return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType);
}
+
+ @Override
+ public Long countLocalArtifactsAll() {
+ return localArtifactRepository.count();
+ }
+
+ @Override
+ public Long countExternalArtifactsAll() {
+ return externalArtifactRepository.count();
+ }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java
index 653d02870..43b8534af 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository.jpa;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -55,7 +54,6 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -438,33 +436,4 @@ public class JpaControllerManagement implements ControllerManagement {
return updateTargetStatus(target, null, System.currentTimeMillis(), address);
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public ActionStatus generateActionStatus() {
- return new JpaActionStatus();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
- final String message) {
- return new JpaActionStatus((JpaAction) action, status, occurredAt, message);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
- final Collection messages) {
-
- final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null);
- messages.forEach(result::addMessage);
-
- return result;
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt) {
- return new JpaActionStatus(action, status, occurredAt);
- }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java
index aa843d8fc..cefa5e937 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java
@@ -84,7 +84,6 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -155,7 +154,8 @@ public class JpaDeploymentManagement implements DeploymentManagement {
@Transactional(isolation = Isolation.READ_COMMITTED)
@CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true)
public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) {
- return assignDistributionSet(dsID, ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs);
+ return assignDistributionSet(dsID, ActionType.FORCED,
+ org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs);
}
@Override
@@ -683,12 +683,6 @@ public class JpaDeploymentManagement implements DeploymentManagement {
return actionRepository.findByRolloutAndStatus((JpaRollout) rollout, actionStatus);
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public Action generateAction() {
- return new JpaAction();
- }
-
@Override
public Page findActionStatusAll(final Pageable pageable) {
return convertAcSPage(actionStatusRepository.findAll(pageable), pageable);
@@ -697,4 +691,19 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private static Page convertAcSPage(final Page findAll, final Pageable pageable) {
return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements());
}
+
+ @Override
+ public Long countActionStatusAll() {
+ return actionStatusRepository.count();
+ }
+
+ @Override
+ public Long countActionsAll() {
+ return actionRepository.count();
+ }
+
+ @Override
+ public Slice findActionsByDistributionSet(final Pageable pageable, final DistributionSet ds) {
+ return actionRepository.findByDistributionSet(pageable, (JpaDistributionSet) ds);
+ }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java
index 426733bcc..e5a38cf51 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java
@@ -62,7 +62,6 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -739,45 +738,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName());
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSetType generateDistributionSetType() {
- return new JpaDistributionSetType();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSet generateDistributionSet() {
- return new JpaDistributionSet();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSetMetadata generateDistributionSetMetadata() {
- return new JpaDistributionSetMetadata();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSetMetadata generateDistributionSetMetadata(final DistributionSet distributionSet,
- final String key, final String value) {
- return new JpaDistributionSetMetadata(key, distributionSet, value);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSetType generateDistributionSetType(final String key, final String name,
- final String description) {
- return new JpaDistributionSetType(key, name, description);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSet generateDistributionSet(final String name, final String version, final String description,
- final DistributionSetType type, final Collection moduleList) {
- return new JpaDistributionSet(name, version, description, type, moduleList);
- }
-
@Override
public Long countDistributionSetsByType(final DistributionSetType type) {
return distributionSetRepository.countByType((JpaDistributionSetType) type);
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java
new file mode 100644
index 000000000..88c34ad11
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java
@@ -0,0 +1,201 @@
+/**
+ * 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.util.Collection;
+
+import org.eclipse.hawkbit.repository.EntityFactory;
+import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
+import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
+import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
+import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
+import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
+import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
+import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
+import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
+import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
+import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
+import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
+import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
+import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
+import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
+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.DistributionSet;
+import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
+import org.eclipse.hawkbit.repository.model.DistributionSetTag;
+import org.eclipse.hawkbit.repository.model.DistributionSetType;
+import org.eclipse.hawkbit.repository.model.Rollout;
+import org.eclipse.hawkbit.repository.model.RolloutGroup;
+import org.eclipse.hawkbit.repository.model.SoftwareModule;
+import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
+import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
+import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
+import org.eclipse.hawkbit.repository.model.TargetTag;
+import org.springframework.stereotype.Service;
+
+/**
+ * JPA Implementation of {@link EntityFactory}.
+ *
+ */
+@Service
+public class JpaEntityFactory implements EntityFactory {
+
+ @Override
+ public DistributionSetType generateDistributionSetType() {
+ return new JpaDistributionSetType();
+ }
+
+ @Override
+ public DistributionSet generateDistributionSet() {
+ return new JpaDistributionSet();
+ }
+
+ @Override
+ public DistributionSetMetadata generateDistributionSetMetadata() {
+ return new JpaDistributionSetMetadata();
+ }
+
+ @Override
+ public DistributionSetMetadata generateDistributionSetMetadata(final DistributionSet distributionSet,
+ final String key, final String value) {
+ return new JpaDistributionSetMetadata(key, distributionSet, value);
+ }
+
+ @Override
+ public DistributionSetType generateDistributionSetType(final String key, final String name,
+ final String description) {
+ return new JpaDistributionSetType(key, name, description);
+ }
+
+ @Override
+ public DistributionSet generateDistributionSet(final String name, final String version, final String description,
+ final DistributionSetType type, final Collection moduleList) {
+ return new JpaDistributionSet(name, version, description, type, moduleList);
+ }
+
+ @Override
+ public Target generateTarget(final String controllerId) {
+ return new JpaTarget(controllerId);
+ }
+
+ @Override
+ public TargetTag generateTargetTag() {
+ return new JpaTargetTag();
+ }
+
+ @Override
+ public DistributionSetTag generateDistributionSetTag() {
+ return new JpaDistributionSetTag();
+ }
+
+ @Override
+ public TargetTag generateTargetTag(final String name, final String description, final String colour) {
+ return new JpaTargetTag(name, description, colour);
+ }
+
+ @Override
+ public DistributionSetTag generateDistributionSetTag(final String name, final String description,
+ final String colour) {
+ return new JpaDistributionSetTag(name, description, colour);
+ }
+
+ @Override
+ public TargetTag generateTargetTag(final String name) {
+ return new JpaTargetTag(name);
+ }
+
+ @Override
+ public DistributionSetTag generateDistributionSetTag(final String name) {
+ return new JpaDistributionSetTag(name);
+ }
+
+ @Override
+ public TargetFilterQuery generateTargetFilterQuery() {
+ return new JpaTargetFilterQuery();
+ }
+
+ @Override
+ public SoftwareModuleType generateSoftwareModuleType() {
+ return new JpaSoftwareModuleType();
+ }
+
+ @Override
+ public SoftwareModule generateSoftwareModule() {
+ return new JpaSoftwareModule();
+ }
+
+ @Override
+ public SoftwareModule generateSoftwareModule(final SoftwareModuleType type, final String name, final String version,
+ final String description, final String vendor) {
+
+ return new JpaSoftwareModule(type, name, version, description, vendor);
+ }
+
+ @Override
+ public SoftwareModuleMetadata generateSoftwareModuleMetadata() {
+ return new JpaSoftwareModuleMetadata();
+ }
+
+ @Override
+ public SoftwareModuleMetadata generateSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key,
+ final String value) {
+ return new JpaSoftwareModuleMetadata(key, softwareModule, value);
+ }
+
+ @Override
+ public SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description,
+ final int maxAssignments) {
+ return new JpaSoftwareModuleType(key, name, description, maxAssignments);
+ }
+
+ @Override
+ public Rollout generateRollout() {
+ return new JpaRollout();
+ }
+
+ @Override
+ public RolloutGroup generateRolloutGroup() {
+ return new JpaRolloutGroup();
+ }
+
+ @Override
+ public Action generateAction() {
+ return new JpaAction();
+ }
+
+ @Override
+ public ActionStatus generateActionStatus() {
+ return new JpaActionStatus();
+ }
+
+ @Override
+ public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
+ final String message) {
+ return new JpaActionStatus((JpaAction) action, status, occurredAt, message);
+ }
+
+ @Override
+ public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt,
+ final Collection messages) {
+
+ final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null);
+ messages.forEach(result::addMessage);
+
+ return result;
+ }
+
+ @Override
+ public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt) {
+ return new JpaActionStatus(action, status, occurredAt);
+ }
+
+}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java
index ea6214824..7d176d40a 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java
@@ -49,7 +49,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -201,9 +200,4 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
return new PageImpl<>(targetWithActionStatus, pageRequest, totalCount);
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public RolloutGroup generateRolloutGroup() {
- return new JpaRolloutGroup();
- }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java
index b3e451932..d412d2164 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java
@@ -667,9 +667,4 @@ public class JpaRolloutManagement implements RolloutManagement {
return ((float) finished / (float) totalGroup) * 100;
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public Rollout generateRollout() {
- return new JpaRollout();
- }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java
index eceec20d1..2fc057aec 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java
@@ -62,7 +62,6 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -663,44 +662,4 @@ public class JpaSoftwareManagement implements SoftwareManagement {
return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList());
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public SoftwareModuleType generateSoftwareModuleType() {
- return new JpaSoftwareModuleType();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public SoftwareModule generateSoftwareModule() {
- return new JpaSoftwareModule();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public SoftwareModule generateSoftwareModule(final SoftwareModuleType type, final String name, final String version,
- final String description, final String vendor) {
-
- return new JpaSoftwareModule(type, name, version, description, vendor);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public SoftwareModuleMetadata generateSoftwareModuleMetadata() {
- return new JpaSoftwareModuleMetadata();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public SoftwareModuleMetadata generateSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key,
- final String value) {
- return new JpaSoftwareModuleMetadata(key, softwareModule, value);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description,
- final int maxAssignments) {
- return new JpaSoftwareModuleType(key, name, description, maxAssignments);
- }
-
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java
index 05d5d486e..be46362a5 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java
@@ -259,28 +259,6 @@ public class JpaSystemManagement implements SystemManagement {
return tenantMetaDataRepository.save((JpaTenantMetaData) metaData);
}
- private DistributionSetType createStandardSoftwareDataSetup() {
- final SoftwareModuleType eclApp = softwareModuleTypeRepository.save(new JpaSoftwareModuleType("application",
- "ECL Application", "Edge Controller Linux base application type", 1));
- final SoftwareModuleType eclOs = softwareModuleTypeRepository.save(
- new JpaSoftwareModuleType("os", "ECL OS", "Edge Controller Linux operation system image type", 1));
- final SoftwareModuleType eclJvm = softwareModuleTypeRepository.save(
- new JpaSoftwareModuleType("runtime", "ECL JVM", "Edge Controller Linux java virtual machine type.", 1));
-
- distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os", "OS only",
- "Standard Edge Controller Linux distribution set type.").addMandatoryModuleType(eclOs));
-
- distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app",
- "OS with optional app", "Standard Edge Controller Linux distribution set type. OS only.")
- .addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp));
-
- return distributionSetTypeRepository.save(
- (JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app_jvm", "OS with optional app and jvm",
- "Standard Edge Controller Linux distribution set type. OS with optional application.")
- .addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp)
- .addOptionalModuleType(eclJvm));
- }
-
/**
* A implementation of the {@link KeyGenerator} to generate a key based on
* either the {@code createInitialTenant} thread local and the
@@ -303,4 +281,18 @@ public class JpaSystemManagement implements SystemManagement {
initialTenantCreation.toUpperCase());
}
}
+
+ private DistributionSetType createStandardSoftwareDataSetup() {
+ final SoftwareModuleType app = softwareModuleTypeRepository
+ .save(new JpaSoftwareModuleType("application", "Application", "Application Addons", Integer.MAX_VALUE));
+ final SoftwareModuleType os = softwareModuleTypeRepository
+ .save(new JpaSoftwareModuleType("os", "Firmware", "Core firmware or operationg system", 1));
+
+ distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os_app", "With app(s)",
+ "Default type with Firmware/OS and optional app(s).").addMandatoryModuleType(os)
+ .addOptionalModuleType(app));
+
+ return distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os", "OS only",
+ "Default type with Firmware/OS only.").addMandatoryModuleType(os));
+ }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java
index 9a44f1319..29fbb8a2b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java
@@ -41,7 +41,6 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -287,41 +286,4 @@ public class JpaTagManagement implements TagManagement {
return convertDsPage(distributionSetTagRepository.findAll(spec, pageable), pageable);
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public TargetTag generateTargetTag() {
- return new JpaTargetTag();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSetTag generateDistributionSetTag() {
- return new JpaDistributionSetTag();
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public TargetTag generateTargetTag(final String name, final String description, final String colour) {
- return new JpaTargetTag(name, description, colour);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSetTag generateDistributionSetTag(final String name, final String description,
- final String colour) {
- return new JpaDistributionSetTag(name, description, colour);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public TargetTag generateTargetTag(final String name) {
- return new JpaTargetTag(name);
- }
-
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public DistributionSetTag generateDistributionSetTag(final String name) {
- return new JpaDistributionSetTag(name);
- }
-
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java
index 8bc4a0833..296483bf8 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java
@@ -109,9 +109,4 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery);
}
- @Override
- public TargetFilterQuery generateTargetFilterQuery() {
- return new JpaTargetFilterQuery();
- }
-
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java
index 8d2fabac7..892ddc771 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java
@@ -61,7 +61,6 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
@@ -403,7 +402,6 @@ public class JpaTargetManagement implements TargetManagement {
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public Target unAssignTag(final String controllerID, final TargetTag targetTag) {
- // TODO : optimize this, findone?
final List allTargets = new ArrayList<>(targetRepository
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))));
final List unAssignTag = unAssignTag(allTargets, targetTag);
@@ -673,9 +671,4 @@ public class JpaTargetManagement implements TargetManagement {
return resultList;
}
- @Override
- @Transactional(propagation = Propagation.SUPPORTS)
- public Target generateTarget(final String controllerId) {
- return new JpaTarget(controllerId);
- }
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java
index dddc01d91..b303f33a4 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java
@@ -53,16 +53,11 @@ public class CacheFieldEntityListener {
@SuppressWarnings("rawtypes")
final String id = ((Identifiable) target).getId().toString();
final Class extends Object> type = target.getClass();
- findCacheFields(type, id, new CacheFieldCallback() {
- @Override
- public void fromCache(final Field field, final String cacheKey, final Serializable id)
- throws IllegalAccessException {
- final Cache cache = cacheManager.getCache(type.getName());
- final ValueWrapper valueWrapper = cache
- .get(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey));
- if (valueWrapper != null && valueWrapper.get() != null) {
- FieldUtils.writeField(field, target, valueWrapper.get(), true);
- }
+ findCacheFields(type, id, (field, cacheKey, id1) -> {
+ final Cache cache = cacheManager.getCache(type.getName());
+ final ValueWrapper valueWrapper = cache.get(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey));
+ if (valueWrapper != null && valueWrapper.get() != null) {
+ FieldUtils.writeField(field, target, valueWrapper.get(), true);
}
});
}
@@ -82,13 +77,9 @@ public class CacheFieldEntityListener {
@SuppressWarnings("rawtypes")
final String id = ((Identifiable) target).getId().toString();
final Class extends Object> type = target.getClass();
- findCacheFields(type, id, new CacheFieldCallback() {
- @Override
- public void fromCache(final Field field, final String cacheKey, final Serializable id)
- throws IllegalAccessException {
- final Cache cache = cacheManager.getCache(type.getName());
- cache.evict(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey));
- }
+ findCacheFields(type, id, (field, cacheKey, id1) -> {
+ final Cache cache = cacheManager.getCache(type.getName());
+ cache.evict(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey));
});
}
}
@@ -109,6 +100,7 @@ public class CacheFieldEntityListener {
}
}
+ @FunctionalInterface
private interface CacheFieldCallback {
/**
* callback methods which is called by the
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java
index 642386c69..0690f72ec 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java
@@ -12,8 +12,9 @@ import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
/**
- *
+ * Verifies {@link RolloutGroup#getErrorConditionExp()}.
*/
+@FunctionalInterface
public interface RolloutGroupConditionEvaluator {
default boolean verifyExpression(final String expression) {
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
new file mode 100644
index 000000000..342e0792b
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java
@@ -0,0 +1,104 @@
+/**
+ * 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 javax.persistence.EntityManager;
+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;
+
+@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class,
+ TestConfiguration.class })
+public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest {
+
+ @PersistenceContext
+ protected EntityManager entityManager;
+
+ @Autowired
+ protected TargetRepository targetRepository;
+
+ @Autowired
+ protected ActionRepository actionRepository;
+
+ @Autowired
+ protected DistributionSetRepository distributionSetRepository;
+
+ @Autowired
+ protected SoftwareModuleRepository softwareModuleRepository;
+
+ @Autowired
+ protected TenantMetaDataRepository tenantMetaDataRepository;
+
+ @Autowired
+ protected DistributionSetTypeRepository distributionSetTypeRepository;
+
+ @Autowired
+ protected SoftwareModuleTypeRepository softwareModuleTypeRepository;
+
+ @Autowired
+ protected TargetTagRepository targetTagRepository;
+
+ @Autowired
+ protected DistributionSetTagRepository distributionSetTagRepository;
+
+ @Autowired
+ protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
+
+ @Autowired
+ protected ActionStatusRepository actionStatusRepository;
+
+ @Autowired
+ protected ExternalArtifactRepository externalArtifactRepository;
+
+ @Autowired
+ protected LocalArtifactRepository artifactRepository;
+
+ @Autowired
+ protected TargetInfoRepository targetInfoRepository;
+
+ @Autowired
+ protected GridFsOperations operations;
+
+ @Autowired
+ protected RolloutGroupRepository rolloutGroupRepository;
+
+ @Autowired
+ protected RolloutRepository rolloutRepository;
+
+ @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
new file mode 100644
index 000000000..38a02c213
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java
@@ -0,0 +1,104 @@
+/**
+ * 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 javax.persistence.EntityManager;
+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 })
+public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB {
+
+ @PersistenceContext
+ protected EntityManager entityManager;
+
+ @Autowired
+ protected TargetRepository targetRepository;
+
+ @Autowired
+ protected ActionRepository actionRepository;
+
+ @Autowired
+ protected DistributionSetRepository distributionSetRepository;
+
+ @Autowired
+ protected SoftwareModuleRepository softwareModuleRepository;
+
+ @Autowired
+ protected TenantMetaDataRepository tenantMetaDataRepository;
+
+ @Autowired
+ protected DistributionSetTypeRepository distributionSetTypeRepository;
+
+ @Autowired
+ protected SoftwareModuleTypeRepository softwareModuleTypeRepository;
+
+ @Autowired
+ protected TargetTagRepository targetTagRepository;
+
+ @Autowired
+ protected DistributionSetTagRepository distributionSetTagRepository;
+
+ @Autowired
+ protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
+
+ @Autowired
+ protected ActionStatusRepository actionStatusRepository;
+
+ @Autowired
+ protected ExternalArtifactRepository externalArtifactRepository;
+
+ @Autowired
+ protected LocalArtifactRepository artifactRepository;
+
+ @Autowired
+ protected TargetInfoRepository targetInfoRepository;
+
+ @Autowired
+ protected GridFsOperations operations;
+
+ @Autowired
+ protected RolloutGroupRepository rolloutGroupRepository;
+
+ @Autowired
+ protected RolloutRepository rolloutRepository;
+
+ @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/ArtifactManagementNoMongoDbTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java
index fd91a2158..42b759b74 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java
@@ -29,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("Artifact Management")
-public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest {
+public class ArtifactManagementNoMongoDbTest extends AbstractJpaIntegrationTest {
@BeforeClass
public static void initialize() {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java
index 4c37c00e3..ea6e8e01b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java
@@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Criteria;
@@ -50,7 +51,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("Artifact Management")
-public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB {
+public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
public ArtifactManagementTest() {
LOG = LoggerFactory.getLogger(ArtifactManagementTest.class);
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java
index c79c47af9..f33c5c170 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java
@@ -33,14 +33,13 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Controller Management")
-public class ControllerManagementTest extends AbstractIntegrationTest {
+public class ControllerManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Controller adds a new action status.")
public void controllerAddsActionStatus() {
final Target target = new JpaTarget("4712");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
Target savedTarget = targetManagement.createTarget(target);
final List toAssign = new ArrayList<>();
@@ -99,8 +98,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest {
// mock
final Target target = new JpaTarget("Rabbit");
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
Target savedTarget = targetManagement.createTarget(target);
final List toAssign = new ArrayList<>();
toAssign.add(savedTarget);
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java
index 0900973d0..3d0114d67 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java
@@ -67,7 +67,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("Deployment Management")
-public class DeploymentManagementTest extends AbstractIntegrationTest {
+public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
@Autowired
private EventBus eventBus;
@@ -75,9 +75,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
@Test
@Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.")
public void findActionWithLazyDetails() {
- final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement,
- distributionSetManagement, new ArrayList());
- final List testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
+ final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
+ new ArrayList());
+ final List testTarget = testdataFactory.createTargets(1);
// one action with one action status is generated
final Long actionId = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0);
final Action action = deploymentManagement.findActionWithDetails(actionId);
@@ -91,9 +91,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
@Test
@Description("Test verifies that the custom query to find all actions include the count of action status is working correctly")
public void findActionsWithStatusCountByTarget() {
- final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement,
- distributionSetManagement, new ArrayList());
- final List testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
+ final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
+ new ArrayList());
+ final List testTarget = testdataFactory.createTargets(1);
// one action with one action status is generated
final Action action = deploymentManagement.findActionWithDetails(
deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0));
@@ -114,8 +114,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
public void assignAndUnassignDistributionSetToTag() {
final List assignDS = new ArrayList<>();
for (int i = 0; i < 4; i++) {
- assignDS.add(TestDataUtil.generateDistributionSet("DS" + i, "1.0", softwareManagement,
- distributionSetManagement, new ArrayList()).getId());
+ assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", new ArrayList())
+ .getId());
}
// not exists
assignDS.add(Long.valueOf(100));
@@ -154,14 +154,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
@Description("Test verifies that an assignment with automatic cancelation works correctly even if the update is split into multiple partitions on the database.")
public void multiAssigmentHistoryOverMultiplePagesResultsInTwoActiveAction() {
- final DistributionSet cancelDs = TestDataUtil.generateDistributionSet("Canceled DS", "1.0", softwareManagement,
- distributionSetManagement, new ArrayList());
+ final DistributionSet cancelDs = testdataFactory.createDistributionSet("Canceled DS", "1.0",
+ new ArrayList());
- final DistributionSet cancelDs2 = TestDataUtil.generateDistributionSet("Canceled DS", "1.2", softwareManagement,
- distributionSetManagement, new ArrayList());
+ final DistributionSet cancelDs2 = testdataFactory.createDistributionSet("Canceled DS", "1.2",
+ new ArrayList());
- List targets = targetManagement
- .createTargets(TestDataUtil.generateTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10));
+ List targets = testdataFactory.createTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10);
targets = deploymentManagement.assignDistributionSet(cancelDs, targets).getAssignedEntity();
targets = deploymentManagement.assignDistributionSet(cancelDs2, targets).getAssignedEntity();
@@ -179,15 +178,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
+ "also the target goes back to IN_SYNC as no open action is left.")
public void manualCancelWithMultipleAssignmentsCancelLastOneFirst() {
JpaTarget target = new JpaTarget("4712");
- final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true);
dsFirst.setRequiredMigrationStep(true);
- final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement, true);
- final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true);
+ final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
- ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
+ ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
target = (JpaTarget) targetManagement.createTarget(target);
// check initial status
@@ -236,15 +232,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
+ "also the target goes back to IN_SYNC as no open action is left.")
public void manualCancelWithMultipleAssignmentsCancelMiddleOneFirst() {
JpaTarget target = new JpaTarget("4712");
- final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true);
dsFirst.setRequiredMigrationStep(true);
- final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement,
- distributionSetManagement, true);
- final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true);
+ final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
- ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
+ ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
target = (JpaTarget) targetManagement.createTarget(target);
// check initial status
@@ -295,13 +288,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
public void forceQuitSetActionToInactive() throws InterruptedException {
JpaTarget target = new JpaTarget("4712");
- final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
- distributionSetManagement, true);
- ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
+ final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
+ ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
target = (JpaTarget) targetManagement.createTarget(target);
- final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
ds.setRequiredMigrationStep(true);
// verify initial status
@@ -336,14 +327,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
@Description("Force Quit an not canceled Assignment. Expected behaviour is that the action can not be force quit and there is thrown an exception.")
public void forceQuitNotAllowedThrowsException() {
- JpaTarget target = new JpaTarget("4712");
- final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement,
- distributionSetManagement, true);
- ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled);
- target = (JpaTarget) targetManagement.createTarget(target);
+ Target target = new JpaTarget("4712");
+ final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true);
+ ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled);
+ target = targetManagement.createTarget(target);
- final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
ds.setRequiredMigrationStep(true);
// verify initial status
@@ -364,14 +353,16 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
}
}
- private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
+ private Action assignSet(final Target target, final DistributionSet ds) {
deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() });
assertThat(
targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus())
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet())
.as("wrong assigned ds").isEqualTo(ds);
- final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0);
+ final Action action = actionRepository
+ .findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent()
+ .get(0);
assertThat(action).as("action should not be null").isNotNull();
return action;
}
@@ -392,14 +383,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final String myCtrlIDPref = "myCtrlID";
final Iterable savedNakedTargets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(10, myCtrlIDPref, "first description"));
+ .createTargets(testdataFactory.generateTargets(10, myCtrlIDPref, "first description"));
final String myDeployedCtrlIDPref = "myDeployedCtrlID";
List savedDeployedTargets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(20, myDeployedCtrlIDPref, "first description"));
+ .createTargets(testdataFactory.generateTargets(20, myDeployedCtrlIDPref, "first description"));
- final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("");
deploymentManagement.assignDistributionSet(ds, savedDeployedTargets);
@@ -446,7 +436,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final EventHandlerMock eventHandlerMock = new EventHandlerMock(0);
eventBus.register(eventHandlerMock);
- final List targets = targetManagement.createTargets(TestDataUtil.generateTargets(10));
+ final List targets = testdataFactory.createTargets(10);
final SoftwareModule ah = softwareManagement
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
@@ -657,7 +647,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets,
deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS");
- DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement);
+ DistributionSet dsA = testdataFactory.createDistributionSet("");
distributionSetManagement.deleteDistributionSet(dsA.getId());
dsA = distributionSetManagement.findDistributionSetById(dsA.getId());
@@ -761,12 +751,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
@Description("Testing if changing target and the status without refreshing the entities from the DB (e.g. concurrent changes from UI and from controller) works")
public void alternatingAssignmentAndAddUpdateActionStatus() {
- final JpaDistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement,
- distributionSetManagement);
- final JpaDistributionSet dsB = TestDataUtil.generateDistributionSet("b", softwareManagement,
- distributionSetManagement);
- Target targ = targetManagement
- .createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("a");
+ final DistributionSet dsB = testdataFactory.createDistributionSet("b");
+ Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
List targs = new ArrayList<>();
targs.add(targ);
@@ -793,7 +780,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
assertThat(deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet())
.as("Installed distribution set of action should be null").isNotNull();
- final Page updAct = actionRepository.findByDistributionSet(pageReq, dsA);
+ final Page updAct = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) dsA);
final Action action = updAct.getContent().get(0);
action.setStatus(Status.FINISHED);
final ActionStatus statusMessage = new JpaActionStatus((JpaAction) action, Status.FINISHED,
@@ -831,11 +818,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
@Description("The test verfies that the DS itself is not changed because of an target assignment"
+ " which is a relationship but not a changed on the entity itself..")
public void checkThatDsRevisionsIsNotChangedWithTargetAssignment() {
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement,
- distributionSetManagement);
- TestDataUtil.generateDistributionSet("b", softwareManagement, distributionSetManagement);
- Target targ = targetManagement
- .createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("a");
+ testdataFactory.createDistributionSet("b");
+ Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description"));
assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo(
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
@@ -854,8 +839,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
public void forceSoftAction() {
// prepare
final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId"));
- final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("a");
// assign ds to create an action
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME,
@@ -878,8 +862,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
public void forceAlreadyForcedActionNothingChanges() {
// prepare
final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId"));
- final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("a");
// assign ds to create an action
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet(
ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME,
@@ -926,14 +909,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
final String deployedTargetPrefix, final int noOfDeployedTargets, final int noOfDistributionSets,
final String distributionSetPrefix) {
final Iterable nakedTargets = targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
+ testdataFactory.generateTargets(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
List deployedTargets = targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(noOfDeployedTargets, deployedTargetPrefix, "first description"));
+ testdataFactory.generateTargets(noOfDeployedTargets, deployedTargetPrefix, "first description"));
// creating 10 DistributionSets
- final Collection dsList = (Collection) TestDataUtil.generateDistributionSets(
- distributionSetPrefix, noOfDistributionSets, softwareManagement, distributionSetManagement);
+ final Collection dsList = testdataFactory.createDistributionSets(distributionSetPrefix,
+ noOfDistributionSets);
String time = String.valueOf(System.currentTimeMillis());
time = time.substring(time.length() - 5);
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java
index f102ac86c..d26474bb4 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java
@@ -31,14 +31,15 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
-import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.DistributionSet;
+import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.fest.assertions.core.Condition;
import org.junit.Test;
import org.springframework.data.domain.Page;
@@ -56,7 +57,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("DistributionSet Management")
-public class DistributionSetManagementTest extends AbstractIntegrationTest {
+public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests the successfull module update of unused distribution set type which is in fact allowed.")
@@ -178,10 +179,10 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
@Test
@Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).")
public void createDuplicateDistributionSetsFailsWithException() {
- TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
+ testdataFactory.createDistributionSet("a");
try {
- TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement);
+ testdataFactory.createDistributionSet("a");
fail("Should not have worked as DS with same UK already exists.");
} catch (final EntityAlreadyExistsException e) {
@@ -239,8 +240,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
final String knownKey = "dsMetaKnownKey";
final String knownValue = "dsMetaKnownValue";
- final DistributionSet ds = TestDataUtil.generateDistributionSet("testDs", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("testDs");
final DistributionSetMetadata metadata = new JpaDistributionSetMetadata(knownKey, ds, knownValue);
final JpaDistributionSetMetadata createdMetadata = (JpaDistributionSetMetadata) distributionSetManagement
@@ -262,8 +262,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
SoftwareModule ah2 = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, "");
SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, "");
- DistributionSet ds = TestDataUtil.generateDistributionSet("ds-1", softwareManagement,
- distributionSetManagement);
+ DistributionSet ds = testdataFactory.createDistributionSet("ds-1");
ah2 = softwareManagement.createSoftwareModule(ah2);
os2 = softwareManagement.createSoftwareModule(os2);
@@ -348,7 +347,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, "");
final SoftwareModule app2 = new JpaSoftwareModule(appType, "app2", "3.0.3", null, "");
- DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement);
+ DistributionSet ds = testdataFactory.createDistributionSet("");
os2 = softwareManagement.createSoftwareModule(os2);
@@ -387,8 +386,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
final String knownUpdateValue = "myNewUpdatedValue";
// create a DS
- final DistributionSet ds = TestDataUtil.generateDistributionSet("testDs", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("testDs");
// initial opt lock revision must be zero
assertThat(ds.getOptLockRevision()).isEqualTo(1L);
@@ -427,13 +425,12 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
@Description("Tests that a DS queue is possible where the result is ordered by the target assignment, i.e. assigned first in the list.")
public void findDistributionSetsAllOrderedByLinkTarget() {
- final List buildDistributionSets = TestDataUtil.generateDistributionSets("dsOrder", 10,
- softwareManagement, distributionSetManagement);
+ final List buildDistributionSets = testdataFactory.createDistributionSets("dsOrder", 10);
final List buildTargetFixtures = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(5, "tOrder", "someDesc"));
+ .createTargets(testdataFactory.generateTargets(5, "tOrder", "someDesc"));
- final Iterator dsIterator = buildDistributionSets.iterator();
+ final Iterator dsIterator = buildDistributionSets.iterator();
final Iterator tIterator = buildTargetFixtures.iterator();
final DistributionSet dsFirst = dsIterator.next();
final DistributionSet dsSecond = dsIterator.next();
@@ -482,12 +479,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
final DistributionSetTag dsTagD = tagManagement
.createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-D"));
- Collection ds100Group1 = (Collection) TestDataUtil.generateDistributionSets("", 100,
- softwareManagement, distributionSetManagement);
- Collection ds100Group2 = (Collection) TestDataUtil.generateDistributionSets("test2", 100,
- softwareManagement, distributionSetManagement);
- DistributionSet dsDeleted = TestDataUtil.generateDistributionSet("deleted", softwareManagement,
- distributionSetManagement);
+ Collection ds100Group1 = testdataFactory.createDistributionSets("", 100);
+ Collection ds100Group2 = testdataFactory.createDistributionSets("test2", 100);
+ DistributionSet dsDeleted = testdataFactory.createDistributionSet("deleted");
final DistributionSet dsInComplete = distributionSetManagement
.createDistributionSet(new JpaDistributionSet("notcomplete", "1", "", standardDsType, null));
@@ -498,8 +492,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
final DistributionSet dsNewType = distributionSetManagement
.createDistributionSet(new JpaDistributionSet("newtype", "1", "", newType, dsDeleted.getModules()));
- deploymentManagement.assignDistributionSet(dsDeleted,
- targetManagement.createTargets(Lists.newArrayList(TestDataUtil.generateTargets(5))));
+ deploymentManagement.assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5)));
distributionSetManagement.deleteDistributionSet(dsDeleted);
dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId());
@@ -724,7 +717,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
@Test
@Description("Simple DS load without the related data that should be loaded lazy.")
public void findDistributionSetsWithoutLazy() {
- TestDataUtil.generateDistributionSets(20, softwareManagement, distributionSetManagement);
+ testdataFactory.createDistributionSets(20);
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true))
.hasSize(20);
@@ -733,10 +726,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
@Test
@Description("Deltes a DS that is no in use. Expected behaviour is a hard delete on the database.")
public void deleteUnassignedDistributionSet() {
- DistributionSet ds1 = TestDataUtil.generateDistributionSet("ds-1", softwareManagement,
- distributionSetManagement);
- DistributionSet ds2 = TestDataUtil.generateDistributionSet("ds-2", softwareManagement,
- distributionSetManagement);
+ DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
+ DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
@@ -755,10 +746,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
@Description("Queries and loads the metadata related to a given software module.")
public void findAllDistributionSetMetadataByDsId() {
// create a DS
- DistributionSet ds1 = TestDataUtil.generateDistributionSet("testDs1", softwareManagement,
- distributionSetManagement);
- DistributionSet ds2 = TestDataUtil.generateDistributionSet("testDs2", softwareManagement,
- distributionSetManagement);
+ DistributionSet ds1 = testdataFactory.createDistributionSet("testDs1");
+ DistributionSet ds2 = testdataFactory.createDistributionSet("testDs2");
for (int index = 0; index < 10; index++) {
@@ -791,12 +780,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest {
@Description("Deltes a DS that is no in use. Expected behaviour is a soft delete on the database, i.e. only marked as "
+ "deleted, kept eas refernce and unavailable for future use..")
public void deleteAssignedDistributionSet() {
- DistributionSet ds1 = TestDataUtil.generateDistributionSet("ds-1", softwareManagement,
- distributionSetManagement);
- DistributionSet ds2 = TestDataUtil.generateDistributionSet("ds-2", softwareManagement,
- distributionSetManagement);
- DistributionSet dsAssigned = TestDataUtil.generateDistributionSet("ds-3", softwareManagement,
- distributionSetManagement);
+ DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1");
+ DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2");
+ DistributionSet dsAssigned = testdataFactory.createDistributionSet("ds-3");
ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion());
ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion());
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java
new file mode 100644
index 000000000..5c4b0efcc
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java
@@ -0,0 +1,109 @@
+/**
+ * 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.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
+import org.eclipse.hawkbit.repository.SystemManagement;
+import org.eclipse.hawkbit.repository.util.TestRepositoryManagement;
+import org.eclipse.hawkbit.security.SystemSecurityContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.gridfs.GridFsOperations;
+import org.springframework.transaction.annotation.Transactional;
+
+public class JpaTestRepositoryManagement implements TestRepositoryManagement {
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Autowired
+ private TargetRepository targetRepository;
+
+ @Autowired
+ private ActionRepository actionRepository;
+
+ @Autowired
+ private DistributionSetRepository distributionSetRepository;
+
+ @Autowired
+ private SoftwareModuleRepository softwareModuleRepository;
+
+ @Autowired
+ private TenantMetaDataRepository tenantMetaDataRepository;
+
+ @Autowired
+ private DistributionSetTypeRepository distributionSetTypeRepository;
+
+ @Autowired
+ private SoftwareModuleTypeRepository softwareModuleTypeRepository;
+
+ @Autowired
+ private TargetTagRepository targetTagRepository;
+
+ @Autowired
+ private DistributionSetTagRepository distributionSetTagRepository;
+
+ @Autowired
+ private SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
+
+ @Autowired
+ private ActionStatusRepository actionStatusRepository;
+
+ @Autowired
+ private ExternalArtifactRepository externalArtifactRepository;
+
+ @Autowired
+ private LocalArtifactRepository artifactRepository;
+
+ @Autowired
+ private TargetInfoRepository targetInfoRepository;
+
+ @Autowired
+ private GridFsOperations operations;
+
+ @Autowired
+ private RolloutGroupRepository rolloutGroupRepository;
+
+ @Autowired
+ private RolloutRepository rolloutRepository;
+
+ @Autowired
+ private TenantAwareCacheManager cacheManager;
+
+ @Autowired
+ private SystemSecurityContext systemSecurityContext;
+
+ @Autowired
+ private SystemManagement systemManagement;
+
+ @Override
+ public void clearTestRepository() {
+ deleteAllRepos();
+ cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear());
+ }
+
+ @Transactional
+ public void deleteAllRepos() {
+ final List tenants = systemSecurityContext.runAsSystem(() -> systemManagement.findTenants());
+ tenants.forEach(tenant -> {
+ try {
+ systemSecurityContext.runAsSystem(() -> {
+ systemManagement.deleteTenant(tenant);
+ return null;
+ });
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ });
+ }
+}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java
index 57fc13379..4fba80616 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java
@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.ReportManagement;
import org.eclipse.hawkbit.repository.ReportManagement.DateTypes;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
-import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
import org.eclipse.hawkbit.repository.model.Action;
@@ -38,6 +37,9 @@ import org.eclipse.hawkbit.repository.report.model.DataReportSeries;
import org.eclipse.hawkbit.repository.report.model.DataReportSeriesItem;
import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries;
import org.eclipse.hawkbit.repository.report.model.SeriesTime;
+import org.eclipse.hawkbit.repository.util.TestdataFactory;
+import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -55,7 +57,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Report Management")
-public class ReportManagementTest extends AbstractIntegrationTest {
+public class ReportManagementTest extends AbstractJpaIntegrationTest {
@Autowired
private ReportManagement reportManagement;
@@ -128,8 +130,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
final LocalDateTime to = LocalDateTime.now();
final LocalDateTime from = to.minusMonths(maxMonthBackAmountReportTargets);
- final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("ds", softwareManagement,
- distributionSetManagement);
+ final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds");
final DynamicDateTimeProvider dynamicDateTimeProvider = new DynamicDateTimeProvider();
auditingHandler.setDateTimeProvider(dynamicDateTimeProvider);
@@ -181,21 +182,18 @@ public class ReportManagementTest extends AbstractIntegrationTest {
final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4"));
final Target knownTarget5 = targetManagement.createTarget(new JpaTarget("t5"));
- final SoftwareModule ah = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
- final SoftwareModule jvm = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
- final SoftwareModule os = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
+ final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
+ final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
+ final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
- final DistributionSet distributionSet1 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah));
- final DistributionSet distributionSet11 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.1", standardDsType, os, jvm, ah));
- final DistributionSet distributionSet2 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds2", "0.0.2", standardDsType, os, jvm, ah));
- final DistributionSet distributionSet3 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds3", "0.0.3", standardDsType, os, jvm, ah));
+ final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
+ final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah)));
+ final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah)));
+ final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah)));
// ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3]
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
@@ -355,21 +353,18 @@ public class ReportManagementTest extends AbstractIntegrationTest {
final Target knownTarget3 = targetManagement.createTarget(new JpaTarget("t3"));
final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4"));
- final SoftwareModule ah = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
- final SoftwareModule jvm = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
- final SoftwareModule os = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
+ final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
+ final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
+ final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
- final DistributionSet distributionSet1 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah));
- final DistributionSet distributionSet11 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.1", standardDsType, os, jvm, ah));
- final DistributionSet distributionSet2 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds2", "0.0.2", standardDsType, os, jvm, ah));
- final DistributionSet distributionSet3 = distributionSetManagement
- .createDistributionSet(TestDataUtil.buildDistributionSet("ds3", "0.0.3", standardDsType, os, jvm, ah));
+ final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
+ final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah)));
+ final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah)));
+ final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah)));
// ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3]
deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId());
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java
index 28ece9239..42e5de498 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java
@@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
-import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.utils.MultipleInvokeHelper;
import org.eclipse.hawkbit.repository.jpa.utils.SuccessCondition;
import org.eclipse.hawkbit.repository.model.Action;
@@ -41,6 +40,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
+import org.eclipse.hawkbit.repository.util.TestdataFactory;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
@@ -49,6 +49,8 @@ import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
+import com.google.common.collect.Lists;
+
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@@ -60,7 +62,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("Rollout Management")
-public class RolloutManagementTest extends AbstractIntegrationTest {
+public class RolloutManagementTest extends AbstractJpaIntegrationTest {
@Autowired
private RolloutManagement rolloutManagement;
@@ -455,8 +457,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
targetToCancel.add(targetList.get(0));
targetToCancel.add(targetList.get(1));
targetToCancel.add(targetList.get(2));
- final DistributionSet dsForCancelTest = TestDataUtil.generateDistributionSet("dsForTest", softwareManagement,
- distributionSetManagement);
+ final DistributionSet dsForCancelTest = testdataFactory.createDistributionSet("dsForTest");
deploymentManagement.assignDistributionSet(dsForCancelTest, targetToCancel);
// 5 targets are canceling but still have the status running and 5 are
// still in SCHEDULED
@@ -480,8 +481,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
rolloutManagement.startRollout(rolloutOne);
rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId());
- final DistributionSet dsForRolloutTwo = TestDataUtil.generateDistributionSet("dsForRolloutTwo",
- softwareManagement, distributionSetManagement);
+ final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsForRolloutTwo");
final Rollout rolloutTwo = createRolloutByVariables("rolloutTwo", "This is the description for rollout two", 1,
"controllerId==rollout-*", dsForRolloutTwo, "50", "80");
@@ -834,7 +834,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
Rollout myRollout = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups,
successCondition, errorCondition, rolloutName, rolloutName);
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountOtherTargets, "others-", "rollout"));
+ targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout"));
final String rsqlParam = "controllerId==*MyRoll*";
@@ -872,10 +872,9 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
final String errorCondition = "80";
final String rolloutName = "rolloutTest";
final String targetPrefixName = rolloutName;
- final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("dsFor" + rolloutName,
- softwareManagement, distributionSetManagement);
+ final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
+ testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder()
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition)
.errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition)
@@ -933,17 +932,14 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
private Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
final int amountOtherTargets, final int groupSize, final String successCondition,
final String errorCondition) {
- final SoftwareModule ah = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
- final SoftwareModule jvm = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
- final SoftwareModule os = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, ""));
- final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet(
- TestDataUtil.buildDistributionSet("rolloutDS", "0.0.0", standardDsType, os, jvm, ah));
- targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(amountTargetsForRollout, "rollout-", "rollout"));
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountOtherTargets, "others-", "rollout"));
+ final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
+ final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
+ final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
+
+ final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("rolloutDS", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah)));
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsForRollout, "rollout-", "rollout"));
+ targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout"));
final String filterQuery = "controllerId==rollout-*";
return createRolloutByVariables("test-rollout-name-1", "test-rollout-description-1", groupSize, filterQuery,
rolloutDS, successCondition, errorCondition);
@@ -952,10 +948,9 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
private Rollout createTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
final int groupSize, final String successCondition, final String errorCondition, final String rolloutName,
final String targetPrefixName) {
- final DistributionSet dsForRolloutTwo = TestDataUtil.generateDistributionSet("dsFor" + rolloutName,
- softwareManagement, distributionSetManagement);
+ final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsFor" + rolloutName);
targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
+ testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName));
return createRolloutByVariables(rolloutName, rolloutName + "description", groupSize,
"controllerId==" + targetPrefixName + "-*", dsForRolloutTwo, successCondition, errorCondition);
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java
index 69e19ea3a..366dd6ec7 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java
@@ -39,6 +39,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -54,7 +55,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Software Management")
-public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
+public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
@Test
@Description("Try to update non updatable fields results in repository doing nothing.")
@@ -227,8 +228,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB {
final SoftwareModule ah2 = softwareManagement
.createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.2", null, ""));
- JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet(
- TestDataUtil.buildDistributionSet("ds-1", "1.0.1", standardDsType, os, jvm, ah2));
+ JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet(testdataFactory
+ .generateDistributionSet("ds-1", "1.0.1", standardDsType, Lists.newArrayList(os, jvm, ah2)));
final JpaTarget target = (JpaTarget) targetManagement.createTarget(new JpaTarget("test123"));
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java
index 185416984..e697f65d8 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java
@@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
+import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
import org.junit.Test;
import ru.yandex.qatools.allure.annotations.Description;
@@ -26,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("System Management")
-public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
+public class SystemManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
@Test
@Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in")
@@ -108,8 +109,8 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
final List createdTargets = createTestTargets(targets);
if (updates > 0) {
for (int x = 0; x < updates; x++) {
- final DistributionSet ds = TestDataUtil.generateDistributionSet("to be deployed" + x,
- softwareManagement, distributionSetManagement, true);
+ final DistributionSet ds = testdataFactory.createDistributionSet("to be deployed" + x,
+ true);
deploymentManagement.assignDistributionSet(ds, createdTargets);
}
@@ -125,7 +126,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
private List createTestTargets(final int targets) {
return targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(targets, "testTargetOfTenant", "testTargetOfTenant"));
+ .createTargets(testdataFactory.generateTargets(targets, "testTargetOfTenant", "testTargetOfTenant"));
}
private void createTestArtifact(final byte[] random) {
@@ -137,8 +138,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
}
private void createDeletedTestArtifact(final byte[] random) {
- final DistributionSet ds = TestDataUtil.generateDistributionSet("deleted garbage", softwareManagement,
- distributionSetManagement, true);
+ final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true);
ds.getModules().stream().forEach(module -> {
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
softwareManagement.deleteSoftwareModule(module);
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java
index 25437b0ed..5f2fe3fbd 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java
@@ -23,13 +23,13 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.DistributionSet;
+import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
-import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
@@ -46,7 +46,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("Tag Management")
-public class TagManagementTest extends AbstractIntegrationTest {
+public class TagManagementTest extends AbstractJpaIntegrationTest {
public TagManagementTest() {
LOG = LoggerFactory.getLogger(TagManagementTest.class);
}
@@ -59,20 +59,13 @@ public class TagManagementTest extends AbstractIntegrationTest {
@Test
@Description("Full DS tag lifecycle tested. Create tags, assign them to sets and delete the tags.")
public void createAndAssignAndDeleteDistributionSetTags() {
- final Collection dsAs = (Collection) TestDataUtil.generateDistributionSets("DS-A", 20,
- softwareManagement, distributionSetManagement);
- final Collection dsBs = (Collection) TestDataUtil.generateDistributionSets("DS-B", 10,
- softwareManagement, distributionSetManagement);
- final Collection dsCs = (Collection) TestDataUtil.generateDistributionSets("DS-C", 25,
- softwareManagement, distributionSetManagement);
- final Collection dsABs = (Collection) TestDataUtil.generateDistributionSets("DS-AB", 5,
- softwareManagement, distributionSetManagement);
- final Collection dsACs = (Collection) TestDataUtil.generateDistributionSets("DS-AC", 11,
- softwareManagement, distributionSetManagement);
- final Collection dsBCs = (Collection) TestDataUtil.generateDistributionSets("DS-BC", 13,
- softwareManagement, distributionSetManagement);
- final Collection dsABCs = (Collection) TestDataUtil.generateDistributionSets("DS-ABC", 9,
- softwareManagement, distributionSetManagement);
+ final Collection dsAs = testdataFactory.createDistributionSets("DS-A", 20);
+ final Collection dsBs = testdataFactory.createDistributionSets("DS-B", 10);
+ final Collection dsCs = testdataFactory.createDistributionSets("DS-C", 25);
+ final Collection dsABs = testdataFactory.createDistributionSets("DS-AB", 5);
+ final Collection dsACs = testdataFactory.createDistributionSets("DS-AC", 11);
+ final Collection dsBCs = testdataFactory.createDistributionSets("DS-BC", 13);
+ final Collection dsABCs = testdataFactory.createDistributionSets("DS-ABC", 9);
final DistributionSetTag tagA = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A"));
final DistributionSetTag tagB = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("B"));
@@ -169,10 +162,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
@Description("Verifies the toogle mechanism by means on assigning tag if at least on DS in the list does not have"
+ "the tag yet. Unassign if all of them have the tag already.")
public void assignAndUnassignDistributionSetTags() {
- final Collection groupA = (Collection) TestDataUtil.generateDistributionSets(20,
- softwareManagement, distributionSetManagement);
- final Collection groupB = (Collection) TestDataUtil.generateDistributionSets("unassigned", 20,
- softwareManagement, distributionSetManagement);
+ final Collection groupA = testdataFactory.createDistributionSets(20);
+ final Collection groupB = testdataFactory.createDistributionSets("unassigned", 20);
final DistributionSetTag tag = tagManagement
.createDistributionSetTag(new JpaDistributionSetTag("tag1", "tagdesc1", ""));
@@ -213,8 +204,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
@Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have"
+ "the tag yet. Unassign if all of them have the tag already.")
public void assignAndUnassignTargetTags() {
- final List groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, ""));
- final List groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb"));
+ final List groupA = targetManagement.createTargets(testdataFactory.generateTargets(20, ""));
+ final List groupB = targetManagement.createTargets(testdataFactory.generateTargets(20, "groupb"));
final TargetTag tag = tagManagement.createTargetTag(new JpaTargetTag("tag1", "tagdesc1", ""));
@@ -451,8 +442,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
}
private List createTargetsWithTags() {
- final List targets = targetManagement.createTargets(TestDataUtil.generateTargets(20));
- final Iterable tags = tagManagement.createTargetTags(TestDataUtil.generateTargetTags(20));
+ final List targets = testdataFactory.createTargets(20);
+ final Iterable tags = tagManagement.createTargetTags(testdataFactory.generateTargetTags(20));
tags.forEach(tag -> targetManagement.toggleTagAssignment(targets, tag));
@@ -461,10 +452,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
private List createDsSetsWithTags() {
- final Collection sets = (Collection) TestDataUtil.generateDistributionSets(20,
- softwareManagement, distributionSetManagement);
- final Iterable tags = tagManagement
- .createDistributionSetTags(TestDataUtil.generateDistributionSetTags(20));
+ final Collection sets = testdataFactory.createDistributionSets(20);
+ final Iterable tags = testdataFactory.createDistributionSetTags(20);
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java
index e2a06d5fc..07b92ebeb 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java
@@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("Target Filter Query Management")
-public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest {
+public class TargetFilterQueryManagenmentTest extends AbstractJpaIntegrationTest {
@Test
@Description("Test creation of target filter query.")
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java
index 7b128de3b..1e8f102c7 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java
@@ -44,7 +44,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Target Management Searches")
-public class TargetManagementSearchTest extends AbstractIntegrationTest {
+public class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests different parameter combinations for target search operations. "
@@ -56,32 +56,30 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
final TargetTag targTagZ = tagManagement.createTargetTag(new JpaTargetTag("TargTag-Z"));
final TargetTag targTagW = tagManagement.createTargetTag(new JpaTargetTag("TargTag-W"));
- final DistributionSet setA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ final DistributionSet setA = testdataFactory.createDistributionSet("");
- final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
- distributionSetManagement);
+ final DistributionSet installedSet = testdataFactory.createDistributionSet("another");
final String targetDsAIdPref = "targ-A";
List targAs = targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(100, targetDsAIdPref, targetDsAIdPref.concat(" description")));
+ testdataFactory.generateTargets(100, targetDsAIdPref, targetDsAIdPref.concat(" description")));
targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedEntity();
final String targetDsBIdPref = "targ-B";
List targBs = targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(100, targetDsBIdPref, targetDsBIdPref.concat(" description")));
+ testdataFactory.generateTargets(100, targetDsBIdPref, targetDsBIdPref.concat(" description")));
targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedEntity();
targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedEntity();
final String targetDsCIdPref = "targ-C";
List targCs = targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(100, targetDsCIdPref, targetDsCIdPref.concat(" description")));
+ testdataFactory.generateTargets(100, targetDsCIdPref, targetDsCIdPref.concat(" description")));
targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedEntity();
targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedEntity();
final String targetDsDIdPref = "targ-D";
final List targDs = targetManagement.createTargets(
- TestDataUtil.buildTargetFixtures(100, targetDsDIdPref, targetDsDIdPref.concat(" description")));
+ testdataFactory.generateTargets(100, targetDsDIdPref, targetDsDIdPref.concat(" description")));
final String assignedC = targCs.iterator().next().getControllerId();
deploymentManagement.assignDistributionSet(setA.getId(), assignedC);
@@ -680,14 +678,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
public void targetSearchWithVariousFilterCombinationsAndOrderByDistributionSet() {
final List notAssigned = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(3, "not", "first description"));
+ .createTargets(testdataFactory.generateTargets(3, "not", "first description"));
List targAssigned = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(3, "assigned", "first description"));
+ .createTargets(testdataFactory.generateTargets(3, "assigned", "first description"));
List targInstalled = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(3, "installed", "first description"));
+ .createTargets(testdataFactory.generateTargets(3, "installed", "first description"));
- final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("a");
targAssigned = deploymentManagement.assignDistributionSet(ds, targAssigned).getAssignedEntity();
targInstalled = deploymentManagement.assignDistributionSet(ds, targInstalled).getAssignedEntity();
@@ -714,10 +711,9 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
@Test
@Description("Verfies that targets with given assigned DS are returned from repository.")
public void findTargetByAssignedDistributionSet() {
- final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
- targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
- List assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
+ final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
+ targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned"));
+ List assignedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
deploymentManagement.assignDistributionSet(assignedSet, assignedtargets);
@@ -734,12 +730,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest {
@Test
@Description("Verfies that targets with given installed DS are returned from repository.")
public void findTargetByInstalledDistributionSet() {
- final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
- final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement,
- distributionSetManagement);
- targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned"));
- List installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
+ final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
+ final DistributionSet installedSet = testdataFactory.createDistributionSet("another");
+ targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned"));
+ List installedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
// set on installed and assign another one
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java
index 10f614caa..79a7ad89f 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java
@@ -43,6 +43,8 @@ import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetIdName;
import org.eclipse.hawkbit.repository.model.TargetTag;
+import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.junit.Test;
import org.springframework.data.domain.PageRequest;
@@ -54,7 +56,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Target Management")
-public class TargetManagementTest extends AbstractIntegrationTest {
+public class TargetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Ensures that retrieving the target security is only permitted with the necessary permissions.")
@@ -193,10 +195,8 @@ public class TargetManagementTest extends AbstractIntegrationTest {
@Test
@Description("Finds a target by given ID and checks if all data is in the reponse (including the data defined as lazy).")
public void findTargetByControllerIDWithDetails() {
- final DistributionSet set = TestDataUtil.generateDistributionSet("test", softwareManagement,
- distributionSetManagement);
- final DistributionSet set2 = TestDataUtil.generateDistributionSet("test2", softwareManagement,
- distributionSetManagement);
+ final DistributionSet set = testdataFactory.createDistributionSet("test");
+ final DistributionSet set2 = testdataFactory.createDistributionSet("test2");
assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong")
.isEqualTo(0);
@@ -248,7 +248,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
@Test
@Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.")
public void createMultipleTargetsDuplicate() {
- final List targets = TestDataUtil.buildTargetFixtures(5, "mySimpleTargs", "my simple targets");
+ final List targets = testdataFactory.generateTargets(5, "mySimpleTargs", "my simple targets");
targetManagement.createTargets(targets);
try {
targetManagement.createTargets(targets);
@@ -323,7 +323,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
public void singleTargetIsInsertedIntoRepo() throws Exception {
final String myCtrlID = "myCtrlID";
- final Target target = TestDataUtil.buildTargetFixture(myCtrlID, "the description!");
+ final Target target = testdataFactory.generateTarget(myCtrlID, "the description!");
Target savedTarget = targetManagement.createTarget(target);
assertNotNull("The target should not be null", savedTarget);
@@ -360,9 +360,9 @@ public class TargetManagementTest extends AbstractIntegrationTest {
@Description("Create multiple tragets as bulk operation and delete them in bulk.")
public void bulkTargetCreationAndDelete() throws Exception {
final String myCtrlID = "myCtrlID";
- final List firstList = TestDataUtil.buildTargetFixtures(100, myCtrlID, "first description");
+ final List firstList = testdataFactory.generateTargets(100, myCtrlID, "first description");
- final Target extra = TestDataUtil.buildTargetFixture("myCtrlID-00081XX", "first description");
+ final Target extra = testdataFactory.generateTarget("myCtrlID-00081XX", "first description");
List firstSaved = targetManagement.createTargets(firstList);
@@ -432,7 +432,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
@Description("Stores target attributes and verfies existence in the repository.")
public void savingTargetControllerAttributes() {
Iterable ts = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(100, "myCtrlID", "first description"));
+ .createTargets(testdataFactory.generateTargets(100, "myCtrlID", "first description"));
final Map attribs = new HashMap<>();
attribs.put("a.b.c", "abc");
@@ -541,17 +541,17 @@ public class TargetManagementTest extends AbstractIntegrationTest {
@Test
@Description("Tests the assigment of tags to the a single target.")
public void targetTagAssignment() {
- Target t1 = TestDataUtil.buildTargetFixture("id-1", "blablub");
+ Target t1 = testdataFactory.generateTarget("id-1", "blablub");
final int noT2Tags = 4;
final int noT1Tags = 3;
final List t1Tags = tagManagement
- .createTargetTags(TestDataUtil.buildTargetTagFixtures(noT1Tags, "tag1"));
+ .createTargetTags(testdataFactory.generateTargetTags(noT1Tags, "tag1"));
t1.getTags().addAll(t1Tags);
t1 = targetManagement.createTarget(t1);
- Target t2 = TestDataUtil.buildTargetFixture("id-2", "blablub");
+ Target t2 = testdataFactory.generateTarget("id-2", "blablub");
final List t2Tags = tagManagement
- .createTargetTags(TestDataUtil.buildTargetTagFixtures(noT2Tags, "tag2"));
+ .createTargetTags(testdataFactory.generateTargetTags(noT2Tags, "tag2"));
t2.getTags().addAll(t2Tags);
t2 = targetManagement.createTarget(t2);
@@ -570,17 +570,17 @@ public class TargetManagementTest extends AbstractIntegrationTest {
@Description("Tests the assigment of tags to multiple targets.")
public void targetTagBulkAssignments() {
final List tagATargets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(10, "tagATargets", "first description"));
+ .createTargets(testdataFactory.generateTargets(10, "tagATargets", "first description"));
final List tagBTargets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(10, "tagBTargets", "first description"));
+ .createTargets(testdataFactory.generateTargets(10, "tagBTargets", "first description"));
final List tagCTargets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(10, "tagCTargets", "first description"));
+ .createTargets(testdataFactory.generateTargets(10, "tagCTargets", "first description"));
final List tagABTargets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(10, "tagABTargets", "first description"));
+ .createTargets(testdataFactory.generateTargets(10, "tagABTargets", "first description"));
final List tagABCTargets = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(10, "tagABCTargets", "first description"));
+ .createTargets(testdataFactory.generateTargets(10, "tagABCTargets", "first description"));
final TargetTag tagA = tagManagement.createTargetTag(new JpaTargetTag("A"));
final TargetTag tagB = tagManagement.createTargetTag(new JpaTargetTag("B"));
@@ -645,20 +645,20 @@ public class TargetManagementTest extends AbstractIntegrationTest {
final TargetTag targTagC = tagManagement.createTargetTag(new JpaTargetTag("Targ-C-Tag"));
final List targAs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
+ .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
final List targBs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(20, "target-id-B", "first description"));
+ .createTargets(testdataFactory.generateTargets(20, "target-id-B", "first description"));
final List targCs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(15, "target-id-C", "first description"));
+ .createTargets(testdataFactory.generateTargets(15, "target-id-C", "first description"));
final List targABs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(12, "target-id-AB", "first description"));
+ .createTargets(testdataFactory.generateTargets(12, "target-id-AB", "first description"));
final List targACs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(13, "target-id-AC", "first description"));
+ .createTargets(testdataFactory.generateTargets(13, "target-id-AC", "first description"));
final List targBCs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(7, "target-id-BC", "first description"));
+ .createTargets(testdataFactory.generateTargets(7, "target-id-BC", "first description"));
final List targABCs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(17, "target-id-ABC", "first description"));
+ .createTargets(testdataFactory.generateTargets(17, "target-id-ABC", "first description"));
targetManagement.toggleTagAssignment(targAs, targTagA);
targetManagement.toggleTagAssignment(targABs, targTagA);
@@ -706,7 +706,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag"));
final List targAs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
+ .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
targetManagement.toggleTagAssignment(targAs, targTagA);
@@ -726,7 +726,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
@Description("Test the optimized quere for retrieving all ID/name pairs of targets.")
public void findAllTargetIdNamePaiss() {
final List targAs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
+ .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
final String[] createdTargetIds = targAs.stream().map(t -> t.getControllerId())
.toArray(size -> new String[size]);
@@ -743,10 +743,10 @@ public class TargetManagementTest extends AbstractIntegrationTest {
final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag"));
final List targAs = targetManagement
- .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
+ .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
targetManagement.toggleTagAssignment(targAs, targTagA);
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-B", "first description"));
+ targetManagement.createTargets(testdataFactory.generateTargets(25, "target-id-B", "first description"));
final String[] tagNames = null;
final List targetsListWithNoTag = targetManagement
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java
index 0e0d50bbc..73feda1c2 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java
@@ -29,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Tenant Configuration Management")
-public class TenantConfigurationManagementTest extends AbstractIntegrationTestWithMongoDB {
+public class TenantConfigurationManagementTest extends AbstractJpaIntegrationTestWithMongoDB {
@Test
@Description("Tests that tenant specific configuration can be persisted and in case the tenant does not have specific configuration the default from environment is used instead.")
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java
index 5339ceef2..8ea794f6a 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java
@@ -16,8 +16,8 @@ import org.eclipse.hawkbit.cache.CacheConstants;
import org.eclipse.hawkbit.cache.TenancyCacheManager;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
-import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator;
-import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil;
+import org.eclipse.hawkbit.repository.util.TestRepositoryManagement;
+import org.eclipse.hawkbit.repository.util.TestdataFactory;
import org.eclipse.hawkbit.security.DdiSecurityProperties;
import org.eclipse.hawkbit.security.SecurityContextTenantAware;
import org.eclipse.hawkbit.security.SpringSecurityAuditorAware;
@@ -52,14 +52,14 @@ import com.mongodb.MongoClientOptions;
@Profile("test")
public class TestConfiguration implements AsyncConfigurer {
- /**
- * DB cleanup utility bean is created.
- *
- * @return the {@link DatabaseCleanupUtil} bean
- */
@Bean
- public DatabaseCleanupUtil createDatabaseCleanupUtil() {
- return new RepositoryDataGenerator.DatabaseCleanupUtil();
+ public TestRepositoryManagement testRepositoryManagement() {
+ return new JpaTestRepositoryManagement();
+ }
+
+ @Bean
+ public TestdataFactory testdataFactory() {
+ return new TestdataFactory();
}
@Bean
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java
deleted file mode 100644
index 296fb98ea..000000000
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java
+++ /dev/null
@@ -1,435 +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 static org.fest.assertions.api.Assertions.assertThat;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Random;
-import java.util.UUID;
-
-import org.apache.commons.io.IOUtils;
-import org.eclipse.hawkbit.repository.ArtifactManagement;
-import org.eclipse.hawkbit.repository.ControllerManagement;
-import org.eclipse.hawkbit.repository.DistributionSetManagement;
-import org.eclipse.hawkbit.repository.SoftwareManagement;
-import org.eclipse.hawkbit.repository.TargetManagement;
-import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaArtifact;
-import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
-import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
-import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
-import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
-import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
-import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
-import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
-import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
-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.DistributionSet;
-import org.eclipse.hawkbit.repository.model.DistributionSetTag;
-import org.eclipse.hawkbit.repository.model.DistributionSetType;
-import org.eclipse.hawkbit.repository.model.SoftwareModule;
-import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
-import org.eclipse.hawkbit.repository.model.Target;
-import org.eclipse.hawkbit.repository.model.TargetTag;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-
-import net._01001111.text.LoremIpsum;
-
-/**
- * Data generator utility for tests.
- *
- *
- *
- */
-public class TestDataUtil {
- private static final LoremIpsum LOREM = new LoremIpsum();
-
- public static DistributionSet createTestDistributionSet(final SoftwareManagement softwareManagement,
- final DistributionSetManagement distributionSetManagement) {
- final Pageable pageReq = new PageRequest(0, 400);
- DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
- distributionSetManagement);
- set.setVersion("anotherVersion");
- set = distributionSetManagement.updateDistributionSet(set);
-
- set.getModules().forEach(module -> {
- module.setDescription("updated description");
- softwareManagement.updateSoftwareModule(module);
- });
-
- // load also lazy stuff
- set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
-
- assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)).hasSize(1);
- return set;
- }
-
- public static List sendUpdateActionStatusToTargets(final ControllerManagement controllerManagament,
- final TargetManagement targetManagement, final ActionRepository actionRepository, final DistributionSet dsA,
- final Iterable targs, final Status status, final String... msgs) {
- final List result = new ArrayList<>();
- for (final Target t : targs) {
- final List findByTarget = actionRepository.findByTarget((JpaTarget) t);
- for (final Action action : findByTarget) {
- result.add(sendUpdateActionStatusToTarget(controllerManagament, targetManagement, status, action, t,
- msgs));
- }
- }
- return result;
- }
-
- private static Target sendUpdateActionStatusToTarget(final ControllerManagement controllerManagament,
- final TargetManagement targetManagement, final Status status, final Action updActA, final Target t,
- final String... msgs) {
- updActA.setStatus(status);
-
- final ActionStatus statusMessages = new JpaActionStatus();
- statusMessages.setAction(updActA);
- statusMessages.setOccurredAt(System.currentTimeMillis());
- statusMessages.setStatus(status);
- for (final String msg : msgs) {
- statusMessages.addMessage(msg);
- }
- controllerManagament.addUpdateActionStatus(statusMessages);
- return targetManagement.findTargetByControllerID(t.getControllerId());
- }
-
- public static List generateDistributionSets(final String suffix, final int number,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
-
- final List sets = new ArrayList<>();
- for (int i = 0; i < number; i++) {
- sets.add(generateDistributionSet(suffix, "v1." + i, softwareManagement, distributionSetManagement, false));
- }
-
- return sets;
- }
-
- public static DistributionSet generateDistributionSetWithNoSoftwareModules(final String name, final String version,
- final DistributionSetManagement distributionSetManagement) {
-
- final DistributionSet dis = new JpaDistributionSet();
- dis.setName(name);
- dis.setVersion(version);
- dis.setDescription("Test describtion for " + name);
- return distributionSetManagement.createDistributionSet(dis);
- }
-
- public static List generateDistributionSets(final int number,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
-
- return generateDistributionSets("", number, softwareManagement, distributionSetManagement);
- }
-
- public static JpaDistributionSet generateDistributionSet(final String suffix, final String version,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
- final boolean isRequiredMigrationStep) {
-
- final SoftwareModule ah = softwareManagement.createSoftwareModule(new JpaSoftwareModule(
- findOrCreateSoftwareModuleType(softwareManagement, "application"), suffix + "application",
- version + "." + new Random().nextInt(100), LOREM.words(20), suffix + " vendor Limited, California"));
- final SoftwareModule jvm = softwareManagement.createSoftwareModule(
- new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "runtime"),
- suffix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20),
- suffix + " vendor GmbH, Stuttgart, Germany"));
- final SoftwareModule os = softwareManagement
- .createSoftwareModule(new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "os"),
- suffix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20),
- suffix + " vendor Limited Inc, California"));
-
- final List mand = new ArrayList<>();
- mand.add(findOrCreateSoftwareModuleType(softwareManagement, "os"));
-
- final List opt = new ArrayList<>();
- opt.add(findOrCreateSoftwareModuleType(softwareManagement, "application"));
- opt.add(findOrCreateSoftwareModuleType(softwareManagement, "runtime"));
-
- return (JpaDistributionSet) distributionSetManagement.createDistributionSet(
- buildDistributionSet(suffix != null && suffix.length() > 0 ? suffix : "DS", version,
- findOrCreateDistributionSetType(distributionSetManagement, "ecl_os_app_jvm",
- "OS mandatory App/JVM optional", mand, opt),
- os, jvm, ah).setRequiredMigrationStep(isRequiredMigrationStep));
- }
-
- public static DistributionSet generateDistributionSet(final String suffix, final String version,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
- final Collection tags) {
-
- final DistributionSet set = generateDistributionSet(suffix, version, softwareManagement,
- distributionSetManagement, false);
-
- final List sets = new ArrayList();
- sets.add(set);
-
- tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
-
- return distributionSetManagement.findDistributionSetById(set.getId());
-
- }
-
- public static List generateTargets(final int number) {
- return generateTargets(0, number, "Test target ");
- }
-
- public static List generateTargets(final int number, final String prefix) {
- return generateTargets(0, number, prefix);
- }
-
- public static List generateTargets(final int start, final int number, final String prefix) {
- final List targets = new ArrayList<>();
- for (int i = start; i < start + number; i++) {
- targets.add(new JpaTarget(prefix + i));
- }
-
- return targets;
- }
-
- public static List generateTargetTags(final int number) {
- final List result = new ArrayList<>();
-
- for (int i = 0; i < number; i++) {
- result.add(new JpaTargetTag("tag" + i, "tagdesc" + i, "" + i));
- }
-
- return result;
- }
-
- public static List generateDistributionSetTags(final int number) {
- final List result = new ArrayList<>();
-
- for (int i = 0; i < number; i++) {
- result.add(new JpaDistributionSetTag("tag" + i, "tagdesc" + i, "" + i));
- }
-
- return result;
- }
-
- public static JpaDistributionSet generateDistributionSet(final String suffix,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
- final boolean isRequiredMigrationStep) {
- return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement,
- isRequiredMigrationStep);
- }
-
- public static JpaDistributionSet generateDistributionSet(final String suffix,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
- return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, false);
- }
-
- public static List generateArtifacts(final ArtifactManagement artifactManagement,
- final Long moduleId) {
- final List artifacts = new ArrayList<>();
- for (int i = 0; i < 3; i++) {
- final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i);
- artifacts.add((AbstractJpaArtifact) artifactManagement.createLocalArtifact(stubInputStream, moduleId,
- "filename" + i, false));
-
- }
-
- return artifacts;
- }
-
- public static Target createTarget(final TargetManagement targetManagement) {
- final String targetExist = "targetExist";
- final Target target = new JpaTarget(targetExist);
- targetManagement.createTarget(target);
- return target;
- }
-
- public static DistributionSet generateDistributionSet(final String suffix,
- final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
- final Collection tags) {
- return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, tags);
- }
-
- public static SoftwareModuleType findOrCreateSoftwareModuleType(final SoftwareManagement softwareManagement,
- final String softwareModuleType) {
- final SoftwareModuleType findSoftwareModuleTypeByKey = softwareManagement
- .findSoftwareModuleTypeByKey(softwareModuleType);
- if (findSoftwareModuleTypeByKey != null) {
- return findSoftwareModuleTypeByKey;
- }
- return softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType(softwareModuleType,
- softwareModuleType, "Standard type " + softwareManagement, 1));
- }
-
- public static DistributionSetType findOrCreateDistributionSetType(
- final DistributionSetManagement distributionSetManagement, final String dsTypeKey, final String dsTypeName,
- final Collection mandatory, final Collection optional) {
- final DistributionSetType findDistributionSetTypeByname = distributionSetManagement
- .findDistributionSetTypeByKey(dsTypeKey);
-
- if (findDistributionSetTypeByname != null) {
- return findDistributionSetTypeByname;
- }
-
- final DistributionSetType type = new JpaDistributionSetType(dsTypeKey, dsTypeName,
- "Standard type" + dsTypeName);
- mandatory.forEach(entry -> type.addMandatoryModuleType(entry));
- optional.forEach(entry -> type.addOptionalModuleType(entry));
-
- return distributionSetManagement.createDistributionSetType(type);
- }
-
- /**
- * builds a set of {@link Target} fixtures from the given parameters.
- *
- * @param noOfTgts
- * number of targets to create
- * @param ctlrIDPrefix
- * prefix used for the controller ID
- * @param descriptionPrefix
- * prefix used for the description
- * @return set of {@link Target}
- */
- public static List buildTargetFixtures(final int noOfTgts, final String ctlrIDPrefix,
- final String descriptionPrefix) {
- return buildTargetFixtures(noOfTgts, ctlrIDPrefix, descriptionPrefix, null);
- }
-
- /**
- * method creates set of targets by by generating the controller ID and the
- * description like: prefix + no of target.
- *
- * @param noOfTgts
- * number of targets which should be created
- * @param ctlrIDPrefix
- * prefix of the controllerID which is concatenated with the
- * number of the target
- * @param descriptionPrefix
- * prefix of the target description which is concatenated with
- * the number of the target
- * @param tags
- * tags which should be added to the created {@link Target}s
- * @return set of created targets
- */
- public static List buildTargetFixtures(final int noOfTgts, final String ctlrIDPrefix,
- final String descriptionPrefix, final TargetTag[] tags) {
- final List list = new ArrayList();
- for (int i = 0; i < noOfTgts; i++) {
- String ctrlID = ctlrIDPrefix;
- if (Strings.isNullOrEmpty(ctrlID)) {
- ctrlID = UUID.randomUUID().toString();
- }
- ctrlID = String.format("%s-%05d", ctrlID, i);
-
- final String description = String.format("the description of ProvisioningTarget: [%s]", ctrlID);
-
- final Target target = buildTargetFixture(ctrlID, description, tags);
- list.add(target);
-
- }
- return list;
- }
-
- /**
- * builds a single {@link Target} fixture from the given parameters.
- *
- * @param ctrlID
- * controllerID
- * @param description
- * the description of the target
- * @param tags
- * assigned {@link TargetTag}s
- * @return the created {@link Target}
- */
- public static Target buildTargetFixture(final String ctrlID, final String description, final TargetTag[] tags) {
- final Target target = new JpaTarget(ctrlID);
- target.setName("Prov.Target ".concat(ctrlID));
- target.setDescription(description);
- if (tags != null && tags.length > 0) {
- for (final TargetTag t : tags) {
- target.getTags().add(t);
- }
- }
- return target;
- }
-
- /**
- * builder method for creating a single target object.
- *
- * @param ctrlID
- * the ID of the target
- * @param description
- * of the target
- * @return the created target object
- */
- public static Target buildTargetFixture(final String ctrlID, final String description) {
- return buildTargetFixture(ctrlID, description, null);
- }
-
- /**
- * builder method for creating a {@link DistributionSet}.
- *
- * @param name
- * of the DS
- * @param version
- * of the DS
- * @param os
- * operating system of the DS
- * @param jvm
- * java virtual machine of the DS
- * @param agentHub
- * of the DS
- * @return the created {@link DistributionSet}
- */
- public static DistributionSet buildDistributionSet(final String name, final String version,
- final DistributionSetType type, final SoftwareModule os, final SoftwareModule jvm,
- final SoftwareModule agentHub) {
- final DistributionSet distributionSet = new JpaDistributionSet(name, version, null, type,
- Lists.newArrayList(os, jvm, agentHub));
- distributionSet.setDescription(
- String.format("description of DistributionSet; name = '%s', version = '%s'", name, version));
- return distributionSet;
- }
-
- /**
- * builder method for creating a set of {@link TargetTag}.
- *
- * @param noOfTags
- * number of {@link TargetTag}. to be created
- * @param tagPrefix
- * prefix for the {@link TargetTag.getName()}
- * @return the created set of {@link TargetTag}s
- */
- public static List buildTargetTagFixtures(final int noOfTags, final String tagPrefix) {
- final List list = new ArrayList<>();
- for (int i = 0; i < noOfTags; i++) {
- String tagName = "myTag";
- if (!Strings.isNullOrEmpty(tagPrefix)) {
- tagName = tagPrefix;
- }
- tagName = String.format("%s-%05d", tagName, i);
-
- final TargetTag targetTag = buildTargetTagFixture(tagName);
- list.add(targetTag);
- }
- return list;
- }
-
- /**
- * builder method for creating a simple {@link TargetTag}.
- *
- * @param tagName
- * name of the Tag
- * @return the {@link TargetTag}
- */
- public static TargetTag buildTargetTagFixture(final String tagName) {
- return new JpaTargetTag(tagName);
- }
-}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java
index 2114afc42..9f4cefa5d 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java
@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
import static org.fest.assertions.api.Assertions.assertThat;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.junit.Test;
@@ -20,7 +20,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Unit Tests - Repository")
@Stories("Repository Model")
-public class ModelEqualsHashcodeTest extends AbstractIntegrationTest {
+public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verfies that different objects even with identical primary key, version and tenant "
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java
index 949e278ab..3138c9f86 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java
@@ -13,7 +13,7 @@ import static org.junit.Assert.fail;
import org.eclipse.hawkbit.repository.ActionFields;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.Action;
@@ -30,7 +30,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter actions")
-public class RSQLActionFieldsTest extends AbstractIntegrationTest {
+public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
private Target target;
private JpaAction action;
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java
index 2c3747586..6604e3152 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java
@@ -15,12 +15,12 @@ import java.util.Arrays;
import org.eclipse.hawkbit.repository.DistributionSetFields;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
+import org.eclipse.hawkbit.repository.util.TestdataFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.Page;
@@ -32,19 +32,18 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter distribution set")
-public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
+public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
@Before
public void seuptBeforeTest() {
- DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement, distributionSetManagement);
+ DistributionSet ds = testdataFactory.createDistributionSet("DS");
ds.setDescription("DS");
ds = distributionSetManagement.updateDistributionSet(ds);
distributionSetManagement
.createDistributionSetMetadata(new JpaDistributionSetMetadata("metaKey", ds, "metaValue"));
- DistributionSet ds2 = TestDataUtil
- .generateDistributionSets("NewDS", 3, softwareManagement, distributionSetManagement).get(0);
+ DistributionSet ds2 = testdataFactory.createDistributionSets("NewDS", 3).get(0);
ds2.setDescription("DS%");
ds2 = distributionSetManagement.updateDistributionSet(ds2);
@@ -89,10 +88,12 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
@Test
@Description("Test filter distribution set by version")
public void testFilterByParameterVersion() {
- assertRSQLQuery(DistributionSetFields.VERSION.name() + "==v1.0", 2);
- assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=v1.0", 2);
- assertRSQLQuery(DistributionSetFields.VERSION.name() + "=in=(v1.0,v1.1)", 3);
- assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(v1.0,error)", 2);
+ assertRSQLQuery(DistributionSetFields.VERSION.name() + "==" + TestdataFactory.DEFAULT_VERSION, 1);
+ assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=" + TestdataFactory.DEFAULT_VERSION, 3);
+ assertRSQLQuery(
+ DistributionSetFields.VERSION.name() + "=in=(" + TestdataFactory.DEFAULT_VERSION + ",1.0.0,1.0.1)", 3);
+ assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(" + TestdataFactory.DEFAULT_VERSION + ",error)",
+ 3);
}
@Test
@@ -121,10 +122,10 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
@Test
@Description("Test filter distribution set by type")
public void testFilterByType() {
- assertRSQLQuery(DistributionSetFields.TYPE.name() + "==ecl_os_app_jvm", 4);
+ assertRSQLQuery(DistributionSetFields.TYPE.name() + "==" + TestdataFactory.DS_TYPE_DEFAULT, 4);
assertRSQLQuery(DistributionSetFields.TYPE.name() + "==noExist*", 0);
- assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(ecl_os_app_jvm,ecl)", 4);
- assertRSQLQuery(DistributionSetFields.TYPE.name() + "=out=(ecl_os_app_jvm)", 0);
+ assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(" + TestdataFactory.DS_TYPE_DEFAULT + ",ecl)", 4);
+ assertRSQLQuery(DistributionSetFields.TYPE.name() + "=out=(" + TestdataFactory.DS_TYPE_DEFAULT + ")", 0);
}
@Test
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java
index af96da86f..65b677693 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java
@@ -14,8 +14,7 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.repository.DistributionSetMetadataFields;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
@@ -30,14 +29,13 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter distribution set metadata")
-public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTest {
+public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegrationTest {
private Long distributionSetId;
@Before
public void setupBeforeTest() {
- final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("DS", softwareManagement,
- distributionSetManagement);
+ final DistributionSet distributionSet = testdataFactory.createDistributionSet("DS");
distributionSetId = distributionSet.getId();
final List metadata = new ArrayList<>();
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java
index 408c1847e..fd48aed94 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java
@@ -11,8 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.RolloutGroupFields;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Rollout;
@@ -30,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter rollout group")
-public class RSQLRolloutGroupFields extends AbstractIntegrationTest {
+public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
private Long rolloutGroupId;
private Rollout rollout;
@@ -38,9 +37,8 @@ public class RSQLRolloutGroupFields extends AbstractIntegrationTest {
@Before
public void seuptBeforeTest() {
final int amountTargets = 20;
- targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout"));
- final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
- distributionSetManagement);
+ targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout"));
+ final DistributionSet dsA = testdataFactory.createDistributionSet("");
rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
rollout = rolloutManagement.findRolloutById(rollout.getId());
this.rolloutGroupId = rollout.getRolloutGroups().get(0).getId();
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java
index 6fb220880..d55de383f 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter software module")
-public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest {
+public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
@Before
public void setupBeforeTest() {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java
index 87f151873..3f843bffc 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java
@@ -14,12 +14,11 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
+import org.eclipse.hawkbit.repository.util.TestdataFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.Page;
@@ -31,15 +30,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter software module metadata")
-public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTest {
+public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegrationTest {
private Long softwareModuleId;
@Before
public void setupBeforeTest() {
- final SoftwareModule softwareModule = softwareManagement.createSoftwareModule(
- new JpaSoftwareModule(TestDataUtil.findOrCreateSoftwareModuleType(softwareManagement, "application"),
- "application", "1.0.0", "Desc", "vendor Limited, California"));
+ final SoftwareModule softwareModule = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
+
softwareModuleId = softwareModule.getId();
final List metadata = new ArrayList<>();
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java
index 3254ee4f6..e1538aaee 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.junit.Test;
import org.springframework.data.domain.Page;
@@ -23,7 +23,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter software module test type")
-public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest {
+public class RSQLSoftwareModuleTypeFieldsTest extends AbstractJpaIntegrationTest {
@Test
@Description("Test filter software module test type by id")
@@ -34,7 +34,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest {
@Test
@Description("Test filter software module test type by name")
public void testFilterByParameterName() {
- assertRSQLQuery(SoftwareModuleTypeFields.NAME.name() + "==ECL*", 3);
+ assertRSQLQuery(SoftwareModuleTypeFields.NAME.name() + "==Firmware", 1);
}
@Test
@@ -55,7 +55,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest {
@Test
@Description("Test filter software module test type by max")
public void testFilterByMaxAssignment() {
- assertRSQLQuery(SoftwareModuleTypeFields.MAXASSIGNMENTS.name() + "==1", 3);
+ assertRSQLQuery(SoftwareModuleTypeFields.MAXASSIGNMENTS.name() + "==1", 2);
}
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java
index a60d17818..3772bb372 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
import static org.fest.assertions.api.Assertions.assertThat;
import org.eclipse.hawkbit.repository.TagFields;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
@@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter target and distribution set tags")
-public class RSQLTagFieldsTest extends AbstractIntegrationTest {
+public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest {
@Before
public void seuptBeforeTest() {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java
index 2e4f0346f..f21e4c938 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java
@@ -15,8 +15,7 @@ import java.util.Arrays;
import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
@@ -25,6 +24,7 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
+import org.eclipse.hawkbit.repository.util.TestdataFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.Page;
@@ -36,19 +36,17 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("RSQL filter target")
-public class RSQLTargetFieldTest extends AbstractIntegrationTest {
+public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
@Before
public void seuptBeforeTest() {
- final DistributionSet ds = TestDataUtil.generateDistributionSet("AssignedDs", softwareManagement,
- distributionSetManagement);
+ final DistributionSet ds = testdataFactory.createDistributionSet("AssignedDs");
- final JpaTarget target = new JpaTarget("targetId123");
+ final Target target = entityFactory.generateTarget("targetId123");
target.setDescription("targetId123");
- final TargetInfo targetInfo = new JpaTargetInfo(target);
+ final TargetInfo targetInfo = target.getTargetInfo();
targetInfo.getControllerAttributes().put("revision", "1.1");
- target.setTargetInfo(targetInfo);
((JpaTargetInfo) target.getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING);
targetManagement.createTarget(target);
@@ -149,11 +147,13 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest {
@Test
@Description("Test filter target by assigned ds version")
public void testFilterByAssignedDsVersion() {
- assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==v1.0", 1);
+ assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==" + TestdataFactory.DEFAULT_VERSION, 1);
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==*1*", 1);
assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==noExist*", 0);
- assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=in=(v1.0,notexist)", 1);
- assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=out=(v1.0,notexist)", 0);
+ assertRSQLQuery(
+ TargetFields.ASSIGNEDDS.name() + ".version=in=(" + TestdataFactory.DEFAULT_VERSION + ",notexist)", 1);
+ assertRSQLQuery(
+ TargetFields.ASSIGNEDDS.name() + ".version=out=(" + TestdataFactory.DEFAULT_VERSION + ",notexist)", 0);
}
@Test
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java
index 1c0beeabf..86a0389d5 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java
@@ -10,14 +10,14 @@ package org.eclipse.hawkbit.repository.jpa.tenancy;
import static org.fest.assertions.api.Assertions.assertThat;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
-import org.eclipse.hawkbit.repository.jpa.WithSpringAuthorityRule;
-import org.eclipse.hawkbit.repository.jpa.WithUser;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule;
+import org.eclipse.hawkbit.repository.util.WithUser;
import org.junit.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Slice;
@@ -34,7 +34,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
*/
@Features("Component Tests - Repository")
@Stories("Multi Tenancy")
-public class MultiTenancyEntityTest extends AbstractIntegrationTest {
+public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
@Test
@Description(value = "Ensures that multiple targets with same controller-ID can be created for different tenants.")
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java
deleted file mode 100644
index 9d41ecb65..000000000
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java
+++ /dev/null
@@ -1,485 +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.utils;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Random;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.stream.IntStream;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import javax.transaction.Transactional;
-
-import org.eclipse.hawkbit.im.authentication.SpPermission;
-import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
-import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
-import org.eclipse.hawkbit.repository.ControllerManagement;
-import org.eclipse.hawkbit.repository.DeploymentManagement;
-import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
-import org.eclipse.hawkbit.repository.DistributionSetManagement;
-import org.eclipse.hawkbit.repository.SoftwareManagement;
-import org.eclipse.hawkbit.repository.TagManagement;
-import org.eclipse.hawkbit.repository.TargetManagement;
-import org.eclipse.hawkbit.repository.jpa.TestDataUtil;
-import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
-import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
-import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
-import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
-import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
-import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
-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.DistributionSet;
-import org.eclipse.hawkbit.repository.model.DistributionSetTag;
-import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
-import org.eclipse.hawkbit.repository.model.Target;
-import org.eclipse.hawkbit.repository.model.TargetTag;
-import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
-import org.eclipse.hawkbit.util.IpUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.data.auditing.AuditingHandler;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.security.authentication.TestingAuthenticationToken;
-import org.springframework.security.core.context.SecurityContext;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.context.SecurityContextImpl;
-
-import net._01001111.text.LoremIpsum;
-
-/**
- * Generates test data for setting up the repository for test or demonstration
- * purpose.
- *
- *
- *
- */
-public final class RepositoryDataGenerator {
- private static final Logger LOG = LoggerFactory.getLogger(RepositoryDataGenerator.class);
-
- public static void initDemoRepo(final ConfigurableApplicationContext context) {
- final PersistentInitDemoDataBuilder initDemoDataBuilder = new PersistentInitDemoDataBuilder(context);
- initDemoDataBuilder.initDemoRepo(20, 0);
- }
-
- public static void initLoadRepo(final ConfigurableApplicationContext context) {
- final PersistentInitDemoDataBuilder initDemoDataBuilder = new PersistentInitDemoDataBuilder(context);
- initDemoDataBuilder.initDemoRepo(200, 200);
- }
-
- /**
- * builder which build initial demo data and stores it to the repos.
- *
- */
- private static final class PersistentInitDemoDataBuilder {
-
- private final SoftwareManagement softwareManagement;
- private final TargetManagement targetManagement;
- private final DeploymentManagement deploymentManagement;
- private final TagManagement tagManagement;
- private final ControllerManagement controllerManagement;
- private final DistributionSetManagement distributionSetManagement;
-
- private final DatabaseCleanupUtil dbCleanupUtil;
-
- private final AuditingHandler auditingHandler;
-
- final LoremIpsum jlorem = new LoremIpsum();
-
- PersistentInitDemoDataBuilder(final ConfigurableApplicationContext context) {
- softwareManagement = context.getBean(SoftwareManagement.class);
- targetManagement = context.getBean(TargetManagement.class);
- tagManagement = context.getBean(TagManagement.class);
- deploymentManagement = context.getBean(DeploymentManagement.class);
- controllerManagement = context.getBean(ControllerManagement.class);
- distributionSetManagement = context.getBean(DistributionSetManagement.class);
-
- dbCleanupUtil = context.getBean(DatabaseCleanupUtil.class);
-
- auditingHandler = context.getBean(AuditingHandler.class);
- }
-
- private void runAsAllAuthorityContext(final Runnable runnable) {
- final SecurityContext oldContext = SecurityContextHolder.getContext();
- try {
- final SecurityContextImpl securityContextImpl = new SecurityContextImpl();
- final TestingAuthenticationToken authentication = new TestingAuthenticationToken("repogenator",
- "repogenator", SpPermission.CREATE_REPOSITORY, SpPermission.CREATE_TARGET,
- SpPermission.DELETE_REPOSITORY, SpPermission.DELETE_TARGET, SpPermission.READ_REPOSITORY,
- SpPermission.READ_TARGET, SpPermission.UPDATE_REPOSITORY, SpPermission.UPDATE_TARGET,
- SpringEvalExpressions.CONTROLLER_ROLE);
- securityContextImpl.setAuthentication(authentication);
- authentication.setDetails(new TenantAwareAuthenticationDetails("default", false));
- SecurityContextHolder.setContext(securityContextImpl);
- runnable.run();
- } finally {
- SecurityContextHolder.setContext(oldContext);
- }
- }
-
- public void generateTestTagetGroup(final String group, final int sizeMultiplikator) {
- final DistributionSetTag dsTag = tagManagement
- .createDistributionSetTag(new JpaDistributionSetTag("For " + group + "s"));
-
- auditingHandler.setDateTimeProvider(() -> {
- final Calendar instance = Calendar.getInstance();
- instance.add(Calendar.MONTH, -new Random().nextInt(7));
-
- return instance;
- });
-
- final List targets = createTargetTestGroup(group, 20 * sizeMultiplikator);
-
- auditingHandler.setDateTimeProvider(() -> {
- final Calendar instance = Calendar.getInstance();
- return instance;
- });
-
- LOG.debug("initDemoRepo - start now real action history for group: {}", group);
-
- // Old history of succesfully finished operations
- IntStream.range(0, 10).forEach(idx -> {
- final DistributionSet dsReal = TestDataUtil.generateDistributionSet(group + " Release", "v1." + idx,
- softwareManagement, distributionSetManagement,
- Arrays.asList(new DistributionSetTag[] { dsTag }));
-
- final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(dsReal,
- targets);
-
- createSimpleActionStatusHistory(result.getActions());
- });
-
- final List> targetGroups = splitIntoGroups(targets);
-
- IntStream.range(0, targetGroups.size()).forEach(idx -> {
- final DistributionSet dsReal = TestDataUtil.generateDistributionSet(group + " Release", "v2." + idx,
- softwareManagement, distributionSetManagement,
- Arrays.asList(new DistributionSetTag[] { dsTag }));
-
- final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(dsReal,
- targetGroups.get(idx));
-
- createActionStatusHistory(result.getActions(), sizeMultiplikator);
- });
-
- LOG.debug("initDemoRepo - real action history finished for group: {}", group);
- }
-
- private List> splitIntoGroups(final List allTargets) {
-
- final int elements = allTargets.size();
-
- final int group1 = elements * (5 + new Random().nextInt(5)) / 100;
- final int group2 = elements * (15 + new Random().nextInt(5)) / 100;
-
- final List> result = new ArrayList>();
-
- result.add(allTargets.subList(0, group1));
- result.add(allTargets.subList(group1, group2));
- result.add(allTargets.subList(group2, elements));
-
- return result;
-
- }
-
- private void createActionStatusHistory(final List actions, final int sizeMultiplikator) {
- final AtomicInteger counter = new AtomicInteger();
-
- int index = 0;
- for (final Long actionGiven : actions) {
- // retrieved
- Action action = controllerManagement.registerRetrieved(
- deploymentManagement.findActionWithDetails(actionGiven),
- "Controller retrieved update action and should start now the download.");
-
- // download
- final ActionStatus download = new JpaActionStatus();
- download.setAction(action);
- download.setStatus(Status.DOWNLOAD);
- download.addMessage("Controller started download.");
- action = controllerManagement.addUpdateActionStatus(download);
-
- // warning
- final ActionStatus warning = new JpaActionStatus();
- warning.setAction(action);
- warning.setStatus(Status.WARNING);
- warning.addMessage("Some warning: " + jlorem.words(new Random().nextInt(50)));
- action = controllerManagement.addUpdateActionStatus(warning);
-
- // garbage
- for (int i = 0; i < new Random().nextInt(10); i++) {
- final ActionStatus running = new JpaActionStatus();
- running.setAction(action);
- running.setStatus(Status.RUNNING);
- running.addMessage("Still running: " + jlorem.words(new Random().nextInt(50)));
- action = controllerManagement.addUpdateActionStatus(running);
- for (int g = 0; g < new Random().nextInt(5); g++) {
- final ActionStatus rand = new JpaActionStatus();
- rand.setAction(action);
- rand.setStatus(Status.RUNNING);
- rand.addMessage(jlorem.words(new Random().nextInt(50)));
- action = controllerManagement.addUpdateActionStatus(rand);
- }
- }
-
- // close
- final ActionStatus close = new JpaActionStatus();
- close.setAction(action);
-
- // with error
- final int incrementAndGet = counter.incrementAndGet();
- if (incrementAndGet % 5 == 0) {
- close.setStatus(Status.ERROR);
- close.addMessage("Controller reported CLOSED with ERROR!");
- action = controllerManagement.addUpdateActionStatus(close);
- }
- // with OK
- else {
- close.setStatus(Status.FINISHED);
- close.addMessage("Controller reported CLOSED with OK!");
- action = controllerManagement.addUpdateActionStatus(close);
- }
-
- index++;
- }
- }
-
- private void createSimpleActionStatusHistory(final List actions) {
- for (final Long actionGiven : actions) {
- // retrieved
- Action action = controllerManagement.registerRetrieved(
- deploymentManagement.findActionWithDetails(actionGiven),
- "Controller retrieved update action and should start now the download.");
-
- // close
- final ActionStatus close = new JpaActionStatus();
- close.setAction(action);
- close.setStatus(Status.FINISHED);
- close.addMessage("Controller reported CLOSED with OK!");
- action = controllerManagement.addUpdateActionStatus(close);
-
- }
- }
-
- private List createTargetTestGroup(final String group, final int targets) {
- LOG.debug("createTargetTestGroup: create group {}", group);
-
- final TargetTag targTag = tagManagement.createTargetTag(new JpaTargetTag(group));
-
- final List targAs = targetManagement.createTargets(buildTargets(targets, group),
- TargetUpdateStatus.REGISTERED, System.currentTimeMillis() - new Random().nextInt(50_000_000),
- generateIPAddress());
- LOG.debug("createTargetTestGroup: {} created", group);
-
- LOG.debug("createTargetTestGroup: {} targets status updated including IP", group);
-
- return targetManagement.toggleTagAssignment(targAs, targTag).getAssignedEntity();
- }
-
- private List buildTargets(final int noOfTgts, final String descriptionPrefix) {
-
- final List result = new ArrayList(noOfTgts);
-
- for (int i = 0; i < noOfTgts; i++) {
- final Target target = new JpaTarget(UUID.randomUUID().toString());
-
- final StringBuilder builder = new StringBuilder();
- builder.append(descriptionPrefix);
- builder.append(jlorem.words(5));
-
- target.setDescription(builder.toString());
- target.getTargetInfo().getControllerAttributes().put("revision", "1.1");
- target.getTargetInfo().getControllerAttributes().put("capacity", "128M");
- target.getTargetInfo().getControllerAttributes().put("serial",
- String.valueOf(System.currentTimeMillis()));
-
- result.add(target);
-
- }
-
- return result;
- }
-
- /**
- * method writes initial test/demo data to the repositories.
- *
- * @param sizeMultiplikator
- * the entire scenario
- * @param loadtestgroups
- * packages of 1_000 targets
- */
- private void initDemoRepo(final int sizeMultiplikator, final int loadtestgroups) {
- final LoremIpsum jlorem = new LoremIpsum();
-
- runAsAllAuthorityContext(() -> {
- dbCleanupUtil.cleanupDB(null);
-
- // generate targets and assign DS
- // 5 groups - 100 targets each -> 500
- final String[] targetTestGroups = { "SHC", "CCU", "Vehicle", "Vending machine", "ECU" };
-
- final String[] modulesTypes = { "HeadUnit_FW", "EDC17_FW", "OSGi_Bundle" };
-
- final DistributionSetTag depTag = tagManagement
- .createDistributionSetTag(new JpaDistributionSetTag("deprecated"));
-
- Arrays.stream(targetTestGroups).forEach(group -> {
- generateTestTagetGroup(group, sizeMultiplikator);
- });
-
- // garbage DS
- LOG.debug("initDemoRepo - start now DS garbage");
- TestDataUtil.generateDistributionSets("Generic Software Package", sizeMultiplikator, softwareManagement,
- distributionSetManagement);
- LOG.debug("initDemoRepo - DS garbage finished");
-
- LOG.debug("initDemoRepo - start now Extra Software Modules and types");
- Arrays.stream(modulesTypes).forEach(typeName -> {
- final SoftwareModuleType smtype = softwareManagement.createSoftwareModuleType(
- new JpaSoftwareModuleType(typeName.toLowerCase().replaceAll("\\s+", ""), typeName,
- jlorem.words(5), Integer.MAX_VALUE));
-
- for (int i1 = 0; i1 < sizeMultiplikator; i1++) {
- softwareManagement.createSoftwareModule(new JpaSoftwareModule(smtype, typeName + i1, "1.0." + i1,
- jlorem.words(5), "the " + typeName + " vendor Inc."));
- }
-
- });
- LOG.debug("initDemoRepo - Extra Software Modules and types finished");
-
- LOG.debug("initDemoRepo - start now target garbage");
-
- // garbage targets
- // unknown
- targetManagement
- .createTargets(TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator));
-
- // registered
- targetManagement.createTargets(
- TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "registered"),
- TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), generateIPAddress());
-
- // pending
- final DistributionSetTag dsTag = tagManagement
- .createDistributionSetTag(new JpaDistributionSetTag("OnlyAssignedTag"));
- final DistributionSet ds = TestDataUtil.generateDistributionSet("Pending DS", "v1.0",
- softwareManagement, distributionSetManagement,
- Arrays.asList(new DistributionSetTag[] { dsTag }));
- deploymentManagement.assignDistributionSet(ds, targetManagement.createTargets(
- TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "pending")));
-
- // Load test means additional 1_000_000 target
-
- for (int i2 = 0; i2 < loadtestgroups; i2++) {
- targetManagement.createTargets(TestDataUtil.generateTargets(i2 * 1_000, 1_000, "loadtest-"));
- }
-
- LOG.debug("initDemoRepo complete");
- });
- }
- /**
- * Adding controller attributes for given {@link Target}.
- */
- // private Target setControllerAttributes( final String targetId ) {
- // final Target target =
- // targetManagement.findTargetByControllerIDWithDetails( targetId );
- // target.getTargetStatus().getControllerAttributes().put( "revision",
- // "1.1" );
- // target.getTargetStatus().getControllerAttributes().put( "capacity",
- // "128M" );
- // target.getTargetStatus().getControllerAttributes().put( "serial",
- // String.valueOf(
- // System.currentTimeMillis()) );
- // return targetManagement.updateTarget( target );
- // }
- }
-
- /**
- *
- * Data clean up class.
- *
- *
- *
- */
- public static class DatabaseCleanupUtil {
-
- private static final Logger LOG = LoggerFactory.getLogger(DatabaseCleanupUtil.class);
- @Autowired
- private EntityManager entityManager;
-
- private static final String[] CLEAN_UP_SQLS = new String[] { "sp_tenant", "sp_tenant_configuration",
- "sp_artifact", "sp_external_artifact", "sp_external_provider", "sp_target_target_tag",
- "sp_target_attributes", "sp_target_tag", "sp_action_status_messages", "sp_action_status", "sp_action",
- "sp_ds_dstag", "sp_distributionset_tag", "sp_target_info", "sp_target", "sp_sw_metadata",
- "sp_ds_metadata", "sp_ds_module", "sp_distribution_set", "sp_base_software_module",
- "sp_ds_type_element", "sp_distribution_set_type", "sp_software_module_type" };
-
- /**
- * delete all entries from the DB tables.
- */
- @Transactional
- @Modifying
- public void cleanupDB(final String database) {
- LOG.debug("Data clean up is started...");
- final boolean isMySql = "MYSQL".equals(database);
- if (isMySql) {
- // disable foreign key check because otherwise mysql cannot
- // delete sp_active_actions due
- // the self constraint within the table, stupid MySql
- entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 0").executeUpdate();
- }
- try {
- final String[] dbCmds = new String[] { "delete from" };
- for (final String dbCmd : dbCmds) {
- for (final String table : CLEAN_UP_SQLS) {
- final String sql = String.format("%s %s", dbCmd, table);
- final Query query = entityManager.createNativeQuery(sql);
- try {
- LOG.debug("cleanup table: {}", sql);
- LOG.debug("cleaned table: {}; deleted {} records", sql, query.executeUpdate());
- } catch (final Exception ex) {
- LOG.error(String.format("error on executing cleanup statement '%s'", sql), ex);
- throw ex;
- }
- }
- }
-
- LOG.debug("Data clean up is finished...");
- } finally {
- if (isMySql) {
- // enable foreign key check again!
- entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate();
- }
- }
- }
- }
-
- /**
- * @return a generated IPv4 address string.
- */
- private static URI generateIPAddress() {
- final Random r = new Random();
- return IpUtil
- .createHttpUri(r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256));
- }
-
- private RepositoryDataGenerator() {
- super();
- }
-
-}
diff --git a/hawkbit-repository/hawkbit-repository-test/pom.xml b/hawkbit-repository/hawkbit-repository-test/pom.xml
new file mode 100644
index 000000000..6b421c8ab
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-test/pom.xml
@@ -0,0 +1,59 @@
+
+
+ 4.0.0
+
+ org.eclipse.hawkbit
+ hawkbit-repository
+ 0.2.0-SNAPSHOT
+
+ hawkbit-repository-test
+ hawkBit :: Repository Test Utilities
+
+
+
+ org.eclipse.hawkbit
+ hawkbit-repository-api
+ ${project.version}
+
+
+ org.eclipse.hawkbit
+ hawkbit-repository-core
+ ${project.version}
+
+
+ org.eclipse.hawkbit
+ hawkbit-artifact-repository-mongo
+ ${project.version}
+
+
+ de.flapdoodle.embed
+ de.flapdoodle.embed.mongo
+
+
+ net._01001111
+ jlorem
+
+
+ commons-io
+ commons-io
+ 2.5
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+
+
+ org.springframework.security
+ spring-security-config
+
+
+
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java
similarity index 51%
rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java
rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java
index a1eff3fae..29bf02fa0 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java
@@ -6,22 +6,15 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
-package org.eclipse.hawkbit.repository.jpa;
-
-import static org.fest.assertions.api.Assertions.assertThat;
-
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
+package org.eclipse.hawkbit.repository.util;
import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter;
-import org.eclipse.hawkbit.RepositoryApplicationConfiguration;
-import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.ArtifactManagement;
+import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
@@ -30,32 +23,13 @@ import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
-import org.eclipse.hawkbit.repository.jpa.ActionRepository;
-import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository;
-import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository;
-import org.eclipse.hawkbit.repository.jpa.DistributionSetTagRepository;
-import org.eclipse.hawkbit.repository.jpa.DistributionSetTypeRepository;
-import org.eclipse.hawkbit.repository.jpa.ExternalArtifactRepository;
-import org.eclipse.hawkbit.repository.jpa.LocalArtifactRepository;
-import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository;
-import org.eclipse.hawkbit.repository.jpa.RolloutRepository;
-import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository;
-import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository;
-import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository;
-import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository;
-import org.eclipse.hawkbit.repository.jpa.TargetRepository;
-import org.eclipse.hawkbit.repository.jpa.TargetTagRepository;
-import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository;
-import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
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;
@@ -63,13 +37,11 @@ import org.junit.runner.RunWith;
import org.junit.runners.model.FrameworkMethod;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.data.auditing.AuditingHandler;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
-import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ActiveProfiles;
@@ -78,12 +50,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class })
@ActiveProfiles({ "test" })
@WithUser(principal = "bumlux", allSpPermissions = true, authorities = "ROLE_CONTROLLER")
// destroy the context after each test class because otherwise we get problem
@@ -96,44 +66,16 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
protected static final Pageable pageReq = new PageRequest(0, 400);
- @PersistenceContext
- protected EntityManager entityManager;
+ /**
+ * Number of {@link DistributionSetType}s that exist in every test case. One
+ * generated by using
+ * {@link TestdataFactory#findOrCreateDefaultTestDsType()} and two
+ * {@link SystemManagement#getTenantMetadata()};
+ */
+ protected static final int DEFAULT_DS_TYPES = Constants.DEFAULT_DS_TYPES_IN_TENANT + 1;
@Autowired
- protected TargetRepository targetRepository;
-
- @Autowired
- protected ActionRepository actionRepository;
-
- @Autowired
- protected DistributionSetRepository distributionSetRepository;
-
- @Autowired
- protected SoftwareModuleRepository softwareModuleRepository;
-
- @Autowired
- protected TenantMetaDataRepository tenantMetaDataRepository;
-
- @Autowired
- protected DistributionSetTypeRepository distributionSetTypeRepository;
-
- @Autowired
- protected SoftwareModuleTypeRepository softwareModuleTypeRepository;
-
- @Autowired
- protected TargetTagRepository targetTagRepository;
-
- @Autowired
- protected DistributionSetTagRepository distributionSetTagRepository;
-
- @Autowired
- protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
-
- @Autowired
- protected ActionStatusRepository actionStatusRepository;
-
- @Autowired
- protected ExternalArtifactRepository externalArtifactRepository;
+ protected EntityFactory entityFactory;
@Autowired
protected SoftwareManagement softwareManagement;
@@ -159,15 +101,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Autowired
protected ArtifactManagement artifactManagement;
- @Autowired
- protected LocalArtifactRepository artifactRepository;
-
- @Autowired
- protected TargetInfoRepository targetInfoRepository;
-
- @Autowired
- protected GridFsOperations operations;
-
@Autowired
protected WebApplicationContext context;
@@ -183,9 +116,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Autowired
protected SystemManagement systemManagement;
- @Autowired
- protected TenantAwareCacheManager cacheManager;
-
@Autowired
protected TenantConfigurationManagement tenantConfigurationManagement;
@@ -195,19 +125,13 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Autowired
protected RolloutGroupManagement rolloutGroupManagement;
- @Autowired
- protected RolloutGroupRepository rolloutGroupRepository;
-
- @Autowired
- protected RolloutRepository rolloutRepository;
-
@Autowired
protected SystemSecurityContext systemSecurityContext;
- protected MockMvc mvc;
-
@Autowired
- protected DatabaseCleanupUtil dbCleanupUtil;
+ protected TestRepositoryManagement testRepositoryManagement;
+
+ protected MockMvc mvc;
protected SoftwareModuleType osType;
protected SoftwareModuleType appType;
@@ -215,13 +139,14 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
protected DistributionSetType standardDsType;
+ @Autowired
+ protected TestdataFactory testdataFactory;
+
@Rule
public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule();
protected Environment environment = null;
- private static CIMySqlTestDatabase tesdatabase;
-
@Override
public void setEnvironment(final Environment environment) {
this.environment = environment;
@@ -230,20 +155,29 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Before
public void before() throws Exception {
mvc = createMvcWebAppContext().build();
+ final String description = "Updated description to have lastmodified available in tests";
- standardDsType = securityRule.runAsPrivileged(() -> systemManagement.getTenantMetadata().getDefaultDsType());
-
- osType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("os"));
- osType.setDescription("Updated description to have lastmodified available in tests");
+ osType = securityRule
+ .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_OS));
+ osType.setDescription(description);
osType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(osType));
- appType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("application"));
- appType.setDescription("Updated description to have lastmodified available in tests");
+ appType = securityRule.runAsPrivileged(
+ () -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_APP, Integer.MAX_VALUE));
+ appType.setDescription(description);
appType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(appType));
- runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("runtime"));
- runtimeType.setDescription("Updated description to have lastmodified available in tests");
+ runtimeType = securityRule
+ .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_RT));
+ runtimeType.setDescription(description);
runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(runtimeType));
+
+ standardDsType = securityRule.runAsPrivileged(() -> testdataFactory.findOrCreateDefaultTestDsType());
+ }
+
+ @After
+ public void after() {
+ testRepositoryManagement.clearTestRepository();
}
protected DefaultMockMvcBuilder createMvcWebAppContext() {
@@ -254,59 +188,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
"/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", "/*/controller/artifacts/**"));
}
- @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();
- }
- }
-
- @After
- public void after() throws Exception {
- deleteAllRepos();
- cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear());
- assertThat(actionStatusRepository.findAll()).isEmpty();
- assertThat(targetRepository.findAll()).isEmpty();
- assertThat(actionRepository.findAll()).isEmpty();
- assertThat(distributionSetRepository.findAll()).isEmpty();
- assertThat(targetTagRepository.findAll()).isEmpty();
- assertThat(distributionSetTagRepository.findAll()).isEmpty();
- assertThat(softwareModuleRepository.findAll()).isEmpty();
- assertThat(softwareModuleTypeRepository.findAll()).isEmpty();
- assertThat(distributionSetTypeRepository.findAll()).isEmpty();
- assertThat(tenantMetaDataRepository.findAll()).isEmpty();
- assertThat(rolloutGroupRepository.findAll()).isEmpty();
- assertThat(rolloutRepository.findAll()).isEmpty();
- }
-
- @Transactional
- protected void deleteAllRepos() throws Exception {
- final List tenants = securityRule.runAs(WithSpringAuthorityRule.withUser(false),
- () -> systemManagement.findTenants());
- tenants.forEach(tenant -> {
- try {
- securityRule.runAs(WithSpringAuthorityRule.withUser(false), () -> {
- systemManagement.deleteTenant(tenant);
- return null;
- });
- } catch (final Exception e) {
- e.printStackTrace();
- }
- });
- }
-
@Rule
public MethodRule watchman = new TestWatchman() {
@Override
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTestWithMongoDB.java
similarity index 89%
rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java
rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTestWithMongoDB.java
index d83f2e5cf..28d8add3a 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTestWithMongoDB.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;
import java.io.IOException;
import java.net.UnknownHostException;
@@ -15,7 +15,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.data.mongodb.gridfs.GridFsOperations;
import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.MongodExecutable;
@@ -38,10 +40,14 @@ import de.flapdoodle.embed.process.runtime.Network;
*
*/
public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegrationTest {
+
protected static volatile MongodExecutable mongodExecutable = null;
private static final AtomicInteger mongoLease = new AtomicInteger(0);
private static volatile Integer port;
+ @Autowired
+ protected GridFsOperations operations;
+
@BeforeClass
public static void setupMongo() throws UnknownHostException, IOException {
mongoLease.incrementAndGet();
@@ -67,8 +73,8 @@ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegra
new ArtifactStoreBuilder().defaults(command)
.download(new DownloadConfigBuilder().defaultsForCommand(command)
.proxyFactory(new HttpProxyFactory(
- System.getProperty("http.proxyHost").trim(),
- Integer.valueOf(System.getProperty("http.proxyPort"))))));
+ System.getProperty("http.proxyHost").trim(), Integer
+ .valueOf(System.getProperty("http.proxyPort"))))));
}
final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version)
@@ -86,7 +92,7 @@ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegra
operations.delete(new Query());
}
- public void internalShutDownMongo() {
+ public static void internalShutDownMongo() {
if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) {
mongodExecutable.stop();
mongodExecutable = null;
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/FreePortFileWriter.java
similarity index 97%
rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java
rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/FreePortFileWriter.java
index 8d900a593..383722a75 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/FreePortFileWriter.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;
import java.io.File;
import java.net.InetSocketAddress;
diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestRepositoryManagement.java
new file mode 100644
index 000000000..ddad59990
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestRepositoryManagement.java
@@ -0,0 +1,22 @@
+/**
+ * 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.util;
+
+/**
+ * Repository support for tests.
+ *
+ */
+@FunctionalInterface
+public interface TestRepositoryManagement {
+ /**
+ * Empty the test repository.
+ */
+ void clearTestRepository();
+
+}
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
new file mode 100644
index 000000000..0597a30cb
--- /dev/null
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java
@@ -0,0 +1,737 @@
+/**
+ * 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.util;
+
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+
+import org.apache.commons.io.IOUtils;
+import org.eclipse.hawkbit.repository.ArtifactManagement;
+import org.eclipse.hawkbit.repository.ControllerManagement;
+import org.eclipse.hawkbit.repository.DeploymentManagement;
+import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
+import org.eclipse.hawkbit.repository.SoftwareManagement;
+import org.eclipse.hawkbit.repository.TagManagement;
+import org.eclipse.hawkbit.repository.TargetManagement;
+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.DistributionSet;
+import org.eclipse.hawkbit.repository.model.DistributionSetTag;
+import org.eclipse.hawkbit.repository.model.DistributionSetType;
+import org.eclipse.hawkbit.repository.model.LocalArtifact;
+import org.eclipse.hawkbit.repository.model.NamedEntity;
+import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
+import org.eclipse.hawkbit.repository.model.SoftwareModule;
+import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
+import org.eclipse.hawkbit.repository.model.Target;
+import org.eclipse.hawkbit.repository.model.TargetTag;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+
+import net._01001111.text.LoremIpsum;
+
+/**
+ * Data generator utility for tests.
+ */
+public class TestdataFactory {
+ private static final LoremIpsum LOREM = new LoremIpsum();
+
+ /**
+ * default {@link Target#getControllerId()}.
+ */
+ public static final String DEFAULT_CONTROLLER_ID = "targetExist";
+
+ /**
+ * Default {@link SoftwareModule#getVendor()}.
+ */
+ public static final String DEFAULT_VENDOR = "Vendor Limited, California";
+
+ /**
+ * Default {@link NamedVersionedEntity#getVersion()}.
+ */
+ public static final String DEFAULT_VERSION = "1.0";
+
+ /**
+ * Default {@link NamedEntity#getDescription()}.
+ */
+ public static final String DEFAULT_DESCRIPTION = "Desc: " + LOREM.words(10);
+
+ /**
+ * Key of test default {@link DistributionSetType}.
+ */
+ public static final String DS_TYPE_DEFAULT = "test_default_ds_type";
+
+ /**
+ * Key of test "os" {@link SoftwareModuleType} -> mandatory firmware in
+ * {@link #DS_TYPE_DEFAULT}.
+ */
+ public static final String SM_TYPE_OS = "os";
+
+ /**
+ * Key of test "runtime" {@link SoftwareModuleType} -> optional firmware in
+ * {@link #DS_TYPE_DEFAULT}.
+ */
+ public static final String SM_TYPE_RT = "runtime";
+
+ /**
+ * Key of test "application" {@link SoftwareModuleType} -> optional software
+ * in {@link #DS_TYPE_DEFAULT}.
+ */
+ public static final String SM_TYPE_APP = "application";
+
+ @Autowired
+ private ControllerManagement controllerManagament;
+
+ @Autowired
+ private SoftwareManagement softwareManagement;
+
+ @Autowired
+ private DistributionSetManagement distributionSetManagement;
+
+ @Autowired
+ private TargetManagement targetManagement;
+
+ @Autowired
+ private DeploymentManagement deploymentManagement;
+
+ @Autowired
+ private TagManagement tagManagement;
+
+ @Autowired
+ private EntityFactory entityFactory;
+
+ @Autowired
+ private ArtifactManagement artifactManagement;
+
+ /**
+ * Creates {@link DistributionSet} in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} and
+ * {@link DistributionSet#isRequiredMigrationStep()} false.
+ *
+ * @param prefix
+ * for {@link SoftwareModule}s and {@link DistributionSet}s name,
+ * vendor and description.
+ *
+ * @return {@link DistributionSet} entity.
+ */
+ public DistributionSet createDistributionSet(final String prefix) {
+ return createDistributionSet(prefix, DEFAULT_VERSION, false);
+ }
+
+ /**
+ * Creates {@link DistributionSet} in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION}.
+ *
+ * @param prefix
+ * for {@link SoftwareModule}s and {@link DistributionSet}s name,
+ * vendor and description.
+ * @param isRequiredMigrationStep
+ * for {@link DistributionSet#isRequiredMigrationStep()}
+ *
+ * @return {@link DistributionSet} entity.
+ */
+ public DistributionSet createDistributionSet(final String prefix, final boolean isRequiredMigrationStep) {
+ return createDistributionSet(prefix, DEFAULT_VERSION, isRequiredMigrationStep);
+ }
+
+ /**
+ * Creates {@link DistributionSet} in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} and
+ * {@link DistributionSet#isRequiredMigrationStep()} false.
+ *
+ * @param prefix
+ * for {@link SoftwareModule}s and {@link DistributionSet}s name,
+ * vendor and description.
+ * @param tags
+ * {@link DistributionSet#getTags()}
+ *
+ * @return {@link DistributionSet} entity.
+ */
+ public DistributionSet createDistributionSet(final String prefix, final Collection tags) {
+ return createDistributionSet(prefix, DEFAULT_VERSION, tags);
+ }
+
+ /**
+ * Creates {@link DistributionSet} in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP}.
+ *
+ * @param prefix
+ * for {@link SoftwareModule}s and {@link DistributionSet}s name,
+ * vendor and description.
+ * @param version
+ * {@link DistributionSet#getVersion()} and
+ * {@link SoftwareModule#getVersion()} extended by a random
+ * number.
+ * @param isRequiredMigrationStep
+ * for {@link DistributionSet#isRequiredMigrationStep()}
+ *
+ * @return {@link DistributionSet} entity.
+ */
+ public DistributionSet createDistributionSet(final String prefix, final String version,
+ final boolean isRequiredMigrationStep) {
+
+ final SoftwareModule appMod = softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule(
+ findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE), prefix + SM_TYPE_APP,
+ version + "." + new Random().nextInt(100), LOREM.words(20), prefix + " vendor Limited, California"));
+ final SoftwareModule runtimeMod = softwareManagement
+ .createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_RT),
+ prefix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20),
+ prefix + " vendor GmbH, Stuttgart, Germany"));
+ final SoftwareModule osMod = softwareManagement
+ .createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_OS),
+ prefix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20),
+ prefix + " vendor Limited Inc, California"));
+
+ return distributionSetManagement
+ .createDistributionSet(generateDistributionSet(prefix != null && prefix.length() > 0 ? prefix : "DS",
+ version, findOrCreateDefaultTestDsType(), Lists.newArrayList(osMod, runtimeMod, appMod))
+ .setRequiredMigrationStep(isRequiredMigrationStep));
+ }
+
+ /**
+ * Creates {@link DistributionSet} in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP}.
+ *
+ * @param prefix
+ * for {@link SoftwareModule}s and {@link DistributionSet}s name,
+ * vendor and description.
+ * @param version
+ * {@link DistributionSet#getVersion()} and
+ * {@link SoftwareModule#getVersion()} extended by a random
+ * number.
+ * @param tags
+ * {@link DistributionSet#getTags()}
+ *
+ * @return {@link DistributionSet} entity.
+ */
+ public DistributionSet createDistributionSet(final String prefix, final String version,
+ final Collection tags) {
+
+ final DistributionSet set = createDistributionSet(prefix, version, false);
+
+ final List sets = new ArrayList<>();
+ sets.add(set);
+
+ tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
+
+ return distributionSetManagement.findDistributionSetById(set.getId());
+
+ }
+
+ /**
+ * Creates {@link DistributionSet}s in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an
+ * iterative number and {@link DistributionSet#isRequiredMigrationStep()}
+ * false.
+ *
+ * @param number
+ * of {@link DistributionSet}s to create
+ *
+ * @return {@link List} of {@link DistributionSet} entities
+ */
+ public List createDistributionSets(final int number) {
+
+ return createDistributionSets("", number);
+ }
+
+ /**
+ * Creates {@link DistributionSet}s in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an
+ * iterative number and {@link DistributionSet#isRequiredMigrationStep()}
+ * false.
+ *
+ * @param prefix
+ * for {@link SoftwareModule}s and {@link DistributionSet}s name,
+ * vendor and description.
+ * @param number
+ * of {@link DistributionSet}s to create
+ *
+ * @return {@link List} of {@link DistributionSet} entities
+ */
+ public List createDistributionSets(final String prefix, final int number) {
+
+ final List sets = new ArrayList<>();
+ for (int i = 0; i < number; i++) {
+ sets.add(createDistributionSet(prefix, DEFAULT_VERSION + "." + i, false));
+ }
+
+ return sets;
+ }
+
+ /**
+ * Creates {@link DistributionSet}s in repository with
+ * {@link #DEFAULT_DESCRIPTION} and
+ * {@link DistributionSet#isRequiredMigrationStep()} false.
+ *
+ * @param name
+ * {@link DistributionSet#getName()}
+ * @param version
+ * {@link DistributionSet#getVersion()}
+ *
+ * @return {@link DistributionSet} entity
+ */
+ public DistributionSet createDistributionSetWithNoSoftwareModules(final String name, final String version) {
+
+ final DistributionSet dis = entityFactory.generateDistributionSet();
+ dis.setName(name);
+ dis.setVersion(version);
+ dis.setDescription(DEFAULT_DESCRIPTION);
+ dis.setType(findOrCreateDefaultTestDsType());
+ return distributionSetManagement.createDistributionSet(dis);
+ }
+
+ /**
+ * Creates {@link LocalArtifact}s for given {@link SoftwareModule} with a
+ * small text payload.
+ *
+ * @param moduleId
+ * the {@link Artifact}s belong to.
+ *
+ * @return {@link LocalArtifact} entity.
+ */
+ public List createLocalArtifacts(final Long moduleId) {
+ final List artifacts = new ArrayList<>();
+ for (int i = 0; i < 3; i++) {
+ final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i, Charset.forName("UTF-8"));
+ artifacts.add(artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false));
+
+ }
+
+ return artifacts;
+ }
+
+ /**
+ * Creates {@link SoftwareModule} with {@link #DEFAULT_VENDOR} and
+ * {@link #DEFAULT_VERSION} and random generated
+ * {@link Target#getDescription()} in the repository.
+ *
+ * @param typeKey
+ * of the {@link SoftwareModuleType}
+ *
+ * @return persisted {@link SoftwareModule}.
+ */
+ public SoftwareModule createSoftwareModule(final String typeKey) {
+ return softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule(
+ findOrCreateSoftwareModuleType(typeKey), typeKey, DEFAULT_VERSION, LOREM.words(10), DEFAULT_VENDOR));
+ }
+
+ /**
+ * @return persisted {@link Target} with {@link #DEFAULT_CONTROLLER_ID}.
+ */
+ public Target createTarget() {
+ return targetManagement.createTarget(entityFactory.generateTarget(DEFAULT_CONTROLLER_ID));
+ }
+
+ /**
+ * Creates {@link DistributionSet}s in repository including three
+ * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT}
+ * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an
+ * iterative number and {@link DistributionSet#isRequiredMigrationStep()}
+ * false.
+ *
+ * @return persisted {@link DistributionSet}.
+ */
+ public DistributionSet createTestDistributionSet() {
+ DistributionSet set = createDistributionSet("");
+ set.setVersion(DEFAULT_VERSION);
+ set = distributionSetManagement.updateDistributionSet(set);
+
+ set.getModules().forEach(module -> {
+ module.setDescription("Updated " + DEFAULT_DESCRIPTION);
+ softwareManagement.updateSoftwareModule(module);
+ });
+
+ // load also lazy stuff
+ set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
+
+ return set;
+ }
+
+ /**
+ * @return {@link DistributionSetType} with key {@link #DS_TYPE_DEFAULT} and
+ * {@link SoftwareModuleType}s {@link #SM_TYPE_OS},
+ * {@link #SM_TYPE_RT} , {@link #SM_TYPE_APP}.
+ */
+ public DistributionSetType findOrCreateDefaultTestDsType() {
+ final List mand = new ArrayList<>();
+ mand.add(findOrCreateSoftwareModuleType(SM_TYPE_OS));
+
+ final List opt = new ArrayList<>();
+ opt.add(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE));
+ opt.add(findOrCreateSoftwareModuleType(SM_TYPE_RT));
+
+ return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional",
+ mand, opt);
+ }
+
+ /**
+ * Creates {@link DistributionSetType} in repository.
+ *
+ * @param dsTypeKey
+ * {@link DistributionSetType#getKey()}
+ * @param dsTypeName
+ * {@link DistributionSetType#getName()}
+ *
+ * @return persisted {@link DistributionSetType}
+ */
+ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) {
+ final DistributionSetType findDistributionSetTypeByname = distributionSetManagement
+ .findDistributionSetTypeByKey(dsTypeKey);
+
+ if (findDistributionSetTypeByname != null) {
+ return findDistributionSetTypeByname;
+ }
+
+ final DistributionSetType type = entityFactory.generateDistributionSetType(dsTypeKey, dsTypeName,
+ LOREM.words(10));
+
+ return distributionSetManagement.createDistributionSetType(type);
+ }
+
+ /**
+ * Finds {@link DistributionSetType} in repository with given
+ * {@link DistributionSetType#getKey()} or creates if it does not exist yet.
+ *
+ * @param dsTypeKey
+ * {@link DistributionSetType#getKey()}
+ * @param dsTypeName
+ * {@link DistributionSetType#getName()}
+ * @param mandatory
+ * {@link DistributionSetType#getMandatoryModuleTypes()}
+ * @param optional
+ * {@link DistributionSetType#getOptionalModuleTypes()}
+ *
+ * @return persisted {@link DistributionSetType}
+ */
+ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName,
+ final Collection mandatory, final Collection optional) {
+ final DistributionSetType findDistributionSetTypeByname = distributionSetManagement
+ .findDistributionSetTypeByKey(dsTypeKey);
+
+ if (findDistributionSetTypeByname != null) {
+ return findDistributionSetTypeByname;
+ }
+
+ final DistributionSetType type = entityFactory.generateDistributionSetType(dsTypeKey, dsTypeName,
+ LOREM.words(10));
+ mandatory.forEach(type::addMandatoryModuleType);
+ optional.forEach(type::addOptionalModuleType);
+
+ return distributionSetManagement.createDistributionSetType(type);
+ }
+
+ /**
+ * Finds {@link SoftwareModuleType} in repository with given
+ * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet
+ * with {@link SoftwareModuleType#getMaxAssignments()} = 1.
+ *
+ * @param key
+ * {@link SoftwareModuleType#getKey()}
+ *
+ * @return persisted {@link SoftwareModuleType}
+ */
+ public SoftwareModuleType findOrCreateSoftwareModuleType(final String key) {
+ return findOrCreateSoftwareModuleType(key, 1);
+ }
+
+ /**
+ * Finds {@link SoftwareModuleType} in repository with given
+ * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet.
+ *
+ * @param key
+ * {@link SoftwareModuleType#getKey()}
+ * @param maxAssignments
+ * {@link SoftwareModuleType#getMaxAssignments()}
+ *
+ * @return persisted {@link SoftwareModuleType}
+ */
+ public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) {
+ final SoftwareModuleType findSoftwareModuleTypeByKey = softwareManagement.findSoftwareModuleTypeByKey(key);
+ if (findSoftwareModuleTypeByKey != null) {
+ return findSoftwareModuleTypeByKey;
+ }
+ return softwareManagement.createSoftwareModuleType(
+ entityFactory.generateSoftwareModuleType(key, key, LOREM.words(10), maxAssignments));
+ }
+
+ /**
+ * builder method for creating a {@link DistributionSet}.
+ *
+ * @param name
+ * {@link DistributionSet#getName()}
+ * @param version
+ * {@link DistributionSet#getVersion()}
+ * @param type
+ * {@link DistributionSet#getType()}
+ * @param modules
+ * {@link DistributionSet#getModules()}
+ *
+ * @return the created {@link DistributionSet}
+ */
+ public DistributionSet generateDistributionSet(final String name, final String version,
+ final DistributionSetType type, final Collection modules) {
+ final DistributionSet distributionSet = entityFactory.generateDistributionSet(name, version, null, type,
+ modules);
+ distributionSet.setDescription(LOREM.words(10));
+ return distributionSet;
+ }
+
+ /**
+ * Creates {@link DistributionSetTag}s in repository.
+ *
+ * @param number
+ * of {@link DistributionSetTag}s
+ *
+ * @return the persisted {@link DistributionSetTag}s
+ */
+ public List createDistributionSetTags(final int number) {
+ final List result = new ArrayList<>();
+
+ for (int i = 0; i < number; i++) {
+ result.add(entityFactory.generateDistributionSetTag("tag" + i, "tagdesc" + i, String.valueOf(i)));
+ }
+
+ return tagManagement.createDistributionSetTags(result);
+ }
+
+ /**
+ * builder method for creating a single target object.
+ *
+ * @param ctrlID
+ * the ID of the target
+ * @param description
+ * of the target
+ * @return the created target object
+ */
+ public Target generateTarget(final String ctrlID, final String description) {
+ return generateTarget(ctrlID, description, null);
+ }
+
+ /**
+ * Builds a single {@link Target} from the given parameters.
+ *
+ * @param ctrlID
+ * controllerID
+ * @param description
+ * the description of the target
+ * @param tags
+ * assigned {@link TargetTag}s
+ * @return the generated {@link Target}
+ */
+ private Target generateTarget(final String ctrlID, final String description, final TargetTag[] tags) {
+ final Target target = entityFactory.generateTarget(ctrlID);
+ target.setName("Prov.Target ".concat(ctrlID));
+ target.setDescription(description);
+ if (tags != null && tags.length > 0) {
+ for (final TargetTag t : tags) {
+ target.getTags().add(t);
+ }
+ }
+ return target;
+ }
+
+ /**
+ * Creates {@link Target}s in repository and with
+ * {@link #DEFAULT_CONTROLLER_ID} as prefix for
+ * {@link Target#getControllerId()}.
+ *
+ * @param number
+ * of {@link Target}s to create
+ *
+ * @return {@link List} of {@link Target} entities
+ */
+ public List createTargets(final int number) {
+ return targetManagement.createTargets(generateTargets(0, number, DEFAULT_CONTROLLER_ID));
+ }
+
+ /**
+ * Builds {@link Target} objects with given prefix for
+ * {@link Target#getControllerId()} followed by a number suffix.
+ *
+ * @param start
+ * value for the controllerId suffix
+ * @param numberOfTargets
+ * of {@link Target}s to generate
+ * @param controllerIdPrefix
+ * for {@link Target#getControllerId()} generation.
+ * @return list of {@link Target} objects
+ */
+ private List generateTargets(final int start, final int numberOfTargets, final String controllerIdPrefix) {
+ final List targets = new ArrayList<>();
+ for (int i = start; i < start + numberOfTargets; i++) {
+ targets.add(entityFactory.generateTarget(controllerIdPrefix + i));
+ }
+
+ return targets;
+ }
+
+ /**
+ * Builds {@link Target} objects with given prefix for
+ * {@link Target#getControllerId()} followed by a number suffix starting
+ * with 0.
+ *
+ * @param numberOfTargets
+ * of {@link Target}s to generate
+ * @param controllerIdPrefix
+ * for {@link Target#getControllerId()} generation.
+ * @return list of {@link Target} objects
+ */
+ public List generateTargets(final int numberOfTargets, final String controllerIdPrefix) {
+ return generateTargets(0, numberOfTargets, controllerIdPrefix);
+ }
+
+ /**
+ * builds a set of {@link Target} fixtures from the given parameters.
+ *
+ * @param numberOfTargets
+ * number of targets to create
+ * @param controllerIdPrefix
+ * prefix used for the controller ID
+ * @param descriptionPrefix
+ * prefix used for the description
+ * @return set of {@link Target}
+ */
+ public List generateTargets(final int numberOfTargets, final String controllerIdPrefix,
+ final String descriptionPrefix) {
+ return generateTargets(numberOfTargets, controllerIdPrefix, descriptionPrefix, null);
+ }
+
+ /**
+ * method creates set of targets by by generating the controller ID and the
+ * description like: prefix + no of target.
+ *
+ * @param noOfTgts
+ * number of targets which should be created
+ * @param controllerIdPrefix
+ * prefix of the controllerID which is concatenated with the
+ * number of the target. Randomly generated if null.
+ * @param descriptionPrefix
+ * prefix of the target description which is concatenated with
+ * the number of the target
+ * @param tags
+ * tags which should be added to the created {@link Target}s
+ * @return set of created targets
+ */
+ private List generateTargets(final int noOfTgts, final String controllerIdPrefix,
+ final String descriptionPrefix, final TargetTag[] tags) {
+ final List list = new ArrayList<>();
+ for (int i = 0; i < noOfTgts; i++) {
+ String ctrlID = controllerIdPrefix;
+ if (Strings.isNullOrEmpty(ctrlID)) {
+ ctrlID = UUID.randomUUID().toString();
+ }
+ ctrlID = String.format("%s-%05d", ctrlID, i);
+
+ final String description = descriptionPrefix + DEFAULT_DESCRIPTION;
+
+ final Target target = generateTarget(ctrlID, description, tags);
+ list.add(target);
+
+ }
+ return list;
+ }
+
+ /**
+ * Generates {@link TargetTag}s.
+ *
+ * @param number
+ * of {@link TargetTag}s to generate.
+ *
+ * @return generated {@link TargetTag}s.
+ */
+ public List generateTargetTags(final int number) {
+ final List result = new ArrayList<>();
+
+ for (int i = 0; i < number; i++) {
+ result.add(entityFactory.generateTargetTag("tag" + i, "tagdesc" + i, String.valueOf(i)));
+ }
+
+ return result;
+ }
+
+ /**
+ * Create a set of {@link TargetTag}s.
+ *
+ * @param noOfTags
+ * number of {@link TargetTag}. to be created
+ * @param tagPrefix
+ * prefix for the {@link TargetTag#getName()}
+ * @return the created set of {@link TargetTag}s
+ */
+ public List generateTargetTags(final int noOfTags, final String tagPrefix) {
+ final List list = new ArrayList<>();
+ for (int i = 0; i < noOfTags; i++) {
+ String tagName = "myTag";
+ if (!Strings.isNullOrEmpty(tagPrefix)) {
+ tagName = tagPrefix;
+ }
+ tagName = String.format("%s-%05d", tagName, i);
+
+ final TargetTag targetTag = entityFactory.generateTargetTag(tagName);
+ list.add(targetTag);
+ }
+ return list;
+ }
+
+ private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, final String... msgs) {
+ updActA.setStatus(status);
+
+ final ActionStatus statusMessages = entityFactory.generateActionStatus();
+ statusMessages.setAction(updActA);
+ statusMessages.setOccurredAt(System.currentTimeMillis());
+ statusMessages.setStatus(status);
+ for (final String msg : msgs) {
+ statusMessages.addMessage(msg);
+ }
+
+ return controllerManagament.addUpdateActionStatus(statusMessages);
+ }
+
+ /**
+ * Append {@link ActionStatus} to all {@link Action}s of given
+ * {@link Target}s.
+ *
+ * @param targets
+ * to add {@link ActionStatus}
+ * @param status
+ * to add
+ * @param msgs
+ * to add
+ *
+ * @return updated {@link Action}.
+ */
+ public List sendUpdateActionStatusToTargets(final Collection targets, final Status status,
+ final String... msgs) {
+ final List result = new ArrayList<>();
+ for (final Target target : targets) {
+ final List findByTarget = deploymentManagement.findActionsByTarget(target);
+ for (final Action action : findByTarget) {
+ result.add(sendUpdateActionStatusToTarget(status, action, msgs));
+ }
+ }
+ return result;
+ }
+}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithSpringAuthorityRule.java
similarity index 99%
rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java
rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithSpringAuthorityRule.java
index e61215973..b456cc32b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithSpringAuthorityRule.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;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithUser.java
similarity index 97%
rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java
rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithUser.java
index 0a936f1c0..04af9196b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java
+++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithUser.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;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
diff --git a/hawkbit-repository/pom.xml b/hawkbit-repository/pom.xml
index 9d95d0a43..981f3225a 100644
--- a/hawkbit-repository/pom.xml
+++ b/hawkbit-repository/pom.xml
@@ -23,6 +23,8 @@
hawkbit-repository-jpa
hawkbit-repository-api
+ hawkbit-repository-test
+ hawkbit-repository-core
diff --git a/hawkbit-rest-core/pom.xml b/hawkbit-rest-core/pom.xml
index 66fb1655a..0b5f39272 100644
--- a/hawkbit-rest-core/pom.xml
+++ b/hawkbit-rest-core/pom.xml
@@ -44,6 +44,12 @@
+
+ org.eclipse.hawkbit
+ hawkbit-repository-test
+ ${project.version}
+ test
+
org.easytesting
fest-assert
diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java
index e86f78d68..1b54eed3e 100644
--- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java
+++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java
@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.rest;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.rest.configuration.RestConfiguration;
import org.eclipse.hawkbit.rest.util.FilterHttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +19,7 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
* Abstract Test for Rest tests.
*/
@SpringApplicationConfiguration(classes = { RestConfiguration.class })
-public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest {
+public abstract class AbstractRestIntegrationTest extends AbstractJpaIntegrationTest {
@Autowired
private FilterHttpResponse filterHttpResponse;
@@ -29,5 +29,4 @@ public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTes
final DefaultMockMvcBuilder createMvcWebAppContext = super.createMvcWebAppContext();
return createMvcWebAppContext.addFilter(filterHttpResponse);
}
-
}
diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java
index d3da40035..81e2c3d16 100644
--- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java
+++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java
@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.rest;
-import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB;
+import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.rest.configuration.RestConfiguration;
import org.eclipse.hawkbit.rest.util.FilterHttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,14 +19,14 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
* Abstract Test for Rest tests.
*/
@SpringApplicationConfiguration(classes = { RestConfiguration.class })
-public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB {
+public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractJpaIntegrationTestWithMongoDB {
@Autowired
private FilterHttpResponse filterHttpResponse;
@Override
protected DefaultMockMvcBuilder createMvcWebAppContext() {
- DefaultMockMvcBuilder createMvcWebAppContext = super.createMvcWebAppContext();
+ final DefaultMockMvcBuilder createMvcWebAppContext = super.createMvcWebAppContext();
return createMvcWebAppContext.addFilter(filterHttpResponse);
}
}
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java
index d6fbada89..49b2dfada 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable;
import java.io.Serializable;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
@@ -66,6 +67,9 @@ public class SoftwareModuleAddUpdateWindow implements Serializable {
@Autowired
private transient SoftwareManagement softwareManagement;
+ @Autowired
+ private transient EntityFactory entityFactory;
+
private Label madatoryLabel;
private TextField nameTextField;
@@ -277,8 +281,8 @@ public class SoftwareModuleAddUpdateWindow implements Serializable {
uiNotifcation.displayValidationError(
i18n.get("message.duplicate.softwaremodule", new Object[] { name, version }));
} else {
- final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(softwareManagement,
- name, version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description);
+ final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name,
+ version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description);
if (newBaseSoftwareModule != null) {
/* display success message */
uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] {
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java
index c71b06671..eb915aef3 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java
@@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -93,6 +94,9 @@ public class CreateUpdateSoftwareTypeLayout extends CustomComponent implements C
@Autowired
private transient SoftwareManagement swTypeManagementService;
+ @Autowired
+ private transient EntityFactory entityFactory;
+
@Autowired
private transient EventBus.SessionEventBus eventBus;
@@ -625,8 +629,8 @@ public class CreateUpdateSoftwareTypeLayout extends CustomComponent implements C
}
if (null != typeNameValue && null != typeKeyValue) {
- SoftwareModuleType newSWType = swTypeManagementService.generateSoftwareModuleType(typeKeyValue,
- typeNameValue, typeDescValue, assignNumber);
+ SoftwareModuleType newSWType = entityFactory.generateSoftwareModuleType(typeKeyValue, typeNameValue,
+ typeDescValue, assignNumber);
newSWType.setColour(colorPicked);
if (null != typeDescValue) {
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java
index 04200208b..ded26b254 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java
@@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
@@ -41,6 +42,7 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery firstPageDistSetType = null;
private transient DistributionSetManagement distributionSetManagement;
+ private transient EntityFactory entityFactory;
/**
* Parametric constructor.
@@ -57,7 +59,7 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery loadBeans(final int startIndex, final int count) {
Page typeBeans;
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java
index 9dcdeb12b..8705f7aa9 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.common;
import java.util.List;
import java.util.Map;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -31,6 +32,7 @@ public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery firstPageSwModuleType = null;
private transient SoftwareManagement softwareManagement;
+ private transient EntityFactory entityFactory;
/**
* Parametric constructor.
@@ -47,7 +49,14 @@ public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery itemIds = (List) selectedTable.getItemIds();
if (null != typeNameValue && null != typeKeyValue && null != itemIds && !itemIds.isEmpty()) {
- DistributionSetType newDistType = distributionSetManagement.generateDistributionSetType(typeKeyValue,
- typeNameValue, typeDescValue);
+ DistributionSetType newDistType = entityFactory.generateDistributionSetType(typeKeyValue, typeNameValue,
+ typeDescValue);
for (final Long id : itemIds) {
final Item item = selectedTable.getItem(id);
final String distTypeName = (String) item.getItemProperty(DIST_TYPE_NAME).getValue();
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java
index a89e98d56..50e89371a 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java
@@ -13,6 +13,7 @@ import java.util.concurrent.Executor;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SpPermissionChecker;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
@@ -95,6 +96,9 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button
@Qualifier("uiExecutor")
private transient Executor executor;
+ @Autowired
+ private transient EntityFactory entityFactory;
+
private HorizontalLayout breadcrumbLayout;
private Button breadcrumbButton;
@@ -503,7 +507,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button
}
private void createTargetFilterQuery() {
- final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.generateTargetFilterQuery();
+ final TargetFilterQuery targetFilterQuery = entityFactory.generateTargetFilterQuery();
targetFilterQuery.setName(nameTextField.getValue());
targetFilterQuery.setQuery(queryTextField.getValue());
targetFilterQueryManagement.createTargetFilterQuery(targetFilterQuery);
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java
index cc52ce795..90b3ad597 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java
@@ -16,6 +16,7 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository;
@@ -94,6 +95,9 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout {
@Autowired
private transient TenantMetaDataRepository tenantMetaDataRepository;
+ @Autowired
+ private transient EntityFactory entityFactory;
+
private Button saveDistributionBtn;
private Button discardDistributionBtn;
private TextField distNameTextField;
@@ -145,12 +149,12 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout {
setSizeUndefined();
addComponents(madatoryLabel, distsetTypeNameComboBox, distNameTextField, distVersionTextField, descTextArea,
reqMigStepCheckbox);
-
+
addComponent(buttonsLayout);
setComponentAlignment(madatoryLabel, Alignment.MIDDLE_LEFT);
distNameTextField.focus();
-
- }
+
+ }
/**
* Create required UI components.
@@ -297,7 +301,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout {
if (mandatoryCheck(name, version, distSetTypeName) && duplicateCheck(name, version)) {
final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final boolean isMigStepReq = reqMigStepCheckbox.getValue();
- DistributionSet newDist = distributionSetManagement.generateDistributionSet();
+ DistributionSet newDist = entityFactory.generateDistributionSet();
setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq);
newDist = distributionSetManagement.createDistributionSet(newDist);
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java
index 56ba4183b..e37086e65 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.dstag;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent;
@@ -48,6 +49,9 @@ public class CreateUpdateDistributionTagLayoutWindow extends CreateUpdateTagLayo
@Autowired
private transient UINotification uiNotification;
+ @Autowired
+ private transient EntityFactory entityFactory;
+
private static final String MISSING_TAG_NAME = "message.error.missing.tagname";
private static final String TARGET_TAG_NAME_DYNAMIC_STYLE = "new-target-tag-name";
private static final String MSG_TEXTFIELD_NAME = "textfield.name";
@@ -98,7 +102,7 @@ public class CreateUpdateDistributionTagLayoutWindow extends CreateUpdateTagLayo
final String tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue());
if (null != tagNameValue) {
- DistributionSetTag newDistTag = tagManagement.generateDistributionSetTag(tagNameValue, tagDescValue,
+ DistributionSetTag newDistTag = entityFactory.generateDistributionSetTag(tagNameValue, tagDescValue,
new Color(0, 146, 58).getCSS());
if (colorPicked != null) {
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java
index 003700df5..9080a433f 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.management.dstag;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.hawkbit.repository.TagManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent;
@@ -53,15 +53,15 @@ public class DistributionTagButtons extends AbstractFilterButtons {
private DistributionTagDropEvent spDistTagDropEvent;
@Autowired
- private TagManagement tagManagement;
+ private ManagementUIState managementUIState;
@Autowired
- private ManagementUIState managementUIState;
+ private transient EntityFactory entityFactory;
@Override
public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) {
super.init(filterButtonClickBehaviour);
- addNewTag(tagManagement.generateDistributionSetTag("NO TAG"));
+ addNewTag(entityFactory.generateDistributionSetTag("NO TAG"));
}
@EventBusListenerMethod(scope = EventScope.SESSION)
@@ -143,7 +143,7 @@ public class DistributionTagButtons extends AbstractFilterButtons {
private void refreshTagTable() {
((LazyQueryContainer) getContainerDataSource()).refresh();
removeGeneratedColumn(FILTER_BUTTON_COLUMN);
- addNewTag(tagManagement.generateDistributionSetTag("NO TAG"));
+ addNewTag(entityFactory.generateDistributionSetTag("NO TAG"));
addColumn();
}
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java
index 23a82da0f..d6a613cf7 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java
@@ -26,6 +26,7 @@ import java.util.concurrent.Executor;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
@@ -97,6 +98,8 @@ public class BulkUploadHandler extends CustomComponent
final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout;
+ private final EntityFactory entityFactory;
+
/**
*
* @param targetBulkUpdateWindowLayout
@@ -124,6 +127,7 @@ public class BulkUploadHandler extends CustomComponent
this.eventBus = targetBulkUpdateWindowLayout.getEventBus();
distributionSetManagement = SpringContextHelper.getBean(DistributionSetManagement.class);
tagManagement = SpringContextHelper.getBean(TagManagement.class);
+ entityFactory = SpringContextHelper.getBean(EntityFactory.class);
}
/**
@@ -380,7 +384,7 @@ public class BulkUploadHandler extends CustomComponent
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
/* create new target entity */
- final Target newTarget = targetManagement.generateTarget(newControllerId);
+ final Target newTarget = entityFactory.generateTarget(newControllerId);
setTargetValues(newTarget, newName, newDesc);
targetManagement.createTarget(newTarget);
managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId);
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java
index ddf109773..be17beb18 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettable;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetIdName;
@@ -69,6 +70,9 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
@Autowired
private transient UINotification uINotification;
+
+ @Autowired
+ private transient EntityFactory entityFactory;
private TextField controllerIDTextField;
private TextField nameTextField;
@@ -245,7 +249,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent {
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
/* create new target entity */
- Target newTarget = targetManagement.generateTarget(newControlllerId);
+ Target newTarget = entityFactory.generateTarget(newControlllerId);
/* set values to the new target entity */
setTargetValues(newTarget, newName, newDesc);
/* save new target */
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java
index e5990be49..80de83982 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettag;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent;
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent;
@@ -49,6 +50,9 @@ public class CreateUpdateTargetTagLayout extends CreateUpdateTagLayout {
@Autowired
private transient UINotification uiNotification;
+ @Autowired
+ private transient EntityFactory entityFactory;
+
private Window targetTagWindow;
@Override
@@ -193,7 +197,7 @@ public class CreateUpdateTargetTagLayout extends CreateUpdateTagLayout {
final String tagNameValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagName.getValue());
final String tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue());
if (null != tagNameValue) {
- TargetTag newTargetTag = tagManagement.generateTargetTag(tagNameValue);
+ TargetTag newTargetTag = entityFactory.generateTargetTag(tagNameValue);
if (null != tagDescValue) {
newTargetTag.setDescription(tagDescValue);
}
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java
index eeac79728..e7e9c64b1 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java
@@ -12,8 +12,8 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SpPermissionChecker;
-import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent;
import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent;
@@ -77,7 +77,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons {
private SpPermissionChecker permChecker;
@Autowired
- private TagManagement tagManagement;
+ private transient EntityFactory entityFactory;
@Autowired
private transient TargetManagement targetManagement;
@@ -94,7 +94,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons {
public void init(final TargetTagFilterButtonClick filterButtonClickBehaviour) {
this.filterButtonClickBehaviour = filterButtonClickBehaviour;
super.init(filterButtonClickBehaviour);
- addNewTargetTag(tagManagement.generateTargetTag("NO TAG"));
+ addNewTargetTag(entityFactory.generateTargetTag("NO TAG"));
}
@EventBusListenerMethod(scope = EventScope.SESSION)
@@ -294,7 +294,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons {
private void refreshContainer() {
removeGeneratedColumn(FILTER_BUTTON_COLUMN);
((LazyQueryContainer) getContainerDataSource()).refresh();
- addNewTargetTag(tagManagement.generateTargetTag("NO TAG"));
+ addNewTargetTag(entityFactory.generateTargetTag("NO TAG"));
addColumn();
}
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java
index f0329e3fe..c909c9c5d 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java
@@ -13,6 +13,7 @@ import java.util.Date;
import java.util.List;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
@@ -108,6 +109,9 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent {
@Autowired
private transient UiProperties uiProperties;
+ @Autowired
+ private transient EntityFactory entityFactory;
+
@Autowired
private I18N i18n;
@@ -479,7 +483,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent {
}
private Rollout saveRollout() {
- Rollout rolloutToCreate = rolloutManagement.generateRollout();
+ Rollout rolloutToCreate = entityFactory.generateRollout();
final int amountGroup = Integer.parseInt(noOfGroups.getValue());
final String targetFilter = getTargetFilterQuery();
final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup);
diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java
index 7ed9c81dd..da0e3e828 100644
--- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java
+++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java
@@ -19,6 +19,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
+import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.model.AssignmentResult;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -430,7 +431,7 @@ public final class HawkbitCommonUtil {
return trimAndNullIfEmpty(orgText) == null ? SPUIDefinitions.SPACE : orgText;
}
- /**
+ /**
* Find extra height required to increase by all the components to utilize
* the full height of browser for the responsive UI.
*
@@ -760,10 +761,10 @@ public final class HawkbitCommonUtil {
* base software module description
* @return BaseSoftwareModule new base software module
*/
- public static SoftwareModule addNewBaseSoftware(final SoftwareManagement softwareManagement, final String bsname,
+ public static SoftwareModule addNewBaseSoftware(final EntityFactory entityFactory, final String bsname,
final String bsversion, final String bsvendor, final SoftwareModuleType bstype, final String description) {
final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class);
- SoftwareModule newSWModule = softwareManagement.generateSoftwareModule();
+ SoftwareModule newSWModule = entityFactory.generateSoftwareModule();
newSWModule.setType(bstype);
newSWModule.setName(bsname);
newSWModule.setVersion(bsversion);
diff --git a/pom.xml b/pom.xml
index 58e7b56dc..add09a1d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -553,7 +553,6 @@
de.flapdoodle.embed
de.flapdoodle.embed.mongo
${embedded-mongo.version}
- test
org.easytesting