Author: cziegeler
Date: Thu Feb 7 06:36:42 2019
New Revision: 1853114
URL: http://svn.apache.org/viewvc?rev=1853114&view=rev
Log:
FELIX-6049 : Listeners registered with boolean property are ignored
Added:
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
(with props)
Modified:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
Modified:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
URL:
http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java?rev=1853114&r1=1853113&r2=1853114&view=diff
==============================================================================
---
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
(original)
+++
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
Thu Feb 7 06:36:42 2019
@@ -22,7 +22,6 @@ import java.util.EventListener;
import java.util.HashSet;
import java.util.Set;
-import org.jetbrains.annotations.NotNull;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestAttributeListener;
@@ -31,6 +30,7 @@ import javax.servlet.http.HttpSessionAtt
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;
+import org.jetbrains.annotations.NotNull;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
@@ -63,7 +63,7 @@ public class ListenerInfo extends Whiteb
public ListenerInfo(final ServiceReference<EventListener> ref)
{
super(ref);
- this.enabled = "true".equalsIgnoreCase(this.getStringProperty(ref,
HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
+ this.enabled = this.getBooleanProperty(ref,
HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER);
final String[] objectClass =
(String[])ref.getProperty(Constants.OBJECTCLASS);
final Set<String> names = new HashSet<String>();
for(final String name : objectClass)
Added:
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java?rev=1853114&view=auto
==============================================================================
---
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
(added)
+++
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
Thu Feb 7 06:36:42 2019
@@ -0,0 +1,75 @@
+/*
+ * 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.http.base.internal.runtime;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.EventListener;
+
+import javax.servlet.ServletContextListener;
+
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+public class ListenerInfoTest
+{
+ @Test
+ public void testEnabled() throws InvalidSyntaxException {
+ Bundle b = mock(Bundle.class);
+ BundleContext bc = mock(BundleContext.class);
+
+ ServiceReference<EventListener> ref = mock(ServiceReference.class);
+ when(ref.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
+ when(ref.getProperty(Constants.OBJECTCLASS))
+ .thenReturn(new String[] {
ServletContextListener.class.getName() });
+ when(ref.getBundle()).thenReturn(b);
+ when(b.getBundleContext()).thenReturn(bc);
+
when(bc.createFilter(ArgumentMatchers.any(String.class))).thenReturn(mock(Filter.class));
+
+ // string true
+
when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER)).thenReturn("true");
+ assertTrue(new ListenerInfo(ref).isValid());
+
+ // string false
+
when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER)).thenReturn("false");
+ assertFalse(new ListenerInfo(ref).isValid());
+
+ // string some text
+
when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER)).thenReturn("text");
+ assertFalse(new ListenerInfo(ref).isValid());
+
+ // string true
+
when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER)).thenReturn(Boolean.TRUE);
+ assertTrue(new ListenerInfo(ref).isValid());
+
+ // string false
+
when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER)).thenReturn(Boolean.FALSE);
+ assertFalse(new ListenerInfo(ref).isValid());
+ }
+}
Propchange:
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange:
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/ListenerInfoTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url