You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
6.6 KiB
168 lines
6.6 KiB
package de.superx.bianalysis; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
import static org.junit.Assert.assertTrue; |
|
|
|
import java.io.File; |
|
import java.util.HashMap; |
|
import java.util.List; |
|
|
|
import org.junit.Test; |
|
|
|
import de.superx.BIATestUtils; |
|
import de.superx.bianalysis.metadata.MetaImport; |
|
import de.superx.bianalysis.metadata.MetadataImporter; |
|
import de.superx.bianalysis.metadata.models.json.MetaObject; |
|
|
|
public class MetadataImporterTest { |
|
|
|
public static final String metaFilesDir = String.join(File.separator, new String[] {"test", "resources", "db", "fixtures", "bianalysis", "metadata_importer_test"}); |
|
|
|
@Test |
|
public void testConformedDimensions() { |
|
String dir = metaFilesDir + File.separator + "conformed_dimensions"; |
|
|
|
MetadataImporter importer = new MetadataImporter(); |
|
importer.setShouldReadYMLDoc(false); |
|
importer.deserializeMetadataFromJsonFiles(dir); |
|
assertEquals(0, importer.errorMessages.size()); |
|
|
|
List<String> actualInserts = importer.getAllUpsertStrings(true); |
|
List<String> expectedInserts = BIATestUtils.readInsertsFromFile(dir + File.separator + "result.sql"); |
|
|
|
assertEquals(expectedInserts.size(), actualInserts.size()); |
|
for (int i = 0; i < expectedInserts.size(); i++) { |
|
String expectedSql = BIATestUtils.formatSQLIfEclipse(expectedInserts.get(i)); |
|
String actualSql = BIATestUtils.formatSQLIfEclipse(actualInserts.get(i)); |
|
assertEquals(expectedSql, actualSql); |
|
} |
|
} |
|
|
|
@Test |
|
public void testWithoutConformedDimensions() { |
|
|
|
System.out.println("\n\n\n\n\n\n"); |
|
String dir = metaFilesDir + File.separator + "app_metaimport"; |
|
|
|
MetadataImporter importer = new MetadataImporter(); |
|
importer.setShouldReadYMLDoc(false); |
|
importer.deserializeMetadataFromJsonFiles(dir); |
|
assertEquals(0, importer.errorMessages.size()); |
|
|
|
List<String> actualInserts = importer.getAllUpsertStrings(true); |
|
List<String> expectedInserts = BIATestUtils.readInsertsFromFile(dir + File.separator + "app_metaimport_result.sql"); |
|
|
|
assertEquals(actualInserts.size(), expectedInserts.size()); |
|
for (int i = 0; i < expectedInserts.size(); i++) { |
|
String expectedSql = BIATestUtils.formatSQLIfEclipse(expectedInserts.get(i)); |
|
String actualSql = BIATestUtils.formatSQLIfEclipse(actualInserts.get(i)); |
|
assertEquals(expectedSql, actualSql); |
|
} |
|
} |
|
|
|
@Test |
|
public void testYML() { |
|
String dir = metaFilesDir + File.separator + "app_metaimport"; |
|
MetadataImporter importer = new MetadataImporter(); |
|
importer.setShouldReadYMLDoc(false); |
|
importer.deserializeMetadataFromJsonFiles(dir); |
|
|
|
// step 1: check markdown definitions |
|
HashMap<String, String> defs = importer.getMarkdownDefinitions(dir); |
|
|
|
String dimApplicant = "Lorem ipsum dolor sit amet, consetetur " |
|
+ "sadipscing elitr, sed diam nonumy"; |
|
|
|
String dimSemester = "Lorem ipsum \"dolor\" sit amet, \"consetetur\" sadipscing " |
|
+ "elitr, sed diam nonumy eirmod tempor invidunt ut labore et " |
|
+ "dolore magna aliquyam"; |
|
|
|
assertEquals(4, defs.keySet().size()); |
|
assertEquals(dimSemester, defs.get("dim_semester")); |
|
assertEquals("Lorem ipsum", defs.get("dim_dummy")); |
|
assertEquals(dimApplicant, defs.get("appl")); |
|
assertEquals("", defs.get("dim_applicant.city")); |
|
|
|
// step 2: check meta objects description attributes |
|
importer.addYMLDescriptionsToMetaObjects(dir, defs); |
|
MetaImport meta = importer.getMetaImport("app_metaimport.json").get(); |
|
|
|
int docIdentifierFound = 0; |
|
for (MetaObject obj : meta.getMetaObjects()) { |
|
String desc = obj.getDescription(); |
|
String id = obj.getId().composedId; |
|
switch (id) { |
|
case "app:78": |
|
case "app:10": |
|
assertEquals(dimSemester, desc); |
|
docIdentifierFound++; |
|
break; |
|
case "app:2": |
|
assertEquals(dimApplicant, desc); |
|
docIdentifierFound++; |
|
break; |
|
case "app:1": |
|
// make sure the json attribute takes precedence over the yml doc |
|
assertEquals("fake description in json", desc); |
|
docIdentifierFound++; |
|
break; |
|
case "app:4": |
|
assertEquals("", desc); |
|
docIdentifierFound++; |
|
break; |
|
case "app:1000": |
|
// role playing dimension with no description -> use description of |
|
// conformed dimension |
|
assertEquals("Meine Dummy Tabelle", desc); |
|
docIdentifierFound++; |
|
break; |
|
case "app:1003": |
|
// role playing dimension with description -> the description of the role |
|
// playing dimension takes precedence |
|
assertEquals("Role Playing Dimension Text", desc); |
|
docIdentifierFound++; |
|
break; |
|
case "app:1001": |
|
// role playing attribute with description -> the description of the role |
|
// playing attribute takes precedence |
|
assertEquals("Role Playing Description", desc); |
|
docIdentifierFound++; |
|
break; |
|
case "app:1002": |
|
// role playing attribute with no description -> use description of |
|
// conformed attribute |
|
assertEquals("Conformed Description für Alter", desc); |
|
docIdentifierFound++; |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
assertEquals(9, docIdentifierFound); |
|
} |
|
|
|
|
|
@Test |
|
public void testAttributeGroup() { |
|
String dir = metaFilesDir + File.separator + "attribute_groups"; |
|
MetadataImporter importer = new MetadataImporter(); |
|
importer.setShouldReadYMLDoc(false); |
|
importer.deserializeMetadataFromJsonFiles(dir); |
|
|
|
List<String> actualInserts = importer.getAllUpsertStrings(false); |
|
List<String> expectedInserts = BIATestUtils.readInsertsFromFile(dir + File.separator + "attribute_groups_app_metaimport_result.sql"); |
|
|
|
assertEquals(actualInserts.size(), expectedInserts.size()); |
|
for (int i = 0; i < expectedInserts.size(); i++) { |
|
String expectedSql = BIATestUtils.formatSQLIfEclipse(expectedInserts.get(i)); |
|
String actualSql = BIATestUtils.formatSQLIfEclipse(actualInserts.get(i)); |
|
assertEquals(expectedSql, actualSql); |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|