preferences.setLanguage(language);
preferences.setUnit(LengthUnit.CENTIMETER);
final ViewFactory viewFactory = new SwingViewFactory();
final URL testedModelName = ImportedFurnitureWizardTest.class.getResource("resources/test.obj");
// 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 testedModelName.toString();
}
public String showSaveDialog(View parentView, String dialogTitle, ContentType contentType, String name) {
return null;
}
};
Home home = new Home();
final HomeController controller =
new HomeController(home, preferences, viewFactory, contentManager);
final JComponent homeView = (JComponent)controller.getView();
final List<CatalogPieceOfFurniture> addedCatalogFurniture = new ArrayList<CatalogPieceOfFurniture>();
preferences.getFurnitureCatalog().addFurnitureListener(new CollectionListener<CatalogPieceOfFurniture>() {
public void collectionChanged(CollectionEvent<CatalogPieceOfFurniture> ev) {
addedCatalogFurniture.add(ev.getItem());
}
});
// 1. Create a frame that displays a home view
JFrame frame = new JFrame("Imported Furniture Wizard Test");
frame.add(homeView);
frame.pack();
// Show home plan frame
showWindow(frame);
JComponentTester tester = new JComponentTester();
tester.waitForIdle();
// 2. Transfer focus to plan view
((JComponent)controller.getPlanController().getView()).requestFocusInWindow();
tester.waitForIdle();
// Check plan view has focus
assertTrue("Plan component doesn't have the focus",
((JComponent)controller.getPlanController().getView()).isFocusOwner());
// Open wizard to import a test object (1 width x 2 depth x 3 height) in plan
tester.invokeLater(new Runnable() {
public void run() {
// Display dialog box later in Event Dispatch Thread to avoid blocking test thread
homeView.getActionMap().get(HomePane.ActionType.IMPORT_FURNITURE).actionPerformed(null);
}
});
// Wait for import furniture view to be shown
tester.waitForFrameShowing(new AWTHierarchy(), preferences.getLocalizedString(
ImportedFurnitureWizardController.class, "importFurnitureWizard.title"));
// Check dialog box is displayed
JDialog wizardDialog = (JDialog)TestUtilities.findComponent(frame, JDialog.class);
assertTrue("Wizard view dialog not showing", wizardDialog.isShowing());
// Retrieve ImportedFurnitureWizardStepsPanel components
ImportedFurnitureWizardStepsPanel panel = (ImportedFurnitureWizardStepsPanel)TestUtilities.findComponent(
frame, ImportedFurnitureWizardStepsPanel.class);
final JButton modelChoiceOrChangeButton = (JButton)TestUtilities.getField(panel, "modelChoiceOrChangeButton");
final JButton turnLeftButton = (JButton)TestUtilities.getField(panel, "turnLeftButton");
final JButton turnDownButton = (JButton)TestUtilities.getField(panel, "turnDownButton");
JCheckBox backFaceShownCheckBox = (JCheckBox)TestUtilities.getField(panel, "backFaceShownCheckBox");
final JTextField nameTextField = (JTextField)TestUtilities.getField(panel, "nameTextField");
final JCheckBox addToCatalogCheckBox = (JCheckBox)TestUtilities.getField(panel, "addToCatalogCheckBox");
final JComboBox categoryComboBox = (JComboBox)TestUtilities.getField(panel, "categoryComboBox");
final JSpinner widthSpinner = (JSpinner)TestUtilities.getField(panel, "widthSpinner");
JSpinner heightSpinner = (JSpinner)TestUtilities.getField(panel, "heightSpinner");
JSpinner depthSpinner = (JSpinner)TestUtilities.getField(panel, "depthSpinner");
final JCheckBox keepProportionsCheckBox = (JCheckBox)TestUtilities.getField(panel, "keepProportionsCheckBox");
JSpinner elevationSpinner = (JSpinner)TestUtilities.getField(panel, "elevationSpinner");
JCheckBox movableCheckBox = (JCheckBox)TestUtilities.getField(panel, "movableCheckBox");
JCheckBox doorOrWindowCheckBox = (JCheckBox)TestUtilities.getField(panel, "doorOrWindowCheckBox");
ColorButton colorButton = (ColorButton)TestUtilities.getField(panel, "colorButton");
final JButton clearColorButton = (JButton)TestUtilities.getField(panel, "clearColorButton");
// Check current step is model
tester.waitForIdle();
assertStepShowing(panel, true, false, false, false);
// 3. Choose tested model
String modelChoiceOrChangeButtonText = modelChoiceOrChangeButton.getText();
tester.invokeAndWait(new Runnable() {
public void run() {
modelChoiceOrChangeButton.doClick();
}
});
// Wait 1 s to let time to Java 3D to load the model
Thread.sleep(1000);
// Check choice button text changed
assertFalse("Choice button text didn't change",
modelChoiceOrChangeButtonText.equals(modelChoiceOrChangeButton.getText()));
// Click on next button
WizardPane view = (WizardPane)TestUtilities.findComponent(frame, WizardPane.class);
// Retrieve wizard view next button
final JButton nextFinishOptionButton = (JButton)TestUtilities.getField(view, "nextFinishOptionButton");
assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
tester.invokeAndWait(new Runnable() {
public void run() {
nextFinishOptionButton.doClick();
}
});
// Check current step is rotation
assertStepShowing(panel, false, true, false, false);
// Check back face shown check box isn't selected by default
assertFalse("Back face shown check box is selected", backFaceShownCheckBox.isSelected());
// 4. Click on left button
float width = (Float)widthSpinner.getValue();
float depth = (Float)depthSpinner.getValue();
float height = (Float)heightSpinner.getValue();
tester.invokeAndWait(new Runnable() {
public void run() {
turnLeftButton.doClick();
}
});
// Check depth and width values were swapped
float newWidth = (Float)widthSpinner.getValue();
float newDepth = (Float)depthSpinner.getValue();
float newHeight = (Float)heightSpinner.getValue();
TestUtilities.assertEqualsWithinEpsilon("Incorrect width", depth, newWidth, 1E-3f);
TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", width, newDepth, 1E-3f);
TestUtilities.assertEqualsWithinEpsilon("Incorrect height", height, newHeight, 1E-3f);
// Click on down button
width = newWidth;
depth = newDepth;
height = newHeight;
tester.invokeAndWait(new Runnable() {
public void run() {
turnDownButton.doClick();
}
});
// Check height and depth values were swapped
newWidth = (Float)widthSpinner.getValue();
newDepth = (Float)depthSpinner.getValue();
newHeight = (Float)heightSpinner.getValue();
TestUtilities.assertEqualsWithinEpsilon("Incorrect width", width, newWidth, 1E-3f);
TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", height, newDepth, 1E-3f);
TestUtilities.assertEqualsWithinEpsilon("Incorrect height", depth, newHeight, 1E-3f);
// 5. Click on next button
assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
tester.invokeAndWait(new Runnable() {
public void run() {
nextFinishOptionButton.doClick();
}
});
// Check current step is attributes
assertStepShowing(panel, false, false, true, false);
// 6. Check default furniture name is the presentation name proposed by content manager
assertEquals("Wrong default name",
contentManager.getPresentationName(testedModelName.toString(), ContentManager.ContentType.MODEL),
nameTextField.getText());
// Check Add to catalog check box isn't selected and category combo box
// is disabled when furniture is imported in home
assertFalse("Add to catalog check box is selected", addToCatalogCheckBox.isSelected());
assertFalse("Category combo box isn't disabled", categoryComboBox.isEnabled());