New manipulator structure - Move the bnd ipojo plugin

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1209867 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java b/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java
new file mode 100644
index 0000000..0ad3002
--- /dev/null
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.bnd;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import aQute.lib.osgi.Analyzer;
+import aQute.lib.osgi.Jar;
+import aQute.lib.osgi.Resource;
+import aQute.lib.osgi.URLResource;
+import aQute.libg.reporter.Reporter;
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+public class PojoizationPluginTestCase extends TestCase {
+
+    @Mock
+    private Reporter reporter;
+
+    @Spy
+    private Analyzer analyzer = new Analyzer();
+
+    @Spy
+    private Jar jar = new Jar("mock.jar");
+
+    @Override
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    public void testAnalysisWithComponentOnlyMetadataXml() throws Exception {
+        PojoizationPlugin plugin = new PojoizationPlugin();
+
+        Map<String, String> props = new HashMap<String, String>();
+
+        Resource resource = new URLResource(getClass().getResource("/metadata-components-only.xml"));
+        doReturn(jar).when(analyzer).getJar();
+        doReturn(resource).when(jar).getResource(eq("META-INF/metadata.xml"));
+
+        plugin.setReporter(reporter);
+        plugin.setProperties(props);
+
+        plugin.analyzeJar(analyzer);
+
+        assertEquals("component { $class=\"com.acme.Thermometer\" }",
+                analyzer.getProperty("IPOJO-Components"));
+    }
+
+    public void testAnalysisWithInstanceOnlyMetadataXml() throws Exception {
+        PojoizationPlugin plugin = new PojoizationPlugin();
+
+        Map<String, String> props = new HashMap<String, String>();
+
+        Resource resource = new URLResource(getClass().getResource("/metadata-instances-only.xml"));
+        doReturn(jar).when(analyzer).getJar();
+        doReturn(resource).when(jar).getResource(eq("META-INF/metadata.xml"));
+
+        plugin.setReporter(reporter);
+        plugin.setProperties(props);
+
+        plugin.analyzeJar(analyzer);
+
+        assertEquals("instance { $component=\"com.acme.Thermometer\" }",
+                analyzer.getProperty("IPOJO-Components"));
+    }
+
+    public void testAnalysisWithComponentsAndInstancesMetadataXml() throws Exception {
+        PojoizationPlugin plugin = new PojoizationPlugin();
+
+        Map<String, String> props = new HashMap<String, String>();
+
+        Resource resource = new URLResource(getClass().getResource("/metadata-components-and-instances.xml"));
+        doReturn(jar).when(analyzer).getJar();
+        doReturn(resource).when(jar).getResource(eq("META-INF/metadata.xml"));
+
+        plugin.setReporter(reporter);
+        plugin.setProperties(props);
+
+        plugin.analyzeJar(analyzer);
+
+        assertEquals("component { $class=\"com.acme.Thermometer\" }" +
+                     "instance { $component=\"com.acme.Thermometer\" }" +
+                     "instance { $component=\"com.acme.Thermometer\" }",
+                     analyzer.getProperty("IPOJO-Components"));
+    }
+}
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-components-and-instances.xml b/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-components-and-instances.xml
new file mode 100644
index 0000000..19bc3d4
--- /dev/null
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-components-and-instances.xml
@@ -0,0 +1,5 @@
+<ipojo>
+  <component class="com.acme.Thermometer" />
+  <instance component="com.acme.Thermometer" />
+  <instance component="com.acme.Thermometer" />
+</ipojo>
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-components-only.xml b/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-components-only.xml
new file mode 100644
index 0000000..cc913fe
--- /dev/null
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-components-only.xml
@@ -0,0 +1,3 @@
+<ipojo>
+  <component class="com.acme.Thermometer"/>
+</ipojo>
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-instances-only.xml b/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-instances-only.xml
new file mode 100644
index 0000000..56aa63a
--- /dev/null
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/test/resources/metadata-instances-only.xml
@@ -0,0 +1,3 @@
+<ipojo>
+    <instance component="com.acme.Thermometer"/>
+</ipojo>
\ No newline at end of file