-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-1739: Handling exceptions gracefully
- Loading branch information
Showing
3 changed files
with
174 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
ui/tests/src/test/java/org/jboss/forge/addon/ui/command/CommandFactoryExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.command; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.controller.CommandController; | ||
import org.jboss.forge.addon.ui.controller.mock.ExampleCommand; | ||
import org.jboss.forge.addon.ui.controller.mock.ExampleNoUICommand; | ||
import org.jboss.forge.addon.ui.controller.mock.FlowExampleStep; | ||
import org.jboss.forge.addon.ui.example.commands.ExampleAnnotatedCommand; | ||
import org.jboss.forge.addon.ui.impl.mock.MockUIContext; | ||
import org.jboss.forge.addon.ui.impl.mock.MockUIRuntime; | ||
import org.jboss.forge.addon.ui.metadata.UICommandMetadata; | ||
import org.jboss.forge.addon.ui.test.impl.UIContextImpl; | ||
import org.jboss.forge.addon.ui.util.Selections; | ||
import org.jboss.forge.arquillian.AddonDependency; | ||
import org.jboss.forge.arquillian.Dependencies; | ||
import org.jboss.forge.arquillian.archive.ForgeArchive; | ||
import org.jboss.forge.furnace.repositories.AddonDependencyEntry; | ||
import org.jboss.forge.furnace.util.Lists; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Test class for the {@link CommandController} feature | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class CommandFactoryExceptionTest | ||
{ | ||
@Deployment | ||
@Dependencies({ @AddonDependency(name = "org.jboss.forge.addon:ui"), | ||
@AddonDependency(name = "org.jboss.forge.addon:ui-test-harness") }) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addClasses(ExceptionCommand.class, ExampleCommand.class, ExampleNoUICommand.class, | ||
ExampleAnnotatedCommand.class, | ||
FlowExampleStep.class) | ||
.addPackage(MockUIRuntime.class.getPackage()) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.addon:ui"), | ||
AddonDependencyEntry.create("org.jboss.forge.addon:ui-test-harness"), | ||
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi")); | ||
|
||
return archive; | ||
} | ||
|
||
@Inject | ||
private CommandFactory commandFactory; | ||
|
||
@Test | ||
public void testInjection() throws Exception | ||
{ | ||
Assert.assertNotNull(commandFactory); | ||
} | ||
|
||
@Test | ||
public void testNoExceptionsOnEnabledCommandNames() | ||
{ | ||
UIContext context = new UIContextImpl(true, Selections.emptySelection()); | ||
Set<String> enabledCommandNames = commandFactory.getEnabledCommandNames(context); | ||
Assert.assertEquals(4, enabledCommandNames.size()); | ||
} | ||
|
||
@Test | ||
public void testNoExceptionsOnCommandsNames() | ||
{ | ||
UIContext context = new UIContextImpl(true, Selections.emptySelection()); | ||
Set<String> commandNames = commandFactory.getCommandNames(context); | ||
Assert.assertEquals(4, commandNames.size()); | ||
|
||
} | ||
|
||
@Test | ||
public void testNoExceptionsOnUICommands() | ||
{ | ||
List<UICommand> list = Lists.toList(commandFactory.getCommands()); | ||
Assert.assertEquals(5, list.size()); | ||
|
||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
ui/tests/src/test/java/org/jboss/forge/addon/ui/command/ExceptionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.command; | ||
|
||
import org.jboss.forge.addon.ui.context.UIBuilder; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.context.UIExecutionContext; | ||
import org.jboss.forge.addon.ui.metadata.UICommandMetadata; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
|
||
public class ExceptionCommand extends AbstractUICommand | ||
{ | ||
@Override | ||
public boolean isEnabled(UIContext context) | ||
{ | ||
throw new NullPointerException(); | ||
} | ||
|
||
@Override | ||
public UICommandMetadata getMetadata(UIContext context) | ||
{ | ||
throw new NullPointerException(); | ||
} | ||
|
||
@Override | ||
public void initializeUI(UIBuilder builder) throws Exception | ||
{ | ||
} | ||
|
||
@Override | ||
public Result execute(UIExecutionContext context) throws Exception | ||
{ | ||
return null; | ||
} | ||
|
||
} |