-
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-1486: Implemented faces-project-stage
- Loading branch information
Showing
6 changed files
with
230 additions
and
3 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
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
91 changes: 91 additions & 0 deletions
91
javaee/impl/src/main/java/org/jboss/forge/addon/javaee/faces/ui/ProjectStageCommand.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,91 @@ | ||
/** | ||
* 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.javaee.faces.ui; | ||
|
||
import javax.faces.application.ProjectStage; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.forge.addon.javaee.faces.FacesFacet; | ||
import org.jboss.forge.addon.javaee.servlet.ServletFacet; | ||
import org.jboss.forge.addon.javaee.ui.AbstractJavaEECommand; | ||
import org.jboss.forge.addon.projects.Project; | ||
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.input.UISelectOne; | ||
import org.jboss.forge.addon.ui.metadata.UICommandMetadata; | ||
import org.jboss.forge.addon.ui.metadata.WithAttributes; | ||
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.Metadata; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class ProjectStageCommand extends AbstractJavaEECommand | ||
{ | ||
|
||
@Inject | ||
@WithAttributes(label = "") | ||
private UISelectOne<ProjectStage> set; | ||
|
||
@Override | ||
public void initializeUI(UIBuilder builder) throws Exception | ||
{ | ||
builder.add(set); | ||
} | ||
|
||
@Override | ||
public UICommandMetadata getMetadata(UIContext context) | ||
{ | ||
return Metadata.from(super.getMetadata(context), getClass()).name("Faces: Project Stage") | ||
.description("Set the project stage of this JSF project") | ||
.category(Categories.create(super.getMetadata(context).getCategory(), "JSF")); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Override | ||
public Result execute(UIExecutionContext context) throws Exception | ||
{ | ||
final Result result; | ||
Project project = getSelectedProject(context.getUIContext()); | ||
FacesFacet facesFacet = project.getFacet(FacesFacet.class); | ||
if (set.hasValue()) | ||
{ | ||
ProjectStage projectStage = set.getValue(); | ||
facesFacet.setProjectStage(projectStage); | ||
result = Results.success("Faces PROJECT_STAGE updated to: " + projectStage); | ||
} | ||
else | ||
{ | ||
result = Results.success("Project stage is currently: " + facesFacet.getProjectStage()); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled(UIContext context) | ||
{ | ||
boolean enabled = super.isEnabled(context); | ||
if (enabled) | ||
{ | ||
final Project project = getSelectedProject(context); | ||
enabled = project.hasFacet(ServletFacet.class) && project.hasFacet(FacesFacet.class); | ||
} | ||
return enabled; | ||
} | ||
|
||
@Override | ||
protected boolean isProjectRequired() | ||
{ | ||
return true; | ||
} | ||
|
||
} |
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
85 changes: 85 additions & 0 deletions
85
...ts/src/test/java/org/jboss/forge/addon/javaee/faces/ui/setup/ProjectStageCommandTest.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,85 @@ | ||
/** | ||
* 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.javaee.faces.ui.setup; | ||
|
||
import javax.faces.application.ProjectStage; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.addon.javaee.ProjectHelper; | ||
import org.jboss.forge.addon.javaee.faces.FacesFacet_2_2; | ||
import org.jboss.forge.addon.javaee.faces.ui.ProjectStageCommand; | ||
import org.jboss.forge.addon.projects.Project; | ||
import org.jboss.forge.addon.ui.controller.CommandController; | ||
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.ui.test.UITestHarness; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class ProjectStageCommandTest | ||
{ | ||
@Deployment | ||
@Dependencies({ | ||
@AddonDependency(name = "org.jboss.forge.addon:ui"), | ||
@AddonDependency(name = "org.jboss.forge.addon:ui-test-harness"), | ||
@AddonDependency(name = "org.jboss.forge.addon:javaee"), | ||
@AddonDependency(name = "org.jboss.forge.addon:projects"), | ||
@AddonDependency(name = "org.jboss.forge.addon:maven") | ||
}) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
return ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addClass(ProjectHelper.class) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"), | ||
AddonDependencyEntry.create("org.jboss.forge.addon:projects"), | ||
AddonDependencyEntry.create("org.jboss.forge.addon:javaee"), | ||
AddonDependencyEntry.create("org.jboss.forge.addon:maven"), | ||
AddonDependencyEntry.create("org.jboss.forge.addon:ui"), | ||
AddonDependencyEntry.create("org.jboss.forge.addon:ui-test-harness") | ||
); | ||
} | ||
|
||
@Inject | ||
private ProjectHelper projectHelper; | ||
|
||
@Inject | ||
private UITestHarness testHarness; | ||
|
||
@Test | ||
public void testSetProjectStage() throws Exception | ||
{ | ||
Project project = projectHelper.createWebProject(); | ||
projectHelper.installServlet_3_1(project); | ||
FacesFacet_2_2 facesFacet = projectHelper.installFaces_2_2(project); | ||
Assert.assertEquals(ProjectStage.Production, facesFacet.getProjectStage()); | ||
try (CommandController controller = testHarness.createCommandController(ProjectStageCommand.class, | ||
project.getProjectRoot())) | ||
{ | ||
controller.initialize(); | ||
Assert.assertTrue(controller.isEnabled()); | ||
controller.setValueFor("set", ProjectStage.Development); | ||
Assert.assertTrue(controller.canExecute()); | ||
controller.execute(); | ||
Assert.assertEquals(ProjectStage.Development, facesFacet.getProjectStage()); | ||
} | ||
} | ||
} |
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