diff --git a/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommand.java b/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommand.java index 1686656a1ba8e1d05b6e150184e7270bffa8c8ed..5fd8d5eddebd45a673c2aae68e5be0cda44d0863 100644 --- a/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommand.java +++ b/vorgang-manager-server/src/main/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommand.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.stream.Stream; import org.bson.Document; -import org.bson.types.ObjectId; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -56,7 +55,7 @@ public class M014_AddItemNameBescheidToPatchAttachedItemCommand { // NOSONAR } List<String> getSendBescheidCommandIds(MongoOperations mongoOperations) { - return getSendBescheidCommands(mongoOperations).map(command -> command.getObjectId(ID_FIELD)).map(ObjectId::toString).toList(); + return getSendBescheidCommands(mongoOperations).map(command -> command.getString(ID_FIELD)).toList(); } private Stream<Document> getSendBescheidCommands(MongoOperations mongoOperations) { diff --git a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommandITCase.java b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommandITCase.java index b702e33e7fd80fcb5d564931f422f787d2f2a745..63f31347438b235956dabae2ed67cbefd3cbeb01 100644 --- a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommandITCase.java +++ b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommandITCase.java @@ -33,7 +33,6 @@ import java.util.Map; import java.util.UUID; import org.bson.Document; -import org.bson.types.ObjectId; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -48,7 +47,6 @@ import de.ozgcloud.common.test.DataITCase; @DataITCase class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { - private static final String ID_FIELD = "_id"; private static final String BESCHEID_ITEM_NAME = "Bescheid"; private static final String ITEM_NAME_FIELD = "itemName"; private static final String PATCH_ATTACHED_ITEM_ORDER = "PATCH_ATTACHED_ITEM"; @@ -72,8 +70,8 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { void setUp() { migrationDbTestUtils.dropCommandCollection(); sendBescheidCommand = saveSendBescheidCommand(); - patchAttachedItemCommand = savePatchAttachedItemSubCommand(sendBescheidCommand.getObjectId(ID_FIELD)); - subCommandWithUnkownOrder = saveSubCommandWithUnkownOrder(sendBescheidCommand.getObjectId(ID_FIELD)); + patchAttachedItemCommand = savePatchAttachedItemSubCommand(sendBescheidCommand.getString(CommandDocumentTestFactory.ID_FIELD)); + subCommandWithUnkownOrder = saveSubCommandWithUnkownOrder(sendBescheidCommand.getString(CommandDocumentTestFactory.ID_FIELD)); patchAttachedItemCommandWithoutParent = savePatchAttachedItemCommandWithoutParent(); patchAttachedItemCommandWithDifferentParent = savePatchAttachedItemCommandWithDifferentParent(); } @@ -83,14 +81,14 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { return migrationDbTestUtils.saveCommand(command); } - private Document savePatchAttachedItemSubCommand(ObjectId id) { - var itemBody = Map.<String, Object>of(PARENT_ID_FIELD, id.toString()); + private Document savePatchAttachedItemSubCommand(String id) { + var itemBody = Map.<String, Object>of(PARENT_ID_FIELD, id); var command = CommandDocumentTestFactory.createWithOrderAndBody(PATCH_ATTACHED_ITEM_ORDER, itemBody); return migrationDbTestUtils.saveCommand(command); } - private Document saveSubCommandWithUnkownOrder(ObjectId id) { - var itemBody = Map.<String, Object>of(PARENT_ID_FIELD, id.toString()); + private Document saveSubCommandWithUnkownOrder(String id) { + var itemBody = Map.<String, Object>of(PARENT_ID_FIELD, id); var command = CommandDocumentTestFactory.createWithBody(itemBody); return migrationDbTestUtils.saveCommand(command); } @@ -113,7 +111,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { void shouldReturnSendBescheidCommandId() { var ids = migration.getSendBescheidCommandIds(mongoOperations); - assertThat(ids).containsExactly(sendBescheidCommand.getObjectId(ID_FIELD).toString()); + assertThat(ids).containsExactly(sendBescheidCommand.getString(CommandDocumentTestFactory.ID_FIELD)); } } @@ -121,11 +119,10 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { class TestBuildQuery { @Test void shouldQueryPatchAttachedItemCommandsWithParentId() { - var query = migration.createQuery(List.of(sendBescheidCommand.getObjectId(ID_FIELD).toString())); + var query = migration.createQuery(List.of(sendBescheidCommand.getString(CommandDocumentTestFactory.ID_FIELD))); var commands = mongoOperations.find(query, Document.class, MigrationDbTestUtils.COMMAND_COLLECTION); - assertThat(commands).usingRecursiveFieldByFieldElementComparator() - .containsExactly(patchAttachedItemCommand); + assertThat(commands).usingRecursiveFieldByFieldElementComparator().containsExactly(patchAttachedItemCommand); } } @@ -133,9 +130,9 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { class TestUpdateDocuments { @Test void shouldModifyPatchAttachedBescheidItem() { - migration.updateDocuments(mongoOperations, List.of(sendBescheidCommand.getObjectId(ID_FIELD).toString())); + migration.updateDocuments(mongoOperations, List.of(sendBescheidCommand.getString(CommandDocumentTestFactory.ID_FIELD))); - var command = migrationDbTestUtils.getCommand(patchAttachedItemCommand.getObjectId(ID_FIELD)); + var command = migrationDbTestUtils.getCommand(patchAttachedItemCommand.getString(CommandDocumentTestFactory.ID_FIELD)); assertThat(command).usingRecursiveComparison().isEqualTo(addItemNameToPatchAttachedItemCommand(patchAttachedItemCommand)); } @@ -159,7 +156,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { void shouldAddItemNameToCommandBody() { migration.doMigration(mongoOperations); - var command = migrationDbTestUtils.getCommand(patchAttachedItemCommand.getObjectId(ID_FIELD)); + var command = migrationDbTestUtils.getCommand(patchAttachedItemCommand.getString(CommandDocumentTestFactory.ID_FIELD)); assertThat(command).usingRecursiveComparison().isEqualTo(addItemNameToPatchAttachedItemCommand(patchAttachedItemCommand)); } @@ -171,7 +168,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { void shouldKeepSendBescheidCommand() { migration.doMigration(mongoOperations); - var command = migrationDbTestUtils.getCommand(sendBescheidCommand.getObjectId(ID_FIELD)); + var command = migrationDbTestUtils.getCommand(sendBescheidCommand.getString(CommandDocumentTestFactory.ID_FIELD)); assertThat(command).usingRecursiveComparison().isEqualTo(sendBescheidCommand); } @@ -182,7 +179,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { void shouldKeepIfOrderIsNotPatchAttachedItem() { migration.doMigration(mongoOperations); - var command = migrationDbTestUtils.getCommand(subCommandWithUnkownOrder.getObjectId(ID_FIELD)); + var command = migrationDbTestUtils.getCommand(subCommandWithUnkownOrder.getString(CommandDocumentTestFactory.ID_FIELD)); assertThat(command).usingRecursiveComparison().isEqualTo(subCommandWithUnkownOrder); } @@ -195,7 +192,8 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { void shouldNotModifyOnMissingParentId() { migration.doMigration(mongoOperations); - var command = migrationDbTestUtils.getCommand(patchAttachedItemCommandWithoutParent.getObjectId(ID_FIELD)); + var command = migrationDbTestUtils + .getCommand(patchAttachedItemCommandWithoutParent.getString(CommandDocumentTestFactory.ID_FIELD)); assertThat(command).usingRecursiveComparison().isEqualTo(patchAttachedItemCommandWithoutParent); } @@ -203,7 +201,8 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { void shouldNotModifyOnDifferentParentId() { migration.doMigration(mongoOperations); - var command = migrationDbTestUtils.getCommand(patchAttachedItemCommandWithDifferentParent.getObjectId(ID_FIELD)); + var command = migrationDbTestUtils + .getCommand(patchAttachedItemCommandWithDifferentParent.getString(CommandDocumentTestFactory.ID_FIELD)); assertThat(command).usingRecursiveComparison().isEqualTo(patchAttachedItemCommandWithDifferentParent); } @@ -222,6 +221,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { private class CommandDocumentTestFactory { + private static final String ID_FIELD = "_id"; public static final String ORDER_FIELD = "order"; public static final String BODY_OBJECT_FIELD = "bodyObject"; @@ -243,6 +243,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase { public static Document create() { var command = new Document(); + command.put(ID_FIELD, UUID.randomUUID().toString()); command.put("vorgangId", VORGANG_ID); command.put("createdAt", CREATED_AT); command.put("createdBy", CREATED_BY); diff --git a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/MigrationDbTestUtils.java b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/MigrationDbTestUtils.java index beed899b7db19434be08fcd9e294dd134eca3e19..e2a0f66a4081be6329d0c1c027b544ea11cf9cbf 100644 --- a/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/MigrationDbTestUtils.java +++ b/vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/MigrationDbTestUtils.java @@ -53,7 +53,7 @@ class MigrationDbTestUtils { return template.save(doc, COMMAND_COLLECTION); } - public Document getCommand(ObjectId id) { + public Document getCommand(String id) { return template.findById(id, Document.class, COMMAND_COLLECTION); }