1818import org .eclipse .hawkbit .repository .DistributionSetManagement ;
1919import org .eclipse .hawkbit .repository .TargetFilterQueryManagement ;
2020import org .eclipse .hawkbit .repository .jpa .AbstractJpaIntegrationTest ;
21+ import org .eclipse .hawkbit .repository .jpa .Jpa ;
2122import org .eclipse .hawkbit .repository .model .Action .ActionStatusCreate ;
2223import org .eclipse .hawkbit .repository .model .Action .Status ;
2324import org .eclipse .hawkbit .repository .model .DistributionSet ;
@@ -149,4 +150,30 @@ void shouldNotFindTargetsIncompatibleWithDS() {
149150 .containsExactlyInAnyOrderElementsOf (testTargets ).as ("does not contain incompatible targets" )
150151 .doesNotContainAnyElementsOf (targetsWithIncompatibleType );
151152 }
153+
154+ @ Test
155+ void shouldFindTargetsWithoutTypeByTypeIdNot () {
156+ final DistributionSet testDs = testdataFactory .createDistributionSet ();
157+ final TargetType targetType = testdataFactory .createTargetType ("testType" , Set .of (testDs .getType ()));
158+ final TargetType targetType2 = testdataFactory .createTargetType ("testType_other" , Set .of (testDs .getType ()));
159+ final TargetFilterQuery tfq = targetFilterQueryManagement
160+ .create (TargetFilterQueryManagement .Create .builder ()
161+ .name ("test-not-filter" ).query ("type.id=not=" + targetType2 .getId ()).build ());
162+ final List <Target > targets = testdataFactory .createTargets (20 , "withOutType" );
163+ final List <Target > targetWithCompatibleTypes = testdataFactory .createTargetsWithType (20 , "compatible" , targetType );
164+
165+ final List <Target > result = targetManagement
166+ .findByTargetFilterQueryAndNonDSAndCompatibleAndUpdatable (testDs .getId (), tfq .getQuery (), PAGE ).getContent ();
167+
168+ // EclipseLink has problems with tenancy - https://github.com/eclipse-hawkbit/hawkbit/issues/2758
169+ if (Jpa .JPA_VENDOR == Jpa .JpaVendor .ECLIPSELINK ) {
170+ assertThat (result )
171+ .as ("count of targets" ).hasSize (targetWithCompatibleTypes .size ())
172+ .as ("contains only targets with type" ).containsAll (targetWithCompatibleTypes ).doesNotContainAnyElementsOf (targets );
173+ } else {
174+ assertThat (result )
175+ .as ("count of targets" ).hasSize (targets .size () + targetWithCompatibleTypes .size ())
176+ .as ("contains all targets" ).containsAll (targetWithCompatibleTypes ).containsAll (targets );
177+ }
178+ }
152179}
0 commit comments