use of com.sun.enterprise.config.serverbeans.Profiler in project Payara by payara.
the class CreateProfilerTest method testExecuteSuccessUpdateExisting.
/**
* Test of execute method, creating a new when there is already one.
* asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
* --enabled=true --classpath "myProfilerClasspath" testProfiler
*/
@Test
public void testExecuteSuccessUpdateExisting() {
assertTrue(parameters.size() == 0);
parameters.set("DEFAULT", "testProfiler");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
parameters = new ParameterMap();
// Create another profiler, see if it overrides the existing one
parameters.set("DEFAULT", "testProfilerNew");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the resource was created
boolean isCreated = false;
Profiler profiler = javaConfig.getProfiler();
if (profiler.getName().equals("testProfilerNew")) {
// assertEquals("myProfilerClasspath", profiler.getClasspath());
assertEquals("true", profiler.getEnabled());
// assertEquals("nativelibrarypath", profiler.getNativeLibraryPath());
isCreated = true;
logger.fine("Profiler element testProfilerNew is created.");
}
assertTrue(isCreated);
// Check the success message
// assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Profiler in project Payara by payara.
the class CreateProfilerTest method testExecuteSuccess.
/**
* Test of execute method, of class CreateProfiler.
* asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
* --enabled=true --classpath "myProfilerClasspath" testProfiler
*/
@Test
public void testExecuteSuccess() {
// Set the options and operand to pass to the command
parameters.set("classpath", "myProfilerClasspath");
parameters.set("enabled", "true");
parameters.set("nativelibrarypath", "myNativeLibraryPath");
parameters.set("property", "a=x:b=y:c=z");
parameters.set("DEFAULT", "testProfiler");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the profiler is created
boolean isCreated = false;
int propertyCount = 0;
Profiler profiler = javaConfig.getProfiler();
if (profiler.getName().equals("testProfiler")) {
assertEquals("myProfilerClasspath", profiler.getClasspath());
assertEquals("true", profiler.getEnabled());
assertEquals("myNativeLibraryPath", profiler.getNativeLibraryPath());
List<Property> properties = profiler.getProperty();
for (Property property : properties) {
if (property.getName().equals("a"))
assertEquals("x", property.getValue());
if (property.getName().equals("b"))
assertEquals("y", property.getValue());
if (property.getName().equals("c"))
assertEquals("z", property.getValue());
propertyCount++;
}
isCreated = true;
logger.fine("Profiler element myProfiler is created.");
}
assertTrue(isCreated);
assertEquals(propertyCount, 3);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check the success message
// assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Profiler in project Payara by payara.
the class CreateProfilerTest method testExecuteSuccessDefaultValues.
/**
* Test of execute method, of class CreateProfiler with default values.
* asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
* --enabled=true --classpath "myProfilerClasspath" testProfiler
*/
@Test
public void testExecuteSuccessDefaultValues() {
// Only pass the required option and operand
assertTrue(parameters.size() == 0);
parameters.set("DEFAULT", "myProfilerAllDefaults");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the resource was created
boolean isCreated = false;
Profiler profiler = javaConfig.getProfiler();
if (profiler.getName().equals("myProfilerAllDefaults")) {
// assertEquals("myProfilerClasspath", profiler.getClasspath());
assertEquals("true", profiler.getEnabled());
// assertEquals("nativelibrarypath", profiler.getNativeLibraryPath());
isCreated = true;
logger.fine("Profiler element myProfilerAllDefaults is created.");
}
assertTrue(isCreated);
// Check the success message
// assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Profiler in project Payara by payara.
the class CreateProfilerTest method testExecuteSuccessNoValueOptionEnabled.
/**
* Test of execute method, of class CreateProfiler when enabled has no value
* asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
* --enabled=true --classpath "myProfilerClasspath" testProfiler
*/
@Test
public void testExecuteSuccessNoValueOptionEnabled() {
// Set enabled without a value: --enabled
assertTrue(parameters.size() == 0);
parameters.set("enabled", "");
parameters.set("DEFAULT", "testProfiler");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check that the profiler is created
boolean isCreated = false;
Profiler profiler = javaConfig.getProfiler();
if (profiler.getName().equals("testProfiler")) {
assertEquals("true", profiler.getEnabled());
isCreated = true;
logger.fine("msg: " + context.getActionReport().getMessage());
}
assertTrue(isCreated);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check the success message
// assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Profiler in project Payara by payara.
the class CreateProfiler method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
if (javaConfig.getProfiler() != null) {
System.out.println("profiler exists. Please delete it first");
report.setMessage(localStrings.getLocalString("create.profiler.alreadyExists", "profiler exists. Please delete it first"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<JavaConfig>() {
public Object run(JavaConfig param) throws PropertyVetoException, TransactionFailure {
Profiler newProfiler = param.createChild(Profiler.class);
newProfiler.setName(name);
newProfiler.setClasspath(classpath);
newProfiler.setEnabled(enabled.toString());
newProfiler.setNativeLibraryPath(nativeLibraryPath);
if (properties != null) {
for (Map.Entry e : properties.entrySet()) {
Property prop = newProfiler.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
newProfiler.getProperty().add(prop);
}
}
param.setProfiler(newProfiler);
return newProfiler;
}
}, javaConfig);
} catch (TransactionFailure e) {
report.setMessage(localStrings.getLocalString("create.profiler.fail", "{0} create failed ", name));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations