@Test public void testExecuteFailDuplicateResource() { parameters.set("mailhost", "localhost"); parameters.set("mailuser", "test"); parameters.set("fromaddress", "test@sun.com"); parameters.set("jndi_name", "dupRes"); org.glassfish.resources.mail.admin.cli.CreateMailResource command1 = habitat.getService(org.glassfish.resources.mail.admin.cli.CreateMailResource.class); assertTrue(command1 != null); cr.getCommandInvocation("create-mail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command1); assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode()); boolean isCreated = false; for (Resource resource : resources.getResources()) { if (resource instanceof MailResource) { MailResource jr = (MailResource) resource; if (jr.getJndiName().equals("dupRes")) { isCreated = true; logger.fine("MailResource config bean dupRes is created."); break; } } } assertTrue(isCreated); org.glassfish.resources.mail.admin.cli.CreateMailResource command2 = habitat.getService(org.glassfish.resources.mail.admin.cli.CreateMailResource.class); cr.getCommandInvocation("create-mail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2); assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode()); int numDupRes = 0; for (Resource resource : resources.getResources()) { if (resource instanceof MailResource) { MailResource jr = (MailResource) resource; if (jr.getJndiName().equals("dupRes")) { numDupRes = numDupRes + 1; } } } assertEquals(1, numDupRes); logger.fine("msg: " + context.getActionReport().getMessage()); }
public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); HashMap attributes = new HashMap(); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO, transportProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_DEBUG, debug.toString()); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.ENABLED, enabled.toString()); attributes.put(ServerTags.DESCRIPTION, description); ResourceStatus rs; try { rs = mailResMgr.create(domain.getResources(), attributes, properties, target); } catch(Exception e) { Logger.getLogger(CreateMailResource.class.getName()).log(Level.SEVERE, "Unable to create Mail Resource " + jndiName, e); String def = "Mail resource: {0} could not be created"; report.setMessage(localStrings.getLocalString("create.mail.resource.fail", def, jndiName) + " " + e.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS; if (rs.getStatus() == ResourceStatus.FAILURE) { ec = ActionReport.ExitCode.FAILURE; if (rs.getMessage() == null) { report.setMessage(localStrings.getLocalString("create.mail.resource.fail", "Unable to create Mail Resource {0}.", jndiName)); } if (rs.getException() != null) report.setFailureCause(rs.getException()); } if(rs.getMessage() != null){ report.setMessage(rs.getMessage()); } report.setActionExitCode(ec); }
CreateMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); HashMap attributes = new HashMap(); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO, transportProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_DEBUG, debug.toString()); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.ENABLED, enabled.toString()); attributes.put(ServerTags.DESCRIPTION, description); ResourceStatus rs; try { rs = mailResMgr.create(domain.getResources(), attributes, properties, target); } catch(Exception e) { Logger.getLogger(CreateMailResource.class.getName()).log(Level.SEVERE, "Unable to create Mail Resource " + jndiName, e); String def = "Mail resource: {0} could not be created"; report.setMessage(localStrings.getLocalString("create.mail.resource.fail", def, jndiName) + " " + e.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS; if (rs.getStatus() == ResourceStatus.FAILURE) { ec = ActionReport.ExitCode.FAILURE; if (rs.getMessage() == null) { report.setMessage(localStrings.getLocalString("create.mail.resource.fail", "Unable to create Mail Resource {0}.", jndiName)); } if (rs.getException() != null) report.setFailureCause(rs.getException()); } if(rs.getMessage() != null){ report.setMessage(rs.getMessage()); } report.setActionExitCode(ec); } }
CreateMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); HashMap attributes = new HashMap(); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO, transportProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_DEBUG, debug.toString()); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.ENABLED, enabled.toString()); attributes.put(ServerTags.DESCRIPTION, description); ResourceStatus rs; try { rs = mailResMgr.create(domain.getResources(), attributes, properties, target); } catch(Exception e) { Logger.getLogger(CreateMailResource.class.getName()).log(Level.SEVERE, "Unable to create Mail Resource " + jndiName, e); String def = "Mail resource: {0} could not be created"; report.setMessage(localStrings.getLocalString("create.mail.resource.fail", def, jndiName) + " " + e.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS; if (rs.getStatus() == ResourceStatus.FAILURE) { ec = ActionReport.ExitCode.FAILURE; if (rs.getMessage() == null) { report.setMessage(localStrings.getLocalString("create.mail.resource.fail", "Unable to create Mail Resource {0}.", jndiName)); } if (rs.getException() != null) report.setFailureCause(rs.getException()); } if(rs.getMessage() != null){ report.setMessage(rs.getMessage()); } report.setActionExitCode(ec); }  }
CreateMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); HashMap attributes = new HashMap(); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO, transportProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_DEBUG, debug.toString()); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.ENABLED, enabled.toString()); attributes.put(ServerTags.DESCRIPTION, description); ResourceStatus rs; try { rs = mailResMgr.create(domain.getResources(), attributes, properties, target); } catch(Exception e) { Logger.getLogger(CreateMailResource.class.getName()).log(Level.SEVERE, "Unable to create Mail Resource " + jndiName, e); String def = "Mail resource: {0} could not be created"; report.setMessage(localStrings.getLocalString("create.mail.resource.fail", def, jndiName) + " " + e.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS; if (rs.getStatus() == ResourceStatus.FAILURE) { ec = ActionReport.ExitCode.FAILURE; if (rs.getMessage() == null) { report.setMessage(localStrings.getLocalString("create.mail.resource.fail", "Unable to create Mail Resource {0}.", jndiName)); } if (rs.getException() != null) report.setFailureCause(rs.getException()); } if(rs.getMessage() != null){ report.setMessage(rs.getMessage()); } report.setActionExitCode(ec); }  void execute(AdminCommandContext context); }
CreateMailResource implements AdminCommand { public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); HashMap attributes = new HashMap(); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO, transportProtocol); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_DEBUG, debug.toString()); attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.ENABLED, enabled.toString()); attributes.put(ServerTags.DESCRIPTION, description); ResourceStatus rs; try { rs = mailResMgr.create(domain.getResources(), attributes, properties, target); } catch(Exception e) { Logger.getLogger(CreateMailResource.class.getName()).log(Level.SEVERE, "Unable to create Mail Resource " + jndiName, e); String def = "Mail resource: {0} could not be created"; report.setMessage(localStrings.getLocalString("create.mail.resource.fail", def, jndiName) + " " + e.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS; if (rs.getStatus() == ResourceStatus.FAILURE) { ec = ActionReport.ExitCode.FAILURE; if (rs.getMessage() == null) { report.setMessage(localStrings.getLocalString("create.mail.resource.fail", "Unable to create Mail Resource {0}.", jndiName)); } if (rs.getException() != null) report.setFailureCause(rs.getException()); } if(rs.getMessage() != null){ report.setMessage(rs.getMessage()); } report.setActionExitCode(ec); }  void execute(AdminCommandContext context);  }