AdviceBinding binding = null;
try
{
System.out.println("TEST ADD CLASS METADATA");
DynamicSimpleClassMetadataLoader loader = new DynamicSimpleClassMetadataLoader(
"T1", "TEST", "org.jboss.test.aop.dynamicgenadvisor.POJO");
loader.addDefaultMetaData("default", "default");
loader.addClassMetaData("class", "class");
loader.addMethodMetaData("* someMethod(..)", "fm", "someMethod");
loader.addFieldMetaData("i", "fm", "i");
AspectManager.instance().addClassMetaData(loader.getClassMetaDataBinding());
binding = new AdviceBinding("all(org.jboss.test.aop.dynamicgenadvisor.POJO)", null);
binding.addInterceptor(MetadataInterceptor.class);
AspectManager.instance().addBinding(binding);
POJO pojo = new POJO();
MetadataInterceptor.clear();
pojo.someMethod(123);
pojo.i = 100;
pojo.notPrepared();
assertTrue(MetadataInterceptor.intercepted);
assertEquals(2, MetadataInterceptor.lastDefaultMetadata.size());
assertEquals(2, MetadataInterceptor.lastClassMetadata.size());
assertEquals(1, MetadataInterceptor.lastMethodMetadata.size());
assertEquals(1, MetadataInterceptor.lastFieldMetadata.size());
//Make sure we get the metadata expected
assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(0));
assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(1));
assertEquals("class", MetadataInterceptor.lastClassMetadata.get(0));
assertEquals("class", MetadataInterceptor.lastClassMetadata.get(1));
assertEquals("someMethod", MetadataInterceptor.lastMethodMetadata.get(0));
assertEquals("i", MetadataInterceptor.lastFieldMetadata.get(0));
AspectManager.instance().removeClassMetaData(loader.getClassMetaDataBinding().getName());
MetadataInterceptor.clear();
pojo.someMethod(123);
pojo.i = 100;
pojo.notPrepared();
assertEquals(0, MetadataInterceptor.lastDefaultMetadata.size());
assertEquals(0, MetadataInterceptor.lastClassMetadata.size());
assertEquals(0, MetadataInterceptor.lastMethodMetadata.size());
assertEquals(0, MetadataInterceptor.lastFieldMetadata.size());
//Try adding metadata again now that instance already exists
AspectManager.instance().addClassMetaData(loader.getClassMetaDataBinding());
MetadataInterceptor.clear();
pojo.someMethod(123);
pojo.i = 100;
pojo.notPrepared();
assertEquals(2, MetadataInterceptor.lastDefaultMetadata.size());
assertEquals(2, MetadataInterceptor.lastClassMetadata.size());
assertEquals(1, MetadataInterceptor.lastMethodMetadata.size());
assertEquals(1, MetadataInterceptor.lastFieldMetadata.size());
//Make sure we get the metadata expected
assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(0));
assertEquals("default", MetadataInterceptor.lastDefaultMetadata.get(1));
assertEquals("class", MetadataInterceptor.lastClassMetadata.get(0));
assertEquals("class", MetadataInterceptor.lastClassMetadata.get(1));
assertEquals("someMethod", MetadataInterceptor.lastMethodMetadata.get(0));
assertEquals("i", MetadataInterceptor.lastFieldMetadata.get(0));
AspectManager.instance().removeClassMetaData(loader.getClassMetaDataBinding().getName());
MetadataInterceptor.clear();
pojo.someMethod(123);
pojo.i = 100;
pojo.notPrepared();