Skip to content
Snippets Groups Projects
Commit bc99ed6e authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6867 OZG-6900 Implement findAllByOrganisationsEinheitId in repository

parent 0668b9ec
Branches
Tags
No related merge requests found
......@@ -28,6 +28,7 @@ import java.util.Optional;
import org.springframework.data.mongodb.core.query.TextCriteria;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
......@@ -54,4 +55,9 @@ interface OrganisationsEinheitRepository extends MongoRepository<OrganisationsEi
default TextCriteria buildTextCriteria(String text) {
return TextCriteria.forDefaultLanguage().matching(text);
}
@Query("{ 'xzufiId._id': ?0 }")
List<OrganisationsEinheit> findByOrganisationsEinheitId(String organisationsEinheitId);
}
......@@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
......@@ -241,4 +242,37 @@ class OrganisationsEinheitRepositoryITCase {
.containsExactly(organisationsEinheit1, organisationsEinheit3, organisationsEinheit2);
}
}
@Nested
class TestFindByOrganisationsEinheitId {
public static final String ORGANISATIONS_EINHEIT_ID = OrganisationsEinheitTestFactory.XZUFI_ID.getId();
private final OrganisationsEinheit organisationsEinheit1 = OrganisationsEinheitTestFactory.createBuilder()
.id(null)
.xzufiId(XzufiId.builder().id(ORGANISATIONS_EINHEIT_ID).schemeAgencyId(UUID.randomUUID().toString()).build())
.build();
private final OrganisationsEinheit organisationsEinheit2 = OrganisationsEinheitTestFactory.createBuilder()
.id(null)
.xzufiId(XzufiId.builder().id(UUID.randomUUID().toString()).schemeAgencyId(UUID.randomUUID().toString()).build())
.build();
private final OrganisationsEinheit organisationsEinheit3 = OrganisationsEinheitTestFactory.createBuilder()
.id(null)
.xzufiId(XzufiId.builder().id(ORGANISATIONS_EINHEIT_ID).schemeAgencyId(UUID.randomUUID().toString()).build())
.build();
@BeforeEach
void initDatabase() {
repository.save(organisationsEinheit1);
repository.save(organisationsEinheit2);
repository.save(organisationsEinheit3);
}
@Test
void shouldFindAllOrganisationsEinheitenWithId() {
var result = repository.findByOrganisationsEinheitId(ORGANISATIONS_EINHEIT_ID);
assertThat(result).usingRecursiveFieldByFieldElementComparatorIgnoringFields("id").containsExactlyInAnyOrder(organisationsEinheit1, organisationsEinheit3);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment