mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Add test to find duplicate names - FlatFileDatabaseManagerTest
This commit is contained in:
parent
834ccc946a
commit
aca1d6c0b1
@ -113,6 +113,9 @@ public class FlatFileDataProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uuids.add(uuid);
|
||||||
|
|
||||||
|
|
||||||
if(names.contains(name)) {
|
if(names.contains(name)) {
|
||||||
//Duplicate entry
|
//Duplicate entry
|
||||||
nameIsDupe = true;
|
nameIsDupe = true;
|
||||||
@ -129,6 +132,8 @@ public class FlatFileDataProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
names.add(name);
|
||||||
|
|
||||||
//Make sure the data is up to date schema wise
|
//Make sure the data is up to date schema wise
|
||||||
if(splitDataLine.length < DATA_ENTRY_COUNT) {
|
if(splitDataLine.length < DATA_ENTRY_COUNT) {
|
||||||
String[] correctSizeSplitData = Arrays.copyOf(splitDataLine, DATA_ENTRY_COUNT);
|
String[] correctSizeSplitData = Arrays.copyOf(splitDataLine, DATA_ENTRY_COUNT);
|
||||||
@ -151,7 +156,7 @@ public class FlatFileDataProcessor {
|
|||||||
if(shouldNotBeEmpty(splitDataLine[i], i)) {
|
if(shouldNotBeEmpty(splitDataLine[i], i)) {
|
||||||
badDataValues[i] = true;
|
badDataValues[i] = true;
|
||||||
anyBadData = true;
|
anyBadData = true;
|
||||||
reportBadDataLine("Data is empty when it should not be at index", "[EMPTY]", lineData);
|
reportBadDataLine("Data is empty when it should not be at index", "[index=" + i + "]", lineData);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,6 +172,8 @@ public class FlatFileDataProcessor {
|
|||||||
if(anyBadData) {
|
if(anyBadData) {
|
||||||
builder.appendFlag(FlatFileDataFlag.BAD_VALUES);
|
builder.appendFlag(FlatFileDataFlag.BAD_VALUES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerData(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldNotBeEmpty(String data, int index) {
|
public boolean shouldNotBeEmpty(String data, int index) {
|
||||||
@ -239,8 +246,10 @@ public class FlatFileDataProcessor {
|
|||||||
switch(dataIndex) {
|
switch(dataIndex) {
|
||||||
case USERNAME_INDEX:
|
case USERNAME_INDEX:
|
||||||
return ExpectedType.STRING;
|
return ExpectedType.STRING;
|
||||||
case 2: //Used to be for something, no longer used
|
case 2: //Assumption: Used to be for something, no longer used
|
||||||
case 3: //Used to be for something, no longer used
|
case 3: //Assumption: Used to be for something, no longer used
|
||||||
|
case 23: //Assumption: Used to be used for something, no longer used
|
||||||
|
case 33: //Assumption: Used to be used for something, no longer used
|
||||||
case HEALTHBAR:
|
case HEALTHBAR:
|
||||||
return ExpectedType.IGNORED;
|
return ExpectedType.IGNORED;
|
||||||
case SKILLS_MINING:
|
case SKILLS_MINING:
|
||||||
|
@ -967,7 +967,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
|||||||
|
|
||||||
public @Nullable List<FlatFileDataFlag> checkFileHealthAndStructure() {
|
public @Nullable List<FlatFileDataFlag> checkFileHealthAndStructure() {
|
||||||
FlatFileDataProcessor dataProcessor = null;
|
FlatFileDataProcessor dataProcessor = null;
|
||||||
int dataFlagCount = 0;
|
|
||||||
|
|
||||||
if (usersFile.exists()) {
|
if (usersFile.exists()) {
|
||||||
BufferedReader bufferedReader = null;
|
BufferedReader bufferedReader = null;
|
||||||
@ -985,8 +984,6 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
dataFlagCount = dataProcessor.getDataFlagCount();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ public class CategorizedFlatFileDataBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CategorizedFlatFileData build() {
|
public CategorizedFlatFileData build() {
|
||||||
assert dataFlags.size() > 0;
|
|
||||||
return new CategorizedFlatFileData(uniqueProcessingId, dataFlags, stringDataRepresentation);
|
return new CategorizedFlatFileData(uniqueProcessingId, dataFlags, stringDataRepresentation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,11 @@ public class FlatFileDatabaseManagerTest {
|
|||||||
"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:"
|
"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 = {
|
||||||
|
"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 String[] corruptDatabaseData = {
|
||||||
"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: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:",
|
"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:",
|
||||||
@ -66,7 +71,7 @@ public class FlatFileDatabaseManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testPurgePowerlessUsers() {
|
public void testPurgePowerlessUsers() {
|
||||||
assertNotNull(db);
|
assertNotNull(db);
|
||||||
addDataToFile(db, normalDatabaseData);
|
replaceDataInFile(db, normalDatabaseData);
|
||||||
int purgeCount = db.purgePowerlessUsers();
|
int purgeCount = db.purgePowerlessUsers();
|
||||||
assertEquals(purgeCount, 1); //1 User should have been purged
|
assertEquals(purgeCount, 1); //1 User should have been purged
|
||||||
}
|
}
|
||||||
@ -75,7 +80,7 @@ public class FlatFileDatabaseManagerTest {
|
|||||||
public void testCheckFileHealthAndStructure() {
|
public void testCheckFileHealthAndStructure() {
|
||||||
assertNotNull(db);
|
assertNotNull(db);
|
||||||
|
|
||||||
addDataToFile(db, badDatabaseData);
|
replaceDataInFile(db, badDatabaseData);
|
||||||
|
|
||||||
List<FlatFileDataFlag> dataFlags = db.checkFileHealthAndStructure();
|
List<FlatFileDataFlag> dataFlags = db.checkFileHealthAndStructure();
|
||||||
assertNotNull(dataFlags);
|
assertNotNull(dataFlags);
|
||||||
@ -84,7 +89,13 @@ public class FlatFileDatabaseManagerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindDuplicateNames() {
|
public void testFindDuplicateNames() {
|
||||||
|
assertNotNull(db);
|
||||||
|
|
||||||
|
replaceDataInFile(db, duplicateNameDatabaseData);
|
||||||
|
|
||||||
|
List<FlatFileDataFlag> dataFlags = db.checkFileHealthAndStructure();
|
||||||
|
assertNotNull(dataFlags);
|
||||||
|
assertTrue(dataFlags.contains(FlatFileDataFlag.DUPLICATE_NAME_FIXABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -119,7 +130,7 @@ public class FlatFileDatabaseManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addDataToFile(@NotNull FlatFileDatabaseManager flatFileDatabaseManager, @NotNull String[] dataEntries) {
|
private void replaceDataInFile(@NotNull FlatFileDatabaseManager flatFileDatabaseManager, @NotNull String[] dataEntries) {
|
||||||
String filePath = flatFileDatabaseManager.getUsersFile().getAbsolutePath();
|
String filePath = flatFileDatabaseManager.getUsersFile().getAbsolutePath();
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
FileWriter out = null;
|
FileWriter out = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user