Last active
August 29, 2015 14:07
-
-
Save rmannibucau/019a24aa16e3520290e7 to your computer and use it in GitHub Desktop.
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
public class SimpleDeploymentExtension implements LoadableExtension { | |
@Override | |
public void register(final ExtensionBuilder extensionBuilder) { | |
extensionBuilder.service(DeploymentScenarioGenerator.class, SimpleDeploymentScenarioGenerator.class); | |
} | |
public static class SimpleDeploymentScenarioGenerator implements DeploymentScenarioGenerator { | |
private static final Method VALIDATE; | |
private static final Method GENERATE; | |
static { | |
try { | |
VALIDATE = AnnotationDeploymentScenarioGenerator.class.getDeclaredMethod("validate", Method.class); | |
VALIDATE.setAccessible(true); | |
GENERATE = AnnotationDeploymentScenarioGenerator.class.getDeclaredMethod("generateDeployment", Method.class); | |
GENERATE.setAccessible(true); | |
} catch (final NoSuchMethodException e) { | |
throw new IllegalStateException(e); | |
} | |
} | |
private final DeploymentScenarioGenerator standard = new AnnotationDeploymentScenarioGenerator(); | |
@Override | |
public List<DeploymentDescription> generate(final TestClass testClass) { | |
final List<DeploymentDescription> stdDeploymentDescriptions = standard.generate(testClass); | |
final App app = testClass.getAnnotation(App.class); | |
if (app != null) { | |
final List<DeploymentDescription> list = new ArrayList<DeploymentDescription>(stdDeploymentDescriptions.size() + 1); | |
Class<?> deploymentClass = app.deploymentClass(); | |
if (deploymentClass == App.class) { | |
deploymentClass = SystemInstance.get().getOptions().get(SimpleDeploymentExtension.class.getName() + ".defaultClass", (Class<?>) null); | |
} | |
String name = app.name(); | |
if (name.isEmpty()) { | |
name = SystemInstance.get().getOptions().get(SimpleDeploymentExtension.class.getName() + ".defaultMethod", (String) null); | |
} | |
try { | |
final Method method = deploymentClass.getMethod(name); | |
VALIDATE.invoke(method); | |
final DeploymentDescription deployment = DeploymentDescription.class.cast(GENERATE.invoke(method)); | |
list.add(deployment); // before others | |
} catch (final Exception e) { | |
throw new IllegalArgumentException(e); | |
} | |
list.addAll(stdDeploymentDescriptions); | |
return list; | |
} | |
return stdDeploymentDescriptions; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment