use of org.jboss.weld.resources.SharedObjectCache in project core by weld.
the class AnnotatedTypesTest method testComparison.
/**
* tests the AnnotatedTypes.compareAnnotatedTypes
*/
@Test
public void testComparison() throws SecurityException, NoSuchFieldException, NoSuchMethodException {
// check that two weld classes on the same underlying are equal
TypeStore ts = new TypeStore();
ClassTransformer ct = new ClassTransformer(ts, new SharedObjectCache(), ReflectionCacheFactory.newInstance(ts), RegistrySingletonProvider.STATIC_INSTANCE);
EnhancedAnnotatedType<Chair> chair1 = EnhancedAnnotatedTypeImpl.of(BackedAnnotatedType.of(Chair.class, ct.getSharedObjectCache(), ct.getReflectionCache(), RegistrySingletonProvider.STATIC_INSTANCE, AnnotatedTypeIdentifier.NULL_BDA_ID), ct);
EnhancedAnnotatedType<Chair> chair2 = EnhancedAnnotatedTypeImpl.of(BackedAnnotatedType.of(Chair.class, ct.getSharedObjectCache(), ct.getReflectionCache(), RegistrySingletonProvider.STATIC_INSTANCE, AnnotatedTypeIdentifier.NULL_BDA_ID), ct);
Assert.assertTrue(AnnotatedTypes.compareAnnotatedTypes(chair1, chair2));
// check that a different implementation of annotated type is equal to the weld implementation
TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
builder.addToClass(new DefaultLiteral());
builder.addToField(Chair.class.getField("legs"), new ProducesLiteral());
builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
AnnotatedType<Chair> chair3 = builder.create();
Assert.assertTrue(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));
// check that the implementation returns false if a field annotation changes
builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
builder.addToClass(new DefaultLiteral());
builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
chair3 = builder.create();
Assert.assertFalse(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));
// check that the implementation returns false if a class level annotation changes
builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
builder.addToClass(new ProducesLiteral());
builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
chair3 = builder.create();
Assert.assertFalse(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));
}
use of org.jboss.weld.resources.SharedObjectCache in project core by weld.
the class SimpleWeldClassTest method testWeldClassForCovariantReturnType.
/*
* description = "WELD-568"
*/
@Category(Broken.class)
@Test
public void testWeldClassForCovariantReturnType() {
TypeStore typeStore = new TypeStore();
EnhancedAnnotatedType<Attacker> weldClass = new ClassTransformer(typeStore, new SharedObjectCache(), ReflectionCacheFactory.newInstance(typeStore), RegistrySingletonProvider.STATIC_INSTANCE).getEnhancedAnnotatedType(Attacker.class, AnnotatedTypeIdentifier.NULL_BDA_ID);
Collection<EnhancedAnnotatedMethod<?, ? super Attacker>> methods = weldClass.getEnhancedMethods();
Assert.assertEquals(4, methods.size());
List<EnhancedAnnotatedMethod<?, ?>> interceptableMethods = Beans.getInterceptableMethods(weldClass);
Assert.assertEquals(4, interceptableMethods.size());
}
use of org.jboss.weld.resources.SharedObjectCache in project core by weld.
the class SimpleWeldClassTest method testWeldClassForGenericSuperclass.
/*
* description = "WELD-568"
*/
@Test
public void testWeldClassForGenericSuperclass() {
TypeStore ts = new TypeStore();
EnhancedAnnotatedType<StringProcessor> weldClass = new ClassTransformer(ts, new SharedObjectCache(), ReflectionCacheFactory.newInstance(ts), RegistrySingletonProvider.STATIC_INSTANCE).getEnhancedAnnotatedType(StringProcessor.class, AnnotatedTypeIdentifier.NULL_BDA_ID);
Collection<EnhancedAnnotatedMethod<?, ? super StringProcessor>> methods = weldClass.getEnhancedMethods();
// assert methods.size() == 2;
List<EnhancedAnnotatedMethod<?, ?>> interceptableMethods = Beans.getInterceptableMethods(weldClass);
Assert.assertEquals(3, interceptableMethods.size());
}
use of org.jboss.weld.resources.SharedObjectCache in project core by weld.
the class AccessibleManagerResolutionTest method beforeMethod.
@BeforeMethod
public void beforeMethod() {
BeanIdentifierIndex beanIdentifierIndex = new BeanIdentifierIndex();
beanIdentifierIndex.build(Collections.<Bean<?>>emptySet());
this.typeStore = new TypeStore();
this.classTransformer = new ClassTransformer(typeStore, new SharedObjectCache(), ReflectionCacheFactory.newInstance(typeStore), RegistrySingletonProvider.STATIC_INSTANCE);
this.services = new SimpleServiceRegistry();
this.services.add(MetaAnnotationStore.class, new MetaAnnotationStore(classTransformer));
this.services.add(ContextualStore.class, new ContextualStoreImpl(STATIC_INSTANCE, beanIdentifierIndex));
this.services.add(ClassTransformer.class, classTransformer);
this.services.add(SharedObjectCache.class, new SharedObjectCache());
this.services.add(WeldConfiguration.class, new WeldConfiguration(this.services, new MockDeployment(services)));
this.services.add(SecurityServices.class, NoopSecurityServices.INSTANCE);
this.services.add(ObserverNotifierFactory.class, DefaultObserverNotifierFactory.INSTANCE);
this.services.add(GlobalObserverNotifierService.class, new GlobalObserverNotifierService(services, RegistrySingletonProvider.STATIC_INSTANCE));
this.services.add(ExpressionLanguageSupport.class, WeldWebModule.EL_SUPPORT);
this.services.add(SpecializationAndEnablementRegistry.class, new SpecializationAndEnablementRegistry());
this.services.add(InterceptorsApiAbstraction.class, new InterceptorsApiAbstraction(DefaultResourceLoader.INSTANCE));
this.services.add(ProxyInstantiator.class, DefaultProxyInstantiator.INSTANCE);
this.services.add(ResourceInjectionFactory.class, new ResourceInjectionFactory());
this.services.add(EjbSupport.class, EjbSupport.NOOP_IMPLEMENTATION);
// create BeanManagerImpl and initialize container
root = BeanManagerImpl.newRootManager(STATIC_INSTANCE, "root", services);
Container.initialize(root, services);
// add injection target service; has to be done once container was initialized
this.services.add(InjectionTargetService.class, new InjectionTargetService(root));
}
use of org.jboss.weld.resources.SharedObjectCache in project core by weld.
the class WeldStartup method setupInitialServices.
private void setupInitialServices() {
if (initialServices.contains(TypeStore.class)) {
return;
}
// instantiate initial services which we need for this phase
TypeStore store = new TypeStore();
SharedObjectCache cache = new SharedObjectCache();
ReflectionCache reflectionCache = ReflectionCacheFactory.newInstance(store);
ClassTransformer classTransformer = new ClassTransformer(store, cache, reflectionCache, contextId);
initialServices.add(TypeStore.class, store);
initialServices.add(SharedObjectCache.class, cache);
initialServices.add(ReflectionCache.class, reflectionCache);
initialServices.add(ClassTransformer.class, classTransformer);
}
Aggregations