ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1572897 - in /ace/trunk: org.apache.ace.feedback.common/ org.apache.ace.feedback.common/src/org/apache/ace/feedback/ org.apache.ace.feedback.common/test/org/ org.apache.ace.feedback.common/test/org/apache/ org.apache.ace.feedback.common/te...
Date Fri, 28 Feb 2014 09:44:14 GMT
Author: jawi
Date: Fri Feb 28 09:44:13 2014
New Revision: 1572897

URL: http://svn.apache.org/r1572897
Log:
ACE-462 - incorrect handling of dictionaries in Events:

- dictionary should be traversed by key, not its value;
- fixed failing itests by making additional package optional.


Added:
    ace/trunk/org.apache.ace.feedback.common/test/org/
    ace/trunk/org.apache.ace.feedback.common/test/org/apache/
    ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/
    ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/feedback/
    ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/feedback/EventTest.java 
 (with props)
Modified:
    ace/trunk/org.apache.ace.feedback.common/   (props changed)
    ace/trunk/org.apache.ace.feedback.common/.classpath
    ace/trunk/org.apache.ace.feedback.common/src/org/apache/ace/feedback/Event.java
    ace/trunk/org.apache.ace.test/bnd.bnd

Propchange: ace/trunk/org.apache.ace.feedback.common/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Feb 28 09:44:13 2014
@@ -1,3 +1,4 @@
 bin
 bin_test
 generated
+test-output

Modified: ace/trunk/org.apache.ace.feedback.common/.classpath
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.feedback.common/.classpath?rev=1572897&r1=1572896&r2=1572897&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.feedback.common/.classpath (original)
+++ ace/trunk/org.apache.ace.feedback.common/.classpath Fri Feb 28 09:44:13 2014
@@ -4,5 +4,6 @@
 	<classpathentry kind="src" output="bin_test" path="test"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
+	<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: ace/trunk/org.apache.ace.feedback.common/src/org/apache/ace/feedback/Event.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.feedback.common/src/org/apache/ace/feedback/Event.java?rev=1572897&r1=1572896&r2=1572897&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.feedback.common/src/org/apache/ace/feedback/Event.java (original)
+++ ace/trunk/org.apache.ace.feedback.common/src/org/apache/ace/feedback/Event.java Fri Feb
28 09:44:13 2014
@@ -59,7 +59,7 @@ public class Event implements Comparable
         m_type = type;
         m_properties = new HashMap<String, String>();
 
-        Enumeration<String> keys = dictionary.elements();
+        Enumeration<String> keys = dictionary.keys();
         while (keys.hasMoreElements()) {
             String key = keys.nextElement();
             m_properties.put(key, dictionary.get(key));
@@ -88,8 +88,7 @@ public class Event implements Comparable
             }
         }
         catch (Exception e) {
-            throw new IllegalArgumentException(
-                "Could not create event from: " + representation, e);
+            throw new IllegalArgumentException("Could not create event from: " + representation,
e);
         }
     }
 

Added: ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/feedback/EventTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/feedback/EventTest.java?rev=1572897&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/feedback/EventTest.java (added)
+++ ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/feedback/EventTest.java Fri
Feb 28 09:44:13 2014
@@ -0,0 +1,124 @@
+/*
+ * 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.ace.feedback;
+
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+import static org.testng.Assert.*;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.testng.annotations.Test;
+
+/**
+ * Test cases for {@link Event}.
+ */
+public class EventTest {
+    private static final String TARGET_ID = "target";
+    private static final long STORE_ID = 1234;
+
+    @Test(groups = { UNIT })
+    public void testCreateEventFromStringOk() throws Exception {
+        String input = "target,1234,1,2,3,key2,value2,key1,value1";
+
+        Event event = new Event(input);
+
+        assertEquals(TARGET_ID, event.getTargetID());
+        assertEquals(STORE_ID, event.getStoreID());
+        assertEquals(1, event.getID());
+        assertEquals(2, event.getTime());
+        assertEquals(3, event.getType());
+
+        Map<String, String> props = event.getProperties();
+        assertNotNull(props);
+        assertFalse(props.isEmpty());
+
+        assertEquals("value1", props.get("key1"));
+        assertEquals("value2", props.get("key2"));
+    }
+
+    @Test(groups = { UNIT })
+    public void testCreateEventWithDictionaryOk() throws Exception {
+        Event event = new Event(TARGET_ID, STORE_ID, 1, 2, 3, createDict("key1", "value1",
"key2", "value2"));
+
+        assertEquals(TARGET_ID, event.getTargetID());
+        assertEquals(STORE_ID, event.getStoreID());
+        assertEquals(1, event.getID());
+        assertEquals(2, event.getTime());
+        assertEquals(3, event.getType());
+
+        Map<String, String> props = event.getProperties();
+        assertNotNull(props);
+        assertFalse(props.isEmpty());
+
+        assertEquals("value1", props.get("key1"));
+        assertEquals("value2", props.get("key2"));
+    }
+
+    @Test(groups = { UNIT })
+    public void testCreateEventWithoutPropertiesOk() throws Exception {
+        Event event = new Event(TARGET_ID, STORE_ID, 1, 2, 3);
+
+        assertEquals(TARGET_ID, event.getTargetID());
+        assertEquals(STORE_ID, event.getStoreID());
+        assertEquals(1, event.getID());
+        assertEquals(2, event.getTime());
+        assertEquals(3, event.getType());
+
+        Map<String, String> props = event.getProperties();
+        assertNotNull(props);
+        assertTrue(props.isEmpty());
+    }
+
+    @Test(groups = { UNIT })
+    public void testCreateEventWithPropertiesOk() throws Exception {
+        Event event = new Event(TARGET_ID, STORE_ID, 1, 2, 3, createMap("key1", "value1",
"key2", "value2"));
+
+        assertEquals(TARGET_ID, event.getTargetID());
+        assertEquals(STORE_ID, event.getStoreID());
+        assertEquals(1, event.getID());
+        assertEquals(2, event.getTime());
+        assertEquals(3, event.getType());
+
+        Map<String, String> props = event.getProperties();
+        assertNotNull(props);
+        assertFalse(props.isEmpty());
+
+        assertEquals("value1", props.get("key1"));
+        assertEquals("value2", props.get("key2"));
+    }
+
+    private Dictionary<String, String> createDict(String... entries) {
+        Dictionary<String, String> result = new Hashtable<String, String>();
+        for (int i = 0; i < entries.length; i += 2) {
+            result.put(entries[i], entries[i + 1]);
+        }
+        return result;
+    }
+
+    private Map<String, String> createMap(String... entries) {
+        Map<String, String> result = new HashMap<String, String>();
+        for (int i = 0; i < entries.length; i += 2) {
+            result.put(entries[i], entries[i + 1]);
+        }
+        return result;
+    }
+}

Propchange: ace/trunk/org.apache.ace.feedback.common/test/org/apache/ace/feedback/EventTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ace/trunk/org.apache.ace.test/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.test/bnd.bnd?rev=1572897&r1=1572896&r2=1572897&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.test/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.test/bnd.bnd Fri Feb 28 09:44:13 2014
@@ -9,6 +9,7 @@ Export-Package: org.apache.ace.it,\
 	org.apache.ace.test.utils
 Import-Package: \
 	junit.framework;resolution:=optional,\
+	org.apache.felix.service.command;resolution:=optional,\
 	*
 Bundle-Version: 1.0.0
 Bundle-Name: Apache ACE Test



Mime
View raw message