Merge pull request #277 from bsinno/fix_unhandled_ConstraintViolationException

Fix unhandled constraint violation exception
This commit is contained in:
Kai Zimmermann
2016-08-24 11:46:43 +02:00
committed by GitHub
14 changed files with 317 additions and 242 deletions

View File

@@ -13,6 +13,7 @@ import java.util.List;
import org.eclipse.hawkbit.repository.model.AssignmentResult;
import org.eclipse.hawkbit.repository.model.Target;
import org.springframework.util.CollectionUtils;
/**
* A bean which holds a complex result of an service operation to combine the
@@ -61,6 +62,10 @@ public class DistributionSetAssignmentResult extends AssignmentResult<Target> {
@Override
public List<Target> getAssignedEntity() {
if (CollectionUtils.isEmpty(assignedTargets)) {
return Collections.emptyList();
}
return targetManagement.findTargetByControllerID(assignedTargets);
}

View File

@@ -16,6 +16,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
@@ -197,7 +198,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that a DS is of default type if not specified explicitly at creation time.")
@Description("Verifies that a DS is of default type if not specified explicitly at creation time.")
public void createDistributionSetWithImplicitType() {
final DistributionSet set = distributionSetManagement
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", null, null));
@@ -208,7 +209,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that multiple DS are of default type if not specified explicitly at creation time.")
@Description("Verifies that multiple DS are of default type if not specified explicitly at creation time.")
public void createMultipleDistributionSetsWithImplicitType() {
List<DistributionSet> sets = new ArrayList<>();
@@ -228,7 +229,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Verfies that a DS entity cannot be used for creation.")
@Description("Verifies that a DS entity cannot be used for creation.")
public void createDistributionSetFailsOnExistingEntity() {
final DistributionSet set = distributionSetManagement
.createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", null, null));
@@ -818,6 +819,27 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
.isEqualTo(2);
}
@Test
@Description("Verify that the DistributionSetAssignmentResult not contains already assigned targets.")
public void verifyDistributionSetAssignmentResultNotContainsAlreadyAssignedTargets() {
DistributionSet dsToTargetAssigned = testdataFactory.createDistributionSet("ds-3");
// create assigned DS
dsToTargetAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsToTargetAssigned.getName(),
dsToTargetAssigned.getVersion());
final Target target = new JpaTarget("4712");
final Target savedTarget = targetManagement.createTarget(target);
final List<Target> toAssign = Lists.newArrayList(savedTarget);
DistributionSetAssignmentResult assignmentResult = deploymentManagement
.assignDistributionSet(dsToTargetAssigned, toAssign);
assertThat(assignmentResult.getAssignedEntity()).hasSize(1);
assignmentResult = deploymentManagement.assignDistributionSet(dsToTargetAssigned, toAssign);
assertThat(assignmentResult.getAssignedEntity()).hasSize(0);
assertThat(distributionSetRepository.findAll()).hasSize(1);
}
private Rollout createRolloutByVariables(final String rolloutName, final String rolloutDescription,
final int groupSize, final String filterQuery, final DistributionSet distributionSet,
final String successCondition, final String errorCondition) {