Distribution set assignment: Fix NPE in AbstractDsAssignmentStrategy (#777)

* Fix NPE
* Add unit test
* Fix review findings

Signed-off-by: Stefan Behl <stefan.behl@bosch-si.com>
This commit is contained in:
Stefan Behl
2018-12-21 13:08:43 +01:00
committed by GitHub
parent a1ace0a463
commit eada7cdd6f
5 changed files with 64 additions and 72 deletions

View File

@@ -273,6 +273,29 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.as("Five targets in repository have DS assigned").hasSize(5);
}
@Test
@Description("Ensures that targets can be assigned even if the specified controller IDs are in different case (e.g. 'TARGET1' instead of 'target1'.")
public void assignTargetsToDistributionSetIgnoreCase() throws Exception {
final DistributionSet createdDs = testdataFactory.createDistributionSet();
// prepare targets
final String[] knownTargetIds = new String[] { "64-da-a0-02-43-8b", "Trg1", "target2", "target4" };
final String[] knownTargetIdDifferentCase = new String[] { "64-DA-A0-02-43-8b", "TRG1", "TarGET2", "target4" };
for (final String targetId : knownTargetIds) {
testdataFactory.createTarget(targetId);
}
final JSONArray list = new JSONArray();
for (final String targetId : knownTargetIdDifferentCase) {
list.put(new JSONObject().put("id", targetId).put("type", "forced"));
}
mvc.perform(post(
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk());
// we just need to make sure that no error 500 is returned
}
@Test
@Description("Ensures that multi target assignment is protected by our 'max targets per manual assignment' quota.")
public void assignMultipleTargetsToDistributionSetUntilQuotaIsExceeded() throws Exception {