TemporaryFileManager tempFileMgr = new TemporaryFileManager(
new TestDeviceRepositoryCreator());
tempFileMgr.executeWith(new TemporaryFileExecutor() {
public void execute(File repository) throws Exception {
DeviceRepositoryAccessorManager deviceRAM =
new DeviceRepositoryAccessorManager(
repository.getPath(),
new TestTransformerMetaFactory(),
new DeviceODOMElementFactory(), false);
Shell shell = new Shell(Display.getDefault(), SWT.SHELL_TRIM);
PolicyOriginSelector selector = new PolicyOriginSelector(
shell, SWT.NONE, deviceRAM, false);
PolicyValueModifierFactory factory =
new PolicyValueModifierFactory(deviceRAM);
final String policyName = "pixelsx";
final String deviceName = "Microsoft-WebTV";
UndoRedoMementoOriginator orig =
new UndoRedoMementoOriginator() {
public UndoRedoMemento takeSnapshot() {
return null;
}
public void restoreSnapshot(UndoRedoInfo undoRedoInfo) {
}
};
DeviceEditorContext context =
DeviceEditorContext.createDeviceEditorContext(
new MockFile("name"),
orig, deviceRAM);
final PolicyValueModifier modifier =
factory.createPolicyValueModifier(shell, SWT.NONE, policyName);
controller = new PolicyController(policyName, selector,
modifier, null, context);
final ResolvedDevicePolicy rdpOriginal =
deviceRAM.resolvePolicy(deviceName, policyName);
// pixelsx is overridden by Microsoft-WebTV.
assertEquals("Microsoft-WebTV does not override pixelsx",
deviceName, rdpOriginal.deviceName);
controller.setDeviceName(deviceName);
// Simulate changing from override to fallback by invoking the private
// PolicyController#handleFallbackSelection method.
try {
PrivateAccessor.invoke(controller,
"handleFallbackSelection", null, null);
} catch (Throwable throwable) {
throw new Exception(throwable);
}
// Retrieve the updated policy.
final ResolvedDevicePolicy rdpFallback =
deviceRAM.resolvePolicy(deviceName, policyName);
// pixelsx was overridden by Microsoft-WebTV but now falls back to TV.
assertEquals("Microsoft-WebTV does not inherit pixelsx from TV",
"TV", rdpFallback.deviceName);
// Simulate a Restore by invoking the private
// PolicyController#handleRestoreSelection method.
try {
PrivateAccessor.invoke(controller,
"handleRestoreSelection", null, null);
} catch (Throwable throwable) {
throw new Exception(throwable);
}
// Retrieve the updated policy.
final ResolvedDevicePolicy rdpRestore =
deviceRAM.resolvePolicy(deviceName, policyName);
// pixelsx has now been restored and should be overridden by
// Microsoft-WebTV.
assertEquals("Microsoft-WebTV does not override pixelsx",
deviceName, rdpRestore.deviceName);