Search in sources :

Example 11 with JdbcResource

use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.

the class JdbcResourcesUtil method getJdbcConnectionPoolOfResource.

public JdbcConnectionPool getJdbcConnectionPoolOfResource(ResourceInfo resourceInfo) {
    JdbcResource resource = null;
    JdbcConnectionPool pool = null;
    Resources resources = getResources(resourceInfo);
    if (resources != null) {
        resource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, resourceInfo.getName());
        if (resource != null) {
            pool = (JdbcConnectionPool) ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, resource.getPoolName());
        }
    }
    return pool;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 12 with JdbcResource

use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.

the class DeleteJdbcResourceTest method testExecuteSuccessTargetServer.

/**
 * Test of execute method, of class DeleteJdbcResource.
 * delete-jdbc-resource --target server jdbc/foo
 */
@Test
public void testExecuteSuccessTargetServer() {
    // Set operand
    parameters.add("target", "server");
    parameters.add("DEFAULT", "jdbc/foo");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource was deleted
    boolean isDeleted = true;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            JdbcResource jr = (JdbcResource) resource;
            if (jr.getJndiName().equals("jdbc/foo")) {
                isDeleted = false;
                logger.fine("JdbcResource config bean jdbc/foo is deleted.");
                continue;
            }
        }
    }
    assertTrue(isDeleted);
    logger.fine("msg: " + context.getActionReport().getMessage());
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource ref was deleted
    Servers servers = habitat.getService(Servers.class);
    boolean isRefDeleted = true;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("jdbc/foo")) {
                    isRefDeleted = false;
                    continue;
                }
            }
        }
    }
    assertTrue(isRefDeleted);
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 13 with JdbcResource

use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.

the class DeleteJdbcResourceTest method testExecuteSuccessDefaultTarget.

/**
 * Test of execute method, of class DeleteJdbcResource.
 * delete-jdbc-resource jdbc/foo
 */
@Test
public void testExecuteSuccessDefaultTarget() {
    // Set operand
    parameters.add("DEFAULT", "jdbc/foo");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource was deleted
    boolean isDeleted = true;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            JdbcResource jr = (JdbcResource) resource;
            if (jr.getJndiName().equals("jdbc/foo")) {
                isDeleted = false;
                logger.fine("JdbcResource config bean jdbc/foo is deleted.");
                continue;
            }
        }
    }
    assertTrue(isDeleted);
    logger.fine("msg: " + context.getActionReport().getMessage());
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the resource ref was deleted
    Servers servers = habitat.getService(Servers.class);
    boolean isRefDeleted = true;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("jdbc/foo")) {
                    isRefDeleted = false;
                    continue;
                }
            }
        }
    }
    assertTrue(isRefDeleted);
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 14 with JdbcResource

use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.

the class CreateJdbcResourceTest method testExecuteSuccessNoValueOptionEnabled.

/**
 * Test of execute method, of class CreateJdbcResource when enabled has no value
 * asadmin create-jdbc-resource --connectionpoolid DerbyPool --enabled
 *         --description "my resource" jdbc/sun
 */
@Test
public void testExecuteSuccessNoValueOptionEnabled() {
    // Set enabled without a value:  --enabled
    parameters.set("enabled", "");
    parameters.set("DEFAULT", "jdbc/sun");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-jdbc-resource", 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 with enabled set to true
    boolean isCreated = false;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            JdbcResource jr = (JdbcResource) resource;
            if (jr.getJndiName().equals("jdbc/sun")) {
                assertEquals("DerbyPool", jr.getPoolName());
                assertEquals("true", jr.getEnabled());
                assertEquals("my resource", jr.getDescription());
                isCreated = true;
                continue;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 15 with JdbcResource

use of org.glassfish.jdbc.config.JdbcResource in project Payara by payara.

the class CreateJdbcResourceTest method testExecuteSuccess.

/**
 * Test of execute method, of class CreateJdbcResource.
 * asadmin create-jdbc-resource --connectionpoolid DerbyPool --enabled=true
 *        --description "my resource" jdbc/foo
 */
@Test
public void testExecuteSuccess() {
    // Set operand
    parameters.set("DEFAULT", "jdbc/foo");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-jdbc-resource", 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;
    for (Resource resource : resources.getResources()) {
        if (resource instanceof JdbcResource) {
            JdbcResource jr = (JdbcResource) resource;
            if (jr.getJndiName().equals("jdbc/foo")) {
                assertEquals("DerbyPool", jr.getPoolName());
                assertEquals("true", jr.getEnabled());
                assertEquals("my resource", jr.getDescription());
                isCreated = true;
                logger.fine("JdbcResource config bean jdbc/foo is created.");
                continue;
            }
        }
    }
    assertTrue(isCreated);
    logger.fine("msg: " + context.getActionReport().getMessage());
    // Check resource-ref created
    Servers servers = habitat.getService(Servers.class);
    boolean isRefCreated = false;
    for (Server server : servers.getServer()) {
        if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            for (ResourceRef ref : server.getResourceRef()) {
                if (ref.getRef().equals("jdbc/foo")) {
                    assertEquals("true", ref.getEnabled());
                    isRefCreated = true;
                    continue;
                }
            }
        }
    }
    assertTrue(isRefCreated);
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

JdbcResource (org.glassfish.jdbc.config.JdbcResource)35 Test (org.junit.Test)12 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)9 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)9 JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)7 Resource (com.sun.enterprise.config.serverbeans.Resource)6 Resources (com.sun.enterprise.config.serverbeans.Resources)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 Domain (com.sun.enterprise.config.serverbeans.Domain)4 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)4 PropertyVetoException (java.beans.PropertyVetoException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 DataSourceDefinitionDescriptor (com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)2 NamingException (javax.naming.NamingException)2 ResourceException (javax.resource.ResourceException)2 XAResource (javax.transaction.xa.XAResource)2 ConnectorRuntime (com.sun.appserv.connectors.internal.api.ConnectorRuntime)1