use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class CreateJavaMailResourceTest method testExecuteWithOptionalValuesSet.
/**
* Test of execute method, of class CreateJavaMailResource when enabled has no value
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com --enabled=false --debug=true
* --storeprotocol=pop
* --storeprotocolclass=com.sun.mail.pop.POPStore
* --transprotocol=lmtp
* --transprotocolclass=com.sun.mail.lmtop.LMTPTransport
* mail/MyMailSession
*/
@Test
public void testExecuteWithOptionalValuesSet() {
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("enabled", "false");
parameters.set("debug", "true");
parameters.set("storeprotocol", "pop");
parameters.set("storeprotocolclass", "com.sun.mail.pop.POPStore");
parameters.set("transprotocol", "lmtp");
parameters.set("transprotocolclass", "com.sun.mail.lmtp.LMTPTransport");
parameters.set("jndi_name", "mail/MyMailSession");
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
assertTrue(command != null);
cr.getCommandInvocation("create-javamail-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")) {
// expect enabled for the resource to be true as resource-ref's enabled
// would be set to false
assertEquals("true", r.getEnabled());
assertEquals("true", r.getDebug());
assertEquals("pop", r.getStoreProtocol());
assertEquals("com.sun.mail.pop.POPStore", r.getStoreProtocolClass());
assertEquals("lmtp", r.getTransportProtocol());
assertEquals("com.sun.mail.lmtp.LMTPTransport", r.getTransportProtocolClass());
assertEquals("false", r.getAuth());
isCreated = true;
break;
}
}
}
assertTrue(isCreated);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ListJavaMailResourcesTest method setUp.
@Before
public void setUp() {
habitat = getHabitat();
parameters = new ParameterMap();
cr = habitat.getService(CommandRunner.class);
assertTrue(cr != null);
Resources resources = habitat.<Domain>getService(Domain.class).getResources();
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJavaMailResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
origNum = origNum + 1;
}
}
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class CreateJndiResourceTest method testExecuteSuccess.
/**
* Test of execute method, of class CreateJndiResource.
* asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
* sample_jndi_resource
*/
@Test
public void testExecuteSuccess() {
parameters.set("jndilookupname", "sample_jndi");
parameters.set("restype", "queue");
parameters.set("factoryclass", "sampleClass");
parameters.set("jndi_name", "sample_jndi_resource");
org.glassfish.resources.admin.cli.CreateJndiResource command = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
cr.getCommandInvocation("create-jndi-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 ExternalJndiResource) {
ExternalJndiResource r = (ExternalJndiResource) resource;
if (r.getJndiName().equals("sample_jndi_resource")) {
assertEquals("queue", r.getResType());
assertEquals("sample_jndi", r.getJndiLookupName());
assertEquals("sampleClass", r.getFactoryClass());
assertEquals("true", r.getEnabled());
isCreated = true;
logger.fine("Jndi Resource config bean sample_jndi_resource 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("sample_jndi_resource")) {
assertEquals("true", ref.getEnabled());
isRefCreated = true;
break;
}
}
}
}
assertTrue(isRefCreated);
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class CreateJndiResourceTest method testExecuteFailDuplicateResource.
/**
* Test of execute method, of class CreateJndiResource.
* asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
* dupRes
* asadmin create-jndi-resource --restype=queue --factoryclass=sampleClass --jndilookupname=sample_jndi
* dupRes
*/
@Test
public void testExecuteFailDuplicateResource() {
parameters.set("jndilookupname", "sample_jndi");
parameters.set("restype", "queue");
parameters.set("factoryclass", "sampleClass");
parameters.set("jndi_name", "dupRes");
org.glassfish.resources.admin.cli.CreateJndiResource command1 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
cr.getCommandInvocation("create-jndi-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 BindableResource) {
BindableResource jr = (BindableResource) resource;
if (jr.getJndiName().equals("dupRes")) {
isCreated = true;
logger.fine("Jndi Resource config bean dupRes is created.");
break;
}
}
}
assertTrue(isCreated);
org.glassfish.resources.admin.cli.CreateJndiResource command2 = habitat.getService(org.glassfish.resources.admin.cli.CreateJndiResource.class);
cr.getCommandInvocation("create-jndi-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 BindableResource) {
BindableResource jr = (BindableResource) resource;
if (jr.getJndiName().equals("dupRes")) {
numDupRes = numDupRes + 1;
}
}
}
assertEquals(1, numDupRes);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class DeleteJndiResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
parameters = new ParameterMap();
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
for (Resource resource : param.getResources()) {
if (resource instanceof BindableResource) {
BindableResource r = (BindableResource) resource;
if (r.getJndiName().equals("sample_jndi_resource") || r.getJndiName().equals("dupRes")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
}
Aggregations