Skip to content
Snippets Groups Projects
Commit be452d66 authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-7515 use string instead of ObjectId

parent 20199ea8
Branches
Tags
1 merge request!11Ozg 7515 migrate patch item command
......@@ -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) {
......
......@@ -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);
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment