cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7105] Enabling a default application only if service beans are available, patch from John Ament applied, This closes #185
Date Mon, 24 Oct 2016 09:35:50 GMT
Repository: cxf
Updated Branches:
  refs/heads/master b6b0b305a -> 81dd064d1


[CXF-7105] Enabling a default application only if service beans are available, patch from
John Ament applied, This closes #185


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

Branch: refs/heads/master
Commit: 81dd064d10ebe9fd286dccf5fd3d566f031bc028
Parents: b6b0b30
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Oct 24 10:34:15 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Oct 24 10:35:32 2016 +0100

----------------------------------------------------------------------
 integration/cdi/pom.xml                         | 10 +++
 .../cxf/cdi/JAXRSCdiResourceExtension.java      |  2 +-
 .../cxf/cdi/JAXRSCdiResourceExtensionTest.java  | 85 ++++++++++++++++++++
 3 files changed, 96 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/81dd064d/integration/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/integration/cdi/pom.xml b/integration/cdi/pom.xml
index d5cdfd8..98ce45a 100644
--- a/integration/cdi/pom.xml
+++ b/integration/cdi/pom.xml
@@ -75,6 +75,16 @@
             <artifactId>slf4j-jdk14</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>2.1.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     
     <build>

http://git-wip-us.apache.org/repos/asf/cxf/blob/81dd064d/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
index 11cbd41..89b0094 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
@@ -121,7 +121,7 @@ public class JAXRSCdiResourceExtension implements Extension {
                 beanManager.createInjectionTarget(busAnnotatedType);
             event.addBean(new CdiBusBean(busInjectionTarget));
         }
-        if (applicationBeans.isEmpty()) {
+        if (applicationBeans.isEmpty() && !serviceBeans.isEmpty()) {
             event.addBean(new DefaultApplicationBean());
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/81dd064d/integration/cdi/src/test/java/org/apache/cxf/cdi/JAXRSCdiResourceExtensionTest.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/test/java/org/apache/cxf/cdi/JAXRSCdiResourceExtensionTest.java
b/integration/cdi/src/test/java/org/apache/cxf/cdi/JAXRSCdiResourceExtensionTest.java
new file mode 100644
index 0000000..de4c0a6
--- /dev/null
+++ b/integration/cdi/src/test/java/org/apache/cxf/cdi/JAXRSCdiResourceExtensionTest.java
@@ -0,0 +1,85 @@
+/**
+ * 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.cdi;
+
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.ProcessBean;
+import javax.ws.rs.Path;
+
+import org.apache.cxf.Bus;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JAXRSCdiResourceExtensionTest {
+    private final JAXRSCdiResourceExtension extension = new JAXRSCdiResourceExtension();
+    @Mock
+    private BeanManager beanManager;
+    @Mock
+    private AfterBeanDiscovery event;
+    @Mock
+    private Bean busBean;
+    @Mock
+    private ProcessBean<? extends Object> processBean;
+    @Mock
+    private Annotated annotated;
+
+    @Test
+    public void shouldNotAddDefaultApplicationWhenNoResourcesDefined() {
+        extension.injectBus(event, beanManager);
+
+        verify(event).addBean(any(CdiBusBean.class));
+        verify(event, never()).addBean(any(DefaultApplicationBean.class));
+    }
+
+    @Test
+    public void shouldNotAddBusBeanIfBeanAlreadySent() {
+        when(processBean.getBean()).thenReturn(busBean);
+        when(processBean.getAnnotated()).thenReturn(annotated);
+        when(busBean.getBeanClass()).thenReturn(Bus.class);
+        when(busBean.getName()).thenReturn(CdiBusBean.CXF);
+        extension.collect(processBean);
+
+        extension.injectBus(event, beanManager);
+
+        verify(event, never()).addBean(any(CdiBusBean.class));
+    }
+
+    @Test
+    public void shouldAddApplicationBeanWhenResourcesProvided() {
+        when(processBean.getBean()).thenReturn(busBean);
+        when(processBean.getAnnotated()).thenReturn(annotated);
+        when(annotated.isAnnotationPresent(Path.class)).thenReturn(true);
+        extension.collect(processBean);
+
+        extension.injectBus(event, beanManager);
+
+        verify(event).addBean(any(DefaultApplicationBean.class));
+    }
+}
\ No newline at end of file


Mime
View raw message