-
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-1046: Introduced InputComponentFactory to allow dynamic creatio…
…n of InputComponents without injection
- Loading branch information
Showing
3 changed files
with
149 additions
and
30 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
ui/api/src/main/java/org/jboss/forge/addon/ui/InputComponentFactory.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,44 @@ | ||
/* | ||
* 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; | ||
|
||
import org.jboss.forge.addon.ui.input.UIInput; | ||
import org.jboss.forge.addon.ui.input.UIInputMany; | ||
import org.jboss.forge.addon.ui.input.UISelectMany; | ||
import org.jboss.forge.addon.ui.input.UISelectOne; | ||
import org.jboss.forge.furnace.services.Exported; | ||
|
||
/** | ||
* Allows creation of input components without injection | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
*/ | ||
@Exported | ||
public interface InputComponentFactory | ||
{ | ||
/** | ||
* Creates an {@link UIInput} component | ||
*/ | ||
public abstract <T> UIInput<T> createInput(String name, Class<T> valueType); | ||
|
||
/** | ||
* Creates an {@link UIInputMany} component | ||
*/ | ||
public abstract <T> UIInputMany<T> createInputMany(String name, Class<T> valueType); | ||
|
||
/** | ||
* Creates an {@link UISelectOne} component | ||
*/ | ||
public abstract <T> UISelectOne<T> createSelectOne(String name, Class<T> valueType); | ||
|
||
/** | ||
* Creates an {@link UISelectMany} component | ||
*/ | ||
public abstract <T> UISelectMany<T> createSelectMany(String name, Class<T> valueType); | ||
} |
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
76 changes: 76 additions & 0 deletions
76
ui/tests/src/test/java/org/jboss/forge/addon/ui/impl/InputComponentFactoryTest.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,76 @@ | ||
/* | ||
* Copyright 2012 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.impl; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.addon.ui.InputComponentFactory; | ||
import org.jboss.forge.addon.ui.input.UIInput; | ||
import org.jboss.forge.addon.ui.input.UIInputMany; | ||
import org.jboss.forge.addon.ui.input.UISelectMany; | ||
import org.jboss.forge.addon.ui.input.UISelectOne; | ||
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.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class InputComponentFactoryTest | ||
{ | ||
@Deployment | ||
@Dependencies({ @AddonDependency(name = "org.jboss.forge.addon:ui", version = "2.0.0-SNAPSHOT"), | ||
@AddonDependency(name = "org.jboss.forge.furnace:container-cdi", version = "2.0.0-SNAPSHOT") }) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.addon:ui", "2.0.0-SNAPSHOT"), | ||
AddonDependencyEntry.create("org.jboss.forge.furnace:container-cdi", "2.0.0-SNAPSHOT")); | ||
|
||
return archive; | ||
} | ||
|
||
@Inject | ||
InputComponentFactory factory; | ||
|
||
@Test | ||
public void testCreateUIInput() throws Exception | ||
{ | ||
UIInput<String> input = factory.createInput("foo", String.class); | ||
Assert.assertNotNull(input); | ||
} | ||
|
||
@Test | ||
public void testCreateUIInputMany() throws Exception | ||
{ | ||
UIInputMany<String> input = factory.createInputMany("foo", String.class); | ||
Assert.assertNotNull(input); | ||
} | ||
|
||
@Test | ||
public void testCreateUISelectMany() throws Exception | ||
{ | ||
UISelectMany<String> input = factory.createSelectMany("foo", String.class); | ||
Assert.assertNotNull(input); | ||
} | ||
|
||
@Test | ||
public void testCreateUISelectOne() throws Exception | ||
{ | ||
UISelectOne<String> input = factory.createSelectOne("foo", String.class); | ||
Assert.assertNotNull(input); | ||
} | ||
} |