Skip to content

Commit

Permalink
FORGE-1503: Added categories to @command
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 27, 2014
1 parent 1a3c992 commit 4cf681a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@
* The handler to determine if this command should be enabled
*/
Class<? extends Predicate<UIContext>>[] enabled() default {};

/**
* Categories for this command
*/
String[] categories() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class ExampleAnnotatedCommand
{
@Command("Annotation Commands: Number 1")
@Command(value = "Annotation Commands: Number 1", categories = { "Root", "Branch" })
public String executeFromAnnotation(
@Option(value = "name", label = "Field Name", required = true) String name,
@Option(value = "elementType", label = "Element Type") ElementType elementType,
Expand All @@ -27,7 +27,7 @@ public String executeFromAnnotation(
return "Hello there !";
}

@Command("Annotation Commands: Number 2")
@Command(value = "Annotation Commands: Number 2", categories = "Root")
public void executeWithReservedParameters(
@Option(value = "name", label = "Field Name", required = true) String name,
UIOutput output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.InputComponents;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.forge.furnace.util.Predicate;
Expand Down Expand Up @@ -61,7 +62,8 @@ public UICommandMetadata getMetadata(UIContext context)
{
name = method.getName();
}
return Metadata.forCommand(method.getDeclaringClass()).name(name).description(ann.help());
return Metadata.forCommand(method.getDeclaringClass()).name(name).description(ann.help())
.category(Categories.create(ann.categories()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.addon.ui.controller.mock.EnabledHandlerCommand;
import org.jboss.forge.addon.ui.example.commands.ExampleAnnotatedCommand;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.arquillian.AddonDependency;
import org.jboss.forge.arquillian.Dependencies;
import org.jboss.forge.arquillian.archive.ForgeArchive;
Expand Down Expand Up @@ -58,7 +60,6 @@ public void testWizardExecution() throws Exception
{
try (CommandController controller = testHarness.createCommandController("Annotation Commands: Number 1"))
{
Assert.assertFalse(controller.isInitialized());
controller.initialize();
Assert.assertTrue(controller.isInitialized());
Assert.assertEquals("Annotation Commands: Number 1", controller.getMetadata().getName());
Expand All @@ -71,6 +72,23 @@ public void testWizardExecution() throws Exception
}
}

@Test
public void testCommandMetadata() throws Exception
{
try (CommandController controller = testHarness.createCommandController("Annotation Commands: Number 1"))
{
UICommandMetadata metadata = controller.getMetadata();
Assert.assertEquals("Annotation Commands: Number 1", metadata.getName());
Assert.assertEquals(Categories.create("Root", "Branch"), metadata.getCategory());
}
try (CommandController controller = testHarness.createCommandController("Annotation Commands: Number 2"))
{
UICommandMetadata metadata = controller.getMetadata();
Assert.assertEquals("Annotation Commands: Number 2", metadata.getName());
Assert.assertEquals(Categories.create("Root"), metadata.getCategory());
}
}

@Test
public void testEnabledHandler() throws Exception
{
Expand Down

0 comments on commit 4cf681a

Please sign in to comment.