Finish test and add assertions for property tags without a value
*/
package org.apache.felix.scr.impl.xml;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.felix.scr.impl.logger.MockBundleLogger;
+import org.apache.felix.scr.impl.metadata.ComponentMetadata;
import org.junit.Test;
import org.mockito.Mockito;
import org.osgi.framework.Bundle;
@@ -35,10 +40,19 @@ public class XmlHandlerTest {
@Test
public void testPropertiesWithoutValue() throws Exception {
final URL url = this.getClass().getClassLoader().getResource("parsertest-nopropvalue.xml");
- parse(url);
+ final List<ComponentMetadata> components = parse(url);
+ assertEquals(1, components.size());
+
+ final ComponentMetadata cm = components.get(0);
+ cm.validate();
+ // the xml has four properties, two of them with no value, so they should not be part of the
+ // component metadata
+ assertEquals(2, cm.getProperties().size());
+ assertNotNull(cm.getProperties().get("service.vendor"));
+ assertNotNull(cm.getProperties().get("jmx.objectname"));
}
- private void parse(final URL descriptorURL) throws Exception {
+ private List<ComponentMetadata> parse(final URL descriptorURL) throws Exception {
final Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(bundle.getLocation()).thenReturn("bundle");
@@ -53,6 +67,7 @@ public class XmlHandlerTest {
parser.parse(stream, handler);
+ return handler.getComponentMetadataList();
} finally {
if (stream != null) {
try {
