Search in sources :

Example 16 with Resource

use of org.apache.openejb.config.sys.Resource in project tomee by apache.

the class ReadDescriptorsTest method testClassAndTypeAvailable.

@Test
public void testClassAndTypeAvailable() {
    final Resource resource = new Resource();
    resource.setClassName("org.apache.openejb.config.ReadDescriptorsTest");
    final Resources resources = new Resources();
    resources.add(resource);
    final Resources checkedResources = ReadDescriptors.check(resources);
    final Resource res = checkedResources.getResource().get(0);
    Assert.assertNull(res.getProperties().getProperty("Lazy"));
    Assert.assertNull(res.getProperties().getProperty("UseAppClassLoader"));
    Assert.assertNull(res.getProperties().getProperty("InitializeAfterDeployment"));
}
Also used : Resource(org.apache.openejb.config.sys.Resource) Resources(org.apache.openejb.config.sys.Resources) Test(org.junit.Test)

Example 17 with Resource

use of org.apache.openejb.config.sys.Resource in project tomee by apache.

the class ServiceClasspathTest method test.

@Test
public void test() throws Exception {
    final String className = "org.superbiz.foo.Orange";
    final File jar = subclass(Color.class, className);
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Openejb openejb = new Openejb();
    final Resource resource = new Resource();
    openejb.getResource().add(resource);
    resource.setClassName(className);
    resource.setType(className);
    resource.setId("Orange");
    resource.getProperties().put("red", "FF");
    resource.getProperties().put("green", "99");
    resource.getProperties().put("blue", "00");
    resource.setClasspath(jar.getAbsolutePath());
    createEnvrt();
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final ResourceInfo serviceInfo = config.configureService(resource, ResourceInfo.class);
    // serviceInfo.classpath = new URI[]{jar.toURI()};
    assembler.createResource(serviceInfo);
    final InitialContext initialContext = new InitialContext();
    final Color color = (Color) initialContext.lookup("openejb:Resource/Orange");
    assertNotNull(color);
    assertEquals("Orange.FF", color.getRed());
    assertEquals("Orange.99", color.getGreen());
    assertEquals("Orange.00", color.getBlue());
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) Resource(org.apache.openejb.config.sys.Resource) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) Openejb(org.apache.openejb.config.sys.Openejb) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 18 with Resource

use of org.apache.openejb.config.sys.Resource in project tomee by apache.

the class AliasesFromXmlTest method ensureAliasesAreParsed.

@Test
public void ensureAliasesAreParsed() throws IOException, SAXException, ParserConfigurationException {
    final String xml = "<?xml version=\"1.0\"?>" + "<openejb>" + "   <Resource id=\"foo\" aliases=\"bar\" type=\"DataSource\" />" + "</openejb>";
    final Openejb openejb = JaxbOpenejb.readConfig(new InputSource(new ByteArrayInputStream(xml.getBytes())));
    assertEquals(1, openejb.getResource().size());
    final Resource resource = openejb.getResource().iterator().next();
    assertEquals(1, resource.getAliases().size());
    assertEquals("foo", resource.getId());
    assertEquals("bar", resource.getAliases().iterator().next());
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(org.apache.openejb.config.sys.Resource) Openejb(org.apache.openejb.config.sys.Openejb) JaxbOpenejb(org.apache.openejb.config.sys.JaxbOpenejb) Test(org.junit.Test)

Example 19 with Resource

use of org.apache.openejb.config.sys.Resource in project tomee by apache.

the class PropertiesProviderFromXmlTest method ensureAliasesAreParsed.

@Test
public void ensureAliasesAreParsed() throws IOException, SAXException, ParserConfigurationException {
    final String xml = "<?xml version=\"1.0\"?>" + "<tomee>" + "   <Resource id=\"foo\" type=\"DataSource\" properties-provider=\"org.acme.Foo\"/>" + "   <Container id=\"bar\" ctype=\"STATELESS\" properties-provider=\"org.acme.Foo\"/>" + "</tomee>";
    final Openejb openejb = JaxbOpenejb.readConfig(new InputSource(new ByteArrayInputStream(xml.getBytes())));
    assertEquals(1, openejb.getResource().size());
    final Resource resource = openejb.getResource().iterator().next();
    assertEquals("foo", resource.getId());
    assertEquals("org.acme.Foo", resource.getPropertiesProvider());
    final Container container = openejb.getContainer().iterator().next();
    assertEquals("bar", container.getId());
    assertEquals("org.acme.Foo", container.getPropertiesProvider());
}
Also used : InputSource(org.xml.sax.InputSource) Container(org.apache.openejb.config.sys.Container) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(org.apache.openejb.config.sys.Resource) Openejb(org.apache.openejb.config.sys.Openejb) JaxbOpenejb(org.apache.openejb.config.sys.JaxbOpenejb) Test(org.junit.Test)

Example 20 with Resource

use of org.apache.openejb.config.sys.Resource in project tomee by apache.

the class ConfigurationFactory method getResourceIds.

public List<String> getResourceIds(final String type, Properties required) {
    final List<String> resourceIds = new ArrayList<String>();
    if (required == null) {
        required = new Properties();
    }
    final OpenEjbConfiguration runningConfig = getRunningConfig();
    if (runningConfig != null) {
        for (final ResourceInfo resourceInfo : runningConfig.facilities.resources) {
            if (logger.isDebugEnabled()) {
                logger.debug(String.format("Trying to match resource type %s with classname %s, service %s.", type, resourceInfo.className, resourceInfo.service));
            }
            if ((type != null && type.equals(resourceInfo.className) || isResourceType(resourceInfo.service, resourceInfo.types, type)) && implies(required, resourceInfo.properties)) {
                resourceIds.add(resourceInfo.id);
                resourceIds.addAll(resourceInfo.aliases);
            }
        }
    }
    if (sys != null) {
        for (final ResourceInfo resourceInfo : sys.facilities.resources) {
            if (isResourceType(resourceInfo.service, resourceInfo.types, type) && implies(required, resourceInfo.properties)) {
                resourceIds.add(resourceInfo.id);
                resourceIds.addAll(resourceInfo.aliases);
            }
        }
        // the above sys instance
        if (openejb != null) {
            for (final Resource resource : openejb.getResource()) {
                final ArrayList<String> types = new ArrayList<String>();
                if (resource.getType() != null) {
                    types.add(resource.getType());
                }
                if (isResourceType("Resource", types, type) && implies(required, resource.getProperties())) {
                    resourceIds.add(resource.getId());
                    resourceIds.addAll(resource.getAliases());
                }
            }
        }
    }
    return resourceIds;
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) ArrayList(java.util.ArrayList) Resource(org.apache.openejb.config.sys.Resource) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration)

Aggregations

Resource (org.apache.openejb.config.sys.Resource)30 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)15 Test (org.junit.Test)12 Properties (java.util.Properties)11 ArrayList (java.util.ArrayList)7 OpenEJBException (org.apache.openejb.OpenEJBException)6 File (java.io.File)5 IOException (java.io.IOException)5 Resources (org.apache.openejb.config.sys.Resources)5 DataSource (javax.sql.DataSource)4 Container (org.apache.openejb.config.sys.Container)4 Openejb (org.apache.openejb.config.sys.Openejb)4 URL (java.net.URL)3 HashMap (java.util.HashMap)3 InitialContext (javax.naming.InitialContext)3 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)3 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)3 SuperProperties (org.apache.openejb.util.SuperProperties)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MalformedURLException (java.net.MalformedURLException)2