LDIFDiffTestCase.java revision a41662c1136b2bb4a4198df89e0e87d2be3ef099
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS.
*/
/**
* A set of test cases for the LDIFDiff tool.
*/
public class LDIFDiffTestCase
extends ToolsTestCase
{
/**
* The path to the file that will be used if there are no differences between
* the source and target LDIF data sets.
*/
private String noDiffsFile =
"diff-nochanges.ldif";
/**
* Make sure that the server is running, since we need it for schema
* handling.
*
* @throws Exception If an unexpected problem occurs.
*/
public void startServer()
throws Exception
{
}
/** Calculates the checksum of a file. */
{
}
{
long checksum = 0L;
{
}
return checksum;
}
/**
* Tests the LDIFDiff tool with an argument that will simply cause it to
* display usage information.
*/
@Test
public void testUsage()
{
}
/**
* Tests the LDIFDiff tool with an invalid set of arguments.
*/
@Test
public void testInvalidArguments()
{
{
"--invalid"
};
}
/**
* Retrieves the names of the files that should be used when testing the
* ldif-diff tool. Each element of the outer array should be an array
* containing the following elements:
* <OL>
* <LI>The path to the source LDIF file</LI>
* <LI>The path to the target LDIF file</LI>
* <LI>The path to the diff file, or {@code null} if the diff is supposed
* to fail</LI>
* </OL>
*/
public Object[][] getTestData()
{
return new Object[][]
{
// Both files are empty.
ldifRoot + "target-empty.ldif",
COMPARE_TRUE },
// Both files are the single-entry source.
ldifRoot + "source-singleentry.ldif",
COMPARE_TRUE },
// Both files are the single-entry target.
ldifRoot + "target-singleentry.ldif",
COMPARE_TRUE },
// Both files are the multiple-entry source.
ldifRoot + "source-multipleentries.ldif",
COMPARE_TRUE },
// Both files are the multiple-entry target.
ldifRoot + "target-multipleentries.ldif",
COMPARE_TRUE },
// The source is empty but the target has a single entry.
ldifRoot + "target-singleentry.ldif",
ldifRoot + "diff-emptytosingle.ldif",
ldifRoot + "diff-emptytosingle.ldif",
// The source has a single entry but the target is empty.
ldifRoot + "target-empty.ldif",
ldifRoot + "diff-singletoempty.ldif",
ldifRoot + "diff-singletoempty.ldif",
// Make a change to only a single entry in the source->target direction.
ldifRoot + "target-singleentry.ldif",
ldifRoot + "diff-singleentry.ldif",
ldifRoot + "diff-singleentry.ldif",
// Make a change to only a single entry in the target->source direction.
ldifRoot + "source-singleentry.ldif",
ldifRoot + "diff-singleentry-reverse.ldif",
ldifRoot + "diff-singleentry-reverse.ldif",
// Make changes to multiple entries in the source->target direction.
ldifRoot + "target-multipleentries.ldif",
ldifRoot + "diff-multipleentries.ldif",
ldifRoot + "diff-multipleentries-singlevalue.ldif",
// Make changes to multiple entries in the target->source direction.
ldifRoot + "source-multipleentries.ldif",
ldifRoot + "diff-multipleentries-reverse.ldif",
ldifRoot +
"diff-multipleentries-reverse-singlevalue.ldif",
// Go from one entry to multiple in the source->target direction.
ldifRoot + "target-multipleentries.ldif",
ldifRoot + "diff-singletomultiple.ldif",
ldifRoot + "diff-singletomultiple-singlevalue.ldif",
// Go from one entry to multiple in the target->source direction.
ldifRoot + "source-multipleentries.ldif",
ldifRoot + "diff-singletomultiple-reverse.ldif",
ldifRoot + "diff-singletomultiple-reverse.ldif",
// Go from multiple entries to one in the source->target direction.
ldifRoot + "target-singleentry.ldif",
ldifRoot + "diff-multipletosingle.ldif",
ldifRoot + "diff-multipletosingle.ldif",
// Go from multiple entries to one in the target->source direction.
ldifRoot + "source-singleentry.ldif",
ldifRoot + "diff-multipletosingle-reverse.ldif",
ldifRoot +
"diff-multipletosingle-reverse-singlevalue.ldif",
// The source file doesn't exist.
ldifRoot + "target-singleentry.ldif",
// The target file doesn't exist.
ldifRoot + "target-notfound.ldif",
};
}
/**
* Tests the LDIFDiff tool with the provided information to ensure that the
* normal mode of operation works as expected. This is a bit tricky because
* the attributes and values will be written in an indeterminate order, so we
* can't just use string equality. We'll have to use a crude checksum
* mechanism to test whether they are equal. Combined with other methods in
* this class, this should be good enough.
*
* @param sourceFile The path to the file containing the source
* data set.
* @param targetFile The path to the file containing the target
* data set.
* @param normalDiffFile The path to the file containing the expected
* diff in "normal" form (at most one record per
* entry), or {@code null} if the diff is
* supposed to fail.
* @param singleValueDiffFile The path to the file containing the expected
* diff in "single-value" form, where each
* attribute-level change results in a separate
* entry per attribute value.
* @param resultCode The result code that should be returned with
* --useCompareResultCode flag
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
{
"-s", sourceFile,
"-t", targetFile,
"-O"
};
String[] argsUseCompare =
{
"-s", sourceFile,
"-t", targetFile,
// No need to write to the outputFile
"--useCompareResultCode"
};
if (normalDiffFile == null)
{
// We expect this to fail, so just make sure that it does.
outputFile.delete();
return;
}
outputFile.delete();
}
/**
* Tests the LDIFDiff tool with the provided information to ensure that the
* single value changes mode of operation works as expected. This is a bit
* tricky because the attributes and values will be written in an
* indeterminate order, so we can't just use string equality. We'll have to
* use a crude checksum mechanism to test whether they are equal. Combined
* with other methods in this class, this should be good enough.
*
* @param sourceFile The path to the file containing the source
* data set.
* @param targetFile The path to the file containing the target
* data set.
* @param normalDiffFile The path to the file containing the expected
* diff in "normal" form (at most one record per
* entry), or {@code null} if the diff is
* supposed to fail.
* @param singleValueDiffFile The path to the file containing the expected
* diff in "single-value" form, where each
* attribute-level change results in a separate
* entry per attribute value.
* @param resultCode The result code that should be returned with
* --useCompareResultCode flag
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
{
"-s", sourceFile,
"-t", targetFile,
"-O",
"-S"
};
String[] argsUseCompare =
{
"-s", sourceFile,
"-t", targetFile,
// No need to write to the outputFile
"--useCompareResultCode"
};
if (singleValueDiffFile == null)
{
// We expect this to fail, so just make sure that it does.
outputFile.delete();
return;
}
outputFile.delete();
}
/**
* Tests the LDIFDiff tool by first identifying the differences between the
* source and the target and then using the LDIFModify tool to apply the
* identified changes to the source LDIF and verify that it matches the
* target.
*
* @param sourceFile The path to the file containing the source
* data set.
* @param targetFile The path to the file containing the target
* data set.
* @param normalDiffFile The path to the file containing the expected
* diff in "normal" form (at most one record per
* entry), or {@code null} if the diff is
* supposed to fail.
* @param singleValueDiffFile The path to the file containing the expected
* diff in "single-value" form, where each
* attribute-level change results in a separate
* entry per attribute value.
* @param resultCode The result code that should be returned with
* --useCompareResultCode flag
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
// If the command is expected to fail, or if there aren't any differences,
// then bail out now.
{
return;
}
// Generate the diff file.
{
"-s", sourceFile,
"-t", targetFile,
};
String[] argsUseCompare =
{
"-s", sourceFile,
"-t", targetFile,
// No need to write to the outputFile
"--useCompareResultCode"
};
// Use LDIFModify to generate a new target file.
{
"-s", sourceFile,
};
0);
// Use LDIFDiff again to verify that there are effectively no differences
// between the original target and the new target.
{
"-s", targetFile,
};
argsUseCompare = new String[]
{
"-s", targetFile,
// No need to write to the outputFile
"--useCompareResultCode"
};
}
/**
* Tests the LDIFDiff tool by first identifying the differences between the
* source and the target (using the single-value format) and then using the
* LDIFModify tool to apply the identified changes to the source LDIF and
* verify that it matches the target.
*
* @param sourceFile The path to the file containing the source
* data set.
* @param targetFile The path to the file containing the target
* data set.
* @param normalDiffFile The path to the file containing the expected
* diff in "normal" form (at most one record per
* entry), or {@code null} if the diff is
* supposed to fail.
* @param singleValueDiffFile The path to the file containing the expected
* diff in "single-value" form, where each
* attribute-level change results in a separate
* entry per attribute value.
* @param resultCode The result code that should be returned with
* --useCompareResultCode flag
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
// If the command is expected to fail, or if there aren't any differences,
// then bail out now.
{
return;
}
// Generate the diff file.
{
"-s", sourceFile,
"-t", targetFile,
"-S"
};
String[] argsUseCompare =
{
"-s", sourceFile,
"-t", targetFile,
// No need to write to the outputFile
"--useCompareResultCode"
};
// Use LDIFModify to generate a new target file.
{
"-s", sourceFile,
};
0);
// Use LDIFDiff again to verify that there are effectively no differences
// between the original target and the new target.
{
"-s", targetFile,
};
argsUseCompare = new String[]
{
"-s", targetFile,
// No need to write to the outputFile
"--useCompareResultCode"
};
}
/**
* Retrieves the names of the files that should be used when testing the
* ldif-diff tool. Each element of the outer array should be an array
* containing the following elements:
* <OL>
* <LI>The path to the source LDIF file</LI>
* <LI>The path to the target LDIF file</LI>
* <LI>The path to the file with attributes to be ignored</LI>
* <LI>The path to the diff file</LI>
* </OL>
*/
public Object[][] getIATestData()
{
return new Object[][]
{
// Make changes to multiple entries in the target->source direction.
ldifRoot + "target-multipleentries.ldif",
ldifRoot + "ignore-attributes",
ldifRoot + "diff-multipleentries-ignore-attributes.ldif" },
ldifRoot + "target-multipleentries.ldif",
ldifRoot + "does-not-exist",
ldifRoot + "diff-multipleentries-ignore-attributes.ldif" }
};
}
/**
* Tests the LDIFDiff tool with the provided information to ensure that the
* normal mode of operation works as expected. This is a bit tricky because
* the attributes and values will be written in an indeterminate order, so we
* can't just use string equality. We'll have to use a crude checksum
* mechanism to test whether they are equal. Combined with other methods in
* this class, this should be good enough.
*
* @param sourceFile The path to the file containing the source
* data set.
* @param targetFile The path to the file containing the target
* data set.
* @param normalDiffFile The path to the file containing the expected
* diff in "normal" form (at most one record per
* entry), or {@code null} if the diff is
* supposed to fail.
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
{
"-s", sourceFile,
"-t", targetFile,
"-a", ignoreAttributesFile,
"-O"
};
{
// We expect this to fail, so just make sure that it does.
return;
}
outputFile.delete();
}
/**
* Retrieves the names of the files that should be used when testing the
* ldif-diff tool. Each element of the outer array should be an array
* containing the following elements:
* <OL>
* <LI>The path to the source LDIF file</LI>
* <LI>The path to the target LDIF file</LI>
* <LI>The path to the file with entries to be ignored</LI>
* <LI>The path to the diff file</LI>
* </OL>
*/
public Object[][] getIETestData()
{
return new Object[][]
{
// Make changes to multiple entries in the target->source direction.
ldifRoot + "target-multipleentries.ldif",
ldifRoot + "ignore-entries",
ldifRoot + "diff-multipleentries-ignore-entries.ldif" },
ldifRoot + "target-multipleentries.ldif",
ldifRoot + "does-not-exist",
ldifRoot + "diff-multipleentries-ignore-entries.ldif" }
};
}
/**
* Tests the LDIFDiff tool with the provided information to ensure that the
* normal mode of operation works as expected. This is a bit tricky because
* the attributes and values will be written in an indeterminate order, so we
* can't just use string equality. We'll have to use a crude checksum
* mechanism to test whether they are equal. Combined with other methods in
* this class, this should be good enough.
*
* @param sourceFile The path to the file containing the source
* data set.
* @param targetFile The path to the file containing the target
* data set.
* @param normalDiffFile The path to the file containing the expected
* diff in "normal" form (at most one record per
* entry), or {@code null} if the diff is
* supposed to fail.
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
{
"-s", sourceFile,
"-t", targetFile,
"-e", ignoreEntriesFile,
"-O"
};
{
// We expect this to fail, so just make sure that it does.
return;
}
outputFile.delete();
}
}