Why my wizard with some steps returns the same step?
n3k0 May 16, 2016 10:58 PMI have a three steps Wizard, but when i make a test BOOM!! it fails, and fails because when the wizard passes to a second step (don't talk about the third) it looks for a parameter of the first step.
Now some code:
My entry point:
public class StartWizard extends AbstractUICommand implements UIWizard { @Inject @WithAttributes(label = "XML Config", description = "Have a XML configuration? Set it", required = true, type = "String") private UIInput<String> xmlInPath; @Override public void initializeUI(UIBuilder uiBuilder) throws Exception { LOG.info("StartWizard -> initializeUI"); uiBuilder.add(xmlInPath); } @Override public NavigationResult next(UINavigationContext uiNavigationContext) throws Exception { uiNavigationContext.getUIContext().getAttributeMap().put("xmlInPath", xmlInPath.getValue()); return Results.navigateTo(ConfigStep.class); } @Override public Result execute(UIExecutionContext uiExecutionContext) throws Exception { Result result = Results.success("Wizard Execute successful! " + xmlInPath.getValue()); return result; } }
The next step:
public class ConfigStep extends AbstractUICommand implements UIWizardStep { protected UIInput<String> url; @Override public void initializeUI(UIBuilder uiBuilder) throws Exception { InputComponentFactory inputComponentFactory = uiBuilder.getInputComponentFactory(); url = inputComponentFactory.createInput("Url", String.class).setLabel("URL").setDescription("Add the URL") .setRequired(true); uiBuilder.add(url); } @Override public NavigationResult next(UINavigationContext uiNavigationContext) throws Exception { Map<String, Object> attributes = new HashMap<String , Object>(); attributes.put("url", url.getValue()); uiNavigationContext.getUIContext().getAttributeMap().putAll(attributes); return Results.navigateTo(XMLStep.class); } @Override public Result execute(UIExecutionContext context) throws Exception { StringBuilder result = new StringBuilder(); result.append(url.getValue()).toString()); return Results.success("config ENDS with values ".concat(result.toString())); } }
(I don't add the third step XMLStep because the test does not reach it )
And finally, the test:
@RunWith(Arquillian.class) public class AddonTest { @Inject private UITestHarness uiTestHarness; @Inject private ResourceFactory resourceFactory; @Test public void testStepsHappyPath() { WizardCommandController startWizardController; WizardCommandController configStepController; WizardCommandController xmlController = null; try { startWizardController = uiTestHarness.createWizardController(StartWizard.class); startWizardController.initialize(); startWizardController.setValueFor("xmlInPath", null); configStepController = startWizardController.next(); configStepController.initialize(); configStepController.setValueFor("url", "The dummy url"); // BOOM!! Here throws an Exception!! xmlController = configStepController.next(); xmlController.initialize(); xmlController.setValueFor("version", "The dummy version" ); xmlController.execute(); } catch (Exception e) { e.printStackTrace(); } } }
AAAaaand finally, the exception is:
tartWizard initializeUI INFORMACIÓN: StartWizard -> initializeUI java.lang.IllegalArgumentException: Input named 'url' does not exist. Valid values: [xmlInPath] .... (other exceptions ...)...
Any ideas?
Thanks in advance.