incubator-ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r942359 - in /incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log: ./ LogDescriptorTest.java LogEventTest.java
Date Sat, 08 May 2010 11:07:23 GMT
Author: marrs
Date: Sat May  8 11:07:23 2010
New Revision: 942359

URL: http://svn.apache.org/viewvc?rev=942359&view=rev
Log:
Added unit tests.

Added:
    incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/
    incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogDescriptorTest.java
    incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogEventTest.java

Added: incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogDescriptorTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogDescriptorTest.java?rev=942359&view=auto
==============================================================================
--- incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogDescriptorTest.java (added)
+++ incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogDescriptorTest.java Sat
May  8 11:07:23 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.log;
+
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+
+import org.apache.ace.repository.SortedRangeSet;
+import org.testng.annotations.Test;
+
+public class LogDescriptorTest {
+
+    @Test(groups = { UNIT })
+    public void serializeDescriptor() {
+        LogDescriptor descriptor = new LogDescriptor("gwid", 1, new SortedRangeSet("2-3"));
+        assert descriptor.toRepresentation().equals("gwid,1,2-3") : "The representation of
our descriptor is incorrect:" + descriptor.toRepresentation();
+    }
+
+    @Test(groups = { UNIT })
+    public void deserializeDescriptor() {
+        LogDescriptor descriptor = new LogDescriptor("gwid,1,2-3");
+        assert descriptor.getGatewayID().equals("gwid") : "Gateway ID not correctly parsed.";
+        assert descriptor.getLogID() == 1 : "Log ID not correctly parsed.";
+        assert descriptor.getRangeSet().toRepresentation().equals("2-3") : "There should
be nothing in the diff between the set in the descriptor and the check-set.";
+    }
+
+    @Test(groups = { UNIT })
+    public void deserializeMultiRangeDescriptor() {
+        LogDescriptor descriptor = new LogDescriptor("gwid,1,1-4$k6$k8$k10-20");
+        assert descriptor.getGatewayID().equals("gwid") : "Gateway ID not correctly parsed.";
+        assert descriptor.getLogID() == 1 : "Log ID not correctly parsed.";
+        String representation = descriptor.getRangeSet().toRepresentation();
+        assert representation.equals("1-4,6,8,10-20") : "There should be nothing in the diff
between the set in the descriptor and the check-set, but we parsed: " + representation;
+    }
+
+    @Test(groups = { UNIT })
+    public void deserializeMultiRangeDescriptorWithFunnyGWID() {
+        String line = "gw$$id,1,1-4$k6$k8$k10-20";
+        LogDescriptor descriptor = new LogDescriptor(line);
+        assert descriptor.getGatewayID().equals("gw$id") : "Gateway ID not correctly parsed.";
+        assert descriptor.getLogID() == 1 : "Log ID not correctly parsed.";
+        assert line.equals(descriptor.toRepresentation()) : "Converting the line back to
the representation failed.";
+        String representation = descriptor.getRangeSet().toRepresentation();
+        assert representation.equals("1-4,6,8,10-20") : "There should be nothing in the diff
between the set in the descriptor and the check-set, but we parsed: " + representation;
+    }
+
+    @Test(groups = { UNIT }, expectedExceptions = IllegalArgumentException.class)
+    public void deserializeInvalidDescriptor() throws Exception {
+        new LogDescriptor("invalidStringRepresentation");
+    }
+}

Added: incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogEventTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogEventTest.java?rev=942359&view=auto
==============================================================================
--- incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogEventTest.java (added)
+++ incubator/ace/trunk/ace-log/src/test/java/org/apache/ace/log/LogEventTest.java Sat May
 8 11:07:23 2010
@@ -0,0 +1,87 @@
+/*
+ * 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.log;
+
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.testng.annotations.Test;
+
+public class LogEventTest {
+    @Test(groups = { UNIT })
+    public void serializeLogEvent() {
+        LogEvent e = new LogEvent("gwid", 1, 2, 3, AuditEvent.FRAMEWORK_STARTED, new Properties());
+        assert e.toRepresentation().equals("gwid,1,2,3," + AuditEvent.FRAMEWORK_STARTED);
+        Properties p = new Properties();
+        p.put(AuditEvent.KEY_ID, "my first value");
+        e = new LogEvent("gwid", 1, 2, 3, AuditEvent.BUNDLE_INSTALLED, p);
+        assert e.toRepresentation().equals("gwid,1,2,3," + AuditEvent.BUNDLE_INSTALLED +
"," + AuditEvent.KEY_ID + ",my first value");
+        e = new LogEvent("gwid,gwid\n\r$", 1, 2, 3, AuditEvent.FRAMEWORK_STARTED, new Properties());
+        assert e.toRepresentation().equals("gwid$kgwid$n$r$$,1,2,3," + AuditEvent.FRAMEWORK_STARTED);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test(groups = { UNIT })
+    public void deserializeLogEvent() {
+        LogEvent e = new LogEvent("gwid$kgwid$n$r$$,1,2,3," + AuditEvent.FRAMEWORK_STARTED
+ ",a,1,b,2,c,3");
+        assert e.getGatewayID().equals("gwid,gwid\n\r$") : "Gateway ID is not correctly parsed";
+        assert e.getLogID() == 1 : "Log ID is not correctly parsed";
+        assert e.getID() == 2 : "ID is not correctly parsed";
+        assert e.getTime() == 3 : "Time is not correctly parsed";
+        assert e.getType() == AuditEvent.FRAMEWORK_STARTED : "Event type is wrong";
+        Dictionary p = e.getProperties();
+        assert p != null : "Properties are not correctly parsed";
+        assert p.get("a").equals("1") : "Property a should be 1";
+        assert p.get("b").equals("2") : "Property a should be 1";
+        assert p.get("c").equals("3") : "Property a should be 1";
+    }
+    @Test(groups = { UNIT })
+    public void deserializeIllegalLogEvent() {
+        try {
+            new LogEvent("garbage in, garbage out!");
+            assert false : "Parsing garbage should result in an exception";
+        }
+        catch (IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            new LogEvent("g$z,1,2,3," + AuditEvent.BUNDLE_STOPPED);
+            assert false : "Parsing illegal token should result in an exception";
+        }
+        catch (IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            new LogEvent("g$,1,2,3," + AuditEvent.BUNDLE_STOPPED);
+            assert false : "Parsing half of a token should result in an exception";
+        }
+        catch (IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            new LogEvent("g$,1,2,3," + AuditEvent.BUNDLE_STOPPED + ",a");
+            assert false : "Parsing only a key should result in an exception";
+        }
+        catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+}



Mime
View raw message