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);
}
}
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);
}
}
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);
}
}
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();
}
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);
}
}
Aggregations