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