Search in sources :

Example 1 with Attribute

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

the class TestBadConfigurations method testPublisherWithBadTypedField.

/**
 * Try to create a publisher with a bad typed field.
 *
 * @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 testPublisherWithBadTypedField() throws ConfigurationException, MissingHandlerException, UnacceptableConfiguration {
    // Remove the name attribute of the publisher and replace with an
    // bad typed field name
    m_publisher.removeAttribute(m_publisherField);
    Attribute badTypedField = new Attribute("field", "m_name");
    m_publisher.addAttribute(badTypedField);
    // 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 an bad typed field is specified.");
    } catch (IllegalStateException e) {
    // OK
    } finally {
        // Restore the original state of the publisher
        m_publisher.removeAttribute(badTypedField);
        m_publisher.addAttribute(m_publisherField);
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Test(org.junit.Test)

Example 2 with Attribute

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

the class TestBadConfigurations method testPublisherWithMalformedTopics.

/**
 * Try to create a publisher with malformed topics.
 *
 * @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 testPublisherWithMalformedTopics() 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", "| |\\| \\/ /-\\ |_ | |)");
    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 3 with Attribute

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

the class TestBadConfigurations method testPublisherWithUnexistingField.

/**
 * Try to create a publisher with an unexisting field.
 *
 * @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 testPublisherWithUnexistingField() throws ConfigurationException, MissingHandlerException, UnacceptableConfiguration {
    // Remove the name attribute of the publisher and replace with an
    // unexisting field name
    m_publisher.removeAttribute(m_publisherField);
    Attribute unexistingField = new Attribute("field", "m_unexistingField");
    m_publisher.addAttribute(unexistingField);
    // 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 an unexisting field is specified.");
    } catch (IllegalStateException e) {
    // OK
    } finally {
        // Restore the original state of the publisher
        m_publisher.removeAttribute(unexistingField);
        m_publisher.addAttribute(m_publisherField);
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Test(org.junit.Test)

Example 4 with Attribute

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

the class TestBadConfigurations method dumpElement.

// DEBUG
private String dumpElement(int level, Element element) {
    StringBuilder sb = new StringBuilder();
    // Enter tag
    for (int i = 0; i < level; i++) {
        sb.append("  ");
    }
    sb.append('<');
    sb.append(element.getName());
    Attribute[] attributes = element.getAttributes();
    for (int i = 0; i < attributes.length; i++) {
        Attribute attribute = attributes[i];
        sb.append(' ');
        sb.append(attribute.getName());
        sb.append('=');
        sb.append(attribute.getValue());
    }
    sb.append(">\n");
    // Children
    Element[] elements = element.getElements();
    for (int i = 0; i < elements.length; i++) {
        sb.append(dumpElement(level + 1, elements[i]));
    }
    // Exit tag
    for (int i = 0; i < level; i++) {
        sb.append("  ");
    }
    sb.append("</" + element.getName() + ">\n");
    return sb.toString();
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Element(org.apache.felix.ipojo.metadata.Element)

Example 5 with Attribute

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

the class TestBadConfigurations method testSubscriberWithMalformedTopics.

/**
 * Try to create a subscriber with malformed topics.
 *
 * @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 testSubscriberWithMalformedTopics() throws ConfigurationException, MissingHandlerException, UnacceptableConfiguration {
    // Remove the topics attribute of the subscriber and replace with a
    // malformed one
    m_subscriber.removeAttribute(m_subscriberTopics);
    Attribute malformedTopics = new Attribute("topics", "| |\\| \\/ /-\\ |_ | |)");
    m_subscriber.addAttribute(malformedTopics);
    // 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 invalid topics are specified.");
    } catch (IllegalStateException e) {
    // OK
    } finally {
        // Restore the original state of the subscriber
        m_subscriber.removeAttribute(malformedTopics);
        m_subscriber.addAttribute(m_subscriberTopics);
    }
}
Also used : Attribute(org.apache.felix.ipojo.metadata.Attribute) Test(org.junit.Test)

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