-
1. Re: Example of wizard addon.
gastaldi May 4, 2016 1:00 AM (in response to n3k0)Hi,
Have a look at the "Implement a multi-step wizard" topic in here: JBoss Forge
Let me know if you have any questions, will be happy to answer them.
-
2. Re: Example of wizard addon.
n3k0 May 8, 2016 1:37 AM (in response to gastaldi)Ok. let's do this.
I have two classes. The first is this:
import javax.inject.Inject; import org.jboss.forge.addon.ui.command.AbstractUICommand; import org.jboss.forge.addon.ui.context.UIBuilder; import org.jboss.forge.addon.ui.context.UIExecutionContext; import org.jboss.forge.addon.ui.context.UINavigationContext; import org.jboss.forge.addon.ui.input.UIInput; import org.jboss.forge.addon.ui.result.NavigationResult; import org.jboss.forge.addon.ui.result.Result; import org.jboss.forge.addon.ui.result.Results; import org.jboss.forge.addon.ui.wizard.UIWizard; public class StartWizard extends AbstractUICommand implements UIWizard { @Inject private UIInput<String> firstName; @Override public void initializeUI(UIBuilder uiBuilder) throws Exception { uiBuilder.add(firstName); } @Override public NavigationResult next(UINavigationContext uiNavigationContext) throws Exception { uiNavigationContext.getUIContext().getAttributeMap().put("firstName", firstName.getValue()); return Results.navigateTo(CommandStep.class); } @Override public Result execute(UIExecutionContext context) throws Exception { return Results.success(); } }
The second class is this:
import javax.inject.Inject; import org.jboss.forge.addon.ui.command.AbstractUICommand; import org.jboss.forge.addon.ui.context.UIBuilder; import org.jboss.forge.addon.ui.context.UIExecutionContext; import org.jboss.forge.addon.ui.context.UINavigationContext; import org.jboss.forge.addon.ui.input.UIInput; import org.jboss.forge.addon.ui.metadata.WithAttributes; import org.jboss.forge.addon.ui.result.NavigationResult; import org.jboss.forge.addon.ui.result.Result; import org.jboss.forge.addon.ui.result.Results; import org.jboss.forge.addon.ui.wizard.UIWizardStep; public class CommandStep extends AbstractUICommand implements UIWizardStep { @Inject @WithAttributes(label = "Last Name", required = true) private UIInput<String> lastName; @Override public void initializeUI(UIBuilder uiBuilder) throws Exception { uiBuilder.add(lastName); } @Override public NavigationResult next(UINavigationContext uiINavigationContext) throws Exception { System.out.println(" end of road...."); return null; } @Override public Result execute(UIExecutionContext uiExecutionContext) throws Exception { String firstName = (String) uiExecutionContext.getUIContext().getAttributeMap().get("firstName"); String fullName = firstName + " " + lastName.getValue(); return Results.success("Hello," + fullName); } }
I think this is cool, apparently mi ultra-basic example is working. So i made a test class. Is this:
import javax.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.forge.arquillian.AddonDependencies; import org.jboss.forge.arquillian.AddonDependency; import org.jboss.forge.arquillian.archive.AddonArchive; import org.jboss.forge.furnace.repositories.AddonDependencyEntry; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jooq.addon.commands.StartWizard; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import static org.hamcrest.CoreMatchers.notNullValue; @RunWith(Arquillian.class) public class AddonTest { @Inject private StartWizard startWizard; @Deployment @AddonDependencies({ @AddonDependency(name = "org.joo.addon:joo-addon", version = "1.0.0-SNAPSHOT" ) }) public static AddonArchive getDeployment() { AddonArchive archive = ShrinkWrap.create(AddonArchive.class).addBeansXML() .addAsServiceProvider(AddonTest.class) .addAsAddonDependencies(AddonDependencyEntry.create("org.joo.addon:joo-addon", "1.0.0-SNAPSHOT" )); return archive; } @Test public void testNotNull() throws Exception { Assert.assertThat(startWizard , notNullValue() ); } }
Unfortunately, my test is not works. The error message is this:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 55.411 sec <<< FAILURE! testNotNull(org.joo.addon.AddonTest) Time elapsed: 0.028 sec <<< ERROR! java.lang.IllegalStateException: Test runner could not locate test class [org.joo.addon.AddonTest] in any deployed Addon - Reason unknown. at org.jboss.forge.arquillian.impl.FurnaceTestMethodExecutor.invoke(FurnaceTestMethodExecutor.java:272) at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:109) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116) at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67) at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142) at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:130) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94) at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145) at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:136) at org.jboss.arquillian.junit.Arquillian$8.evaluate(Arquillian.java:363) at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:245) at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:422) at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54) at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:259) at org.jboss.arquillian.junit.Arquillian$7.evaluate(Arquillian.java:321) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:204) at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:422) at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54) at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Weld SE container org.jboss.forge.addon:convert shut down by shutdown hook Weld SE container org.jboss.forge.addon:ui shut down by shutdown hook Weld SE container org.jboss.forge.addon:configuration shut down by shutdown hook Weld SE container org.jboss.forge.addon:parser-java shut down by shutdown hook Weld SE container org.jboss.forge.addon:shell shut down by shutdown hook Weld SE container org.jboss.forge.addon:bean-validation shut down by shutdown hook Weld SE container org.jboss.forge.addon:javaee shut down by shutdown hook Results : Tests in error: testNotNull(org.joo.addon.AddonTest): Test runner could not locate test class [org.joo.addon.AddonTest] in any deployed Addon - Reason unknown. Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
I hope you can help me.
-
3. Re: Example of wizard addon.
gastaldi May 8, 2016 9:50 AM (in response to n3k0)Your getDeployment method needs an @AddonDependency on the CDI container because this test will be run as a separate addon.
You can also remove the getDeployment method completely and it should work just fine.
-
4. Re: Example of wizard addon.
n3k0 May 8, 2016 7:54 PM (in response to gastaldi)That's pretty cool, i did what you said and the test runs with no problems:
import javax.inject.Inject; import org.jboss.arquillian.junit.Arquillian; import org.jooq.addon.commands.StartWizard; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.jboss.forge.addon.ui.controller.CommandController; import org.jboss.forge.addon.ui.result.Failed; import org.jboss.forge.addon.ui.result.Result; import org.jboss.forge.addon.ui.test.UITestHarness; @RunWith(Arquillian.class) public class AddonTest { @Inject private UITestHarness uiTestHarness; @Test public void testWizard()throws Exception{ CommandController startWizardController = uiTestHarness.createCommandController(StartWizard.class); startWizardController.initialize(); Assert.assertTrue(startWizardController.isValid()); startWizardController.setValueFor("firstName", "el gato"); Result result = startWizardController.execute(); Assert.assertFalse(result instanceof Failed); String message = result.getMessage(); Assert.assertNotNull( message ); // can i add here more code in order to test the second class (the command) ?? } }
This test is fine for the first class (the init wizard) how i can make the complete flow between the two classes? I mean, put the first name, "jump" to the second class, put the second name, and get the data entered in the
result.getMessage()
In the result of the second class. Is this possible?
Thanks in advance.
-
5. Re: Example of wizard addon.
gastaldi May 8, 2016 8:07 PM (in response to n3k0)Use UITestHarness.createWizardController and call next() to move to the next step. Then call execute() to get a CompositeResult which can be iterated and call getMessage() - each item in the CompositeResult as the result for each step
-
6. Re: Example of wizard addon.
n3k0 May 8, 2016 9:09 PM (in response to gastaldi)Thanks for your help, aaaand your patience, the test method was thus finally:
@RunWith(Arquillian.class) public class AddonTest { @Inject private UITestHarness uiTestHarness; @Test public void testWizard()throws Exception{ WizardCommandController startWizardController = uiTestHarness.createWizardController(StartWizard.class); startWizardController.initialize(); Assert.assertTrue(startWizardController.isValid()); startWizardController.setValueFor("firstName", "el gato"); WizardCommandController nextController = startWizardController.next(); nextController.setValueFor("lastName", "no last Name"); CompositeResult compositeResult = (CompositeResult) nextController.execute(); for(Result result : compositeResult.getResults()){ System.out.println(result.getMessage()); } } }
Thanks again!
-
7. Re: Example of wizard addon.
gastaldi May 8, 2016 11:31 PM (in response to n3k0)You are very welcome. Don´t forget to call initialize() on the controller returned by next().
Also, feel free to star our project at GitHub - forge/core: Forge Core Framework APIs and Implementation if you feel like