You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2023/06/27 09:34:27 UTC

[sling-org-apache-sling-testing-osgi-mock] branch issue/SLING-11913 created (now a98ce9b)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to branch issue/SLING-11913
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git


      at a98ce9b  cleanups in MockBundle

This branch includes the following new commits:

     new f10ec2a  SLING-11913 - Implement MockBundle.getVersion
     new a98ce9b  cleanups in MockBundle

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-testing-osgi-mock] 01/02: SLING-11913 - Implement MockBundle.getVersion

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch issue/SLING-11913
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit f10ec2a52a9f88fe07818d7513696ecffcc1aa7a
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Jun 27 11:20:50 2023 +0200

    SLING-11913 - Implement MockBundle.getVersion
---
 .../apache/sling/testing/mock/osgi/MockBundle.java   | 20 +++++++++++++++-----
 .../apache/sling/testing/mock/osgi/package-info.java |  2 +-
 .../sling/testing/mock/osgi/MockBundleTest.java      | 13 +++++++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
index f53abd4..2e3f2a1 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
@@ -49,6 +49,7 @@ public final class MockBundle implements Bundle {
     private Map<String, String> headers = Collections.emptyMap();
     private String symbolicName;
     private long lastModified;
+    private Version version = Version.emptyVersion;
 
     /**
      * Constructor
@@ -194,6 +195,20 @@ public final class MockBundle implements Bundle {
             return null;
         }
     }
+    
+    @Override
+    public Version getVersion() {
+        return version;
+    }
+    
+    /**
+     * Sets a new version for this bundle
+     * 
+     * @param version the new version
+     */
+    public void setVersion(Version version) {
+        this.version = version;
+    }
 
     // --- unsupported operations ---
     @Override
@@ -271,11 +286,6 @@ public final class MockBundle implements Bundle {
         throw new UnsupportedOperationException();
     }
 
-    @Override
-    public Version getVersion() {
-        throw new UnsupportedOperationException();
-    }
-
     @Override
     public int compareTo(Bundle o) {
         throw new UnsupportedOperationException();
diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
index b6ba265..cd480aa 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
@@ -19,5 +19,5 @@
 /**
  * Mock implementation of selected OSGi APIs.
  */
-@org.osgi.annotation.versioning.Version("3.6.0")
+@org.osgi.annotation.versioning.Version("3.7.0")
 package org.apache.sling.testing.mock.osgi;
diff --git a/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java
index 3f73c32..b87426a 100644
--- a/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java
+++ b/core/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleTest.java
@@ -30,6 +30,7 @@ import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
 
 import com.google.common.collect.ImmutableMap;
 
@@ -154,4 +155,16 @@ public class MockBundleTest {
         assertTrue(paths.contains("bundleData/nested/first.txt"));
         assertTrue(paths.contains("bundleData/nested/second.txt"));
     }
+    
+    @Test
+    public void getVersion_default() {
+        assertEquals(Version.emptyVersion, bundle.getVersion());
+    }
+    
+    @Test
+    public void getVersion_custom() {
+        bundle.setVersion(new Version(3, 2, 1));
+        assertEquals("3.2.1", bundle.getVersion().toString());
+    }
+    
 }


[sling-org-apache-sling-testing-osgi-mock] 02/02: cleanups in MockBundle

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch issue/SLING-11913
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit a98ce9ba9b3642fb9042876f3c98d21a7f794344
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Jun 27 11:34:05 2023 +0200

    cleanups in MockBundle
---
 .../java/org/apache/sling/testing/mock/osgi/MockBundle.java  | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
index 2e3f2a1..105c022 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundle.java
@@ -23,12 +23,12 @@ import java.io.InputStream;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.security.cert.X509Certificate;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Map;
-import java.util.Vector;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.osgi.framework.Bundle;
@@ -100,7 +100,7 @@ public final class MockBundle implements Bundle {
 
     @Override
     public Dictionary<String, String> getHeaders(final String locale) {
-        // localziation not supported, always return default headers
+        // localization not supported, always return default headers
         return getHeaders();
     }
 
@@ -148,7 +148,7 @@ public final class MockBundle implements Bundle {
             return null;
         }
 
-        Vector<String> matching = new Vector<String>();
+        List<String> matching = new ArrayList<>();
 
         try {
             File file = new File(res.toURI());
@@ -158,9 +158,7 @@ public final class MockBundle implements Bundle {
                     matching.add(relativeWithTrailingSlash(queryPath.substring(1, queryPath.length())) + name);
                 }
             }
-        } catch (URISyntaxException e) {
-            throw new RuntimeException("Failed opening file from " + res , e);
-        } catch ( RuntimeException e) {
+        } catch (URISyntaxException | RuntimeException e) {
             throw new RuntimeException("Failed opening file from " + res , e);
         }
 
@@ -168,7 +166,7 @@ public final class MockBundle implements Bundle {
             return null;
         }
 
-        return matching.elements();
+        return Collections.enumeration(matching);
     }
 
     private String relativeWithTrailingSlash(String queryPath) {