manager.executeWith(new TemporaryFileExecutor() {
public void execute(File repository) throws Exception {
MDPRArchiveAccessor archiveAccessor = new MDPRArchiveAccessor(
repository.getPath(), transformerMetaFactory);
final EclipseDeviceRepository writeRepository =
new EclipseDeviceRepository(archiveAccessor,
jdomFactory,
false,
true,
null);
// There should not be a pre-existing custom policy properties
// file.
boolean existsBefore =
archiveAccessor.getArchive().exists(customPolicyProps);
assertFalse("Custom policies.properties should not exist",
existsBefore);
// Set the custom properties on the accessor.
PrivateAccessor.setField(writeRepository, "properties", properties);
// Write out the properties, standard and custom, and save the
// repository.
writeRepository.writeProperties();
if (logger.isDebugEnabled()) {
// Print out details about the original repository archive
// and copy it to /tmp/r1.zip. This was added to help debug
// problems with committing VBM:2004110904.
dumpFile(repository, new File("/tmp/r1.zip"));
}
writeRepository.saveRepositoryArchive();
if (logger.isDebugEnabled()) {
// Print out details about the modifed repository archive
// and copy it to /tmp/r2.zip. This was added to help debug
// problems with committing VBM:2004110904.
dumpFile(repository, new File("/tmp/r2.zip"));
}
// Create a brand new accessor to read the saved modified
// repository. This ensures starting from a "clean slate".
final EclipseDeviceRepository readRepository =
new EclipseDeviceRepository(archiveAccessor,
jdomFactory,
false,
true,
null);
// The custom policy properties file should now exist, and be the
// "default".
boolean existsAfter =
archiveAccessor.getArchive().exists(customPolicyProps);
assertTrue("Custom policies.properties should exist",
existsAfter);
// Check that the customPropertiesPath field is set correctly.
String actualPath =
(String) PrivateAccessor.getField(readRepository,
"customPropertiesPath");
assertEquals("Custom properties file should be the default",
customPolicyProps,
actualPath);
final Properties propertiesRead = readRepository.getProperties();
// Check the custom policy's name is read back
String name = (String) propertiesRead.get(customNameKey);
assertEquals("Custom name should be the same",
customNameValue, name);