* @author Emmanuel Puybaret
*/
public class BackgroundImageWizardTest extends ComponentTestFixture {
public void testBackgroundImageWizard() throws ComponentSearchException, InterruptedException,
NoSuchFieldException, IllegalAccessException, InvocationTargetException {
final UserPreferences preferences = new DefaultUserPreferences();
// Ensure we use centimeter unit
preferences.setUnit(LengthUnit.CENTIMETER);
final URL testedImageName = BackgroundImageWizardTest.class.getResource("resources/test.png");
// Create a dummy content manager
final ContentManager contentManager = new ContentManager() {
public Content getContent(String contentName) throws RecorderException {
try {
// Let's consider contentName is a URL
return new URLContent(new URL(contentName));
} catch (IOException ex) {
fail();
return null;
}
}
public String getPresentationName(String contentName, ContentType contentType) {
return "test";
}
public boolean isAcceptable(String contentName, ContentType contentType) {
return true;
}
public String showOpenDialog(View parentView, String dialogTitle, ContentType contentType) {
// Return tested model name URL
return testedImageName.toString();
}
public String showSaveDialog(View parentView, String dialogTitle, ContentType contentType, String name) {
return null;
}
};
Home home = new Home();
ViewFactory viewFactory = new SwingViewFactory();
final HomeController controller = new HomeController(home, preferences, viewFactory, contentManager);
final JComponent homeView = (JComponent)controller.getView();
// 1. Create a frame that displays a home view
JFrame frame = new JFrame("Background Image Wizard Test");
frame.add(homeView);
frame.pack();
// Show home plan frame
showWindow(frame);
JComponentTester tester = new JComponentTester();
tester.waitForIdle();
// Check home background image is empty
assertEquals("Home background image isn't empty", null, home.getBackgroundImage());
// 2. Open wizard to import a background image
runAction(controller, HomeView.ActionType.IMPORT_BACKGROUND_IMAGE, tester);
// Wait for import furniture view to be shown
tester.waitForFrameShowing(new AWTHierarchy(), preferences.getLocalizedString(
BackgroundImageWizardController.class, "wizard.title"));
// Check dialog box is displayed
JDialog wizardDialog = (JDialog)TestUtilities.findComponent(frame, JDialog.class);
assertTrue("Wizard view dialog not showing", wizardDialog.isShowing());