cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject cxf-dosgi git commit: [DOSGI-262] Add support for Features annotation
Date Mon, 10 Apr 2017 14:05:58 GMT
Repository: cxf-dosgi
Updated Branches:
  refs/heads/master 43ec61137 -> a3a979380


[DOSGI-262] Add support for Features annotation


Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/a3a97938
Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/a3a97938
Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/a3a97938

Branch: refs/heads/master
Commit: a3a97938043a250fcf1e3c76b861600e4a9ee83f
Parents: 43ec611
Author: Christian Schneider <chris@die-schneider.net>
Authored: Mon Apr 10 16:05:52 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Mon Apr 10 16:05:52 2017 +0200

----------------------------------------------------------------------
 .../common/intent/impl/IntentManagerImpl.java   | 11 +++++
 .../intent/impl/DummyServiceWithLogging.java    | 27 ++++++++++++
 .../intent/impl/DummyServiceWithLoggingIP.java  | 34 +++++++++++++++
 .../intent/impl/IntentManagerImplTest.java      | 46 ++++++++++++++++++++
 4 files changed, 118 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a3a97938/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
b/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
index 10e4a05..67d82a7 100644
--- a/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
+++ b/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
@@ -31,6 +31,7 @@ import java.util.concurrent.Callable;
 import org.apache.cxf.dosgi.common.api.IntentsProvider;
 import org.apache.cxf.dosgi.common.intent.IntentManager;
 import org.apache.cxf.dosgi.common.util.PropertyHelper;
+import org.apache.cxf.feature.Features;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
@@ -197,6 +198,16 @@ public class IntentManagerImpl implements IntentManager {
         if (serviceBean instanceof IntentsProvider) {
             intents.addAll(((IntentsProvider)serviceBean).getIntents());
         }
+        Features features = serviceBean.getClass().getAnnotation(Features.class);
+        if (features != null && features.classes() != null) {
+            for (Class<?> clazz : features.classes()) {
+                try {
+                    intents.add(clazz.newInstance());
+                } catch (Exception e) {
+                    throw new RuntimeException("Could not instantiate feature from class
" + clazz.getName(), e);
+                }
+            }
+        }
         return intents;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a3a97938/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLogging.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLogging.java
b/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLogging.java
new file mode 100644
index 0000000..8f46d82
--- /dev/null
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLogging.java
@@ -0,0 +1,27 @@
+/**
+ * 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.cxf.dosgi.common.intent.impl;
+
+import org.apache.cxf.feature.Features;
+import org.apache.cxf.transport.common.gzip.GZIPFeature;
+
+@Features(classes = GZIPFeature.class)
+public class DummyServiceWithLogging {
+
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a3a97938/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLoggingIP.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLoggingIP.java
b/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLoggingIP.java
new file mode 100644
index 0000000..f0773c6
--- /dev/null
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/DummyServiceWithLoggingIP.java
@@ -0,0 +1,34 @@
+/**
+ * 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.cxf.dosgi.common.intent.impl;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.cxf.dosgi.common.api.IntentsProvider;
+import org.apache.cxf.transport.common.gzip.GZIPFeature;
+
+public class DummyServiceWithLoggingIP implements IntentsProvider {
+
+    @Override
+    public List<?> getIntents() {
+        return Arrays.asList(new GZIPFeature());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/a3a97938/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImplTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImplTest.java
b/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImplTest.java
new file mode 100644
index 0000000..4f55b54
--- /dev/null
+++ b/common/src/test/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImplTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.cxf.dosgi.common.intent.impl;
+
+import java.util.List;
+
+import org.apache.cxf.transport.common.gzip.GZIPFeature;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class IntentManagerImplTest {
+
+    @Test
+    public void testIntentsFromFeatureAnn() {
+        IntentManagerImpl im = new IntentManagerImpl();
+        List<Object> intents = im.getIntentsFromService(new DummyServiceWithLogging());
+        Assert.assertEquals(1, intents.size());
+        Object feature = intents.iterator().next();
+        Assert.assertEquals(GZIPFeature.class, feature.getClass());
+    }
+    
+    @Test
+    public void testIntentsFromIntentsProvider() {
+        IntentManagerImpl im = new IntentManagerImpl();
+        List<Object> intents = im.getIntentsFromService(new DummyServiceWithLoggingIP());
+        Assert.assertEquals(1, intents.size());
+        Object feature = intents.iterator().next();
+        Assert.assertEquals(GZIPFeature.class, feature.getClass());
+    }
+}


Mime
View raw message