diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementSearchTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementSearchTest.java index 7b289cfd1..1cb0fa3ef 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementSearchTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/TargetManagementSearchTest.java @@ -18,6 +18,7 @@ import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.Jpa; import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -149,4 +150,30 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest { .containsExactlyInAnyOrderElementsOf(testTargets).as("does not contain incompatible targets") .doesNotContainAnyElementsOf(targetsWithIncompatibleType); } + + @Test + void shouldFindTargetsWithoutTypeByTypeIdNot() { + final DistributionSet testDs = testdataFactory.createDistributionSet(); + final TargetType targetType = testdataFactory.createTargetType("testType", Set.of(testDs.getType())); + final TargetType targetType2 = testdataFactory.createTargetType("testType_other", Set.of(testDs.getType())); + final TargetFilterQuery tfq = targetFilterQueryManagement + .create(TargetFilterQueryManagement.Create.builder() + .name("test-not-filter").query("type.id=not=" + targetType2.getId()).build()); + final List targets = testdataFactory.createTargets(20, "withOutType"); + final List targetWithCompatibleTypes = testdataFactory.createTargetsWithType(20, "compatible", targetType); + + final List result = targetManagement + .findByTargetFilterQueryAndNonDSAndCompatibleAndUpdatable(testDs.getId(), tfq.getQuery(), PAGE).getContent(); + + // EclipseLink has problems with tenancy - https://github.com/eclipse-hawkbit/hawkbit/issues/2758 + if (Jpa.JPA_VENDOR == Jpa.JpaVendor.ECLIPSELINK) { + assertThat(result) + .as("count of targets").hasSize(targetWithCompatibleTypes.size()) + .as("contains only targets with type").containsAll(targetWithCompatibleTypes).doesNotContainAnyElementsOf(targets); + } else { + assertThat(result) + .as("count of targets").hasSize(targets.size() + targetWithCompatibleTypes.size()) + .as("contains all targets").containsAll(targetWithCompatibleTypes).containsAll(targets); + } + } } \ No newline at end of file