Package org.apache.felix.ipojo.metadata

Examples of org.apache.felix.ipojo.metadata.Element


        List<Element> originalMetadata = provider.getMetadatas();
        // 1.2 Manipulation
        Manipulator manipulator = new Manipulator(this.getClass().getClassLoader());
        manipulator.prepare(origin);
        byte[] clazz = manipulator.manipulate(origin);
        Element originalManipulationMetadata = manipulator.getManipulationMetadata();
        // 1.3 Check that the class is valid
        ManipulatedClassLoader classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
        Class cl = classloader.findClass("test.PlentyOfAnnotations");
        Assert.assertNotNull(cl);

        // ---------------

        // Step 2 - Second collection and manipulation
        // We use the output class as entry.
        // 2.1 Metadata collection
        store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", clazz);
        provider = new AnnotationMetadataProvider(store, reporter);
        List<Element> metadataAfterOneManipulation = provider.getMetadatas();
        // 2.2 Manipulation
        manipulator = new Manipulator(this.getClass().getClassLoader());
        manipulator.prepare(clazz);
        byte[] clazz2 = manipulator.manipulate(clazz);
        Element manipulationMetadataAfterSecondManipulation = manipulator.getManipulationMetadata();
        // 2.3 Check that the class is valid
        classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
        cl = classloader.findClass("test.PlentyOfAnnotations");
        Assert.assertNotNull(cl);

        // ---------------

        // Step 3 - Third collection and manipulation
        // We use the output class of 2 as entry.
        // 3.1 Metadata collection
        store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", clazz2);
        provider = new AnnotationMetadataProvider(store, reporter);
        List<Element> metadataAfterTwoManipulation = provider.getMetadatas();
        // 3.2 Manipulation
        manipulator = new Manipulator(this.getClass().getClassLoader());
        manipulator.prepare(clazz2);
        byte[] clazz3 = manipulator.manipulate(clazz2);
        Element manipulationMetadataAfterThirdManipulation = manipulator.getManipulationMetadata();
        // 3.3 Check that the class is valid
        classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
        cl = classloader.findClass("test.PlentyOfAnnotations");
        Assert.assertNotNull(cl);

        // ---------------
        // Verification

        // Unchanged metadata
        Assert.assertEquals(originalMetadata.toString(), metadataAfterOneManipulation.toString());
        Assert.assertEquals(originalMetadata.toString(), metadataAfterTwoManipulation.toString());

        // Unchanged manipulation metadata
        Assert.assertEquals(originalManipulationMetadata.toString(),
                manipulationMetadataAfterSecondManipulation.toString());
        Assert.assertEquals(originalManipulationMetadata.toString(),
                manipulationMetadataAfterThirdManipulation.toString());

    }
View Full Code Here


    public void testGetMetadatas() throws Exception {
        CompositeMetadataProvider provider = new CompositeMetadataProvider(reporter);
        provider.addMetadataProvider(delegate1);
        provider.addMetadataProvider(delegate2);

        Element returned = newComponentElement("type1");
        when(delegate1.getMetadatas()).thenReturn(Collections.singletonList(returned));

        Element returned2 = newComponentElement("type2");
        when(delegate2.getMetadatas()).thenReturn(Collections.singletonList(returned2));

        List<Element> meta = provider.getMetadatas();
        assertEquals(2, meta.size());
    }
View Full Code Here

    public void testGetMetadatasWithDuplicate() throws Exception {
        CompositeMetadataProvider provider = new CompositeMetadataProvider(reporter);
        provider.addMetadataProvider(delegate1);
        provider.addMetadataProvider(delegate2);

        Element returned = newComponentElement("type1");
        when(delegate1.getMetadatas()).thenReturn(Collections.singletonList(returned));

        Element returned2 = newComponentElement("type1");
        when(delegate2.getMetadatas()).thenReturn(Collections.singletonList(returned2));

        List<Element> meta = provider.getMetadatas();
        assertEquals(1, meta.size());
View Full Code Here

    public void testGetMetadatasWithInstances() throws Exception {
        CompositeMetadataProvider provider = new CompositeMetadataProvider(reporter);
        provider.addMetadataProvider(delegate1);
        provider.addMetadataProvider(delegate2);

        Element returned = newInstanceElement("type1", "name1");
        when(delegate1.getMetadatas()).thenReturn(Collections.singletonList(returned));

        // Try with a duplicate instance name
        Element returned2 = newInstanceElement("type1", "name2");
        when(delegate2.getMetadatas()).thenReturn(Collections.singletonList(returned2));

        List<Element> meta = provider.getMetadatas();
        assertEquals(2, meta.size());
    }
View Full Code Here

        List<Element> meta = provider.getMetadatas();
        assertEquals(2, meta.size());
    }

    private Element newComponentElement(String type) {
        Element main = new Element("component", null);
        main.addAttribute(new Attribute("name", type));
        return main;
    }
View Full Code Here

        main.addAttribute(new Attribute("name", type));
        return main;
    }

    private Element newInstanceElement(String type, String name) {
        Element main = new Element("instance", null);
        main.addAttribute(new Attribute("component", type));
        main.addAttribute(new Attribute("name", name));
        return main;
    }
View Full Code Here

public class CacheableMetadataProviderTestCase extends TestCase {
    public void testGetMetadatas() throws Exception {
        MetadataProvider delegate = mock(MetadataProvider.class);
        CacheableMetadataProvider provider = new CacheableMetadataProvider(delegate);

        Element returned = new Element("test", null);
        when(delegate.getMetadatas()).thenReturn(Collections.singletonList(returned));

        provider.getMetadatas();
        provider.getMetadatas();
        provider.getMetadatas();
View Full Code Here

    public void setUp() throws Exception {
        filter = new ManipulatedMetadataFilter();
    }

    public void testFilterPrefixedMethod() throws Exception {
        Element main = new Element("test", null);
        main.addAttribute(new Attribute("name", ClassManipulator.PREFIX + "PropertyName"));

        Assert.assertTrue(filter.accept(main));
    }
View Full Code Here

        Assert.assertTrue(filter.accept(main));
    }

    public void testFilterInstanceManagerValue() throws Exception {
        Element main = new Element("test", null);
        main.addAttribute(new Attribute("name", InstanceManager.class.getName()));

        Assert.assertTrue(filter.accept(main));
    }
View Full Code Here

        Assert.assertTrue(filter.accept(main));
    }

    public void testFilterInstanceManagerSetter() throws Exception {
        Element main = new Element("test", null);
        main.addAttribute(new Attribute("name", "_setInstanceManager"));

        Assert.assertTrue(filter.accept(main));
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.metadata.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.