@Test public void testExecuteSuccess() { 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 command = habitat.getService(org.glassfish.resources.mail.admin.cli.CreateMailResource.class); assertTrue(command != null); cr.getCommandInvocation("create-mail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command); assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode()); boolean isCreated = false; for (Resource resource : resources.getResources()) { if (resource instanceof MailResource) { MailResource r = (MailResource) resource; if (r.getJndiName().equals("mail/MyMailSession")) { assertEquals("localhost", r.getHost()); assertEquals("test", r.getUser()); assertEquals("test@sun.com", r.getFrom()); assertEquals("true", r.getEnabled()); assertEquals("false", r.getDebug()); assertEquals("imap", r.getStoreProtocol()); assertEquals("com.sun.mail.imap.IMAPStore", r.getStoreProtocolClass()); assertEquals("smtp", r.getTransportProtocol()); assertEquals("com.sun.mail.smtp.SMTPTransport", r.getTransportProtocolClass()); isCreated = true; logger.fine("MailResource config bean mail/MyMailSession is created."); break; } } } assertTrue(isCreated); logger.fine("msg: " + context.getActionReport().getMessage()); 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("mail/MyMailSession")) { assertEquals("true", ref.getEnabled()); isRefCreated = true; break; } } } } assertTrue(isRefCreated); }
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);  }