@Test public void testExecuteSuccessDefaultTarget() { parameters.set("mailhost", "localhost"); parameters.set("mailuser", "test"); parameters.set("fromaddress", "test@sun.com"); parameters.set("jndi_name", "mail/MyMailSession"); org.glassfish.resources.mail.admin.cli.CreateMailResource createCommand = habitat.getService(org.glassfish.resources.mail.admin.cli.CreateMailResource.class); assertTrue(createCommand != null); cr.getCommandInvocation("create-mail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand); assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode()); parameters = new ParameterMap(); parameters.set("jndi_name", "mail/MyMailSession"); org.glassfish.resources.mail.admin.cli.DeleteMailResource deleteCommand = habitat.getService(org.glassfish.resources.mail.admin.cli.DeleteMailResource.class); assertTrue(deleteCommand != null); cr.getCommandInvocation("delete-mail-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 MailResource) { MailResource jr = (MailResource) resource; if (jr.getJndiName().equals("mail/MyMailSession")) { isDeleted = false; logger.fine("MailResource config bean mail/MyMailSession 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("mail/MyMailSession")) { isRefDeleted = false; break; } } } } assertTrue(isRefDeleted); }
public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); if (!isResourceExists(domain.getResources(), jndiName)) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (environment.isDas()) { if ("domain".equals(target)) { if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) { report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } else { if (!resourceUtil.isResourceRefInTarget(jndiName, target)) { report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) { report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } } try { resourceUtil.deleteResourceRef(jndiName, target); ConfigSupport.apply(new SingleConfigCode<Resources>() { public Object run(Resources param) throws PropertyVetoException, TransactionFailure { MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName); return param.getResources().remove(resource); } }, domain.getResources()); report.setMessage(localStrings.getLocalString( "delete.mail.resource.success", "Mail resource {0} deleted", jndiName)); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (TransactionFailure tfe) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(tfe); } }
DeleteMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); if (!isResourceExists(domain.getResources(), jndiName)) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (environment.isDas()) { if ("domain".equals(target)) { if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) { report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } else { if (!resourceUtil.isResourceRefInTarget(jndiName, target)) { report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) { report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } } try { resourceUtil.deleteResourceRef(jndiName, target); ConfigSupport.apply(new SingleConfigCode<Resources>() { public Object run(Resources param) throws PropertyVetoException, TransactionFailure { MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName); return param.getResources().remove(resource); } }, domain.getResources()); report.setMessage(localStrings.getLocalString( "delete.mail.resource.success", "Mail resource {0} deleted", jndiName)); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (TransactionFailure tfe) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(tfe); } } }
DeleteMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); if (!isResourceExists(domain.getResources(), jndiName)) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (environment.isDas()) { if ("domain".equals(target)) { if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) { report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } else { if (!resourceUtil.isResourceRefInTarget(jndiName, target)) { report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) { report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } } try { resourceUtil.deleteResourceRef(jndiName, target); ConfigSupport.apply(new SingleConfigCode<Resources>() { public Object run(Resources param) throws PropertyVetoException, TransactionFailure { MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName); return param.getResources().remove(resource); } }, domain.getResources()); report.setMessage(localStrings.getLocalString( "delete.mail.resource.success", "Mail resource {0} deleted", jndiName)); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (TransactionFailure tfe) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(tfe); } }  }
DeleteMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); if (!isResourceExists(domain.getResources(), jndiName)) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (environment.isDas()) { if ("domain".equals(target)) { if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) { report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } else { if (!resourceUtil.isResourceRefInTarget(jndiName, target)) { report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) { report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } } try { resourceUtil.deleteResourceRef(jndiName, target); ConfigSupport.apply(new SingleConfigCode<Resources>() { public Object run(Resources param) throws PropertyVetoException, TransactionFailure { MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName); return param.getResources().remove(resource); } }, domain.getResources()); report.setMessage(localStrings.getLocalString( "delete.mail.resource.success", "Mail resource {0} deleted", jndiName)); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (TransactionFailure tfe) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(tfe); } }  void execute(AdminCommandContext context); }
DeleteMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); if (!isResourceExists(domain.getResources(), jndiName)) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (environment.isDas()) { if ("domain".equals(target)) { if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) { report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } else { if (!resourceUtil.isResourceRefInTarget(jndiName, target)) { report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) { report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; } } } try { resourceUtil.deleteResourceRef(jndiName, target); ConfigSupport.apply(new SingleConfigCode<Resources>() { public Object run(Resources param) throws PropertyVetoException, TransactionFailure { MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName); return param.getResources().remove(resource); } }, domain.getResources()); report.setMessage(localStrings.getLocalString( "delete.mail.resource.success", "Mail resource {0} deleted", jndiName)); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (TransactionFailure tfe) { report.setMessage(localStrings.getLocalString( "delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(tfe); } }  void execute(AdminCommandContext context);  }