Search in sources :

Example 61 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class TestBadLFCCallback method getNothing.

private Element getNothing() {
    Element elem = new Element("component", "");
    elem.addAttribute(new Attribute("classname", clazz));
    Element callback = new Element("callback", "");
    elem.addElement(callback);
    elem.addElement(manipulation);
    return elem;
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 62 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class TestBadConfigurations method testSubscriberWithUnappropriatedDataType.

/**
 * Try to create a subscriber with a data type that does not match with the
 * callback parameter type.
 *
 * @throws org.apache.felix.ipojo.ConfigurationException
 *          something bad happened
 * @throws org.apache.felix.ipojo.MissingHandlerException
 *          something bad happened
 * @throws org.apache.felix.ipojo.UnacceptableConfiguration
 *          something bad happened
 */
@Test
public void testSubscriberWithUnappropriatedDataType() throws ConfigurationException, MissingHandlerException, UnacceptableConfiguration {
    // Remove the data-type attribute of the subscriber and replace with a
    // malformed one
    m_subscriber.removeAttribute(m_subscriberDataType);
    Attribute unknownType = new Attribute("data-type", "java.lang.String");
    m_subscriber.addAttribute(unknownType);
    // Create and try to start the factory
    ComponentFactory fact = new ComponentFactory(bc, m_consumer);
    try {
        fact.start();
        // Should not be executed
        fact.stop();
        fail("The factory must not start when unappropriated data type is specified.");
    } catch (IllegalStateException e) {
    // OK
    } finally {
        // Restore the original state of the subscriber
        m_subscriber.removeAttribute(unknownType);
        m_subscriber.addAttribute(m_subscriberDataType);
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Test(org.junit.Test)

Example 63 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class TestBadConfigurations method testPublisherWithPatternTopic.

/**
 * Try to create a publisher with a pattern topic (ending with '*') instead of a fixed topic.
 *
 * @throws org.apache.felix.ipojo.ConfigurationException
 *          something bad happened
 * @throws org.apache.felix.ipojo.MissingHandlerException
 *          something bad happened
 * @throws org.apache.felix.ipojo.UnacceptableConfiguration
 *          something bad happened
 */
@Test
public void testPublisherWithPatternTopic() throws ConfigurationException, MissingHandlerException, UnacceptableConfiguration {
    // Remove the topics attribute of the publisher and replace with a
    // malformed one
    m_publisher.removeAttribute(m_publisherTopics);
    Attribute malformedTopics = new Attribute("topics", "a/pattern/topic/*");
    m_publisher.addAttribute(malformedTopics);
    // Create and try to start the factory
    ComponentFactory fact = new ComponentFactory(bc, m_provider);
    try {
        fact.start();
        // Should not be executed
        fact.stop();
        fail("The factory must not start when invalid topics are specified.");
    } catch (IllegalStateException e) {
    // OK
    } finally {
        // Restore the original state of the publisher
        m_publisher.removeAttribute(malformedTopics);
        m_publisher.addAttribute(m_publisherTopics);
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Test(org.junit.Test)

Example 64 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class TestBadConfigurations method testSubscriberWithUnknownDataType.

/**
 * Try to create a subscriber with unknown data type.
 *
 * @throws org.apache.felix.ipojo.ConfigurationException
 *          something bad happened
 * @throws org.apache.felix.ipojo.MissingHandlerException
 *          something bad happened
 * @throws org.apache.felix.ipojo.UnacceptableConfiguration
 *          something bad happened
 */
@Test
public void testSubscriberWithUnknownDataType() throws ConfigurationException, MissingHandlerException, UnacceptableConfiguration {
    // Remove the data-type attribute of the subscriber and replace with a
    // malformed one
    m_subscriber.removeAttribute(m_subscriberDataType);
    Attribute unknownType = new Attribute("data-type", "org.unknown.Clazz");
    m_subscriber.addAttribute(unknownType);
    // Create and try to start the factory
    ComponentFactory fact = new ComponentFactory(bc, m_consumer);
    try {
        fact.start();
        // Should not be executed
        fact.stop();
        fail("The factory must not start when unknown data type is specified.");
    } catch (IllegalStateException e) {
    // OK
    } finally {
        // Restore the original state of the subscriber
        m_subscriber.removeAttribute(unknownType);
        m_subscriber.addAttribute(m_subscriberDataType);
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Test(org.junit.Test)

Example 65 with Attribute

use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.

the class TestBadConfigurations method setUp.

/**
 * Initialization before test cases.
 * <p/>
 * Create all the instances
 */
@Before
public void setUp() {
    m_utils = new EahTestUtils(bc, ipojoHelper);
    /**
     * Get the list of available components.
     */
    try {
        String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
        m_components = ManifestMetadataParser.parseHeaderMetadata(header).getElements("component");
    } catch (ParseException e) {
        fail("Parse Exception when parsing iPOJO-Component");
    }
    /**
     * Initialize the standard publishing component (based on the
     * asynchronous donut provider).
     */
    m_provider = new Element("component", "");
    m_provider.addAttribute(new Attribute("className", "org.apache.felix.ipojo.handler.eventadmin.test.donut.DonutProviderImpl"));
    m_provider.addAttribute(new Attribute("name", "standard donut provider for bad tests"));
    // The provided service of the publisher
    Element providesDonutProvider = new Element("provides", "");
    providesDonutProvider.addAttribute(new Attribute("interface", "org.apache.felix.ipojo.handler.eventadmin.test.donut.DonutProvider"));
    Element providesDonutProviderProperty = new Element("property", "");
    providesDonutProviderProperty.addAttribute(new Attribute("name", "name"));
    providesDonutProviderProperty.addAttribute(new Attribute("field", "m_name"));
    providesDonutProviderProperty.addAttribute(new Attribute("value", "Unknown donut vendor"));
    providesDonutProvider.addElement(providesDonutProviderProperty);
    m_provider.addElement(providesDonutProvider);
    // The event publisher, corresponding to the following description :
    // <ev:publisher name="donut-publisher" field="m_publisher"
    // topics="food/donuts" data-key="food" synchronous="false"/>
    m_publisher = new Element("publisher", NAMESPACE);
    m_publisherName = new Attribute("name", "donut-publisher");
    m_publisherField = new Attribute("field", "m_publisher");
    m_publisherTopics = new Attribute("topics", "food/donuts");
    m_publisherDataKey = new Attribute("data-key", "food");
    m_publisherSynchronous = new Attribute("synchronous", "false");
    m_publisher.addAttribute(m_publisherName);
    m_publisher.addAttribute(m_publisherField);
    m_publisher.addAttribute(m_publisherTopics);
    m_publisher.addAttribute(m_publisherDataKey);
    m_publisher.addAttribute(m_publisherSynchronous);
    m_provider.addElement(m_publisher);
    m_provider.addElement(getManipulationForComponent("donut-provider"));
    /**
     * Initialize the standard subscribing component (based on the donut
     * consumer).
     */
    m_consumer = new Element("component", "");
    m_consumer.addAttribute(new Attribute("className", "org.apache.felix.ipojo.handler.eventadmin.test.donut.DonutConsumerImpl"));
    m_consumer.addAttribute(new Attribute("name", "standard donut consumer for bad tests"));
    // The provided service of the publisher
    Element providesDonutConsumer = new Element("provides", "");
    providesDonutConsumer.addAttribute(new Attribute("interface", "org.apache.felix.ipojo.handler.eventadmin.test.donut.DonutConsumer"));
    Element providesDonutConsumerNameProperty = new Element("property", "");
    providesDonutConsumerNameProperty.addAttribute(new Attribute("name", "name"));
    providesDonutConsumerNameProperty.addAttribute(new Attribute("field", "m_name"));
    providesDonutConsumerNameProperty.addAttribute(new Attribute("value", "Unknown donut consumer"));
    providesDonutConsumer.addElement(providesDonutConsumerNameProperty);
    Element providesDonutConsumerSlowProperty = new Element("property", "");
    providesDonutConsumerSlowProperty.addAttribute(new Attribute("name", "slow"));
    providesDonutConsumerSlowProperty.addAttribute(new Attribute("field", "m_isSlow"));
    providesDonutConsumerSlowProperty.addAttribute(new Attribute("value", "false"));
    providesDonutConsumer.addElement(providesDonutConsumerSlowProperty);
    m_consumer.addElement(providesDonutConsumer);
    // The event publisher, corresponding to the following description :
    // <ev:subscriber name="donut-subscriber" callback="receiveDonut"
    // topics="food/donuts" data-key="food"
    // data-type="org.apache.felix.ipojo.handler.eventadmin.test.donut.Donut"/>
    m_subscriber = new Element("subscriber", NAMESPACE);
    m_subscriberName = new Attribute("name", "donut-subscriber");
    m_subscriberCallback = new Attribute("callback", "receiveDonut");
    m_subscriberTopics = new Attribute("topics", "food/donuts");
    m_subscriberDataKey = new Attribute("data-key", "food");
    m_subscriberDataType = new Attribute("data-type", "org.apache.felix.ipojo.handler.eventadmin.test.donut.Donut");
    m_subscriber.addAttribute(m_subscriberName);
    m_subscriber.addAttribute(m_subscriberCallback);
    m_subscriber.addAttribute(m_subscriberTopics);
    m_subscriber.addAttribute(m_subscriberDataKey);
    m_subscriber.addAttribute(m_subscriberDataType);
    m_consumer.addElement(m_subscriber);
    m_consumer.addElement(getManipulationForComponent("donut-consumer"));
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element) ParseException(org.apache.felix.ipojo.parser.ParseException) Before(org.junit.Before)

Aggregations

Attribute (org.apache.felix.ipojo.metadata.Attribute)125 Element (org.apache.felix.ipojo.metadata.Element)109 Test (org.junit.Test)9 PojoMetadata (org.apache.felix.ipojo.parser.PojoMetadata)6 Iterator (java.util.Iterator)4 Enumeration (java.util.Enumeration)3 Map (java.util.Map)3 Set (java.util.Set)3 ServiceReference (org.osgi.framework.ServiceReference)3 List (java.util.List)2 Entry (java.util.Map.Entry)2 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)2 FieldMetadata (org.apache.felix.ipojo.parser.FieldMetadata)2 MethodMetadata (org.apache.felix.ipojo.parser.MethodMetadata)2 Type (org.objectweb.asm.Type)2 Member (java.lang.reflect.Member)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1