Add REST (un)assign ds tag tests (#1899)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -172,14 +172,14 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtDistributionSet>> assignDistributionSets(
|
||||
public ResponseEntity<Void> assignDistributionSets(
|
||||
final Long distributionsetTagId,
|
||||
final List<Long> distributionsetIds) {
|
||||
log.debug("Assign DistributionSet {} for ds tag {}", distributionsetIds.size(), distributionsetTagId);
|
||||
final List<DistributionSet> assignedDs = this.distributionSetManagement
|
||||
.assignTag(distributionsetIds, distributionsetTagId);
|
||||
log.debug("Assigned DistributionSet {}", assignedDs.size());
|
||||
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs));
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
import org.eclipse.hawkbit.rest.util.JsonBuilder;
|
||||
@@ -338,11 +339,105 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that tag assignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
|
||||
@Description("Verifies that tag assignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetUpdatedEvent.class, count = 1) })
|
||||
public void assignDistributionSet() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final DistributionSet set = testdataFactory.createDistributionSetsWithoutModules(1).get(0);
|
||||
|
||||
mvc
|
||||
.perform(
|
||||
post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
|
||||
set.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
|
||||
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
|
||||
.containsOnly(set.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that tag assignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
|
||||
@Expect(type = DistributionSetUpdatedEvent.class, count = 2) })
|
||||
public void assignDistributionSets() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(2);
|
||||
|
||||
mvc
|
||||
.perform(
|
||||
put(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
|
||||
.content(JsonBuilder.toArray(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
|
||||
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
|
||||
.containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that tag unassignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
|
||||
@Expect(type = DistributionSetUpdatedEvent.class, count = 3) })
|
||||
public void unassignDistributionSet() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final int setsAssigned = 2;
|
||||
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned);
|
||||
final DistributionSet assigned = sets.get(0);
|
||||
final DistributionSet unassigned = sets.get(1);
|
||||
|
||||
distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId());
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
|
||||
unassigned.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
|
||||
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
|
||||
.containsOnly(assigned.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that tag unassignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 3),
|
||||
@Expect(type = DistributionSetUpdatedEvent.class, count = 5) })
|
||||
public void unassignDistributionSets() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(3);
|
||||
final DistributionSet assigned = sets.get(0);
|
||||
final DistributionSet unassigned0 = sets.get(1);
|
||||
final DistributionSet unassigned1 = sets.get(2);
|
||||
|
||||
distributionSetManagement.assignTag(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()), tag.getId());
|
||||
|
||||
mvc
|
||||
.perform(
|
||||
delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
|
||||
.content(JsonBuilder.toArray(List.of(unassigned0.getId(), unassigned1.getId())))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
|
||||
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
|
||||
.containsOnly(assigned.getId());
|
||||
}
|
||||
|
||||
// DEPRECATED flows
|
||||
|
||||
@Test
|
||||
@Description("Verifies that tag assignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({
|
||||
@Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
|
||||
@Expect(type = DistributionSetUpdatedEvent.class, count = 2) })
|
||||
public void assignDistributionSetsWithRequestBody() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final int setsAssigned = 2;
|
||||
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned);
|
||||
@@ -364,27 +459,4 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
|
||||
result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0)))
|
||||
.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that tag unassignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 2),
|
||||
@Expect(type = DistributionSetUpdatedEvent.class, count = 3) })
|
||||
public void unassignDistributionSet() throws Exception {
|
||||
final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0);
|
||||
final int setsAssigned = 2;
|
||||
final List<DistributionSet> sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned);
|
||||
final DistributionSet assigned = sets.get(0);
|
||||
final DistributionSet unassigned = sets.get(1);
|
||||
|
||||
distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId());
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/"
|
||||
+ unassigned.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
|
||||
|
||||
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
|
||||
.containsOnly(assigned.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,9 +268,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 1) })
|
||||
public void assignTarget() throws Exception {
|
||||
final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0);
|
||||
final int targetsAssigned = 1;
|
||||
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
|
||||
final Target assigned = targets.get(0);
|
||||
final Target assigned = testdataFactory.createTargets(1).get(0);
|
||||
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" +
|
||||
assigned.getControllerId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
@@ -288,13 +286,12 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 2) })
|
||||
public void assignTargets() throws Exception {
|
||||
final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0);
|
||||
final int targetsAssigned = 2;
|
||||
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
|
||||
final List<Target> targets = testdataFactory.createTargets(2);
|
||||
final Target assigned0 = targets.get(0);
|
||||
final Target assigned1 = targets.get(1);;
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
|
||||
.content(JsonBuilder.controllerIds(Arrays.asList(assigned0.getControllerId(), assigned1.getControllerId())))
|
||||
.content(JsonBuilder.toArray(Arrays.asList(assigned0.getControllerId(), assigned1.getControllerId())))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
@@ -305,12 +302,13 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
|
||||
@Test
|
||||
@Description("Verifies that tag unassignments done through tag API command are correctly stored in the repository.")
|
||||
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 3) })
|
||||
@ExpectEvents({
|
||||
@Expect(type = TargetTagCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 2),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 3) })
|
||||
public void unassignTarget() throws Exception {
|
||||
final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0);
|
||||
final int targetsAssigned = 2;
|
||||
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
|
||||
final List<Target> targets = testdataFactory.createTargets(2);
|
||||
final Target assigned = targets.get(0);
|
||||
final Target unassigned = targets.get(1);
|
||||
|
||||
@@ -332,8 +330,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 5) })
|
||||
public void unassignTargets() throws Exception {
|
||||
final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0);
|
||||
final int targetsAssigned = 3;
|
||||
final List<Target> targets = testdataFactory.createTargets(targetsAssigned);
|
||||
final List<Target> targets = testdataFactory.createTargets(3);
|
||||
final Target assigned = targets.get(0);
|
||||
final Target unassigned0 = targets.get(1);
|
||||
final Target unassigned1 = targets.get(2);
|
||||
@@ -341,7 +338,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
|
||||
targetManagement.assignTag(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId());
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")
|
||||
.content(JsonBuilder.controllerIds(Arrays.asList(unassigned0.getControllerId(), unassigned1.getControllerId())))
|
||||
.content(JsonBuilder.toArray(Arrays.asList(unassigned0.getControllerId(), unassigned1.getControllerId())))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user