use of org.apache.openejb.config.provider.ProviderLoader in project tomee by apache.
the class ProviderManagerTest method testInheritedAttributes.
public void testInheritedAttributes() throws Exception {
final ProviderManager manager = new ProviderManager(new ProviderLoader() {
@Override
public ServiceProvider load(final ID id) {
if ("color".equalsIgnoreCase(id.getName())) {
final ServiceProvider color = new ServiceProvider();
color.setClassName(Color.class.getName());
color.setFactoryName("fooFactory");
color.setId("Color");
color.setService("Resource");
color.setConstructor("one, two, three");
color.setDescription("the description");
color.setDisplayName("the display name");
color.getProperties().setProperty("red", "0");
color.getProperties().setProperty("green", "0");
color.getProperties().setProperty("blue", "0");
color.getTypes().add(Color.class.getName());
return color;
}
if ("red".equalsIgnoreCase(id.getName())) {
final ServiceProvider red = new ServiceProvider();
red.setId("Red");
red.setParent("Color");
red.getProperties().setProperty("red", "255");
return red;
}
if ("orange".equalsIgnoreCase(id.getName())) {
final ServiceProvider orange = new ServiceProvider();
orange.setId("Orange");
orange.setParent("Red");
orange.getProperties().setProperty("green", "200");
return orange;
}
throw new IllegalStateException(id.toString());
}
@Override
public List<ServiceProvider> load(final String namespace) {
final List<ServiceProvider> list = new ArrayList<>();
list.add(load(new ID(namespace, "color")));
list.add(load(new ID(namespace, "red")));
list.add(load(new ID(namespace, "orange")));
return list;
}
});
{
// Assert Orange
// Should have inherited from Red
final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("Resource", provider.getService());
assertEquals("one, two, three", provider.getConstructor());
assertEquals("the description", provider.getDescription());
assertEquals("the display name", provider.getDisplayName());
assertEquals("fooFactory", provider.getFactoryName());
assertEquals("255", provider.getProperties().getProperty("reD"));
assertEquals("200", provider.getProperties().get("grEeN"));
assertEquals("0", provider.getProperties().get("bLue"));
assertEquals(1, provider.getTypes().size());
}
{
// Assert Red
// Should have inherited green and blue values from Color
final ServiceProvider provider = manager.get("dEFaulT", "REd");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("Resource", provider.getService());
assertEquals("one, two, three", provider.getConstructor());
assertEquals("the description", provider.getDescription());
assertEquals("the display name", provider.getDisplayName());
assertEquals("fooFactory", provider.getFactoryName());
assertEquals("255", provider.getProperties().getProperty("rED"));
assertEquals("0", provider.getProperties().get("grEEN"));
assertEquals("0", provider.getProperties().get("bLUe"));
}
{
// Assert Color
// Must be able to retrieve provider and properties in a case-insensitive manner
final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("Resource", provider.getService());
assertEquals("one, two, three", provider.getConstructor());
assertEquals("the description", provider.getDescription());
assertEquals("the display name", provider.getDisplayName());
assertEquals("fooFactory", provider.getFactoryName());
assertEquals("0", provider.getProperties().getProperty("rEd"));
assertEquals("0", provider.getProperties().get("grEEn"));
assertEquals("0", provider.getProperties().get("blUE"));
}
assertEquals(3, manager.getAll().size());
}
use of org.apache.openejb.config.provider.ProviderLoader in project tomee by apache.
the class ProviderManagerTest method testLoader.
public void testLoader() throws Exception {
final ProviderManager manager = new ProviderManager(new ProviderLoader() {
@Override
public ServiceProvider load(final ID id) {
if ("color".equalsIgnoreCase(id.getName())) {
final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
color.getProperties().setProperty("red", "0");
color.getProperties().setProperty("green", "0");
color.getProperties().setProperty("blue", "0");
return color;
}
if ("red".equalsIgnoreCase(id.getName())) {
final ServiceProvider red = new ServiceProvider();
red.setId("Red");
red.setParent("Color");
red.getProperties().setProperty("red", "255");
return red;
}
if ("orange".equalsIgnoreCase(id.getName())) {
final ServiceProvider orange = new ServiceProvider();
orange.setId("Orange");
orange.setParent("Red");
orange.getProperties().setProperty("green", "200");
return orange;
}
throw new IllegalStateException(id.toString());
}
@Override
public List<ServiceProvider> load(final String namespace) {
return null;
}
});
assertEquals(0, manager.getAll().size());
{
// Assert Orange
// Should have inherited from Red
final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("255", provider.getProperties().getProperty("reD"));
assertEquals("200", provider.getProperties().get("grEeN"));
assertEquals("0", provider.getProperties().get("bLue"));
}
{
// Assert Red
// Should have inherited green and blue values from Color
final ServiceProvider provider = manager.get("dEFaulT", "REd");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("255", provider.getProperties().getProperty("rED"));
assertEquals("0", provider.getProperties().get("grEEN"));
assertEquals("0", provider.getProperties().get("bLUe"));
}
{
// Assert Color
// Must be able to retrieve provider and properties in a case-insensitive manner
final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("0", provider.getProperties().getProperty("rEd"));
assertEquals("0", provider.getProperties().get("grEEn"));
assertEquals("0", provider.getProperties().get("blUE"));
}
assertEquals(3, manager.getAll().size());
}
use of org.apache.openejb.config.provider.ProviderLoader in project tomee by apache.
the class ProviderManagerTest method testCircularDependency.
public void testCircularDependency() throws Exception {
final ProviderManager manager = new ProviderManager(new ProviderLoader() {
@Override
public ServiceProvider load(final ID id) {
if ("color".equalsIgnoreCase(id.getName())) {
final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
color.setParent("Orange");
color.getProperties().setProperty("red", "0");
color.getProperties().setProperty("green", "0");
color.getProperties().setProperty("blue", "0");
return color;
}
if ("red".equalsIgnoreCase(id.getName())) {
final ServiceProvider red = new ServiceProvider();
red.setId("Red");
red.setParent("Color");
red.getProperties().setProperty("red", "255");
return red;
}
if ("orange".equalsIgnoreCase(id.getName())) {
final ServiceProvider orange = new ServiceProvider();
orange.setId("Orange");
orange.setParent("Red");
orange.getProperties().setProperty("green", "200");
return orange;
}
throw new IllegalStateException(id.toString());
}
@Override
public List<ServiceProvider> load(final String namespace) {
return null;
}
});
assertEquals(0, manager.getAll().size());
try {
manager.get("dEFAUlT", "orAngE");
fail("ProviderCircularReferenceException should have been thrown");
} catch (final ProviderCircularReferenceException e) {
// pass
}
}
use of org.apache.openejb.config.provider.ProviderLoader in project tomee by apache.
the class ProviderManagerTest method testLoaderLoadNamespace.
public void testLoaderLoadNamespace() throws Exception {
final ProviderManager manager = new ProviderManager(new ProviderLoader() {
@Override
public ServiceProvider load(final ID id) {
if ("color".equalsIgnoreCase(id.getName())) {
final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
color.getProperties().setProperty("red", "0");
color.getProperties().setProperty("green", "0");
color.getProperties().setProperty("blue", "0");
return color;
}
if ("red".equalsIgnoreCase(id.getName())) {
final ServiceProvider red = new ServiceProvider();
red.setId("Red");
red.setParent("Color");
red.getProperties().setProperty("red", "255");
return red;
}
if ("orange".equalsIgnoreCase(id.getName())) {
final ServiceProvider orange = new ServiceProvider();
orange.setId("Orange");
orange.setParent("Red");
orange.getProperties().setProperty("green", "200");
return orange;
}
throw new IllegalStateException(id.toString());
}
@Override
public List<ServiceProvider> load(final String namespace) {
final List<ServiceProvider> list = new ArrayList<>();
list.add(load(new ID(namespace, "color")));
list.add(load(new ID(namespace, "red")));
list.add(load(new ID(namespace, "orange")));
return list;
}
});
assertEquals(0, manager.getAll().size());
manager.get("default", "Color");
assertEquals(1, manager.getAll().size());
manager.load("default");
assertEquals(3, manager.getAll().size());
{
// Assert Orange
// Should have inherited from Red
final ServiceProvider provider = manager.get("dEFAUlT", "orAngE");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("255", provider.getProperties().getProperty("reD"));
assertEquals("200", provider.getProperties().get("grEeN"));
assertEquals("0", provider.getProperties().get("bLue"));
}
{
// Assert Red
// Should have inherited green and blue values from Color
final ServiceProvider provider = manager.get("dEFaulT", "REd");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("255", provider.getProperties().getProperty("rED"));
assertEquals("0", provider.getProperties().get("grEEN"));
assertEquals("0", provider.getProperties().get("bLUe"));
}
{
// Assert Color
// Must be able to retrieve provider and properties in a case-insensitive manner
final ServiceProvider provider = manager.get("DeFaulT", "CoLoR");
assertNotNull(provider);
assertEquals(Color.class.getName(), provider.getClassName());
assertEquals("0", provider.getProperties().getProperty("rEd"));
assertEquals("0", provider.getProperties().get("grEEn"));
assertEquals("0", provider.getProperties().get("blUE"));
}
assertEquals(3, manager.getAll().size());
}
use of org.apache.openejb.config.provider.ProviderLoader in project tomee by apache.
the class ServiceProviderInheritanceTest method test.
public void test() throws Exception {
SystemInstance.get().setComponent(ProviderManager.class, new ProviderManager(new ProviderLoader() {
final ProviderLoader loader = new ServiceJarXmlLoader();
@Override
public ServiceProvider load(final ID id) {
{
// try the regular loader
final ServiceProvider provider = loader.load(id);
if (provider != null)
return provider;
}
if ("color".equalsIgnoreCase(id.getName())) {
final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
color.getProperties().setProperty("red", "0");
color.getProperties().setProperty("green", "0");
color.getProperties().setProperty("blue", "0");
color.getTypes().add(Color.class.getName());
return color;
}
if ("red".equalsIgnoreCase(id.getName())) {
final ServiceProvider red = new ServiceProvider();
red.setId("Red");
red.setParent("Color");
red.getProperties().setProperty("red", "255");
return red;
}
if ("orange".equalsIgnoreCase(id.getName())) {
final ServiceProvider orange = new ServiceProvider();
orange.setId("Orange");
orange.setParent("Red");
orange.getProperties().setProperty("green", "200");
return orange;
}
throw new IllegalStateException(id.toString());
}
@Override
public List<ServiceProvider> load(final String namespace) {
final List<ServiceProvider> list = loader.load(namespace);
list.add(load(new ID(namespace, "color")));
list.add(load(new ID(namespace, "red")));
list.add(load(new ID(namespace, "orange")));
return list;
}
}));
final ConfigurationFactory factory = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createSecurityService(factory.configureService(SecurityServiceInfo.class));
assembler.createTransactionManager(factory.configureService(TransactionServiceInfo.class));
{
final Resource orange = new Resource("Orange", Color.class.getName(), "Orange");
final ResourceInfo resourceInfo = factory.configureService(orange, ResourceInfo.class);
assertEquals(Color.class.getName(), resourceInfo.className);
assertEquals("Orange", resourceInfo.id);
assertEquals(3, resourceInfo.properties.size());
assertEquals("255", resourceInfo.properties.get("red"));
assertEquals("200", resourceInfo.properties.get("green"));
assertEquals("0", resourceInfo.properties.get("blue"));
assembler.createResource(resourceInfo);
}
{
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(MyBean.class));
final AppContext application = assembler.createApplication(factory.configureApplication(new EjbModule(ejbJar)));
final MyBean myBean = (MyBean) application.getBeanContexts().get(0).getBusinessLocalBeanHome().create();
final Color color = myBean.getColor();
assertNotNull(color);
assertEquals(255, color.getRed());
assertEquals(200, color.getGreen());
assertEquals(0, color.getBlue());
}
}
Aggregations