use of org.glassfish.api.admin.CommandModel in project Payara by payara.
the class MapInjectionResolverTest method getParamValueTest.
@Test
public void getParamValueTest() {
try {
DummyCommand dc = new DummyCommand();
Class<?> cl = dc.getClass();
ParameterMap params = new ParameterMap();
params.add("hello", "world");
CommandModel dccm = new CommandModelImpl(dc.getClass());
MapInjectionResolver mir = new MapInjectionResolver(dccm, params);
AnnotatedElement ae = (AnnotatedElement) cl.getDeclaredField("hello");
String hello = mir.getValue(dc, ae, null, String.class);
assertEquals("hello should be world", "world", hello);
} catch (Exception ex) {
ex.printStackTrace();
fail("unexpected exception");
}
}
use of org.glassfish.api.admin.CommandModel in project Payara by payara.
the class CommandRunnerTest method getUsageTextTest.
@Test
public void getUsageTextTest() {
String expectedUsageText = "Usage: dummy-admin --foo=foo [--bar=false] --hello=there world ";
DummyAdminCommand dac = new DummyAdminCommand();
CommandModel model = new CommandModelImpl(DummyAdminCommand.class);
String actualUsageText = cr.getUsageText(model);
assertEquals(expectedUsageText, actualUsageText);
}
use of org.glassfish.api.admin.CommandModel in project Payara by payara.
the class Util method getMethodParameterList.
public static String getMethodParameterList(CommandModel cm, boolean withType, boolean includeOptional) {
StringBuilder sb = new StringBuilder();
Collection<CommandModel.ParamModel> params = cm.getParameters();
if ((params != null) && (!params.isEmpty())) {
String sep = "";
for (CommandModel.ParamModel model : params) {
Param param = model.getParam();
boolean include = true;
if (param.optional() && !includeOptional) {
continue;
}
sb.append(sep);
if (withType) {
String type = model.getType().getName();
if (model.getType().isArray()) {
type = model.getType().getName().substring(2);
type = type.substring(0, type.length() - 1) + "[]";
} else if (type.startsWith("java.lang")) {
type = model.getType().getSimpleName();
}
sb.append(type);
}
sb.append(" _").append(Util.eleminateHypen(model.getName()));
sep = ", ";
}
}
return sb.toString();
}
use of org.glassfish.api.admin.CommandModel in project Payara by payara.
the class StatusGenerator method getParamMetaData.
public Collection<CommandModel.ParamModel> getParamMetaData(String commandName) {
CommandRunner cr = serviceLocator.getService(CommandRunner.class);
CommandModel cm = cr.getModel(commandName, RestLogging.restLogger);
Collection<CommandModel.ParamModel> params = cm.getParameters();
return params;
}
use of org.glassfish.api.admin.CommandModel in project Payara by payara.
the class ResourceUtil method getParamMetaData.
/**
* Constructs and returns the parameter meta-data.
*
* @param commandName the command associated with the resource method
* @param commandParamsToSkip the command parameters for which not to
* include the meta-data.
* @param habitat the habitat
* @param logger the logger to use
* @return Collection the meta-data for the parameter of the resource
* method.
*/
public static Collection<CommandModel.ParamModel> getParamMetaData(String commandName, Collection<String> commandParamsToSkip, ServiceLocator habitat) {
CommandModel cm = habitat.<CommandRunner>getService(CommandRunner.class).getModel(commandName, RestLogging.restLogger);
Collection<String> parameterNames = cm.getParametersNames();
ArrayList<CommandModel.ParamModel> metaData = new ArrayList<CommandModel.ParamModel>();
CommandModel.ParamModel paramModel;
for (String name : parameterNames) {
paramModel = cm.getModelFor(name);
String parameterName = (paramModel.getParam().primary()) ? "id" : paramModel.getName();
if (!commandParamsToSkip.contains(parameterName)) {
metaData.add(paramModel);
}
}
// print(metaData);
return metaData;
}
Aggregations