refactored test data generation. Refactored entity factor methods.

Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-05-31 08:51:49 +02:00
parent a4e0fc2457
commit 7a98c58407
137 changed files with 2937 additions and 2593 deletions

View File

@@ -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" })

View File

@@ -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

View File

@@ -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 {
}

View File

@@ -48,6 +48,12 @@
<!-- Test -->
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-rest-core</artifactId>

View File

@@ -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<InputStream> 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;

View File

@@ -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<List<org.eclipse.hawkbit.ddi.json.model.DdiArtifact>> 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());

View File

@@ -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<Target> 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<Target> 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<Target> targets = new ArrayList<Target>();
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<Target> 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<Target> 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<Target> 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<Target> 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);

View File

@@ -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<Target> toAssign = new ArrayList<Target>();
@@ -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<Target> toAssign = new ArrayList<Target>();
@@ -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<Target> toAssign = new ArrayList<Target>();
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<Target> toAssign = new ArrayList<Target>();
toAssign.add(target);

View File

@@ -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<String, String> 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<String, String> 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

View File

@@ -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<Target> 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<Target> saved = deploymentManagement
.assignDistributionSet(ds.getId(), ActionType.SOFT, Constants.NO_FORCE_TIME, savedTarget.getControllerId())
.getAssignedEntity();
List<Target> 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<Target> 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<Target> 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<Target> 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<Target> 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())

View File

@@ -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<Target> toAssign = new ArrayList<Target>();
final List<Target> toAssign = new ArrayList<>();
toAssign.add(savedTarget);
savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next();
final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);

View File

@@ -73,6 +73,12 @@
<!-- Test -->
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>

View File

@@ -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;
}
}

View File

@@ -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.

View File

@@ -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<DbArtifact> 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());
}

View File

@@ -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<Action> actionList = new ArrayList<>();
actionList.add(action);

View File

@@ -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();

View File

@@ -47,6 +47,12 @@
</dependency>
<!-- Test -->
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-rest-core</artifactId>

View File

@@ -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<DistributionSet> dsFromRequest(final Iterable<MgmtDistributionSetRequestBodyPost> sets,
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement,
final EntityFactory entityFactory) {
final List<DistributionSet> 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<DistributionSetMetadata> fromRequestDsMetadata(final DistributionSet ds,
final List<MgmtMetadata> metadata, final DistributionSetManagement distributionSetManagement) {
final List<MgmtMetadata> metadata, final EntityFactory entityFactory) {
final List<DistributionSetMetadata> 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;
}

View File

@@ -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<DistributionSet> createdDSets = this.distributionSetManagement.createDistributionSets(
MgmtDistributionSetMapper.dsFromRequest(sets, this.softwareManagement, this.distributionSetManagement));
final Iterable<DistributionSet> 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<DistributionSetMetadata> created = this.distributionSetManagement.createDistributionSetMetadata(
MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, distributionSetManagement));
MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, entityFactory));
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED);
}

View File

@@ -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<PagedList<MgmtTag>> 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<DistributionSetTag> createdTags = this.tagManagement
.createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(tagManagement, tags));
.createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(entityFactory, tags));
return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
}

View File

@@ -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<DistributionSetType> smFromRequest(final DistributionSetManagement distributionSetManagement,
static List<DistributionSetType> smFromRequest(final EntityFactory entityFactory,
final SoftwareManagement softwareManagement,
final Iterable<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
final List<DistributionSetType> 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

View File

@@ -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<PagedList<MgmtDistributionSetType>> 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<List<MgmtDistributionSetType>> createDistributionSetTypes(
@RequestBody final List<MgmtDistributionSetTypeRequestBodyPost> distributionSetTypes) {
final List<DistributionSetType> createdSoftwareModules = distributionSetManagement
.createDistributionSetTypes(MgmtDistributionSetTypeMapper.smFromRequest(distributionSetManagement,
softwareManagement, distributionSetTypes));
final List<DistributionSetType> createdSoftwareModules = distributionSetManagement.createDistributionSetTypes(
MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, softwareManagement, distributionSetTypes));
return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toTypesResponse(createdSoftwareModules),
HttpStatus.CREATED);

View File

@@ -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);

View File

@@ -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<PagedList<MgmtRolloutResponseBody>> 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);

View File

@@ -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<SoftwareModuleMetadata> fromRequestSwMetadata(final SoftwareManagement softwareManagement,
static List<SoftwareModuleMetadata> fromRequestSwMetadata(final EntityFactory entityFactory,
final SoftwareModule sw, final List<MgmtMetadata> metadata) {
final List<SoftwareModuleMetadata> 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<SoftwareModule> smFromRequest(final Iterable<MgmtSoftwareModuleRequestBodyPost> smsRest,
final SoftwareManagement softwareManagement) {
static List<SoftwareModule> smFromRequest(final EntityFactory entityFactory,
final Iterable<MgmtSoftwareModuleRequestBodyPost> smsRest, final SoftwareManagement softwareManagement) {
final List<SoftwareModule> mappedList = new ArrayList<>();
for (final MgmtSoftwareModuleRequestBodyPost smRest : smsRest) {
mappedList.add(fromRequest(smRest, softwareManagement));
mappedList.add(fromRequest(entityFactory, smRest, softwareManagement));
}
return mappedList;
}

View File

@@ -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<MgmtArtifact> uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
@RequestParam("file") final MultipartFile file,
@@ -158,8 +162,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
public ResponseEntity<List<MgmtSoftwareModule>> createSoftwareModules(
@RequestBody final List<MgmtSoftwareModuleRequestBodyPost> softwareModules) {
LOG.debug("creating {} softwareModules", softwareModules.size());
final Iterable<SoftwareModule> createdSoftwareModules = softwareManagement
.createSoftwareModule(MgmtSoftwareModuleMapper.smFromRequest(softwareModules, softwareManagement));
final Iterable<SoftwareModule> 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<SoftwareModuleMetadata> created = softwareManagement.createSoftwareModuleMetadata(
MgmtSoftwareModuleMapper.fromRequestSwMetadata(softwareManagement, sw, metadataRest));
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, sw, metadataRest));
return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(created), HttpStatus.CREATED);

View File

@@ -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<SoftwareModuleType> smFromRequest(final SoftwareManagement softwareManagement,
static List<SoftwareModuleType> smFromRequest(final EntityFactory entityFactory,
final Iterable<MgmtSoftwareModuleTypeRequestBodyPost> smTypesRest) {
final List<SoftwareModuleType> 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());

View File

@@ -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<PagedList<MgmtSoftwareModuleType>> 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<MgmtSoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
final List<SoftwareModuleType> createdSoftwareModules = this.softwareManagement.createSoftwareModuleType(
MgmtSoftwareModuleTypeMapper.smFromRequest(softwareManagement, softwareModuleTypes));
MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes));
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules),
HttpStatus.CREATED);

View File

@@ -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<TargetTag> mapTargeTagFromRequest(final TagManagement tagManagement,
static List<TargetTag> mapTargeTagFromRequest(final EntityFactory entityFactory,
final Iterable<MgmtTagRequestBodyPut> tags) {
final List<TargetTag> 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<DistributionSetTag> mapDistributionSetTagFromRequest(final TagManagement tagManagement,
static List<DistributionSetTag> mapDistributionSetTagFromRequest(final EntityFactory entityFactory,
final Iterable<MgmtTagRequestBodyPut> tags) {
final List<DistributionSetTag> 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;

View File

@@ -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<Target> fromRequest(final TargetManagement targetManagement,
static List<Target> fromRequest(final EntityFactory entityFactory,
final Iterable<MgmtTargetRequestBody> targetsRest) {
final List<Target> 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;

View File

@@ -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<MgmtTarget> getTarget(@PathVariable("targetId") final String targetId) {
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
@@ -105,7 +109,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity<List<MgmtTarget>> createTargets(@RequestBody final List<MgmtTargetRequestBody> targets) {
LOG.debug("creating {} targets", targets.size());
final Iterable<Target> 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);
}

View File

@@ -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<PagedList<MgmtTag>> 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<List<MgmtTag>> createTargetTags(@RequestBody final List<MgmtTagRequestBodyPut> tags) {
LOG.debug("creating {} target tags", tags.size());
final List<TargetTag> createdTargetTags = this.tagManagement
.createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(tagManagement, tags));
.createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(entityFactory, tags));
return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED);
}

View File

@@ -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<Long> smIDs = new ArrayList<Long>();
SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Dysnomia ", "15,772", null, null);
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Eris", "560a");
final List<Long> 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<Long> 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<Long> 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<Long> smIDs = new ArrayList<Long>();
SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Europa", "3,551", null, null);
final List<Long> 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<DistributionSet> 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<DistributionSet> 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<DistributionSet> 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<DistributionSet> 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<DistributionSet> 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;

View File

@@ -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<DistributionSetType> 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<DistributionSetType> 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++;

View File

@@ -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()));
}

View File

@@ -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<Target> 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);

View File

@@ -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<SoftwareModule> 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<SoftwareModule> 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++;

View File

@@ -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<SoftwareModuleType> 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<SoftwareModuleType> 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++;

View File

@@ -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<Action> 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<Target> targets = new ArrayList<>();
targets.add(target);
final Iterator<JpaDistributionSet> sets = TestDataUtil
.generateDistributionSets(2, softwareManagement, distributionSetManagement).iterator();
final Iterator<DistributionSet> 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<String, String> 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

View File

@@ -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);
}

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<Configuration status="WARN" monitorInterval="30">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="[%t] [%-5level] %logger{36} - %msg%n" charset="UTF-8"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.eclipse.hawkbit.MockMvcResultPrinter" level="error" />
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.eclipse.hawkbit.eventbus.DeadEventListener" level="WARN" />
<Logger name="org.springframework.boot.actuate.audit.listener.AuditListener" level="WARN" />
<Logger name="org.hibernate.validator.internal.util.Version" level="WARN" />
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="WARN" />
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="WARN" />
<Logger name="org.apache.tomcat.jdbc.pool.ConnectionPool" level="DEBUG" />
<Logger name="org.apache.catalina.startup.DigesterFactory" level="ERROR" />
<Logger name="org.eclipse.hawkbit.rest.util.MockMvcResultPrinter" level="DEBUG" />
<!-- Security Log with hints on potential attacks -->
<logger name="server-security" level="INFO" />
<Root level="INFO">
<AppenderRef ref="Console" />
</Root>
</configuration>

View File

@@ -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.
*

View File

@@ -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.
}

View File

@@ -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<String> 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);
}

View File

@@ -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<Action> findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target);
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Slice<Action> 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.
*

View File

@@ -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<SoftwareModule> moduleList);
}

View File

@@ -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<String> 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<SoftwareModule> 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);
}

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -601,14 +601,4 @@ public interface TargetManagement {
+ SpringEvalExpressions.IS_CONTROLLER)
List<Target> updateTargets(@NotNull Collection<Target> targets);
/**
* Generates an empty {@link Target} without persisting it.
*
* @param controllerID
* of the {@link Target}
*
* @return {@link Target} object
*/
Target generateTarget(@NotEmpty String controllerID);
}

View File

@@ -16,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
* Management service for statistics of a single tenant.
*
*/
@FunctionalInterface
public interface TenantStatsManagement {
/**

View File

@@ -0,0 +1,29 @@
<!--
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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository</artifactId>
<version>0.2.0-SNAPSHOT</version>
</parent>
<artifactId>hawkbit-repository-core</artifactId>
<name>hawkBit :: Repository Core Implementation Support</name>
<dependencies>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -52,19 +52,20 @@
<artifactId>hawkbit-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-artifact-repository-mongo</artifactId>
<version>${project.version}</version>
</dependency>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>net._01001111</groupId>
<artifactId>jlorem</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
@@ -96,6 +97,12 @@
</dependency>
<!-- Test -->
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@@ -121,21 +128,11 @@
<artifactId>allure-junit-adaptor</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.data</groupId> -->
<!-- <artifactId>spring-data-rest-webmvc</artifactId> -->
<!-- <scope>test</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-aspects</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
@@ -150,12 +147,7 @@
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
@@ -170,7 +162,6 @@
<groupId>cz.jirutka.rsql</groupId>
<artifactId>rsql-parser</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -1,15 +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
-->
<FindBugsFilter>
<Match>
<Method name="~_persistence_[sg]et.*" />
</Match>
</FindBugsFilter>

View File

@@ -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 {
}

View File

@@ -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,

View File

@@ -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();
}
}

View File

@@ -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<String> 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);
}
}

View File

@@ -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<ActionStatus> findActionStatusAll(final Pageable pageable) {
return convertAcSPage(actionStatusRepository.findAll(pageable), pageable);
@@ -697,4 +691,19 @@ public class JpaDeploymentManagement implements DeploymentManagement {
private static Page<ActionStatus> convertAcSPage(final Page<JpaActionStatus> 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<Action> findActionsByDistributionSet(final Pageable pageable, final DistributionSet ds) {
return actionRepository.findByDistributionSet(pageable, (JpaDistributionSet) ds);
}
}

View File

@@ -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<SoftwareModule> moduleList) {
return new JpaDistributionSet(name, version, description, type, moduleList);
}
@Override
public Long countDistributionSetsByType(final DistributionSetType type) {
return distributionSetRepository.countByType((JpaDistributionSetType) type);

View File

@@ -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<SoftwareModule> 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<String> 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);
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -109,9 +109,4 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery);
}
@Override
public TargetFilterQuery generateTargetFilterQuery() {
return new JpaTargetFilterQuery();
}
}

View File

@@ -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<Target> allTargets = new ArrayList<>(targetRepository
.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))));
final List<Target> 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);
}
}

View File

@@ -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

View File

@@ -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) {

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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() {

View File

@@ -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);
}

View File

@@ -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<Target> 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<Target> toAssign = new ArrayList<>();
toAssign.add(savedTarget);

View File

@@ -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<DistributionSetTag>());
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
new ArrayList<DistributionSetTag>());
final List<Target> 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<DistributionSetTag>());
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
new ArrayList<DistributionSetTag>());
final List<Target> 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<Long> assignDS = new ArrayList<>();
for (int i = 0; i < 4; i++) {
assignDS.add(TestDataUtil.generateDistributionSet("DS" + i, "1.0", softwareManagement,
distributionSetManagement, new ArrayList<DistributionSetTag>()).getId());
assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", new ArrayList<DistributionSetTag>())
.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<DistributionSetTag>());
final DistributionSet cancelDs = testdataFactory.createDistributionSet("Canceled DS", "1.0",
new ArrayList<DistributionSetTag>());
final DistributionSet cancelDs2 = TestDataUtil.generateDistributionSet("Canceled DS", "1.2", softwareManagement,
distributionSetManagement, new ArrayList<DistributionSetTag>());
final DistributionSet cancelDs2 = testdataFactory.createDistributionSet("Canceled DS", "1.2",
new ArrayList<DistributionSetTag>());
List<Target> targets = targetManagement
.createTargets(TestDataUtil.generateTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10));
List<Target> 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<Target> savedNakedTargets = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(10, myCtrlIDPref, "first description"));
.createTargets(testdataFactory.generateTargets(10, myCtrlIDPref, "first description"));
final String myDeployedCtrlIDPref = "myDeployedCtrlID";
List<Target> 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<Target> targets = targetManagement.createTargets(TestDataUtil.generateTargets(10));
final List<Target> 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<Target> 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<Action> updAct = actionRepository.findByDistributionSet(pageReq, dsA);
final Page<Action> 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<Target> nakedTargets = targetManagement.createTargets(
TestDataUtil.buildTargetFixtures(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
testdataFactory.generateTargets(noOfUndeployedTargets, undeployedTargetPrefix, "first description"));
List<Target> deployedTargets = targetManagement.createTargets(
TestDataUtil.buildTargetFixtures(noOfDeployedTargets, deployedTargetPrefix, "first description"));
testdataFactory.generateTargets(noOfDeployedTargets, deployedTargetPrefix, "first description"));
// creating 10 DistributionSets
final Collection<DistributionSet> dsList = (Collection) TestDataUtil.generateDistributionSets(
distributionSetPrefix, noOfDistributionSets, softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsList = testdataFactory.createDistributionSets(distributionSetPrefix,
noOfDistributionSets);
String time = String.valueOf(System.currentTimeMillis());
time = time.substring(time.length() - 5);

View File

@@ -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<JpaDistributionSet> buildDistributionSets = TestDataUtil.generateDistributionSets("dsOrder", 10,
softwareManagement, distributionSetManagement);
final List<DistributionSet> buildDistributionSets = testdataFactory.createDistributionSets("dsOrder", 10);
final List<Target> buildTargetFixtures = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(5, "tOrder", "someDesc"));
.createTargets(testdataFactory.generateTargets(5, "tOrder", "someDesc"));
final Iterator<JpaDistributionSet> dsIterator = buildDistributionSets.iterator();
final Iterator<DistributionSet> dsIterator = buildDistributionSets.iterator();
final Iterator<Target> 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<DistributionSet> ds100Group1 = (Collection) TestDataUtil.generateDistributionSets("", 100,
softwareManagement, distributionSetManagement);
Collection<DistributionSet> ds100Group2 = (Collection) TestDataUtil.generateDistributionSets("test2", 100,
softwareManagement, distributionSetManagement);
DistributionSet dsDeleted = TestDataUtil.generateDistributionSet("deleted", softwareManagement,
distributionSetManagement);
Collection<DistributionSet> ds100Group1 = testdataFactory.createDistributionSets("", 100);
Collection<DistributionSet> 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());

View File

@@ -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<String> tenants = systemSecurityContext.runAsSystem(() -> systemManagement.findTenants());
tenants.forEach(tenant -> {
try {
systemSecurityContext.runAsSystem(() -> {
systemManagement.deleteTenant(tenant);
return null;
});
} catch (final Exception e) {
e.printStackTrace();
}
});
}
}

View File

@@ -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());

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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<Target> 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<Target> 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);

View File

@@ -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<DistributionSet> dsAs = (Collection) TestDataUtil.generateDistributionSets("DS-A", 20,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsBs = (Collection) TestDataUtil.generateDistributionSets("DS-B", 10,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsCs = (Collection) TestDataUtil.generateDistributionSets("DS-C", 25,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsABs = (Collection) TestDataUtil.generateDistributionSets("DS-AB", 5,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsACs = (Collection) TestDataUtil.generateDistributionSets("DS-AC", 11,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsBCs = (Collection) TestDataUtil.generateDistributionSets("DS-BC", 13,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsABCs = (Collection) TestDataUtil.generateDistributionSets("DS-ABC", 9,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> dsAs = testdataFactory.createDistributionSets("DS-A", 20);
final Collection<DistributionSet> dsBs = testdataFactory.createDistributionSets("DS-B", 10);
final Collection<DistributionSet> dsCs = testdataFactory.createDistributionSets("DS-C", 25);
final Collection<DistributionSet> dsABs = testdataFactory.createDistributionSets("DS-AB", 5);
final Collection<DistributionSet> dsACs = testdataFactory.createDistributionSets("DS-AC", 11);
final Collection<DistributionSet> dsBCs = testdataFactory.createDistributionSets("DS-BC", 13);
final Collection<DistributionSet> 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<DistributionSet> groupA = (Collection) TestDataUtil.generateDistributionSets(20,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> groupB = (Collection) TestDataUtil.generateDistributionSets("unassigned", 20,
softwareManagement, distributionSetManagement);
final Collection<DistributionSet> groupA = testdataFactory.createDistributionSets(20);
final Collection<DistributionSet> 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<Target> groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, ""));
final List<Target> groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb"));
final List<Target> groupA = targetManagement.createTargets(testdataFactory.generateTargets(20, ""));
final List<Target> 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<JpaTargetTag> createTargetsWithTags() {
final List<Target> targets = targetManagement.createTargets(TestDataUtil.generateTargets(20));
final Iterable<TargetTag> tags = tagManagement.createTargetTags(TestDataUtil.generateTargetTags(20));
final List<Target> targets = testdataFactory.createTargets(20);
final Iterable<TargetTag> tags = tagManagement.createTargetTags(testdataFactory.generateTargetTags(20));
tags.forEach(tag -> targetManagement.toggleTagAssignment(targets, tag));
@@ -461,10 +452,8 @@ public class TagManagementTest extends AbstractIntegrationTest {
private List<DistributionSetTag> createDsSetsWithTags() {
final Collection<DistributionSet> sets = (Collection) TestDataUtil.generateDistributionSets(20,
softwareManagement, distributionSetManagement);
final Iterable<DistributionSetTag> tags = tagManagement
.createDistributionSetTags(TestDataUtil.generateDistributionSetTags(20));
final Collection<DistributionSet> sets = testdataFactory.createDistributionSets(20);
final Iterable<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(20);
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));

View File

@@ -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.")

View File

@@ -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<Target> 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<Target> 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<Target> 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<Target> 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<Target> notAssigned = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(3, "not", "first description"));
.createTargets(testdataFactory.generateTargets(3, "not", "first description"));
List<Target> targAssigned = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(3, "assigned", "first description"));
.createTargets(testdataFactory.generateTargets(3, "assigned", "first description"));
List<Target> 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<Target> assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned"));
final DistributionSet assignedSet = testdataFactory.createDistributionSet("");
targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned"));
List<Target> 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<Target> 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<Target> installedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned"));
// set on installed and assign another one
deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> {

View File

@@ -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<Target> targets = TestDataUtil.buildTargetFixtures(5, "mySimpleTargs", "my simple targets");
final List<Target> 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<Target> firstList = TestDataUtil.buildTargetFixtures(100, myCtrlID, "first description");
final List<Target> 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<Target> 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<Target> ts = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(100, "myCtrlID", "first description"));
.createTargets(testdataFactory.generateTargets(100, "myCtrlID", "first description"));
final Map<String, String> 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<TargetTag> 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<TargetTag> 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<Target> tagATargets = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagATargets", "first description"));
.createTargets(testdataFactory.generateTargets(10, "tagATargets", "first description"));
final List<Target> tagBTargets = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagBTargets", "first description"));
.createTargets(testdataFactory.generateTargets(10, "tagBTargets", "first description"));
final List<Target> tagCTargets = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagCTargets", "first description"));
.createTargets(testdataFactory.generateTargets(10, "tagCTargets", "first description"));
final List<Target> tagABTargets = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(10, "tagABTargets", "first description"));
.createTargets(testdataFactory.generateTargets(10, "tagABTargets", "first description"));
final List<Target> 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<Target> targAs = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description"));
.createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description"));
final List<Target> targBs = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(20, "target-id-B", "first description"));
.createTargets(testdataFactory.generateTargets(20, "target-id-B", "first description"));
final List<Target> targCs = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(15, "target-id-C", "first description"));
.createTargets(testdataFactory.generateTargets(15, "target-id-C", "first description"));
final List<Target> targABs = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(12, "target-id-AB", "first description"));
.createTargets(testdataFactory.generateTargets(12, "target-id-AB", "first description"));
final List<Target> targACs = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(13, "target-id-AC", "first description"));
.createTargets(testdataFactory.generateTargets(13, "target-id-AC", "first description"));
final List<Target> targBCs = targetManagement
.createTargets(TestDataUtil.buildTargetFixtures(7, "target-id-BC", "first description"));
.createTargets(testdataFactory.generateTargets(7, "target-id-BC", "first description"));
final List<Target> 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<Target> 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<Target> 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<Target> 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<Target> targetsListWithNoTag = targetManagement

View File

@@ -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.")

View File

@@ -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

View File

@@ -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<Target> sendUpdateActionStatusToTargets(final ControllerManagement controllerManagament,
final TargetManagement targetManagement, final ActionRepository actionRepository, final DistributionSet dsA,
final Iterable<Target> targs, final Status status, final String... msgs) {
final List<Target> result = new ArrayList<>();
for (final Target t : targs) {
final List<Action> 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<JpaDistributionSet> generateDistributionSets(final String suffix, final int number,
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
final List<JpaDistributionSet> 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<JpaDistributionSet> 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<SoftwareModuleType> mand = new ArrayList<>();
mand.add(findOrCreateSoftwareModuleType(softwareManagement, "os"));
final List<SoftwareModuleType> 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<DistributionSetTag> tags) {
final DistributionSet set = generateDistributionSet(suffix, version, softwareManagement,
distributionSetManagement, false);
final List<DistributionSet> sets = new ArrayList<DistributionSet>();
sets.add(set);
tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag));
return distributionSetManagement.findDistributionSetById(set.getId());
}
public static List<Target> generateTargets(final int number) {
return generateTargets(0, number, "Test target ");
}
public static List<Target> generateTargets(final int number, final String prefix) {
return generateTargets(0, number, prefix);
}
public static List<Target> generateTargets(final int start, final int number, final String prefix) {
final List<Target> targets = new ArrayList<>();
for (int i = start; i < start + number; i++) {
targets.add(new JpaTarget(prefix + i));
}
return targets;
}
public static List<TargetTag> generateTargetTags(final int number) {
final List<TargetTag> result = new ArrayList<>();
for (int i = 0; i < number; i++) {
result.add(new JpaTargetTag("tag" + i, "tagdesc" + i, "" + i));
}
return result;
}
public static List<DistributionSetTag> generateDistributionSetTags(final int number) {
final List<DistributionSetTag> 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<AbstractJpaArtifact> generateArtifacts(final ArtifactManagement artifactManagement,
final Long moduleId) {
final List<AbstractJpaArtifact> 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<DistributionSetTag> 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<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> 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<Target> 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<Target> buildTargetFixtures(final int noOfTgts, final String ctlrIDPrefix,
final String descriptionPrefix, final TargetTag[] tags) {
final List<Target> list = new ArrayList<Target>();
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<TargetTag> buildTargetTagFixtures(final int noOfTags, final String tagPrefix) {
final List<TargetTag> 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);
}
}

View File

@@ -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 "

View File

@@ -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;

View File

@@ -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

Some files were not shown because too many files have changed in this diff Show More