use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class DeleteCustomResourceTest method testExecuteSuccessDefaultTarget.
/**
* Test of execute method, of class DeleteCustomResource.
* delete-custom-resource sample_custom_resource
*/
@Test
public void testExecuteSuccessDefaultTarget() {
org.glassfish.resources.admin.cli.CreateCustomResource createCommand = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
assertTrue(createCommand != null);
parameters.set("restype", "topic");
parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
parameters.set("jndi_name", "sample_custom_resource");
cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
parameters = new ParameterMap();
org.glassfish.resources.admin.cli.DeleteCustomResource deleteCommand = habitat.getService(org.glassfish.resources.admin.cli.DeleteCustomResource.class);
assertTrue(deleteCommand != null);
parameters.set("jndi_name", "sample_custom_resource");
cr.getCommandInvocation("delete-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isDeleted = true;
for (Resource resource : resources.getResources()) {
if (resource instanceof CustomResource) {
CustomResource jr = (CustomResource) resource;
if (jr.getJndiName().equals("sample_custom_resource")) {
isDeleted = false;
logger.fine("CustomResource config bean sample_custom_resource is deleted.");
break;
}
}
}
assertTrue(isDeleted);
logger.fine("msg: " + context.getActionReport().getMessage());
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
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("sample_custom_resource")) {
isRefDeleted = false;
break;
}
}
}
}
assertTrue(isRefDeleted);
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class CreateCustomResourceTest method testExecuteSuccess.
/**
* Test of execute method, of class CreateCustomResource.
* asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
* sample_custom_resource
*/
@Test
public void testExecuteSuccess() {
parameters.set("restype", "topic");
parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
parameters.set("jndi_name", "sample_custom_resource");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-custom-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 CustomResource) {
CustomResource r = (CustomResource) resource;
if (r.getJndiName().equals("sample_custom_resource")) {
assertEquals("topic", r.getResType());
assertEquals("javax.naming.spi.ObjectFactory", r.getFactoryClass());
assertEquals("true", r.getEnabled());
isCreated = true;
logger.fine("Custom Resource config bean sample_custom_resource is created.");
break;
}
}
}
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("sample_custom_resource")) {
assertEquals("true", ref.getEnabled());
isRefCreated = true;
break;
}
}
}
}
assertTrue(isRefCreated);
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class DeleteCustomResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
for (Resource resource : param.getResources()) {
if (resource instanceof CustomResource) {
CustomResource r = (CustomResource) resource;
if (r.getJndiName().equals("sample_custom_resource")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
parameters = new ParameterMap();
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class CreateCustomResourceTest method testExecuteFailDuplicateResource.
/**
* Test of execute method, of class CreateCustomResource.
* asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
* dupRes
* asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
* dupRes
*/
@Test
public void testExecuteFailDuplicateResource() {
parameters.set("restype", "topic");
parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
parameters.set("jndi_name", "dupRes");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-custom-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 CustomResource) {
CustomResource jr = (CustomResource) resource;
if (jr.getJndiName().equals("dupRes")) {
isCreated = true;
logger.fine("Custom Resource config bean dupRes is created.");
break;
}
}
}
assertTrue(isCreated);
// Try to create a duplicate resource dupRes. Get a new instance of the command.
org.glassfish.resources.admin.cli.CreateCustomResource command2 = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
// Check that the 2nd resource was NOT created
int numDupRes = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof CustomResource) {
CustomResource jr = (CustomResource) resource;
if (jr.getJndiName().equals("dupRes")) {
numDupRes = numDupRes + 1;
}
}
}
assertEquals(1, numDupRes);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of org.glassfish.resources.config.CustomResource in project Payara by payara.
the class CreateCustomResourceTest method testExecuteWithOptionalValuesSet.
/**
* Test of execute method, of class CreateCustomResource.
* asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
* --enabled=false --description=Administered Object sample_custom_resource
*/
@Test
public void testExecuteWithOptionalValuesSet() {
parameters.set("restype", "topic");
parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
parameters.set("enabled", "false");
parameters.set("description", "Administered Object");
parameters.set("jndi_name", "sample_custom_resource");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-custom-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 CustomResource) {
CustomResource r = (CustomResource) resource;
if (r.getJndiName().equals("sample_custom_resource")) {
assertEquals("topic", r.getResType());
assertEquals("javax.naming.spi.ObjectFactory", r.getFactoryClass());
// expect enabled for the resource to be true as resource-ref's enabled
// would be set to false
assertEquals("true", r.getEnabled());
assertEquals("Administered Object", r.getDescription());
isCreated = true;
logger.fine("Custom Resource config bean sample_custom_resource is created.");
break;
}
}
}
assertTrue(isCreated);
logger.fine("msg: " + context.getActionReport().getMessage());
}
Aggregations