Search in sources :

Example 1 with Profiler

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());
}
Also used : Profiler(com.sun.enterprise.config.serverbeans.Profiler) ParameterMap(org.glassfish.api.admin.ParameterMap) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 2 with Profiler

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());
}
Also used : Profiler(com.sun.enterprise.config.serverbeans.Profiler) Property(org.jvnet.hk2.config.types.Property) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 3 with Profiler

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());
}
Also used : Profiler(com.sun.enterprise.config.serverbeans.Profiler) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 4 with Profiler

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());
}
Also used : Profiler(com.sun.enterprise.config.serverbeans.Profiler) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 5 with Profiler

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);
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Profiler(com.sun.enterprise.config.serverbeans.Profiler) ActionReport(org.glassfish.api.ActionReport) Property(org.jvnet.hk2.config.types.Property)

Aggregations

Profiler (com.sun.enterprise.config.serverbeans.Profiler)6 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)4 Test (org.junit.Test)4 Property (org.jvnet.hk2.config.types.Property)3 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)2 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Config (com.sun.enterprise.config.serverbeans.Config)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Server (com.sun.enterprise.config.serverbeans.Server)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ActionReport (org.glassfish.api.ActionReport)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1 TranslatedConfigView (org.glassfish.config.support.TranslatedConfigView)1 Changed (org.jvnet.hk2.config.Changed)1 TYPE (org.jvnet.hk2.config.Changed.TYPE)1