Optimize UI queries (#1234)
* first iteration of query optimization for target and distribution set * fixed type distribution set filter * adapted all ui dataproviders to use repository count * adapted test to not check target attributes within search query * unified search behaviuor for ds and sm * removed unneccessary count queries for some mgmt calls * removed unneccessary type id proprty from ProxyDistributionSetInfo to minimize lazy fetches * refactored mgmt classes * removed duplication of name version filter * fixed copy rollout compatibility check * cleaned-up management left overs * added index to rollouts table on tenant/status queries Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch.io>
This commit is contained in:
@@ -45,6 +45,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetInvalidation;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetInvalidation.CancelationType;
|
||||
@@ -215,9 +216,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("entity with invalid description should not be created")
|
||||
.isThrownBy(() -> distributionSetManagement.create(
|
||||
entityFactory.distributionSet().create().name("a").version("a")
|
||||
.description(INVALID_TEXT_HTML)));
|
||||
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
|
||||
.version("a").description(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("entity with too long description should not be updated")
|
||||
@@ -225,8 +225,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.description(RandomStringUtils.randomAlphanumeric(513))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("entity with invalid characters should not be updated")
|
||||
.isThrownBy(() -> distributionSetManagement
|
||||
.as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement
|
||||
.update(entityFactory.distributionSet().update(set.getId()).description(INVALID_TEXT_HTML)));
|
||||
}
|
||||
|
||||
@@ -253,8 +252,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("entity with invalid characters should not be updated")
|
||||
.isThrownBy(() -> distributionSetManagement
|
||||
.as("entity with invalid characters should not be updated").isThrownBy(() -> distributionSetManagement
|
||||
.update(entityFactory.distributionSet().update(set.getId()).name(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
@@ -383,7 +381,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// add some meta data entries
|
||||
final DistributionSet ds3 = testdataFactory.createDistributionSet("ds3");
|
||||
final int firstHalf = Math.round(((float) maxMetaData) / 2.f);
|
||||
final int firstHalf = Math.round((maxMetaData) / 2.f);
|
||||
for (int i = 0; i < firstHalf; ++i) {
|
||||
createDistributionSetMetadata(ds3.getId(), new JpaDistributionSetMetadata("k" + i, ds3, "v" + i));
|
||||
}
|
||||
@@ -415,7 +413,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignedDS.stream().map(c -> (JpaDistributionSet) c)
|
||||
.forEach(ds -> assertThat(ds.getTags().size()).as("ds has wrong tag size").isEqualTo(1));
|
||||
|
||||
DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.getByName(TAG1_NAME));
|
||||
final DistributionSetTag findDistributionSetTag = getOrThrow(distributionSetTagManagement.getByName(TAG1_NAME));
|
||||
|
||||
assertThat(assignedDS.size()).as("assigned ds has wrong size")
|
||||
.isEqualTo(distributionSetManagement.findByTag(PAGE, tag.getId()).getNumberOfElements());
|
||||
@@ -549,7 +547,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// assign some software modules
|
||||
final DistributionSet ds3 = testdataFactory.createDistributionSetWithNoSoftwareModules("ds3", "1.0");
|
||||
final int firstHalf = Math.round(((float) maxModules) / 2.f);
|
||||
final int firstHalf = Math.round((maxModules) / 2.f);
|
||||
for (int i = 0; i < firstHalf; ++i) {
|
||||
distributionSetManagement.assignSoftwareModules(ds3.getId(), singletonList(modules.get(i)));
|
||||
}
|
||||
@@ -566,9 +564,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final SoftwareModule softwareModule = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class)
|
||||
.as("Invalid distributionSet should throw an exception")
|
||||
.isThrownBy(() -> distributionSetManagement.assignSoftwareModules(distributionSet.getId(),
|
||||
singletonList(softwareModule.getId())));
|
||||
.as("Invalid distributionSet should throw an exception").isThrownBy(() -> distributionSetManagement
|
||||
.assignSoftwareModules(distributionSet.getId(), singletonList(softwareModule.getId())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -576,10 +573,9 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
void verifyUnassignSoftwareModulesToInvalidDistributionSet() {
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||
final SoftwareModule softwareModule = testdataFactory.createSoftwareModuleOs();
|
||||
distributionSetManagement.assignSoftwareModules(distributionSet.getId(),
|
||||
singletonList(softwareModule.getId()));
|
||||
distributionSetInvalidationManagement.invalidateDistributionSet(new DistributionSetInvalidation(
|
||||
singletonList(distributionSet.getId()), CancelationType.NONE, false));
|
||||
distributionSetManagement.assignSoftwareModules(distributionSet.getId(), singletonList(softwareModule.getId()));
|
||||
distributionSetInvalidationManagement.invalidateDistributionSet(
|
||||
new DistributionSetInvalidation(singletonList(distributionSet.getId()), CancelationType.NONE, false));
|
||||
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class)
|
||||
.as("Invalid distributionSet should throw an exception").isThrownBy(() -> distributionSetManagement
|
||||
@@ -647,13 +643,12 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assignDistributionSet(dsFour.getId(), tSecond.getControllerId());
|
||||
|
||||
final DistributionSetFilterBuilder distributionSetFilterBuilder = new DistributionSetFilterBuilder()
|
||||
.setIsDeleted(false).setIsComplete(true).setSelectDSWithNoTag(Boolean.FALSE);
|
||||
final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false)
|
||||
.setIsComplete(true).setSelectDSWithNoTag(Boolean.FALSE).build();
|
||||
|
||||
// target first only has an assigned DS-three so check order correct
|
||||
final List<DistributionSet> tFirstPin = distributionSetManagement
|
||||
.findByFilterAndAssignedInstalledDsOrderedByLinkTarget(PAGE, distributionSetFilterBuilder,
|
||||
tFirst.getControllerId())
|
||||
.findByDistributionSetFilterOrderByLinkedTarget(PAGE, distributionSetFilter, tFirst.getControllerId())
|
||||
.getContent();
|
||||
assertThat(tFirstPin.get(0)).isEqualTo(dsThree);
|
||||
assertThat(tFirstPin).hasSize(10);
|
||||
@@ -661,8 +656,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// target second has installed DS-2 and assigned DS-4 so check order
|
||||
// correct
|
||||
final List<DistributionSet> tSecondPin = distributionSetManagement
|
||||
.findByFilterAndAssignedInstalledDsOrderedByLinkTarget(PAGE, distributionSetFilterBuilder,
|
||||
tSecond.getControllerId())
|
||||
.findByDistributionSetFilterOrderByLinkedTarget(PAGE, distributionSetFilter, tSecond.getControllerId())
|
||||
.getContent();
|
||||
assertThat(tSecondPin.get(0)).isEqualTo(dsSecond);
|
||||
assertThat(tSecondPin.get(1)).isEqualTo(dsFour);
|
||||
@@ -724,15 +718,14 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
validateDeleted(dsDeleted, sizeOfAllDistributionSets - 1);
|
||||
validateCompleted(dsInComplete, sizeOfAllDistributionSets - 1);
|
||||
validateType(newType, dsNewType, sizeOfAllDistributionSets - 1);
|
||||
validateSearchText(dsGroup2, "%" + dsGroup2Prefix);
|
||||
validateFilterString(allDistributionSets, dsGroup2Prefix);
|
||||
validateSearchText(allDistributionSets, dsGroup2Prefix);
|
||||
validateTags(dsTagA, dsTagB, dsTagC, dsGroup1WithGroup2, dsGroup1);
|
||||
validateDeletedAndCompleted(dsGroup1WithGroup2, dsNewType, dsDeleted);
|
||||
validateDeletedAndCompletedAndType(dsGroup1WithGroup2, dsDeleted, newType, dsNewType);
|
||||
validateDeletedAndCompletedAndTypeAndSearchText(dsGroup2, newType, "%" + dsGroup2Prefix);
|
||||
validateDeletedAndCompletedAndTypeAndFilterString(dsGroup1WithGroup2, dsDeleted, dsInComplete, dsNewType,
|
||||
newType, ":1");
|
||||
validateDeletedAndCompletedAndTypeAndSearchTextAndTag(dsGroup2, dsTagA, "%" + dsGroup2Prefix);
|
||||
validateDeletedAndCompletedAndTypeAndSearchText(dsGroup2, newType, dsGroup2Prefix);
|
||||
validateDeletedAndCompletedAndTypeAndSearchText(dsGroup1WithGroup2, dsDeleted, dsInComplete, dsNewType, newType,
|
||||
":1");
|
||||
validateDeletedAndCompletedAndTypeAndSearchTextAndTag(dsGroup2, dsTagA, dsGroup2Prefix);
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -764,59 +757,51 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Step
|
||||
private void validateType(final DistributionSetType newType, final DistributionSet dsNewType,
|
||||
final int standardDsTypeSize) {
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setType(newType),
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setTypeId(newType.getId()),
|
||||
singletonList(dsNewType));
|
||||
|
||||
assertThatFilterHasSizeAndDoesNotContainDistributionSet(
|
||||
getDistributionSetFilterBuilder().setType(standardDsType), standardDsTypeSize, dsNewType);
|
||||
getDistributionSetFilterBuilder().setTypeId(standardDsType.getId()), standardDsTypeSize, dsNewType);
|
||||
}
|
||||
|
||||
@Step
|
||||
private void validateSearchText(final List<DistributionSet> withText, final String text) {
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setSearchText(text),
|
||||
withText);
|
||||
}
|
||||
|
||||
@Step
|
||||
private void validateFilterString(final List<DistributionSet> allDistributionSets, final String dsNamePrefix) {
|
||||
private void validateSearchText(final List<DistributionSet> allDistributionSets, final String dsNamePrefix) {
|
||||
|
||||
final List<DistributionSet> withTestNamePrefix = allDistributionSets.stream()
|
||||
.filter(ds -> ds.getName().startsWith(dsNamePrefix)).collect(Collectors.toList());
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setFilterString(dsNamePrefix), withTestNamePrefix);
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setSearchText(dsNamePrefix),
|
||||
withTestNamePrefix);
|
||||
|
||||
final List<DistributionSet> withTestNameExact = withTestNamePrefix.stream()
|
||||
.filter(ds -> ds.getName().equals(dsNamePrefix)).collect(Collectors.toList());
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setFilterString(dsNamePrefix + ":"), withTestNameExact);
|
||||
getDistributionSetFilterBuilder().setSearchText(dsNamePrefix + ":"), withTestNameExact);
|
||||
|
||||
final List<DistributionSet> withTestNameExactAndVersionPrefix = withTestNameExact.stream()
|
||||
.filter(ds -> ds.getVersion().startsWith("1")).collect(Collectors.toList());
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setFilterString(dsNamePrefix + ":1"),
|
||||
getDistributionSetFilterBuilder().setSearchText(dsNamePrefix + ":1"),
|
||||
withTestNameExactAndVersionPrefix);
|
||||
|
||||
final List<DistributionSet> dsWithExactNameAndVersion = withTestNameExactAndVersionPrefix.stream()
|
||||
.filter(ds -> ds.getVersion().equals("1.0.0")).collect(Collectors.toList());
|
||||
assertThat(dsWithExactNameAndVersion).hasSize(1);
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setFilterString(dsNamePrefix + ":1.0.0"), dsWithExactNameAndVersion);
|
||||
getDistributionSetFilterBuilder().setSearchText(dsNamePrefix + ":1.0.0"), dsWithExactNameAndVersion);
|
||||
|
||||
final List<DistributionSet> withVersionPrefix = allDistributionSets.stream()
|
||||
.filter(ds -> ds.getVersion().startsWith("1.0.")).collect(Collectors.toList());
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setFilterString(":1.0."),
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setSearchText(":1.0."),
|
||||
withVersionPrefix);
|
||||
|
||||
final List<DistributionSet> withVersionExact = withVersionPrefix.stream()
|
||||
.filter(ds -> ds.getVersion().equals("1.0.0")).collect(Collectors.toList());
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setFilterString(":1.0.0"),
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setSearchText(":1.0.0"),
|
||||
withVersionExact);
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setFilterString(":"),
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setSearchText(":"),
|
||||
allDistributionSets);
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setFilterString(" : "),
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setSearchText(" : "),
|
||||
allDistributionSets);
|
||||
}
|
||||
|
||||
@@ -864,18 +849,14 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Step
|
||||
private void validateDeletedAndCompletedAndType(final List<DistributionSet> deletedAndCompletedAndStandardType,
|
||||
final DistributionSet dsDeleted, final DistributionSetType newType, final DistributionSet dsNewType) {
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE)
|
||||
.setIsComplete(Boolean.TRUE).setType(standardDsType), deletedAndCompletedAndStandardType);
|
||||
|
||||
.setIsComplete(Boolean.TRUE).setTypeId(standardDsType.getId()), deletedAndCompletedAndStandardType);
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setType(standardDsType).setIsDeleted(Boolean.TRUE), singletonList(dsDeleted));
|
||||
|
||||
.setTypeId(standardDsType.getId()).setIsDeleted(Boolean.TRUE), singletonList(dsDeleted));
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE)
|
||||
.setIsComplete(Boolean.FALSE).setType(standardDsType));
|
||||
|
||||
.setIsComplete(Boolean.FALSE).setTypeId(standardDsType.getId()));
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType),
|
||||
getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setTypeId(newType.getId()),
|
||||
singletonList(dsNewType));
|
||||
}
|
||||
|
||||
@@ -884,21 +865,23 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<DistributionSet> completedAndStandardTypeAndSearchText, final DistributionSetType newType,
|
||||
final String text) {
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setType(standardDsType).setSearchText(text), completedAndStandardTypeAndSearchText);
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE)
|
||||
.setIsComplete(Boolean.TRUE).setTypeId(standardDsType.getId()).setSearchText(text),
|
||||
completedAndStandardTypeAndSearchText);
|
||||
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setIsDeleted(Boolean.TRUE).setType(standardDsType).setSearchText(text));
|
||||
.setIsDeleted(Boolean.TRUE).setTypeId(standardDsType.getId()).setSearchText(text + ":"));
|
||||
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(getDistributionSetFilterBuilder().setType(standardDsType)
|
||||
.setSearchText(text).setIsComplete(Boolean.FALSE).setIsDeleted(Boolean.FALSE));
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(
|
||||
getDistributionSetFilterBuilder().setTypeId(standardDsType.getId()).setSearchText(text)
|
||||
.setIsComplete(Boolean.FALSE).setIsDeleted(Boolean.FALSE));
|
||||
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(getDistributionSetFilterBuilder().setType(newType)
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(getDistributionSetFilterBuilder().setTypeId(newType.getId())
|
||||
.setSearchText(text).setIsComplete(Boolean.TRUE).setIsDeleted(Boolean.FALSE));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void validateDeletedAndCompletedAndTypeAndFilterString(
|
||||
private void validateDeletedAndCompletedAndTypeAndSearchText(
|
||||
final List<DistributionSet> completedAndNotDeletedStandardTypeAndFilterString,
|
||||
final DistributionSet dsDeleted, final DistributionSet dsInComplete, final DistributionSet dsNewType,
|
||||
final DistributionSetType newType, final String filterString) {
|
||||
@@ -907,23 +890,25 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
completedAndNotDeletedStandardTypeAndFilterString);
|
||||
completedAndStandardTypeAndFilterString.add(dsDeleted);
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setType(standardDsType).setFilterString(filterString), completedAndStandardTypeAndFilterString);
|
||||
.setTypeId(standardDsType.getId()).setSearchText(filterString),
|
||||
completedAndStandardTypeAndFilterString);
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setIsDeleted(Boolean.FALSE)
|
||||
.setType(standardDsType).setFilterString(filterString),
|
||||
.setTypeId(standardDsType.getId()).setSearchText(filterString),
|
||||
completedAndNotDeletedStandardTypeAndFilterString);
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setIsDeleted(Boolean.TRUE).setType(standardDsType).setFilterString(filterString),
|
||||
.setIsDeleted(Boolean.TRUE).setTypeId(standardDsType.getId()).setSearchText(filterString),
|
||||
singletonList(dsDeleted));
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setType(standardDsType)
|
||||
.setFilterString(filterString).setIsComplete(Boolean.FALSE).setIsDeleted(Boolean.FALSE),
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setTypeId(standardDsType.getId()).setSearchText(filterString)
|
||||
.setIsComplete(Boolean.FALSE).setIsDeleted(Boolean.FALSE),
|
||||
singletonList(dsInComplete));
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setType(newType)
|
||||
.setFilterString(filterString).setIsComplete(Boolean.TRUE).setIsDeleted(Boolean.FALSE),
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(getDistributionSetFilterBuilder().setTypeId(newType.getId())
|
||||
.setSearchText(filterString).setIsComplete(Boolean.TRUE).setIsDeleted(Boolean.FALSE),
|
||||
singletonList(dsNewType));
|
||||
}
|
||||
|
||||
@@ -933,13 +918,13 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String text) {
|
||||
|
||||
assertThatFilterContainsOnlyGivenDistributionSets(
|
||||
getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(standardDsType)
|
||||
getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setTypeId(standardDsType.getId())
|
||||
.setSearchText(text).setTagNames(singletonList(dsTagA.getName())),
|
||||
completedAndStandartTypeAndSearchTextAndTagA);
|
||||
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(getDistributionSetFilterBuilder().setType(standardDsType)
|
||||
.setSearchText(text).setTagNames(singletonList(dsTagA.getName())).setIsComplete(Boolean.FALSE)
|
||||
.setIsDeleted(Boolean.FALSE));
|
||||
assertThatFilterDoesNotContainAnyDistributionSet(getDistributionSetFilterBuilder()
|
||||
.setTypeId(standardDsType.getId()).setSearchText(text).setTagNames(singletonList(dsTagA.getName()))
|
||||
.setIsComplete(Boolean.FALSE).setIsDeleted(Boolean.FALSE));
|
||||
}
|
||||
|
||||
private DistributionSetFilterBuilder getDistributionSetFilterBuilder() {
|
||||
@@ -983,7 +968,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.delete(ds1.getId());
|
||||
// not assigned so not marked as deleted but fully deleted
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(1);
|
||||
assertThat(distributionSetManagement.findByCompleted(PAGE, true).getTotalElements()).isEqualTo(1);
|
||||
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1027,11 +1012,15 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Page<DistributionSetMetadata> metadataOfDs2 = distributionSetManagement
|
||||
.findMetaDataByDistributionSetId(PageRequest.of(0, 100), ds2.getId());
|
||||
|
||||
assertThat(metadataOfDs1.getNumberOfElements()).isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet());
|
||||
assertThat(metadataOfDs1.getTotalElements()).isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet());
|
||||
assertThat(metadataOfDs1.getNumberOfElements())
|
||||
.isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet());
|
||||
assertThat(metadataOfDs1.getTotalElements())
|
||||
.isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet());
|
||||
|
||||
assertThat(metadataOfDs2.getNumberOfElements()).isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet() - 1);
|
||||
assertThat(metadataOfDs2.getTotalElements()).isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet() - 1);
|
||||
assertThat(metadataOfDs2.getNumberOfElements())
|
||||
.isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet() - 1);
|
||||
assertThat(metadataOfDs2.getTotalElements())
|
||||
.isEqualTo(quotaManagement.getMaxMetaDataEntriesPerDistributionSet() - 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1056,7 +1045,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// not assigned so not marked as deleted
|
||||
assertThat(distributionSetRepository.findAll()).hasSize(4);
|
||||
assertThat(distributionSetManagement.findByCompleted(PAGE, true).getTotalElements()).isEqualTo(2);
|
||||
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1131,7 +1120,7 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
// can be removed with java-11
|
||||
private <T> T getOrThrow(Optional<T> opt) {
|
||||
private <T> T getOrThrow(final Optional<T> opt) {
|
||||
return opt.orElseThrow(NoSuchElementException::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
/**
|
||||
@@ -103,71 +104,43 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagB.getName()).get());
|
||||
toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagC.getName()).get());
|
||||
|
||||
DistributionSetFilterBuilder distributionSetFilterBuilder;
|
||||
|
||||
// search for not deleted
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||
.setTagNames(Arrays.asList(tagA.getName()));
|
||||
assertEquals(dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
||||
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||
.getTotalElements(),
|
||||
"filter works not correct");
|
||||
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||
.setTagNames(Arrays.asList(tagB.getName()));
|
||||
assertEquals(
|
||||
dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
||||
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||
.getTotalElements(),
|
||||
"filter works not correct");
|
||||
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||
.setTagNames(Arrays.asList(tagC.getName()));
|
||||
assertEquals(dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
|
||||
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||
.getTotalElements(),
|
||||
"filter works not correct");
|
||||
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true)
|
||||
.setTagNames(Arrays.asList(tagX.getName()));
|
||||
assertEquals(0, distributionSetManagement
|
||||
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements(),
|
||||
"filter works not correct");
|
||||
|
||||
assertEquals(5, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||
final DistributionSetFilterBuilder distributionSetFilterBuilder = getDistributionSetFilterBuilder()
|
||||
.setIsComplete(true);
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.setTagNames(Arrays.asList(tagA.getName())),
|
||||
Stream.of(dsAs, dsABs, dsACs, dsABCs));
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.setTagNames(Arrays.asList(tagB.getName())),
|
||||
Stream.of(dsBs, dsABs, dsBCs, dsABCs));
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.setTagNames(Arrays.asList(tagC.getName())),
|
||||
Stream.of(dsCs, dsACs, dsBCs, dsABCs));
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.setTagNames(Arrays.asList(tagX.getName())),
|
||||
Stream.empty());
|
||||
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(5);
|
||||
distributionSetTagManagement.delete(tagY.getName());
|
||||
assertEquals(4, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(4);
|
||||
distributionSetTagManagement.delete(tagX.getName());
|
||||
assertEquals(3, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(3);
|
||||
distributionSetTagManagement.delete(tagB.getName());
|
||||
assertEquals(2, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown(), "wrong tag size");
|
||||
assertThat(distributionSetTagRepository.findAll()).hasSize(2);
|
||||
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setTagNames(Arrays.asList(tagA.getName()));
|
||||
assertEquals(dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown()
|
||||
+ dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||
.getTotalElements(),
|
||||
"filter works not correct");
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.setTagNames(Arrays.asList(tagA.getName())),
|
||||
Stream.of(dsAs, dsABs, dsACs, dsABCs));
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.setTagNames(Arrays.asList(tagB.getName())),
|
||||
Stream.empty());
|
||||
verifyExpectedFilteredDistributionSets(distributionSetFilterBuilder.setTagNames(Arrays.asList(tagC.getName())),
|
||||
Stream.of(dsCs, dsACs, dsBCs, dsABCs));
|
||||
}
|
||||
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setTagNames(Arrays.asList(tagB.getName()));
|
||||
assertEquals(0, distributionSetManagement
|
||||
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).getTotalElements(),
|
||||
"filter works not correct");
|
||||
|
||||
distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE)
|
||||
.setTagNames(Arrays.asList(tagC.getName()));
|
||||
assertEquals(dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown()
|
||||
+ dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(),
|
||||
distributionSetManagement.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build())
|
||||
.getTotalElements(),
|
||||
"filter works not correct");
|
||||
@Step
|
||||
private void verifyExpectedFilteredDistributionSets(final DistributionSetFilterBuilder distributionSetFilterBuilder,
|
||||
final Stream<Collection<DistributionSet>> expectedFilteredDistributionSets) {
|
||||
final Collection<Long> retrievedFilteredDsIds = distributionSetManagement
|
||||
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).stream()
|
||||
.map(DistributionSet::getId).collect(Collectors.toList());
|
||||
final Collection<Long> expectedFilteredDsIds = expectedFilteredDistributionSets.flatMap(Collection::stream)
|
||||
.map(DistributionSet::getId).collect(Collectors.toList());
|
||||
assertThat(retrievedFilteredDsIds).hasSameElementsAs(expectedFilteredDsIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,11 +155,11 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
|
||||
// toggle A only -> A is now assigned
|
||||
DistributionSetTagAssignmentResult result = toggleTagAssignment(groupA, tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAlreadyAssigned()).isZero();
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement
|
||||
.get(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassigned()).isZero();
|
||||
assertThat(result.getUnassignedEntity()).isEmpty();
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
@@ -196,14 +169,14 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
assertThat(result.getAssigned()).isEqualTo(20);
|
||||
assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement
|
||||
.get(groupB.stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassigned()).isEqualTo(0);
|
||||
assertThat(result.getUnassigned()).isZero();
|
||||
assertThat(result.getUnassignedEntity()).isEmpty();
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
// toggle A+B -> both unassigned
|
||||
result = toggleTagAssignment(concat(groupA, groupB), tag);
|
||||
assertThat(result.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAlreadyAssigned()).isZero();
|
||||
assertThat(result.getAssigned()).isZero();
|
||||
assertThat(result.getAssignedEntity()).isEmpty();
|
||||
assertThat(result.getUnassigned()).isEqualTo(40);
|
||||
assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.ValidationException;
|
||||
|
||||
@@ -139,8 +140,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that a running action is auto canceled by a rollout which assigns another distribution-set.")
|
||||
void rolloutAssignsNewDistributionSetAndAutoCloseActiveActions() {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(
|
||||
TenantConfigurationKey.REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED, true);
|
||||
tenantConfigurationManagement
|
||||
.addOrUpdateConfiguration(TenantConfigurationKey.REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED, true);
|
||||
|
||||
try {
|
||||
// manually assign distribution set to target
|
||||
@@ -197,9 +198,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = RolloutGroupUpdatedEvent.class, count = 5),
|
||||
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
|
||||
@Expect(type = RolloutCreatedEvent.class, count = 1),
|
||||
@Expect(type = RolloutUpdatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 125)})
|
||||
@Expect(type = RolloutCreatedEvent.class, count = 1), @Expect(type = RolloutUpdatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 125) })
|
||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
testdataFactory.createRollout("xxx");
|
||||
|
||||
@@ -255,7 +255,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
scheduledGroups.forEach(group -> assertThat(group.getStatus())
|
||||
.as("group which should be in scheduled state is in " + group.getStatus() + " state")
|
||||
.isEqualTo(RolloutGroupStatus.SCHEDULED));
|
||||
// verify that the first group actions has been started and are in state running
|
||||
// verify that the first group actions has been started and are in state
|
||||
// running
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
assertThat(runningActions).hasSize(amountTargetsForRollout / amountGroups)
|
||||
.as("Created actions are initiated by rollout creator")
|
||||
@@ -522,8 +523,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
// finish running actions, 2 actions should be finished
|
||||
assertThat(changeStatusForAllRunningActions(createdRollout, Status.FINISHED)).isEqualTo(2);
|
||||
assertThat(getRollout(createdRollout.getId()).getStatus())
|
||||
.isEqualTo(RolloutStatus.RUNNING);
|
||||
assertThat(getRollout(createdRollout.getId()).getStatus()).isEqualTo(RolloutStatus.RUNNING);
|
||||
|
||||
}
|
||||
// check rollout to see that all actions and all groups are finished and
|
||||
@@ -1006,7 +1006,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
changeStatusForAllRunningActions(rolloutD, Status.FINISHED);
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
final Page<Rollout> rolloutPage = rolloutManagement
|
||||
final Slice<Rollout> rolloutPage = rolloutManagement
|
||||
.findAllWithDetailedStatus(new OffsetBasedPageRequest(0, 100, Sort.by(Direction.ASC, "name")), false);
|
||||
final List<Rollout> rolloutList = rolloutPage.getContent();
|
||||
|
||||
@@ -1387,12 +1387,9 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// group1 exceeds the quota
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(() -> rolloutManagement.create(
|
||||
entityFactory.rollout()
|
||||
.create()
|
||||
.name(rolloutName)
|
||||
.description(rolloutName)
|
||||
.targetFilterQuery("controllerId==" + rolloutName + "-*")
|
||||
.set(distributionSet), Arrays.asList(group1, group2), conditions));
|
||||
entityFactory.rollout().create().name(rolloutName).description(rolloutName)
|
||||
.targetFilterQuery("controllerId==" + rolloutName + "-*").set(distributionSet),
|
||||
Arrays.asList(group1, group2), conditions));
|
||||
|
||||
// create group definitions
|
||||
final RolloutGroupCreate group3 = entityFactory.rolloutGroup().create().conditions(conditions).name("group3")
|
||||
@@ -1402,37 +1399,23 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// group4 exceeds the quota
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(() -> rolloutManagement.create(
|
||||
entityFactory.rollout()
|
||||
.create()
|
||||
.name(rolloutName)
|
||||
.description(rolloutName)
|
||||
.targetFilterQuery("controllerId==" + rolloutName + "-*")
|
||||
.set(distributionSet), Arrays.asList(group3, group4), conditions));
|
||||
entityFactory.rollout().create().name(rolloutName).description(rolloutName)
|
||||
.targetFilterQuery("controllerId==" + rolloutName + "-*").set(distributionSet),
|
||||
Arrays.asList(group3, group4), conditions));
|
||||
|
||||
// create group definitions
|
||||
final RolloutGroupCreate group5 = entityFactory.rolloutGroup()
|
||||
.create()
|
||||
.conditions(conditions)
|
||||
.name("group5")
|
||||
final RolloutGroupCreate group5 = entityFactory.rolloutGroup().create().conditions(conditions).name("group5")
|
||||
.targetPercentage(33.3F);
|
||||
final RolloutGroupCreate group6 = entityFactory.rolloutGroup()
|
||||
.create()
|
||||
.conditions(conditions)
|
||||
.name("group6")
|
||||
final RolloutGroupCreate group6 = entityFactory.rolloutGroup().create().conditions(conditions).name("group6")
|
||||
.targetPercentage(66.6F);
|
||||
final RolloutGroupCreate group7 = entityFactory.rolloutGroup()
|
||||
.create()
|
||||
.conditions(conditions)
|
||||
.name("group7")
|
||||
final RolloutGroupCreate group7 = entityFactory.rolloutGroup().create().conditions(conditions).name("group7")
|
||||
.targetPercentage(100.0F);
|
||||
|
||||
// should work fine
|
||||
assertThat(rolloutManagement.create(entityFactory.rollout()
|
||||
.create()
|
||||
.name(rolloutName)
|
||||
.description(rolloutName)
|
||||
.targetFilterQuery("controllerId==" + rolloutName + "-*")
|
||||
.set(distributionSet), Arrays.asList(group5, group6, group7), conditions)).isNotNull();
|
||||
assertThat(rolloutManagement.create(
|
||||
entityFactory.rollout().create().name(rolloutName).description(rolloutName)
|
||||
.targetFilterQuery("controllerId==" + rolloutName + "-*").set(distributionSet),
|
||||
Arrays.asList(group5, group6, group7), conditions)).isNotNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -1603,8 +1586,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
final RolloutCreate rollout = generateTargetsAndRollout(rolloutName, targets);
|
||||
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(
|
||||
() -> rolloutManagement.create(rollout, maxGroups + 1, conditions))
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
||||
.isThrownBy(() -> rolloutManagement.create(rollout, maxGroups + 1, conditions))
|
||||
.withMessageContaining("not be greater than " + maxGroups);
|
||||
|
||||
}
|
||||
@@ -1625,8 +1608,7 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
.errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition)
|
||||
.errorAction(RolloutGroupErrorAction.PAUSE, null).build();
|
||||
final RolloutCreate rolloutToCreate = entityFactory.rollout().create().name(rolloutName)
|
||||
.description("some description").targetFilterQuery("id==" + rolloutName + "-*")
|
||||
.set(distributionSet);
|
||||
.description("some description").targetFilterQuery("id==" + rolloutName + "-*").set(distributionSet);
|
||||
|
||||
Rollout myRollout = rolloutManagement.create(rolloutToCreate, amountGroups, conditions);
|
||||
myRollout = getRollout(myRollout.getId());
|
||||
@@ -1783,8 +1765,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Creating a rollout without weight value when multi assignment in enabled.")
|
||||
void weightNotRequiredInMultiAssignmentMode() {
|
||||
enableMultiAssignments();
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(
|
||||
10, 10, 2, "50", "80", ActionType.FORCED, null);
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 2, "50", "80",
|
||||
ActionType.FORCED, null);
|
||||
assertThat(rollout).isNotNull();
|
||||
}
|
||||
|
||||
@@ -1854,8 +1836,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
void createRolloutWithInvalidDistributionSet() {
|
||||
final DistributionSet distributionSet = testdataFactory.createAndInvalidateDistributionSet();
|
||||
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class).as(
|
||||
"Invalid distributionSet should throw an exception")
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class)
|
||||
.as("Invalid distributionSet should throw an exception")
|
||||
.isThrownBy(() -> testdataFactory.createRolloutByVariables("createRolloutWithInvalidDistributionSet",
|
||||
"desc", 2, "name==*", distributionSet, "50", "80"));
|
||||
}
|
||||
@@ -1865,8 +1847,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
void createRolloutWithIncompleteDistributionSet() {
|
||||
final DistributionSet distributionSet = testdataFactory.createIncompleteDistributionSet();
|
||||
|
||||
assertThatExceptionOfType(IncompleteDistributionSetException.class).as(
|
||||
"Incomplete distributionSet should throw an exception")
|
||||
assertThatExceptionOfType(IncompleteDistributionSetException.class)
|
||||
.as("Incomplete distributionSet should throw an exception")
|
||||
.isThrownBy(() -> testdataFactory.createRolloutByVariables("createRolloutWithIncompleteDistributionSet",
|
||||
"desc", 2, "name==*", distributionSet, "50", "80"));
|
||||
}
|
||||
@@ -1880,10 +1862,9 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
"desc", 2, "name==*", distributionSet, "50", "80");
|
||||
final DistributionSet invalidDistributionSet = testdataFactory.createAndInvalidateDistributionSet();
|
||||
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class).as(
|
||||
"Invalid distributionSet should throw an exception")
|
||||
.isThrownBy(() -> rolloutManagement.update(
|
||||
entityFactory.rollout().update(rollout.getId()).set(invalidDistributionSet.getId())));
|
||||
assertThatExceptionOfType(InvalidDistributionSetException.class)
|
||||
.as("Invalid distributionSet should throw an exception").isThrownBy(() -> rolloutManagement
|
||||
.update(entityFactory.rollout().update(rollout.getId()).set(invalidDistributionSet.getId())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1895,9 +1876,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
"desc", 2, "name==*", distributionSet, "50", "80");
|
||||
final DistributionSet incompleteDistributionSet = testdataFactory.createIncompleteDistributionSet();
|
||||
|
||||
assertThatExceptionOfType(IncompleteDistributionSetException.class).as(
|
||||
"Incomplete distributionSet should throw an exception")
|
||||
.isThrownBy(() -> rolloutManagement.update(
|
||||
assertThatExceptionOfType(IncompleteDistributionSetException.class)
|
||||
.as("Incomplete distributionSet should throw an exception").isThrownBy(() -> rolloutManagement.update(
|
||||
entityFactory.rollout().update(rollout.getId()).set(incompleteDistributionSet.getId())));
|
||||
}
|
||||
|
||||
@@ -1920,11 +1900,8 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
targets.addAll(targetsWithoutType);
|
||||
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
final RolloutCreate rolloutToCreate = entityFactory.rollout()
|
||||
.create()
|
||||
.name(rolloutName)
|
||||
.targetFilterQuery("name==*")
|
||||
.set(testDs);
|
||||
final RolloutCreate rolloutToCreate = entityFactory.rollout().create().name(rolloutName)
|
||||
.targetFilterQuery("name==*").set(testDs);
|
||||
|
||||
final Rollout createdRollout = rolloutManagement.create(rolloutToCreate, 1, conditions);
|
||||
|
||||
@@ -1932,19 +1909,18 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
final Rollout testRollout = reloadRollout(createdRollout);
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(Pageable.unpaged(),
|
||||
testRollout.getId()).getContent();
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement
|
||||
.findByRollout(Pageable.unpaged(), testRollout.getId()).getContent();
|
||||
|
||||
assertThat(testRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||
assertThat(testRollout.getTotalTargets()).isEqualTo(targets.size());
|
||||
assertThat(rolloutGroups).hasSize(1);
|
||||
assertThat(rolloutGroups.get(0).getTotalTargets()).isEqualTo(targets.size());
|
||||
|
||||
final List<Target> rolloutGroupTargets = rolloutGroupManagement.findTargetsOfRolloutGroup(Pageable.unpaged(),
|
||||
rolloutGroups.get(0).getId()).getContent();
|
||||
final List<Target> rolloutGroupTargets = rolloutGroupManagement
|
||||
.findTargetsOfRolloutGroup(Pageable.unpaged(), rolloutGroups.get(0).getId()).getContent();
|
||||
|
||||
assertThat(rolloutGroupTargets).hasSize(targets.size())
|
||||
.containsExactlyInAnyOrderElementsOf(targets)
|
||||
assertThat(rolloutGroupTargets).hasSize(targets.size()).containsExactlyInAnyOrderElementsOf(targets)
|
||||
.doesNotContainAnyElementsOf(incompatibleTargets);
|
||||
}
|
||||
|
||||
@@ -2049,13 +2025,10 @@ class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void awaitRunningState(final Long myRolloutId) {
|
||||
Awaitility.await()
|
||||
.atMost(Duration.TEN_SECONDS)
|
||||
.pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS)
|
||||
.with()
|
||||
.until(() -> WithSpringAuthorityRule.runAsPrivileged(
|
||||
Awaitility.await().atMost(Duration.TEN_SECONDS).pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS).with()
|
||||
.until(() -> WithSpringAuthorityRule
|
||||
.runAsPrivileged(
|
||||
() -> rolloutManagement.get(myRolloutId).orElseThrow(NoSuchElementException::new))
|
||||
.getStatus()
|
||||
.equals(RolloutStatus.RUNNING));
|
||||
.getStatus().equals(RolloutStatus.RUNNING));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +81,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
verifyThrownExceptionBy(
|
||||
() -> softwareModuleManagement
|
||||
.create(Collections
|
||||
.singletonList(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID))),
|
||||
() -> softwareModuleManagement.create(Collections
|
||||
.singletonList(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID))),
|
||||
"SoftwareModuleType");
|
||||
verifyThrownExceptionBy(
|
||||
() -> softwareModuleManagement
|
||||
@@ -195,21 +194,20 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "poky", osType.getId()).getContent()).hasSize(1);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "poky", osType.getId()).getContent().get(0))
|
||||
.isEqualTo(os);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "oracle%", runtimeType.getId()).getContent())
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "oracle", runtimeType.getId()).getContent())
|
||||
.hasSize(1);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "oracle%", runtimeType.getId()).getContent().get(0))
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "oracle", runtimeType.getId()).getContent().get(0))
|
||||
.isEqualTo(jvm);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0.1", appType.getId()).getContent()).hasSize(1);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0.1", appType.getId()).getContent().get(0))
|
||||
.isEqualTo(ah);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0%", appType.getId()).getContent()).hasSize(2);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, ":1.0.1", appType.getId()).getContent()).hasSize(1)
|
||||
.first().isEqualTo(ah);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, ":1.0", appType.getId()).getContent()).hasSize(2);
|
||||
|
||||
// no we search with on entity marked as deleted
|
||||
softwareModuleManagement.delete(
|
||||
softwareModuleRepository.findByAssignedToAndType(PAGE, ds, appType).getContent().get(0).getId());
|
||||
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0%", appType.getId()).getContent()).hasSize(1);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, "1.0%", appType.getId()).getContent().get(0))
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, ":1.0", appType.getId()).getContent()).hasSize(1);
|
||||
assertThat(softwareModuleManagement.findByTextAndType(PAGE, ":1.0", appType.getId()).getContent().get(0))
|
||||
.isEqualTo(ah);
|
||||
}
|
||||
|
||||
@@ -694,7 +692,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// add some meta data entries
|
||||
final SoftwareModule module3 = testdataFactory.createSoftwareModuleApp("m3");
|
||||
final int firstHalf = Math.round(((float) maxMetaData) / 2.f);
|
||||
final int firstHalf = Math.round((maxMetaData) / 2.f);
|
||||
for (int i = 0; i < firstHalf; ++i) {
|
||||
softwareModuleManagement.createMetaData(
|
||||
entityFactory.softwareModuleMetadata().create(module3.getId()).key("k" + i).value("v" + i));
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
@@ -417,26 +418,33 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
final Page<TargetFilterQuery> tfqList = targetFilterQueryManagement
|
||||
.findByAutoAssignDSAndRsql(PageRequest.of(0, 500), distributionSet.getId(), rsql);
|
||||
|
||||
assertThat(tfqList.getTotalElements()).isEqualTo(expectedFilterQueries.length);
|
||||
verifyExpectedFilterQueriesInList(tfqList, expectedFilterQueries);
|
||||
}
|
||||
|
||||
private void verifyExpectedFilterQueriesInList(final Page<TargetFilterQuery> tfqList,
|
||||
private void verifyExpectedFilterQueriesInList(final Slice<TargetFilterQuery> tfqList,
|
||||
final TargetFilterQuery... expectedFilterQueries) {
|
||||
assertThat(expectedFilterQueries.length).as("Target filter query count")
|
||||
.isEqualTo((int) tfqList.getTotalElements());
|
||||
|
||||
assertThat(tfqList.map(TargetFilterQuery::getId)).containsExactly(
|
||||
Arrays.stream(expectedFilterQueries).map(TargetFilterQuery::getId).toArray(Long[]::new));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyFindForAllWithAutoAssignDs(final TargetFilterQuery... expectedFilterQueries) {
|
||||
final Page<TargetFilterQuery> tfqList = targetFilterQueryManagement
|
||||
final Slice<TargetFilterQuery> tfqList = targetFilterQueryManagement
|
||||
.findWithAutoAssignDS(PageRequest.of(0, 500));
|
||||
|
||||
assertThat(tfqList.getNumberOfElements()).isEqualTo(expectedFilterQueries.length);
|
||||
verifyExpectedFilterQueriesInList(tfqList, expectedFilterQueries);
|
||||
}
|
||||
|
||||
private void verifyExpectedFilterQueriesInList(final Page<TargetFilterQuery> tfqList,
|
||||
final TargetFilterQuery... expectedFilterQueries) {
|
||||
assertThat(expectedFilterQueries).as("Target filter query count").hasSize((int) tfqList.getTotalElements());
|
||||
|
||||
assertThat(tfqList.map(TargetFilterQuery::getId)).containsExactly(
|
||||
Arrays.stream(expectedFilterQueries).map(TargetFilterQuery::getId).toArray(Long[]::new));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Creating or updating a target filter query with autoassignment and no-value weight when multi assignment in enabled.")
|
||||
public void weightNotRequiredInMultiAssignmentMode() {
|
||||
|
||||
@@ -15,13 +15,10 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.UpdateMode;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -110,19 +107,6 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
final String installedC = targCs.iterator().next().getControllerId();
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(installedSet.getId(), assignedC));
|
||||
|
||||
// add attributes to match against only attribute value or attribute
|
||||
// value and name
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
attributes.put("key", "targ-C-attribute-value");
|
||||
final Target targAttribute = controllerManagement.updateControllerAttributes(targCs.get(0).getControllerId(),
|
||||
attributes, UpdateMode.REPLACE);
|
||||
// prepare one target with an attribute value equal to controller id
|
||||
Target targAttributeId = targCs.get(15);
|
||||
final Map<String, String> idAttributes = new HashMap<>();
|
||||
idAttributes.put("key", targAttributeId.getControllerId());
|
||||
targAttributeId = controllerManagement.updateControllerAttributes(targAttributeId.getControllerId(),
|
||||
idAttributes, UpdateMode.REPLACE);
|
||||
|
||||
// set one installed DS also
|
||||
controllerManagement.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(actionId).status(Status.FINISHED).message("message"));
|
||||
@@ -142,9 +126,6 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// try to find several targets with different filter settings
|
||||
verifyThat1TargetHasNameAndId("targ-A-special", targSpecialName.getControllerId());
|
||||
verifyThat1TargetHasAttributeValue("%c-attribute%", targAttribute.getControllerId());
|
||||
verifyThat1TargetHasAttributeValue("%" + targAttributeId.getControllerId() + "%",
|
||||
targAttributeId.getControllerId());
|
||||
verifyThatRepositoryContains500Targets();
|
||||
verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs);
|
||||
@@ -183,8 +164,10 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
verifyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
|
||||
targetManagement.getByControllerID(installedC).get());
|
||||
verifyThat1TargetHasTypeAndDSAssigned(targetTypeX, setB, targetManagement.getByControllerID(assignedE).get());
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(setA, targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(installedSet, targetManagement.getByControllerID(Collections.singletonList(installedC)));
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(setA,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(installedSet,
|
||||
targetManagement.getByControllerID(Collections.singletonList(installedC)));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTypeAssigned(targetTypeX, targEs);
|
||||
verifyThat400TargetsContainsGivenTextAndHaveNoTypeAssigned(concat(targAs, targBs, targCs, targDs));
|
||||
|
||||
@@ -481,14 +464,6 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countByFilters(filterParamsByControllerId)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat1TargetHasAttributeValue(final String value, final String controllerId) {
|
||||
final FilterParams filterParams = new FilterParams(null, null, value, null, Boolean.FALSE);
|
||||
assertThat(targetManagement.findByFilters(PAGE, filterParams).getContent()).as("has number of elements")
|
||||
.hasSize(1).as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countByFilters(filterParams)));
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(final TargetTag targTagY,
|
||||
final TargetTag targTagW, final List<Target> expected) {
|
||||
@@ -544,7 +519,8 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(final DistributionSet set, final List<Target> expected) {
|
||||
private void verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(final DistributionSet set,
|
||||
final List<Target> expected) {
|
||||
final FilterParams filterParams = new FilterParams(null, set.getId(), Boolean.TRUE, null);
|
||||
assertThat(targetManagement.findByFilters(PAGE, filterParams).getContent()).as("has number of elements")
|
||||
.hasSize(expected.size()).as("that number is also returned by count query")
|
||||
@@ -556,11 +532,12 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
private void verifyThat100TargetsContainsGivenTextAndHaveTypeAssigned(final TargetType targetType,
|
||||
final List<Target> expected) {
|
||||
final FilterParams filterParams = new FilterParams("%targ-E%", null, Boolean.FALSE, targetType.getId());
|
||||
List<Target> filteredTargets = targetManagement.findByFilters(PAGE, filterParams).getContent();
|
||||
final List<Target> filteredTargets = targetManagement.findByFilters(PAGE, filterParams).getContent();
|
||||
assertThat(filteredTargets).as("has number of elements").hasSize(100)
|
||||
.as("that number is also returned by count query")
|
||||
.hasSize(Ints.saturatedCast(targetManagement.countByFilters(filterParams)));
|
||||
// Comparing the controller ids, as one of the targets was modified, so a 1:1
|
||||
// Comparing the controller ids, as one of the targets was modified, so
|
||||
// a 1:1
|
||||
// comparison of the objects is not possible
|
||||
assertThat(filteredTargets.stream().map(Target::getControllerId).collect(Collectors.toList()))
|
||||
.containsAll(expected.stream().map(Target::getControllerId).collect(Collectors.toList()));
|
||||
@@ -787,19 +764,18 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verifies that targets with given target type are returned from repository.")
|
||||
public void findTargetByTargetType() {
|
||||
TargetType testType = testdataFactory.createTargetType("testType", Collections.singletonList(standardDsType));
|
||||
List<Target> unassigned = testdataFactory.createTargets(9, "unassigned");
|
||||
List<Target> assigned = testdataFactory.createTargetsWithType(11, "assigned", testType);
|
||||
final TargetType testType = testdataFactory.createTargetType("testType",
|
||||
Collections.singletonList(standardDsType));
|
||||
final List<Target> unassigned = testdataFactory.createTargets(9, "unassigned");
|
||||
final List<Target> assigned = testdataFactory.createTargetsWithType(11, "assigned", testType);
|
||||
|
||||
assertThat(targetManagement.findByFilters(PAGE,
|
||||
new FilterParams(null,null, false, testType.getId())))
|
||||
assertThat(targetManagement.findByFilters(PAGE, new FilterParams(null, null, false, testType.getId())))
|
||||
.as("Contains the targets with set type").containsAll(assigned)
|
||||
.as("and that means the following expected amount").hasSize(11);
|
||||
assertThat(targetManagement.countByFilters(new FilterParams(null,null, false, testType.getId())))
|
||||
assertThat(targetManagement.countByFilters(new FilterParams(null, null, false, testType.getId())))
|
||||
.as("Count the targets with set type").isEqualTo(11);
|
||||
|
||||
assertThat(targetManagement.findByFilters(PAGE,
|
||||
new FilterParams(null, null, true, null)))
|
||||
assertThat(targetManagement.findByFilters(PAGE, new FilterParams(null, null, true, null)))
|
||||
.as("Contains the targets without a type").containsAll(unassigned)
|
||||
.as("and that means the following expected amount").hasSize(9);
|
||||
assertThat(targetManagement.countByFilters(new FilterParams(null, null, true, null)))
|
||||
|
||||
@@ -69,6 +69,7 @@ import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@@ -160,10 +161,9 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
verifyThrownExceptionBy(() -> targetManagement.deleteMetaData(target.getControllerId(), NOT_EXIST_ID),
|
||||
"TargetMetadata");
|
||||
verifyThrownExceptionBy(() -> targetManagement.getMetaDataByControllerId(NOT_EXIST_ID, "xxx"), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.findMetaDataByControllerId(PAGE, NOT_EXIST_ID),
|
||||
verifyThrownExceptionBy(() -> targetManagement.findMetaDataByControllerId(PAGE, NOT_EXIST_ID), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.findMetaDataByControllerIdAndRsql(PAGE, NOT_EXIST_ID, "key==*"),
|
||||
"Target");
|
||||
verifyThrownExceptionBy(
|
||||
() -> targetManagement.findMetaDataByControllerIdAndRsql(PAGE, NOT_EXIST_ID, "key==*"), "Target");
|
||||
verifyThrownExceptionBy(
|
||||
() -> targetManagement.updateMetadata(NOT_EXIST_ID, entityFactory.generateTargetMetadata("xxx", "xxx")),
|
||||
"Target");
|
||||
@@ -222,8 +222,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Verify that a target with with invalid properties cannot be created or updated")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetUpdatedEvent.class) })
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class) })
|
||||
void createAndUpdateTargetWithInvalidFields() {
|
||||
final Target target = testdataFactory.createTarget();
|
||||
|
||||
@@ -243,8 +242,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.description(RandomStringUtils.randomAlphanumeric(513))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be created")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.as("target with invalid description should not be created").isThrownBy(() -> targetManagement
|
||||
.create(entityFactory.target().create().controllerId("a").description(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
@@ -253,9 +251,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.description(RandomStringUtils.randomAlphanumeric(513))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be updated")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.update(entityFactory.target().update(target.getControllerId()).description(INVALID_TEXT_HTML)));
|
||||
.as("target with invalid description should not be updated").isThrownBy(() -> targetManagement.update(
|
||||
entityFactory.target().update(target.getControllerId()).description(INVALID_TEXT_HTML)));
|
||||
}
|
||||
|
||||
@Step
|
||||
@@ -267,8 +264,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be created")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.as("target with invalid name should not be created").isThrownBy(() -> targetManagement
|
||||
.create(entityFactory.target().create().controllerId("a").name(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
@@ -277,14 +273,12 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be updated")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.as("target with invalid name should not be updated").isThrownBy(() -> targetManagement
|
||||
.update(entityFactory.target().update(target.getControllerId()).name(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too short name should not be updated")
|
||||
.isThrownBy(
|
||||
() -> targetManagement.update(entityFactory.target().update(target.getControllerId()).name("")));
|
||||
.as("target with too short name should not be updated").isThrownBy(() -> targetManagement
|
||||
.update(entityFactory.target().update(target.getControllerId()).name("")));
|
||||
|
||||
}
|
||||
|
||||
@@ -297,8 +291,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.securityToken(RandomStringUtils.randomAlphanumeric(Target.SECURITY_TOKEN_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be created")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.as("target with invalid token should not be created").isThrownBy(() -> targetManagement
|
||||
.create(entityFactory.target().create().controllerId("a").securityToken(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
@@ -307,13 +300,11 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.securityToken(RandomStringUtils.randomAlphanumeric(Target.SECURITY_TOKEN_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(
|
||||
.as("target with invalid token should not be updated").isThrownBy(() -> targetManagement.update(
|
||||
entityFactory.target().update(target.getControllerId()).securityToken(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too short token should not be updated")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.as("target with too short token should not be updated").isThrownBy(() -> targetManagement
|
||||
.update(entityFactory.target().update(target.getControllerId()).securityToken("")));
|
||||
}
|
||||
|
||||
@@ -325,8 +316,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a")
|
||||
.address(RandomStringUtils.randomAlphanumeric(513))));
|
||||
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class)
|
||||
.as("target with invalid should not be created")
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class).as("target with invalid should not be created")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.create(entityFactory.target().create().controllerId("a").address(INVALID_TEXT_HTML)));
|
||||
|
||||
@@ -336,8 +326,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.address(RandomStringUtils.randomAlphanumeric(513))));
|
||||
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class)
|
||||
.as("target with invalid address should not be updated")
|
||||
.isThrownBy(() -> targetManagement
|
||||
.as("target with invalid address should not be updated").isThrownBy(() -> targetManagement
|
||||
.update(entityFactory.target().update(target.getControllerId()).address(INVALID_TEXT_HTML)));
|
||||
}
|
||||
|
||||
@@ -357,24 +346,19 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.controllerId(RandomStringUtils.randomAlphanumeric(Target.CONTROLLER_ID_MAX_SIZE + 1))));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid controller id should not be created")
|
||||
.isThrownBy(
|
||||
.as("target with invalid controller id should not be created").isThrownBy(
|
||||
() -> targetManagement.create(entityFactory.target().create().controllerId(INVALID_TEXT_HTML)));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as(WHITESPACE_ERROR)
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId(" ")));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as(WHITESPACE_ERROR)
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a b")));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as(WHITESPACE_ERROR)
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId(" ")));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as(WHITESPACE_ERROR)
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("aaa bbb")));
|
||||
|
||||
}
|
||||
@@ -402,7 +386,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignedTargets.forEach(target -> assertThat(
|
||||
targetTagManagement.findByTarget(PAGE, target.getControllerId()).getNumberOfElements()).isEqualTo(1));
|
||||
|
||||
TargetTag findTargetTag = targetTagManagement.getByName("Tag1").orElseThrow(IllegalStateException::new);
|
||||
final TargetTag findTargetTag = targetTagManagement.getByName("Tag1").orElseThrow(IllegalStateException::new);
|
||||
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
|
||||
.isEqualTo(targetManagement.findByTag(PAGE, targetTag.getId()).getNumberOfElements());
|
||||
|
||||
@@ -473,20 +457,15 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet testDs2 = testdataFactory.createDistributionSet("test2");
|
||||
|
||||
assertThat(targetManagement.countByAssignedDistributionSet(testDs1.getId()))
|
||||
.as("For newly created distributions sets the assigned target count should be zero")
|
||||
.isZero();
|
||||
.as("For newly created distributions sets the assigned target count should be zero").isZero();
|
||||
assertThat(targetManagement.countByInstalledDistributionSet(testDs1.getId()))
|
||||
.as("For newly created distributions sets the installed target count should be zero")
|
||||
.isZero();
|
||||
.as("For newly created distributions sets the installed target count should be zero").isZero();
|
||||
assertThat(targetManagement.existsByInstalledOrAssignedDistributionSet(testDs1.getId()))
|
||||
.as("Exists assigned or installed query should return false for new distribution sets")
|
||||
.isFalse();
|
||||
.as("Exists assigned or installed query should return false for new distribution sets").isFalse();
|
||||
assertThat(targetManagement.countByAssignedDistributionSet(testDs2.getId()))
|
||||
.as("For newly created distributions sets the assigned target count should be zero")
|
||||
.isZero();
|
||||
.as("For newly created distributions sets the assigned target count should be zero").isZero();
|
||||
assertThat(targetManagement.countByInstalledDistributionSet(testDs2.getId()))
|
||||
.as("For newly created distributions sets the installed target count should be zero")
|
||||
.isZero();
|
||||
.as("For newly created distributions sets the installed target count should be zero").isZero();
|
||||
assertThat(targetManagement.existsByInstalledOrAssignedDistributionSet(testDs2.getId()))
|
||||
.as("For newly created distributions sets the assigned target count should be zero").isFalse();
|
||||
|
||||
@@ -508,8 +487,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isZero();
|
||||
assertThat(targetManagement.countByInstalledDistributionSet(testDs1.getId())).as("Target count is wrong")
|
||||
.isEqualTo(1);
|
||||
assertThat(targetManagement.existsByInstalledOrAssignedDistributionSet(testDs1.getId())).as("Target count is wrong")
|
||||
.isTrue();
|
||||
assertThat(targetManagement.existsByInstalledOrAssignedDistributionSet(testDs1.getId()))
|
||||
.as("Target count is wrong").isTrue();
|
||||
assertThat(targetManagement.countByAssignedDistributionSet(testDs2.getId())).as("Target count is wrong")
|
||||
.isEqualTo(1);
|
||||
assertThat(targetManagement.countByInstalledDistributionSet(testDs2.getId())).as("Target count is wrong")
|
||||
@@ -520,14 +499,11 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final DistributionSet assignedDs = deploymentManagement.getAssignedDistributionSet("4711")
|
||||
.orElseThrow(NoSuchElementException::new);
|
||||
assertThat(assignedDs).as("Assigned ds size is wrong")
|
||||
.isEqualTo(testDs2);
|
||||
assertThat(assignedDs).as("Assigned ds size is wrong").isEqualTo(testDs2);
|
||||
|
||||
final DistributionSet installedDs = deploymentManagement.getInstalledDistributionSet("4711")
|
||||
.orElseThrow(NoSuchElementException::new);
|
||||
assertThat(installedDs)
|
||||
.as("Installed ds is wrong")
|
||||
.isEqualTo(testDs1);
|
||||
assertThat(installedDs).as("Installed ds is wrong").isEqualTo(testDs1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -556,14 +532,14 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* verifies, that all {@link TargetTag} of parameter. NOTE: it's accepted that
|
||||
* the target have additional tags assigned to them which are not contained
|
||||
* within parameter tags.
|
||||
* verifies, that all {@link TargetTag} of parameter. NOTE: it's accepted
|
||||
* that the target have additional tags assigned to them which are not
|
||||
* contained within parameter tags.
|
||||
*
|
||||
* @param strict
|
||||
* if true, the given targets MUST contain EXACTLY ALL given tags,
|
||||
* AND NO OTHERS. If false, the given targets MUST contain ALL given
|
||||
* tags, BUT MAY CONTAIN FURTHER ONE
|
||||
* if true, the given targets MUST contain EXACTLY ALL given
|
||||
* tags, AND NO OTHERS. If false, the given targets MUST contain
|
||||
* ALL given tags, BUT MAY CONTAIN FURTHER ONE
|
||||
* @param targets
|
||||
* targets to be verified
|
||||
* @param tags
|
||||
@@ -615,7 +591,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(createdAt).as("CreatedAt compared with modifiedAt").isEqualTo(modifiedAt);
|
||||
|
||||
Awaitility.await().until( () -> System.currentTimeMillis() > createdAt + 1);
|
||||
Awaitility.await().until(() -> System.currentTimeMillis() > createdAt + 1);
|
||||
|
||||
savedTarget = targetManagement.update(
|
||||
entityFactory.target().update(savedTarget.getControllerId()).description("changed description"));
|
||||
@@ -625,7 +601,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
modifiedAt = savedTarget.getLastModifiedAt();
|
||||
|
||||
final Target foundTarget = targetManagement.getByControllerID(savedTarget.getControllerId()).orElseThrow(IllegalStateException::new);
|
||||
final Target foundTarget = targetManagement.getByControllerID(savedTarget.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(foundTarget).as("The target should not be null").isNotNull();
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
|
||||
.isEqualTo(foundTarget.getControllerId());
|
||||
@@ -718,13 +695,15 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<TargetTag> t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2");
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Collections.singletonList(t2.getControllerId()), tag.getId()));
|
||||
|
||||
final Target t11 = targetManagement.getByControllerID(t1.getControllerId()).orElseThrow(IllegalStateException::new);
|
||||
final Target t11 = targetManagement.getByControllerID(t1.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class));
|
||||
|
||||
final Target t21 = targetManagement.getByControllerID(t2.getControllerId()).orElseThrow(IllegalStateException::new);
|
||||
final Target t21 = targetManagement.getByControllerID(t2.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).containsAll(t2Tags);
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong")
|
||||
@@ -909,10 +888,12 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
testdataFactory.createTargets(25, "target-id-B", "first description");
|
||||
|
||||
final Page<Target> foundTargets = targetManagement.findByRsql(PAGE, rsqlFilter);
|
||||
final Slice<Target> foundTargets = targetManagement.findByRsql(PAGE, rsqlFilter);
|
||||
final long foundTargetsCount = targetManagement.countByRsql(rsqlFilter);
|
||||
|
||||
assertThat(targetManagement.count()).as("Total targets").isEqualTo(50L);
|
||||
assertThat(foundTargets.getTotalElements()).as("Targets in RSQL filter").isEqualTo(27L);
|
||||
assertThat(foundTargets.getNumberOfElements()).as("Targets in RSQL filter").isEqualTo(foundTargetsCount)
|
||||
.isEqualTo(27L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1033,11 +1014,12 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// create target meta data entry
|
||||
insertTargetMetadata(knownKey, knownValue, target);
|
||||
|
||||
Target changedLockRevisionTarget = targetManagement.get(target.getId()).orElseThrow(NoSuchElementException::new);
|
||||
Target changedLockRevisionTarget = targetManagement.get(target.getId())
|
||||
.orElseThrow(NoSuchElementException::new);
|
||||
assertThat(changedLockRevisionTarget.getOptLockRevision()).isEqualTo(2);
|
||||
|
||||
// Unsure if needed maybe to wait for a db flush?
|
||||
// Thread.sleep(100);
|
||||
// Thread.sleep(100);
|
||||
|
||||
// update the target metadata
|
||||
final JpaTargetMetadata updated = (JpaTargetMetadata) targetManagement.updateMetadata(target.getControllerId(),
|
||||
@@ -1117,7 +1099,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(targetFound1.get().getTargetType().getId()).isEqualTo(targetType.getId());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@WithUser(allSpPermissions = true)
|
||||
@Description("Tests the assignment of types to multiple targets.")
|
||||
@@ -1150,7 +1132,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
checkTargetsHaveType(typeATargets, typeA);
|
||||
checkTargetsHaveType(typeBTargets, typeB);
|
||||
|
||||
// verify that type assignment does not throw an error if target list includes an unknown id
|
||||
// verify that type assignment does not throw an error if target list
|
||||
// includes an unknown id
|
||||
targetManagement.deleteByControllerID(typeATargets.get(0).getControllerId());
|
||||
final TargetTypeAssignmentResult resultC = initiateTypeAssignment(typeATargets, typeB);
|
||||
assertThat(resultC.getAssigned()).isEqualTo(9);
|
||||
@@ -1159,7 +1142,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void checkTargetsHaveType(final List<Target> targets, final TargetType type) {
|
||||
List<JpaTarget> foundTargets = targetRepository
|
||||
final List<JpaTarget> foundTargets = targetRepository
|
||||
.findAllById(targets.stream().map(Identifiable::getId).collect(Collectors.toList()));
|
||||
for (final Target target : foundTargets) {
|
||||
if (!type.getName().equals(type.getName())) {
|
||||
@@ -1167,7 +1150,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Description("Queries and loads the metadata related to a given target.")
|
||||
void findAllTargetMetadataByControllerId() {
|
||||
@@ -1205,14 +1188,13 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// create a target
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget");
|
||||
// initial opt lock revision must be one
|
||||
Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound).isPresent();
|
||||
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(targetFound.get().getTargetType()).isNull();
|
||||
|
||||
// assign target type to target
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target type with id=null cannot be assigned")
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as("target type with id=null cannot be assigned")
|
||||
.isThrownBy(() -> targetManagement.assignType(targetFound.get().getControllerId(), null));
|
||||
|
||||
assertThatExceptionOfType(EntityNotFoundException.class)
|
||||
@@ -1220,7 +1202,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isThrownBy(() -> targetManagement.assignType(targetFound.get().getControllerId(), 114L));
|
||||
|
||||
// opt lock revision is not changed
|
||||
Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
|
||||
final Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound1).isPresent();
|
||||
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(1);
|
||||
}
|
||||
@@ -1230,12 +1212,12 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Checks that target type can be unassigned from target.")
|
||||
void unAssignTargetTypeFromTarget() {
|
||||
// create a target type
|
||||
TargetType targetType = testdataFactory.findOrCreateTargetType("targettype");
|
||||
final TargetType targetType = testdataFactory.findOrCreateTargetType("targettype");
|
||||
assertThat(targetType).isNotNull();
|
||||
// create a target
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetType.getId());
|
||||
// initial opt lock revision must be one
|
||||
Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound).isPresent();
|
||||
assertThat(targetFound.get().getOptLockRevision()).isEqualTo(1);
|
||||
assertThat(targetFound.get().getTargetType().getName()).isEqualTo(targetType.getName());
|
||||
@@ -1244,7 +1226,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.unAssignType(targetFound.get().getControllerId());
|
||||
|
||||
// opt lock revision must be changed
|
||||
Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
|
||||
final Optional<JpaTarget> targetFound1 = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound1).isPresent();
|
||||
assertThat(targetFound1.get().getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(targetFound1.get().getTargetType()).isNull();
|
||||
@@ -1275,9 +1257,11 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void validateFoundTargetsByRsql(final String rsqlFilter, final String... controllerIds) {
|
||||
final Page<Target> foundTargetsByMetadataAndControllerId = targetManagement.findByRsql(PAGE, rsqlFilter);
|
||||
final Slice<Target> foundTargetsByMetadataAndControllerId = targetManagement.findByRsql(PAGE, rsqlFilter);
|
||||
final long foundTargetsByMetadataAndControllerIdCount = targetManagement.countByRsql(rsqlFilter);
|
||||
|
||||
assertThat(foundTargetsByMetadataAndControllerId.getTotalElements()).as("Targets count in RSQL filter is wrong")
|
||||
assertThat(foundTargetsByMetadataAndControllerId.getNumberOfElements())
|
||||
.as("Targets count in RSQL filter is wrong").isEqualTo(foundTargetsByMetadataAndControllerIdCount)
|
||||
.isEqualTo(controllerIds.length);
|
||||
assertThat(foundTargetsByMetadataAndControllerId.getContent().stream().map(Target::getControllerId))
|
||||
.as("Targets found by RSQL filter have wrong controller ids").containsExactlyInAnyOrder(controllerIds);
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
@@ -88,8 +88,10 @@ class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
|
||||
targetType1 = targetTypeManagement.create(entityFactory.targetType().create().name("Type1").description("Desc. Type1"));
|
||||
targetType2 = targetTypeManagement.create(entityFactory.targetType().create().name("Type2").description("Desc. Type2"));
|
||||
targetType1 = targetTypeManagement
|
||||
.create(entityFactory.targetType().create().name("Type1").description("Desc. Type1"));
|
||||
targetType2 = targetTypeManagement
|
||||
.create(entityFactory.targetType().create().name("Type2").description("Desc. Type2"));
|
||||
|
||||
targetManagement.assignType(target.getControllerId(), targetType1.getId());
|
||||
targetManagement.assignType(target2.getControllerId(), targetType2.getId());
|
||||
@@ -317,10 +319,10 @@ class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedTargets) {
|
||||
final Page<Target> findTargetPage = targetManagement.findByRsql(PAGE, rsqlParam);
|
||||
final long countTargetsAll = findTargetPage.getTotalElements();
|
||||
final Slice<Target> findTargetPage = targetManagement.findByRsql(PAGE, rsqlParam);
|
||||
final long countTargetsAll = targetManagement.countByRsql(rsqlParam);
|
||||
assertThat(findTargetPage).isNotNull();
|
||||
assertThat(countTargetsAll).isEqualTo(expectedTargets);
|
||||
assertThat(findTargetPage.getNumberOfElements()).isEqualTo(countTargetsAll).isEqualTo(expectedTargets);
|
||||
}
|
||||
|
||||
private void assertRSQLQueryThrowsException(final String rsqlParam) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithSpringAuthorityRule;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
@@ -155,11 +154,11 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
createDistributionSetForTenant(anotherTenant);
|
||||
|
||||
// ensure both tenants see their distribution sets
|
||||
final Page<DistributionSet> findDistributionSetsForTenant = findDistributionSetForTenant(tenant);
|
||||
final Slice<DistributionSet> findDistributionSetsForTenant = findDistributionSetForTenant(tenant);
|
||||
assertThat(findDistributionSetsForTenant).hasSize(1);
|
||||
assertThat(findDistributionSetsForTenant.getContent().get(0).getTenant().toUpperCase())
|
||||
.isEqualTo(tenant.toUpperCase());
|
||||
final Page<DistributionSet> findDistributionSetsForAnotherTenant = findDistributionSetForTenant(anotherTenant);
|
||||
final Slice<DistributionSet> findDistributionSetsForAnotherTenant = findDistributionSetForTenant(anotherTenant);
|
||||
assertThat(findDistributionSetsForAnotherTenant).hasSize(1);
|
||||
assertThat(findDistributionSetsForAnotherTenant.getContent().get(0).getTenant().toUpperCase())
|
||||
.isEqualTo(anotherTenant.toUpperCase());
|
||||
@@ -188,7 +187,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
return runAsTenant(tenant, () -> testdataFactory.createDistributionSet());
|
||||
}
|
||||
|
||||
private Page<DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
|
||||
private Slice<DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
|
||||
return runAsTenant(tenant, () -> distributionSetManagement.findByCompleted(PAGE, true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user