Skip to content
Snippets Groups Projects
Commit d171d91d authored by Lukas Malte Monnerjahn's avatar Lukas Malte Monnerjahn
Browse files

OZG-4948 OZG-5058 Simplify test

parent a98b0e30
Branches
Tags
No related merge requests found
......@@ -12,6 +12,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import java.util.List;
import static de.ozgcloud.admin.migration.M001_CreateEmptyPostfachIfMissing.SETTINGS_COLLECTION;
import static de.ozgcloud.admin.migration.M001_CreateEmptyPostfachIfMissing.TYPE_NAME_KEY;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
@DataITCase
......@@ -36,8 +37,12 @@ class M001_CreateEmptyPostfachIfMissingITCase {
changeUnit.doMigration(template);
List<Document> settings = findAllSettings();
assertThat(settings).hasSize(1)
.anyMatch(this::isEmptyPostfachSetting);
assertThat(settings).hasSize(1);
Document document = settings.getFirst();
System.out.println(document);
assertThat(document)
.usingRecursiveComparison().ignoringFields("_id")
.isEqualTo(MigrationTestFactory.createEmptyPostfach());
}
@Test
......@@ -48,9 +53,9 @@ class M001_CreateEmptyPostfachIfMissingITCase {
changeUnit.doMigration(template);
List<Document> settings = findAllSettings();
assertThat(settings).hasSize(2)
.anyMatch(this::isEmptyPostfachSetting)
.contains(settingItem);
assertThat(settings)
.extracting(TYPE_NAME_KEY)
.containsExactly("SomeType", MigrationTestFactory.ITEM_TYPE_VALUE_POSTFACH);
}
@Test
......@@ -67,27 +72,13 @@ class M001_CreateEmptyPostfachIfMissingITCase {
return template.findAll(Document.class, SETTINGS_COLLECTION);
}
private boolean isEmptyPostfachSetting(Document document) {
return document.containsKey(MigrationTestFactory.ITEM_TYPE_KEY) &&
document.get(MigrationTestFactory.ITEM_TYPE_KEY)
.equals(MigrationTestFactory.ITEM_TYPE_VALUE_POSTFACH) &&
!document.containsKey(MigrationTestFactory.ITEM_SETTINGS_KEY);
}
}
static class MigrationTestFactory {
public static final String ITEM_TYPE_KEY = "name";
public static final String ITEM_SETTINGS_KEY = "settings";
static Document createSettingsItem(String itemType, Document itemValue) {
var settingsItem = new Document();
settingsItem.put(ITEM_TYPE_KEY, itemType);
settingsItem.put(ITEM_SETTINGS_KEY, itemValue);
return settingsItem;
}
public static final String ITEM_ID = "_id";
public static final String ITEM_TYPE_VALUE_POSTFACH = "Postfach";
public static final String POSTFACH_ABSENDER_KEY = "absender";
......@@ -97,5 +88,19 @@ class M001_CreateEmptyPostfachIfMissingITCase {
return createSettingsItem(ITEM_TYPE_VALUE_POSTFACH, postfach);
}
static Document createEmptyPostfach() {
var postfach = new Document();
postfach.put(ITEM_TYPE_KEY, ITEM_TYPE_VALUE_POSTFACH);
postfach.put(ITEM_ID, null);
return postfach;
}
static Document createSettingsItem(String itemType, Document itemValue) {
var settingsItem = new Document();
settingsItem.put(ITEM_TYPE_KEY, itemType);
settingsItem.put(ITEM_SETTINGS_KEY, itemValue);
return settingsItem;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment