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;
}
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);
}
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);
}
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());
}
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);
}
Aggregations