|
@@ -42,26 +42,50 @@ public class FlatFileDatabaseManagerTest {
|
|
|
}
|
|
|
|
|
|
//Nothing wrong with this database
|
|
|
- private static String[] normalDatabaseData = {
|
|
|
+ private static final String[] normalDatabaseData = {
|
|
|
"nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
"mrfloris:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:631e3896-da2a-4077-974b-d047859d76bc:5:1600906906:",
|
|
|
"powerless:0:::0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0::0:0:0:0:0:0:0:0:0::0:0:0:0:HEARTS:0:0:e0d07db8-f7e8-43c7-9ded-864dfc6f3b7c:5:1600906906:"
|
|
|
};
|
|
|
|
|
|
- private static String[] duplicateNameDatabaseData = {
|
|
|
+ private static final String[] outdatedDatabaseData = {
|
|
|
+ "nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
+ "mrfloris:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:631e3896-da2a-4077-974b-d047859d76bc:5:1600906906:",
|
|
|
+ "powerless:0:::0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0::0:0:0:0:0:0:0:0:0::0:0:0:0:HEARTS:0:0:e0d07db8-f7e8-43c7-9ded-864dfc6f3b7c:" //This user is missing data added after UUID index
|
|
|
+ };
|
|
|
+
|
|
|
+ private static final String[] emptyLineDatabaseData = {
|
|
|
+ "nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
+ "mrfloris:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:631e3896-da2a-4077-974b-d047859d76bc:5:1600906906:",
|
|
|
+ "powerless:0:::0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0::0:0:0:0:0:0:0:0:0::0:0:0:0:HEARTS:0:0:e0d07db8-f7e8-43c7-9ded-864dfc6f3b7c:5:1600906906:",
|
|
|
+ "" //EMPTY LINE
|
|
|
+ };
|
|
|
+
|
|
|
+ private static final String[] emptyNameDatabaseData = {
|
|
|
+ ":1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
+ "mrfloris:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:631e3896-da2a-4077-974b-d047859d76bc:5:1600906906:",
|
|
|
+ "powerless:0:::0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0::0:0:0:0:0:0:0:0:0::0:0:0:0:HEARTS:0:0:e0d07db8-f7e8-43c7-9ded-864dfc6f3b7c:5:1600906906:"
|
|
|
+ };
|
|
|
+
|
|
|
+ private static final String[] duplicateNameDatabaseData = {
|
|
|
"nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
"nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:631e3896-da2a-4077-974b-d047859d76bc:0:0:",
|
|
|
};
|
|
|
|
|
|
- private static String[] corruptDatabaseData = {
|
|
|
+ private static final String[] duplicateUUIDDatabaseData = {
|
|
|
"nossr50:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
+ "mrfloris:1000:::0:1000:640:1000:1000:1000:1000:1000:1000:1000:1000:16:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
+ };
|
|
|
+
|
|
|
+ private static final String[] corruptDatabaseData = {
|
|
|
+ "nossr50:1000:::0:100:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
"mrfloris:2420:::0:2452:0:1983:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:631e3896-da2a-4077-974b-d047859d76bc:5:1600906906:",
|
|
|
"corruptdataboy:の:::ののの0:2452:0:1983:1937:1790:3042ののののの:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617のののののの583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:d20c6e8d-5615-4284-b8d1-e20b92011530:5:1600906906:",
|
|
|
"のjapaneseuserの:333:::0:2452:0:444:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:25870f0e-7558-4659-9f60-417e24cb3332:5:1600906906:",
|
|
|
"sameUUIDasjapaneseuser:333:::0:442:0:544:1937:1790:3042:1138:3102:2408:3411:0:0:0:0:0:0:0:0::642:0:1617583171:0:1617165043:0:1617583004:1617563189:1616785408::2184:0:0:1617852413:HEARTS:415:0:25870f0e-7558-4659-9f60-417e24cb3332:5:1600906906:",
|
|
|
};
|
|
|
|
|
|
- private static String[] badDatabaseData = {
|
|
|
+ private static final String[] badDatabaseData = {
|
|
|
//First entry here is missing some values
|
|
|
"nossr50:1000:0:500:0:0:0:0:0::1000:0:0:0:1593543012:0:0:0:0::1000:0:0:1593806053:HEARTS:1000:0:588fe472-1c82-4c4e-9aa1-7eefccb277e3:0:0:",
|
|
|
//Second entry here has an integer value replaced by a string
|
|
@@ -70,7 +94,6 @@ public class FlatFileDatabaseManagerTest {
|
|
|
|
|
|
@Test
|
|
|
public void testPurgePowerlessUsers() {
|
|
|
- assertNotNull(db);
|
|
|
replaceDataInFile(db, normalDatabaseData);
|
|
|
int purgeCount = db.purgePowerlessUsers();
|
|
|
assertEquals(purgeCount, 1); //1 User should have been purged
|
|
@@ -78,8 +101,6 @@ public class FlatFileDatabaseManagerTest {
|
|
|
|
|
|
@Test
|
|
|
public void testCheckFileHealthAndStructure() {
|
|
|
- assertNotNull(db);
|
|
|
-
|
|
|
replaceDataInFile(db, badDatabaseData);
|
|
|
|
|
|
List<FlatFileDataFlag> dataFlags = db.checkFileHealthAndStructure();
|
|
@@ -89,38 +110,37 @@ public class FlatFileDatabaseManagerTest {
|
|
|
|
|
|
@Test
|
|
|
public void testFindDuplicateNames() {
|
|
|
- assertNotNull(db);
|
|
|
-
|
|
|
- replaceDataInFile(db, duplicateNameDatabaseData);
|
|
|
-
|
|
|
- List<FlatFileDataFlag> dataFlags = db.checkFileHealthAndStructure();
|
|
|
- assertNotNull(dataFlags);
|
|
|
- assertTrue(dataFlags.contains(FlatFileDataFlag.DUPLICATE_NAME_FIXABLE));
|
|
|
+ addDataAndCheckForFlag(db, duplicateNameDatabaseData, FlatFileDataFlag.DUPLICATE_NAME_FIXABLE);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testFindDuplicateUUIDs() {
|
|
|
-
|
|
|
+ addDataAndCheckForFlag(db, duplicateUUIDDatabaseData, FlatFileDataFlag.DUPLICATE_UUID);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testFindCorruptData() {
|
|
|
-
|
|
|
+ addDataAndCheckForFlag(db, corruptDatabaseData, FlatFileDataFlag.JUNK);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testFindEmptyNames() {
|
|
|
+ addDataAndCheckForFlag(db, emptyNameDatabaseData, FlatFileDataFlag.MISSING_NAME);
|
|
|
+ }
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testFindEmptyLine() {
|
|
|
+ addDataAndCheckForFlag(db, emptyLineDatabaseData, FlatFileDataFlag.EMPTY_LINE);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testFindBadValues() {
|
|
|
-
|
|
|
+ addDataAndCheckForFlag(db, badDatabaseData, FlatFileDataFlag.BAD_VALUES);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testFindOutdatedData() {
|
|
|
-
|
|
|
+ addDataAndCheckForFlag(db, outdatedDatabaseData, FlatFileDataFlag.INCOMPLETE);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -182,4 +202,12 @@ public class FlatFileDatabaseManagerTest {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void addDataAndCheckForFlag(@NotNull FlatFileDatabaseManager targetDatabase, @NotNull String[] data, @NotNull FlatFileDataFlag flag) {
|
|
|
+ replaceDataInFile(targetDatabase, data);
|
|
|
+
|
|
|
+ List<FlatFileDataFlag> dataFlags = targetDatabase.checkFileHealthAndStructure();
|
|
|
+ assertNotNull(dataFlags);
|
|
|
+ assertTrue(dataFlags.contains(flag));
|
|
|
+ }
|
|
|
}
|