servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r708207 - in /servicemix/smx4/kernel/trunk/gshell/gshell-features: ./ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/servicemix/ src/test/java/org/apache/servicemix/kernel/ src/test/java/org/a...
Date Mon, 27 Oct 2008 15:00:36 GMT
Author: gnodet
Date: Mon Oct 27 08:00:36 2008
New Revision: 708207

URL: http://svn.apache.org/viewvc?rev=708207&view=rev
Log:
Add some tests to the features service

Added:
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/RepositoryTest.java
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo1.xml
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo2.xml
Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml?rev=708207&r1=708206&r2=708207&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/pom.xml Mon Oct 27 08:00:36 2008
@@ -69,6 +69,17 @@
             <groupId>org.springframework.osgi</groupId>
             <artifactId>spring-osgi-core</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

Added: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java?rev=708207&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/FeaturesServiceTest.java
Mon Oct 27 08:00:36 2008
@@ -0,0 +1,102 @@
+/*
+ * 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.servicemix.kernel.gshell.features;
+
+import java.net.URI;
+import java.io.InputStream;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.apache.servicemix.kernel.gshell.features.internal.FeaturesServiceImpl;
+import org.easymock.EasyMock;
+import org.osgi.service.prefs.PreferencesService;
+import org.osgi.service.prefs.Preferences;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Bundle;
+
+public class FeaturesServiceTest {
+
+    @Test
+    public void testInstallFeature() throws Exception {
+        URI uri = getClass().getResource("repo2.xml").toURI();
+
+        Preferences prefs = EasyMock.createMock(Preferences.class);
+        PreferencesService preferencesService = EasyMock.createMock(PreferencesService.class);
+        Preferences repositoriesNode = EasyMock.createMock(Preferences.class);
+        Preferences featuresNode = EasyMock.createMock(Preferences.class);
+        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
+        Bundle installedBundle = EasyMock.createMock(Bundle.class);
+
+        expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
+        expect(prefs.node("repositories")).andReturn(repositoriesNode);
+        repositoriesNode.clear();
+        repositoriesNode.putInt("count", 1);
+        repositoriesNode.put("item.0", uri.toString());
+        expect(prefs.node("features")).andReturn(featuresNode);
+        featuresNode.clear();
+        prefs.putBoolean("bootFeaturesInstalled", false);
+        prefs.flush();
+
+        replay(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext,
installedBundle);
+
+        FeaturesServiceImpl svc = new FeaturesServiceImpl();
+        svc.setPreferences(preferencesService);
+        svc.setBundleContext(bundleContext);
+        svc.addRepository(uri);
+        
+        Repository[] repositories = svc.listRepositories();
+        assertNotNull(repositories);
+        assertEquals(1, repositories.length);
+        assertNotNull(repositories[0]);
+        Feature[] features = repositories[0].getFeatures();
+        assertNotNull(features);
+        assertEquals(1, features.length);
+        assertNotNull(features[0]);
+        assertEquals("f1", features[0].getName());
+        assertNotNull(features[0].getDependencies());
+        assertEquals(0, features[0].getDependencies().size());
+        assertNotNull(features[0].getBundles());
+        assertEquals(1, features[0].getBundles().size());
+        assertEquals("http://repo1.maven.org/maven2/org/apache/geronimo/specs/geronimo-stax-api_1.0_spec/1.0.1/geronimo-stax-api_1.0_spec-1.0.1.jar",
features[0].getBundles().get(0));
+
+        verify(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext,
installedBundle);
+
+        reset(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext, installedBundle);
+
+        expect(bundleContext.getBundles()).andReturn(new Bundle[0]);
+        expect(bundleContext.installBundle(isA(String.class),
+                                           isA(InputStream.class))).andReturn(installedBundle);
+        installedBundle.start();
+        expect(installedBundle.getBundleId()).andReturn(12345L);
+
+        expect(preferencesService.getUserPreferences("FeaturesServiceState")).andStubReturn(prefs);
+        expect(prefs.node("repositories")).andReturn(repositoriesNode);
+        repositoriesNode.clear();
+        repositoriesNode.putInt("count", 1);
+        repositoriesNode.put("item.0", uri.toString());
+        expect(prefs.node("features")).andReturn(featuresNode);
+        featuresNode.clear();
+        featuresNode.put("f1", "12345");
+        prefs.putBoolean("bootFeaturesInstalled", false);
+        prefs.flush();
+
+        replay(preferencesService, prefs, repositoriesNode, featuresNode, bundleContext,
installedBundle);
+
+        svc.installFeature("f1");
+    }
+}

Added: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/RepositoryTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/RepositoryTest.java?rev=708207&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/RepositoryTest.java
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/RepositoryTest.java
Mon Oct 27 08:00:36 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.servicemix.kernel.gshell.features;
+
+import java.net.URI;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.apache.servicemix.kernel.gshell.features.internal.RepositoryImpl;
+
+
+public class RepositoryTest {
+
+    @Test
+    public void testLoad() throws Exception {
+        RepositoryImpl r = new RepositoryImpl(getClass().getResource("repo1.xml").toURI());
+        // Check repo
+        URI[] repos = r.getRepositories();
+        assertNotNull(repos);
+        assertEquals(1, repos.length);
+        assertEquals(URI.create("urn:r1"), repos[0]);
+        // Check features
+        Feature[] features = r.getFeatures();
+        assertNotNull(features);
+        assertEquals(2, features.length);
+        assertNotNull(features[0]);
+        assertEquals("f1", features[0].getName());
+        assertNotNull(features[0].getConfigurations());
+        assertEquals(1, features[0].getConfigurations().size());
+        assertNotNull(features[0].getConfigurations().get("c1"));
+        assertEquals(1, features[0].getConfigurations().get("c1").size());
+        assertEquals("v", features[0].getConfigurations().get("c1").get("k"));
+        assertNotNull(features[0].getDependencies());
+        assertEquals(0, features[0].getDependencies().size());
+        assertNotNull(features[0].getBundles());
+        assertEquals(2, features[0].getBundles().size());
+        assertEquals("b1", features[0].getBundles().get(0));
+        assertEquals("b2", features[0].getBundles().get(1));
+        assertNotNull(features[1]);
+        assertEquals("f2", features[1].getName());
+        assertNotNull(features[1].getConfigurations());
+        assertEquals(0, features[1].getConfigurations().size());
+        assertNotNull(features[1].getDependencies());
+        assertEquals(1, features[1].getDependencies().size());
+        assertEquals("f1", features[1].getDependencies().get(0));
+        assertNotNull(features[1].getBundles());
+        assertEquals(1, features[1].getBundles().size());
+        assertEquals("b3", features[1].getBundles().get(0));
+    }
+}

Added: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo1.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo1.xml?rev=708207&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo1.xml
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo1.xml
Mon Oct 27 08:00:36 2008
@@ -0,0 +1,14 @@
+<features>
+    <repository>urn:r1</repository>
+    <feature name="f1">
+        <config name="c1">
+            k=v
+        </config>
+        <bundle>b1</bundle>
+        <bundle>b2</bundle>
+    </feature>
+    <feature name="f2">
+        <feature>f1</feature>
+        <bundle>b3</bundle>
+    </feature>
+</features>
\ No newline at end of file

Added: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo2.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo2.xml?rev=708207&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo2.xml
(added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/resources/org/apache/servicemix/kernel/gshell/features/repo2.xml
Mon Oct 27 08:00:36 2008
@@ -0,0 +1,5 @@
+<features>
+    <feature name="f1">
+        <bundle>http://repo1.maven.org/maven2/org/apache/geronimo/specs/geronimo-stax-api_1.0_spec/1.0.1/geronimo-stax-api_1.0_spec-1.0.1.jar</bundle>
+    </feature>
+</features>
\ No newline at end of file



Mime
View raw message