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"));
}
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());
}
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());
}
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());
}
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;
}
Aggregations