Author: borges
Date: 2012-01-12 07:10:54 -0500 (Thu, 12 Jan 2012)
New Revision: 12017
Added:
trunk/hornetq-core/src/test/java/org/hornetq/core/filter/
trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/
trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/FilterTest.java
trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/OperatorTest.java
trunk/hornetq-core/src/test/java/org/hornetq/util/
trunk/hornetq-core/src/test/java/org/hornetq/util/CompressionUtilTest.java
trunk/hornetq-core/src/test/java/org/hornetq/util/ConcurrentHashSetTest.java
trunk/hornetq-core/src/test/java/org/hornetq/util/TimeAndCounterIDGeneratorTest.java
trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesConversionTest.java
trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesTest.java
trunk/hornetq-core/src/test/java/org/hornetq/util/XMLUtilTest.java
Removed:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/FilterTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/CompressionUtilTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/ConcurrentHashSetTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TimeAndCounterIDGeneratorTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesConversionTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/XMLUtilTest.java
Log:
Move tests into hq-core, avoid cluttering std.out
Copied: trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/FilterTest.java
(from rev 12016,
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/FilterTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/FilterTest.java
(rev 0)
+++
trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/FilterTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -0,0 +1,699 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.core.filter.impl;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hornetq.api.core.HornetQException;
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.core.filter.Filter;
+import org.hornetq.core.server.ServerMessage;
+import org.hornetq.core.server.impl.ServerMessageImpl;
+import org.hornetq.tests.util.RandomUtil;
+
+/**
+ * Tests the compliance with the HornetQ Filter syntax.
+ *
+ * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
+ * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
+ */
+public class FilterTest extends TestCase
+{
+ private Filter filter;
+
+ private ServerMessage message;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ message = new ServerMessageImpl(1, 1000);
+ }
+
+ public void testFilterForgets() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("color =
'RED'"));
+
+ message.putStringProperty(new SimpleString("color"), new
SimpleString("RED"));
+ Assert.assertTrue(filter.match(message));
+ message = new ServerMessageImpl();
+ Assert.assertFalse(filter.match(message));
+ }
+
+ public void testInvalidString() throws Exception
+ {
+ testInvalidFilter("color = 'red");
+ testInvalidFilter(new SimpleString("color = 'red"));
+
+ testInvalidFilter("3");
+ testInvalidFilter(new SimpleString("3"));
+ }
+
+ public void testNullFilter() throws Exception
+ {
+ Assert.assertNull(FilterImpl.createFilter((String)null));
+ Assert.assertNull(FilterImpl.createFilter(""));
+ Assert.assertNull(FilterImpl.createFilter((SimpleString)null));
+ Assert.assertNull(FilterImpl.createFilter(new SimpleString("")));
+ }
+
+ public void testHQDurable() throws Exception
+ {
+ filter = FilterImpl.createFilter(new
SimpleString("HQDurable='DURABLE'"));
+
+ message.setDurable(true);
+
+ Assert.assertTrue(filter.match(message));
+
+ message.setDurable(false);
+
+ Assert.assertFalse(filter.match(message));
+
+ filter = FilterImpl.createFilter(new
SimpleString("HQDurable='NON_DURABLE'"));
+
+ message = new ServerMessageImpl();
+ message.setDurable(true);
+
+ Assert.assertFalse(filter.match(message));
+
+ message.setDurable(false);
+
+ Assert.assertTrue(filter.match(message));
+
+ }
+
+ public void testHQSize() throws Exception
+ {
+ message.setAddress(RandomUtil.randomSimpleString());
+
+ int encodeSize = message.getEncodeSize();
+
+ Filter moreThanSmall = FilterImpl.createFilter(new SimpleString("HQSize >
" + (encodeSize - 1)));
+ Filter lessThanLarge = FilterImpl.createFilter(new SimpleString("HQSize <
" + (encodeSize + 1)));
+
+ Filter lessThanSmall = FilterImpl.createFilter(new SimpleString("HQSize <
" + encodeSize));
+ Filter moreThanLarge = FilterImpl.createFilter(new SimpleString("HQSize >
" + encodeSize));
+
+ Assert.assertTrue(moreThanSmall.match(message));
+ Assert.assertTrue(lessThanLarge.match(message));
+
+ Assert.assertFalse(lessThanSmall.match(message));
+ Assert.assertFalse(moreThanLarge.match(message));
+
+ }
+
+ public void testHQPriority() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("HQPriority=3"));
+
+ for (int i = 0; i < 10; i++)
+ {
+ message.setPriority((byte)i);
+
+ if (i == 3)
+ {
+ Assert.assertTrue(filter.match(message));
+ }
+ else
+ {
+ Assert.assertFalse(filter.match(message));
+ }
+ }
+ }
+
+ public void testHQTimestamp() throws Exception
+ {
+ filter = FilterImpl.createFilter(new
SimpleString("HQTimestamp=12345678"));
+
+ message.setTimestamp(87654321);
+
+ Assert.assertFalse(filter.match(message));
+
+ message.setTimestamp(12345678);
+
+ Assert.assertTrue(filter.match(message));
+ }
+
+ public void testBooleanTrue() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("MyBoolean=true"));
+
+ testBoolean("MyBoolean", true);
+ }
+
+ public void testIdentifier() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("MyBoolean"));
+
+ testBoolean("MyBoolean", true);
+ }
+
+ public void testDifferentNullString() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("prop <>
'foo'"));
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("NOT (prop =
'foo')"));
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("prop <>
'foo'"));
+ doPutStringProperty("prop", "bar");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("prop <>
'foo'"));
+ doPutStringProperty("prop", "foo");
+ Assert.assertFalse(filter.match(message));
+ }
+
+ public void testBooleanFalse() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("MyBoolean=false"));
+ testBoolean("MyBoolean", false);
+ }
+
+ private void testBoolean(final String name, final boolean flag) throws Exception
+ {
+ message.putBooleanProperty(new SimpleString(name), flag);
+ Assert.assertTrue(filter.match(message));
+
+ message.putBooleanProperty(new SimpleString(name), !flag);
+ Assert.assertTrue(!filter.match(message));
+ }
+
+ public void testStringEquals() throws Exception
+ {
+ // First, simple test of string equality and inequality
+ filter = FilterImpl.createFilter(new
SimpleString("MyString='astring'"));
+
+ doPutStringProperty("MyString", "astring");
+ Assert.assertTrue(filter.match(message));
+
+ doPutStringProperty("MyString", "NOTastring");
+ Assert.assertTrue(!filter.match(message));
+
+ // test empty string
+ filter = FilterImpl.createFilter(new
SimpleString("MyString=''"));
+
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue("test 1", filter.match(message));
+
+ doPutStringProperty("MyString", "NOTastring");
+ Assert.assertTrue("test 2", !filter.match(message));
+
+ // test literal apostrophes (which are escaped using two apostrophes
+ // in selectors)
+ filter = FilterImpl.createFilter(new SimpleString("MyString='test
JBoss''s filter'"));
+
+ // note: apostrophes are not escaped in string properties
+ doPutStringProperty("MyString", "test JBoss's filter");
+ // this test fails -- bug 530120
+ // assertTrue("test 3", filter.match(message));
+
+ doPutStringProperty("MyString", "NOTastring");
+ Assert.assertTrue("test 4", !filter.match(message));
+
+ }
+
+ public void testNOT_INWithNullProperty() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("myNullProp NOT IN
('foo','jms','test')"));
+
+ assertFalse(filter.match(message));
+
+ message.putStringProperty("myNullProp", "JMS");
+ assertTrue(filter.match(message));
+ }
+
+ public void testNOT_LIKEWithNullProperty() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("myNullProp NOT LIKE
'1_3'"));
+
+ assertFalse(filter.match(message));
+
+ message.putStringProperty("myNullProp", "JMS");
+ assertTrue(filter.match(message));
+ }
+
+ public void testIS_NOT_NULLWithNullProperty() throws Exception
+ {
+ filter = FilterImpl.createFilter(new SimpleString("myNullProp IS NOT
NULL"));
+
+ assertFalse(filter.match(message));
+
+ message.putStringProperty("myNullProp", "JMS");
+ assertTrue(filter.match(message));
+ }
+
+ public void testStringLike() throws Exception
+ {
+ // test LIKE operator with no wildcards
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'astring'"));
+ Assert.assertFalse(filter.match(message));
+
+ // test where LIKE operand matches
+ doPutStringProperty("MyString", "astring");
+ Assert.assertTrue(filter.match(message));
+
+ // test one character string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a'"));
+ doPutStringProperty("MyString", "a");
+ Assert.assertTrue(filter.match(message));
+
+ // test empty string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
''"));
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(filter.match(message));
+
+ // tests where operand does not match
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'astring'"));
+
+ // test with extra characters at beginning
+ doPutStringProperty("MyString", "NOTastring");
+ Assert.assertTrue(!filter.match(message));
+
+ // test with extra characters at end
+ doPutStringProperty("MyString", "astringNOT");
+ Assert.assertTrue(!filter.match(message));
+
+ // test with extra characters in the middle
+ doPutStringProperty("MyString", "astNOTring");
+ Assert.assertTrue(!filter.match(message));
+
+ // test where operand is entirely different
+ doPutStringProperty("MyString", "totally different");
+ Assert.assertTrue(!filter.match(message));
+
+ // test case sensitivity
+ doPutStringProperty("MyString", "ASTRING");
+ Assert.assertTrue(!filter.match(message));
+
+ // test empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // test lower-case 'like' operator?
+ }
+
+ public void testStringLikeUnderbarWildcard() throws Exception
+ {
+ // test LIKE operator with the _ wildcard, which
+ // matches any single character
+
+ // first, some tests with the wildcard by itself
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'_'"));
+ Assert.assertFalse(filter.match(message));
+
+ // test match against single character
+ doPutStringProperty("MyString", "a");
+ Assert.assertTrue(filter.match(message));
+
+ // test match failure against multiple characters
+ doPutStringProperty("MyString", "aaaaa");
+ Assert.assertTrue(!filter.match(message));
+
+ // test match failure against the empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // next, tests with wildcard at the beginning of the string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'_bcdf'"));
+
+ // test match at beginning of string
+ doPutStringProperty("MyString", "abcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // match failure in first character after wildcard
+ doPutStringProperty("MyString", "aXcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in middle character
+ doPutStringProperty("MyString", "abXdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in last character
+ doPutStringProperty("MyString", "abcdX");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure with empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at beginning
+ doPutStringProperty("MyString", "XXXabcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at the end
+ doPutStringProperty("MyString", "abcdfXXX");
+ Assert.assertTrue(!filter.match(message));
+
+ // test that the _ wildcard does not match the 'empty' character
+ doPutStringProperty("MyString", "bcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // next, tests with wildcard at the end of the string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'abcd_'"));
+
+ // test match at end of string
+ doPutStringProperty("MyString", "abcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // match failure in first character before wildcard
+ doPutStringProperty("MyString", "abcXf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in middle character
+ doPutStringProperty("MyString", "abXdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in first character
+ doPutStringProperty("MyString", "Xbcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure with empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at beginning
+ doPutStringProperty("MyString", "XXXabcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at the end
+ doPutStringProperty("MyString", "abcdfXXX");
+ Assert.assertTrue(!filter.match(message));
+
+ // test that the _ wildcard does not match the 'empty' character
+ doPutStringProperty("MyString", "abcd");
+ Assert.assertTrue(!filter.match(message));
+
+ // test match in middle of string
+
+ // next, tests with wildcard in the middle of the string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'ab_df'"));
+
+ // test match in the middle of string
+ doPutStringProperty("MyString", "abcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // match failure in first character before wildcard
+ doPutStringProperty("MyString", "aXcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in first character after wildcard
+ doPutStringProperty("MyString", "abcXf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in last character
+ doPutStringProperty("MyString", "abcdX");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure with empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at beginning
+ doPutStringProperty("MyString", "XXXabcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at the end
+ doPutStringProperty("MyString", "abcdfXXX");
+ Assert.assertTrue(!filter.match(message));
+
+ // test that the _ wildcard does not match the 'empty' character
+ doPutStringProperty("MyString", "abdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // test match failures
+ }
+
+ public void testNotLikeExpression() throws Exception
+ {
+ // Should evaluate to false when the property MyString is not set
+ filter = FilterImpl.createFilter(new SimpleString("NOT (MyString LIKE
'%')"));
+
+ Assert.assertFalse(filter.match(message));
+ }
+
+ public void testStringLikePercentWildcard() throws Exception
+ {
+ // test LIKE operator with the % wildcard, which
+ // matches any sequence of characters
+ // note many of the tests are similar to those for _
+
+ // first, some tests with the wildcard by itself
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'%'"));
+ Assert.assertFalse(filter.match(message));
+
+ // test match against single character
+ doPutStringProperty("MyString", "a");
+ Assert.assertTrue(filter.match(message));
+
+ // test match against multiple characters
+ doPutStringProperty("MyString", "aaaaa");
+ Assert.assertTrue(filter.match(message));
+
+ doPutStringProperty("MyString", "abcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // test match against the empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(filter.match(message));
+
+ // next, tests with wildcard at the beginning of the string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'%bcdf'"));
+
+ // test match with single character at beginning of string
+ doPutStringProperty("MyString", "Xbcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // match with multiple characters at beginning
+ doPutStringProperty("MyString", "XXbcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // match failure in middle character
+ doPutStringProperty("MyString", "abXdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in last character
+ doPutStringProperty("MyString", "abcdX");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure with empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at the end
+ doPutStringProperty("MyString", "abcdfXXX");
+ Assert.assertTrue(!filter.match(message));
+
+ // test that the % wildcard matches the empty string
+ doPutStringProperty("MyString", "bcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // next, tests with wildcard at the end of the string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'abcd%'"));
+
+ // test match of single character at end of string
+ doPutStringProperty("MyString", "abcdf");
+ Assert.assertTrue(filter.match(message));
+
+ // test match of multiple characters at end of string
+ doPutStringProperty("MyString", "abcdfgh");
+ Assert.assertTrue(filter.match(message));
+
+ // match failure in first character before wildcard
+ doPutStringProperty("MyString", "abcXf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in middle character
+ doPutStringProperty("MyString", "abXdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in first character
+ doPutStringProperty("MyString", "Xbcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure with empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at beginning
+ doPutStringProperty("MyString", "XXXabcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // test that the % wildcard matches the empty string
+ doPutStringProperty("MyString", "abcd");
+ Assert.assertTrue(filter.match(message));
+
+ // next, tests with wildcard in the middle of the string
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'ab%df'"));
+
+ // test match with single character in the middle of string
+ doPutStringProperty("MyString", "abXdf");
+ Assert.assertTrue(filter.match(message));
+
+ // test match with multiple characters in the middle of string
+ doPutStringProperty("MyString", "abXXXdf");
+ Assert.assertTrue(filter.match(message));
+
+ // match failure in first character before wildcard
+ doPutStringProperty("MyString", "aXcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in first character after wildcard
+ doPutStringProperty("MyString", "abcXf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure in last character
+ doPutStringProperty("MyString", "abcdX");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure with empty string
+ doPutStringProperty("MyString", "");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at beginning
+ doPutStringProperty("MyString", "XXXabcdf");
+ Assert.assertTrue(!filter.match(message));
+
+ // match failure due to extra characters at the end
+ doPutStringProperty("MyString", "abcdfXXX");
+ Assert.assertTrue(!filter.match(message));
+
+ // test that the % wildcard matches the empty string
+ doPutStringProperty("MyString", "abdf");
+ Assert.assertTrue(filter.match(message));
+
+ }
+
+ public void testStringLikePunctuation() throws Exception
+ {
+ // test proper handling of some punctuation characters.
+ // non-trivial since the underlying implementation might
+ // (and in fact currently does) use a general-purpose
+ // RE library, which has a different notion of which
+ // characters are wildcards
+
+ // the particular tests here are motivated by the
+ // wildcards of the current underlying RE engine,
+ // GNU regexp.
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a^$b'"));
+ Assert.assertFalse(filter.match(message));
+
+ doPutStringProperty("MyString", "a^$b");
+ Assert.assertTrue(filter.match(message));
+
+ // this one has a double backslash since backslash
+ // is interpreted specially by Java
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a\\dc'"));
+ doPutStringProperty("MyString", "a\\dc");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a.c'"));
+ doPutStringProperty("MyString", "abc");
+ Assert.assertTrue(!filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[abc]'"));
+ doPutStringProperty("MyString", "[abc]");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[^abc]'"));
+ doPutStringProperty("MyString", "[^abc]");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[a-c]'"));
+ doPutStringProperty("MyString", "[a-c]");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[:alpha]'"));
+ doPutStringProperty("MyString", "[:alpha]");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)'"));
+ doPutStringProperty("MyString", "(abc)");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a|bc'"));
+ doPutStringProperty("MyString", "a|bc");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)?'"));
+ doPutStringProperty("MyString", "(abc)?");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)*'"));
+ doPutStringProperty("MyString", "(abc)*");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)+'"));
+ doPutStringProperty("MyString", "(abc)+");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc){3}'"));
+ doPutStringProperty("MyString", "(abc){3}");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc){3,5}'"));
+ doPutStringProperty("MyString", "(abc){3,5}");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc){3,}'"));
+ doPutStringProperty("MyString", "(abc){3,}");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(?=abc)'"));
+ doPutStringProperty("MyString", "(?=abc)");
+ Assert.assertTrue(filter.match(message));
+
+ filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(?!abc)'"));
+ doPutStringProperty("MyString", "(?!abc)");
+ Assert.assertTrue(filter.match(message));
+ }
+
+ // Private
-----------------------------------------------------------------------------------
+
+ private void doPutStringProperty(final String key, final String value)
+ {
+ message.putStringProperty(new SimpleString(key), new SimpleString(value));
+ }
+
+ private void testInvalidFilter(final String filterString) throws Exception
+ {
+ try
+ {
+ filter = FilterImpl.createFilter(filterString);
+ Assert.fail("Should throw exception");
+ }
+ catch (HornetQException e)
+ {
+ Assert.assertEquals(HornetQException.INVALID_FILTER_EXPRESSION, e.getCode());
+ }
+ }
+
+ private void testInvalidFilter(final SimpleString filterString) throws Exception
+ {
+ try
+ {
+ filter = FilterImpl.createFilter(filterString);
+ Assert.fail("Should throw exception");
+ }
+ catch (HornetQException e)
+ {
+ Assert.assertEquals(HornetQException.INVALID_FILTER_EXPRESSION, e.getCode());
+ }
+ }
+
+}
Copied: trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/OperatorTest.java
(from rev 12016,
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/OperatorTest.java
(rev 0)
+++
trunk/hornetq-core/src/test/java/org/hornetq/core/filter/impl/OperatorTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -0,0 +1,459 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.core.filter.impl;
+
+import java.util.HashSet;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.core.filter.impl.Operator;
+
+/**
+ * A OperatorTest
+ *
+ * @author <a href="jmesnil(a)redhat.com">Jeff Mesnil</a>
+ *
+ * Created 3 nov. 2008 17:22:22
+ *
+ *
+ */
+public class OperatorTest extends TestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+ private static void assertSuccess(final int op, final Object arg1, final Object
expectedResult) throws Exception
+ {
+ OperatorTest.assertOperationSuccess(new Operator(op, arg1), expectedResult);
+ }
+
+ private static void assertSuccess(final int op, final Object arg1, final Object arg2,
final Object expectedResult) throws Exception
+ {
+ OperatorTest.assertOperationSuccess(new Operator(op, arg1, arg2), expectedResult);
+ }
+
+ private static void assertSuccess(final int op,
+ final Object arg1,
+ final Object arg2,
+ final Object arg3,
+ final Object expectedResult) throws Exception
+ {
+ OperatorTest.assertOperationSuccess(new Operator(op, arg1, arg2, arg3),
expectedResult);
+ }
+
+ private static void assertOperationSuccess(final Operator operator, final Object
expectedResult) throws Exception
+ {
+ Assert.assertEquals(expectedResult, operator.apply());
+ }
+
+ private static void assertFailure(final int op, final Object arg1) throws Exception
+ {
+ OperatorTest.assertOperationFailure(new Operator(op, arg1));
+ }
+
+ private static void assertFailure(final int op, final Object arg1, final Object arg2)
throws Exception
+ {
+ OperatorTest.assertOperationFailure(new Operator(op, arg1, arg2));
+ }
+
+ private static void assertFailure(final int op, final Object arg1, final Object arg2,
final Object arg3) throws Exception
+ {
+ OperatorTest.assertOperationFailure(new Operator(op, arg1, arg2, arg3));
+ }
+
+ private static void assertOperationFailure(final Operator operator)
+ {
+ try
+ {
+ operator.apply();
+ Assert.fail("expected to throw an exception");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void test_EQUAL() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.EQUAL, 1, 1, true);
+ OperatorTest.assertSuccess(Operator.EQUAL, 1, 1.0, true);
+ OperatorTest.assertSuccess(Operator.EQUAL, 1, null, null);
+ OperatorTest.assertSuccess(Operator.EQUAL, 1.0, 1, true);
+ OperatorTest.assertSuccess(Operator.EQUAL, 1.0, 1.0, true);
+ OperatorTest.assertSuccess(Operator.EQUAL, 1.0, null, null);
+
+ OperatorTest.assertSuccess(Operator.EQUAL, false, false, true);
+ OperatorTest.assertSuccess(Operator.EQUAL, true, false, false);
+ OperatorTest.assertSuccess(Operator.EQUAL, false, true, false);
+ OperatorTest.assertSuccess(Operator.EQUAL, true, true, true);
+
+ SimpleString foo = new SimpleString("foo");
+ SimpleString foo2 = new SimpleString("foo");
+ SimpleString bar = new SimpleString("bar");
+ OperatorTest.assertSuccess(Operator.EQUAL, foo, foo, true);
+ OperatorTest.assertSuccess(Operator.EQUAL, foo, foo2, true);
+ OperatorTest.assertSuccess(Operator.EQUAL, foo, bar, false);
+ OperatorTest.assertSuccess(Operator.EQUAL, foo, null, false);
+
+ OperatorTest.assertSuccess(Operator.EQUAL, null, 1.0, false);
+ }
+
+ public void test_DIFFERENT() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.DIFFERENT, 2, 1, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, 2, 1.0, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, 2, null, null);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, 2.0, 1, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, 2.0, 1.0, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, 2.0, null, null);
+
+ OperatorTest.assertSuccess(Operator.DIFFERENT, false, false, false);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, true, false, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, false, true, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, true, true, false);
+
+ SimpleString foo = new SimpleString("foo");
+ SimpleString foo2 = new SimpleString("foo");
+ SimpleString bar = new SimpleString("bar");
+ OperatorTest.assertSuccess(Operator.DIFFERENT, foo, foo, false);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, foo, foo2, false);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, foo, bar, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, foo, null, null);
+
+ OperatorTest.assertSuccess(Operator.DIFFERENT, null, 1.0, true);
+ OperatorTest.assertSuccess(Operator.DIFFERENT, null, null, false);
+ }
+
+ public void test_IS_NULL() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.IS_NULL, null, true);
+ OperatorTest.assertSuccess(Operator.IS_NULL, 1, false);
+ }
+
+ public void test_IS_NOT_NULL() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.IS_NOT_NULL, null, false);
+ OperatorTest.assertSuccess(Operator.IS_NOT_NULL, 1, true);
+ }
+
+ public void test_ADD() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.ADD, 1, 1, 2L);
+ OperatorTest.assertSuccess(Operator.ADD, 1.0, 1, 2.0);
+ OperatorTest.assertSuccess(Operator.ADD, 1, 1.0, 2.0);
+ OperatorTest.assertSuccess(Operator.ADD, 1.0, 1.0, 2.0);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.ADD, true, 1.0);
+ OperatorTest.assertFailure(Operator.ADD, 1, true);
+ }
+
+ public void test_SUB() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.SUB, 2, 1, 1L);
+ OperatorTest.assertSuccess(Operator.SUB, 2.0, 1, 1.0);
+ OperatorTest.assertSuccess(Operator.SUB, 2, 1.0, 1.0);
+ OperatorTest.assertSuccess(Operator.SUB, 2.0, 1.0, 1.0);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.SUB, true, 1.0);
+ OperatorTest.assertFailure(Operator.SUB, 1, true);
+ }
+
+ public void test_MUL() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.MUL, 2, 1, 2L);
+ OperatorTest.assertSuccess(Operator.MUL, 2.0, 1, 2.0);
+ OperatorTest.assertSuccess(Operator.MUL, 2, 1.0, 2.0);
+ OperatorTest.assertSuccess(Operator.MUL, 2.0, 1.0, 2.0);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.MUL, 2, null, null);
+ OperatorTest.assertSuccess(Operator.MUL, null, 1.0, null);
+ OperatorTest.assertFailure(Operator.MUL, true, 1.0);
+ OperatorTest.assertFailure(Operator.MUL, 1, true);
+ }
+
+ public void test_DIV() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.DIV, 2, 2, 1L);
+ OperatorTest.assertSuccess(Operator.DIV, 2.0, 2, 1.0);
+ OperatorTest.assertSuccess(Operator.DIV, 2, 2.0, 1.0);
+ OperatorTest.assertSuccess(Operator.DIV, 2.0, 2.0, 1.0);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.DIV, 2, null, null);
+ OperatorTest.assertSuccess(Operator.DIV, null, 1.0, null);
+ OperatorTest.assertFailure(Operator.DIV, true, 1.0);
+ OperatorTest.assertFailure(Operator.DIV, 1, true);
+ }
+
+ public void test_NEG() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.NEG, 1, -1L);
+ OperatorTest.assertSuccess(Operator.NEG, -1.0, 1.0);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.NEG, true);
+ }
+
+ public void test_AND() throws Exception
+ {
+ // NULL and NULL -> NULL
+ OperatorTest.assertSuccess(Operator.AND, null, null, null);
+ // NULL and F -> F
+ OperatorTest.assertSuccess(Operator.AND, null, false, false);
+ // NULL and T -> NULL
+ OperatorTest.assertSuccess(Operator.AND, null, true, null);
+
+ // F and NULL -> F
+ OperatorTest.assertSuccess(Operator.AND, false, null, false);
+ // F and F -> F
+ OperatorTest.assertSuccess(Operator.AND, false, false, false);
+ // F and T -> F
+ OperatorTest.assertSuccess(Operator.AND, false, true, false);
+
+ // T and NULL -> NULL
+ OperatorTest.assertSuccess(Operator.AND, true, null, null);
+ // T and F -> F
+ OperatorTest.assertSuccess(Operator.AND, true, false, false);
+ // T and T -> T
+ OperatorTest.assertSuccess(Operator.AND, true, true, true);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.AND, 1.0, true);
+ OperatorTest.assertFailure(Operator.AND, true, 1.0);
+ OperatorTest.assertFailure(Operator.AND, null, 1.0);
+ }
+
+ public void test_OR() throws Exception
+ {
+ // NULL OR NULL -> NULL
+ OperatorTest.assertSuccess(Operator.OR, null, null, null);
+ // NULL OR F -> NULL
+ OperatorTest.assertSuccess(Operator.OR, null, false, null);
+ // NULL OR T -> T
+ OperatorTest.assertSuccess(Operator.OR, null, true, true);
+
+ // F or NULL -> NULL
+ OperatorTest.assertSuccess(Operator.OR, false, null, null);
+ // F or F -> F
+ OperatorTest.assertSuccess(Operator.OR, false, false, false);
+ // F or T -> F
+ OperatorTest.assertSuccess(Operator.OR, false, true, true);
+
+ // T or NULL -> T
+ OperatorTest.assertSuccess(Operator.OR, true, null, true);
+ // T or F -> T
+ OperatorTest.assertSuccess(Operator.OR, true, false, true);
+ // T or T -> T
+ OperatorTest.assertSuccess(Operator.OR, true, true, true);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.OR, 1.0, true);
+ OperatorTest.assertFailure(Operator.OR, false, 1.0);
+ OperatorTest.assertFailure(Operator.OR, null, 1.0);
+ }
+
+ public void test_NOT() throws Exception
+ {
+ // NOT NULL -> NULL
+ OperatorTest.assertSuccess(Operator.NOT, null, null);
+ // NOT F -> T
+ OperatorTest.assertSuccess(Operator.NOT, false, true);
+ // NOT T -> F
+ OperatorTest.assertSuccess(Operator.NOT, true, false);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.NOT, 1.0);
+ }
+
+ public void test_GT() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.GT, 2, 1, true);
+ OperatorTest.assertSuccess(Operator.GT, 2.0, 1, true);
+ OperatorTest.assertSuccess(Operator.GT, 2, 1.0, true);
+ OperatorTest.assertSuccess(Operator.GT, 2.0, 1.0, true);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.GT, 2.0, true, false);
+ OperatorTest.assertSuccess(Operator.GT, 2, null, null);
+ OperatorTest.assertSuccess(Operator.GT, true, 1.0, false);
+ OperatorTest.assertSuccess(Operator.GT, null, 1, null);
+ OperatorTest.assertSuccess(Operator.GT, true, true, false);
+ OperatorTest.assertSuccess(Operator.GT, null, null, null);
+ }
+
+ public void test_GE() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.GE, 1, 1, true);
+ OperatorTest.assertSuccess(Operator.GE, 1.0, 1, true);
+ OperatorTest.assertSuccess(Operator.GE, 1, 1.0, true);
+ OperatorTest.assertSuccess(Operator.GE, 1.0, 1.0, true);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.GE, 2.0, true, false);
+ OperatorTest.assertSuccess(Operator.GE, 2, null, null);
+ OperatorTest.assertSuccess(Operator.GE, true, 1.0, false);
+ OperatorTest.assertSuccess(Operator.GE, null, 1, null);
+ OperatorTest.assertSuccess(Operator.GE, true, true, false);
+ OperatorTest.assertSuccess(Operator.GE, null, null, null);
+ }
+
+ public void test_LT() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.LT, 1, 2, true);
+ OperatorTest.assertSuccess(Operator.LT, 1.0, 2, true);
+ OperatorTest.assertSuccess(Operator.LT, 1, 2.0, true);
+ OperatorTest.assertSuccess(Operator.LT, 1.0, 2.0, true);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.LT, 1.0, true, false);
+ OperatorTest.assertSuccess(Operator.LT, 1, null, null);
+ OperatorTest.assertSuccess(Operator.LT, true, 2.0, false);
+ OperatorTest.assertSuccess(Operator.LT, null, 2, null);
+ OperatorTest.assertSuccess(Operator.LT, true, true, false);
+ OperatorTest.assertSuccess(Operator.LT, null, null, null);
+ }
+
+ public void test_LE() throws Exception
+ {
+ OperatorTest.assertSuccess(Operator.LE, 1, 1, true);
+ OperatorTest.assertSuccess(Operator.LE, 1.0, 1, true);
+ OperatorTest.assertSuccess(Operator.LE, 1, 1.0, true);
+ OperatorTest.assertSuccess(Operator.LE, 1.0, 1.0, true);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.LE, 1.0, true, false);
+ OperatorTest.assertSuccess(Operator.LE, 1, null, null);
+ OperatorTest.assertSuccess(Operator.LE, true, 1.0, false);
+ OperatorTest.assertSuccess(Operator.LE, null, 1, null);
+ OperatorTest.assertSuccess(Operator.LE, true, true, false);
+ OperatorTest.assertSuccess(Operator.LE, null, null, null);
+ }
+
+ public void test_BETWEEN() throws Exception
+ {
+ // 2 BETWEEN 1 AND 3
+ OperatorTest.assertSuccess(Operator.BETWEEN, 2, 1, 3, true);
+ OperatorTest.assertSuccess(Operator.BETWEEN, 2.0, 1.0, 3.0, true);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.BETWEEN, true, 1, 3, false);
+ OperatorTest.assertSuccess(Operator.BETWEEN, null, null, 3, null);
+ }
+
+ public void test_NOT_BETWEEN() throws Exception
+ {
+ // 2 NOT BETWEEN 3 AND 4
+ OperatorTest.assertSuccess(Operator.NOT_BETWEEN, 2, 3, 4, true);
+ OperatorTest.assertSuccess(Operator.NOT_BETWEEN, 2.0, 3.0, 4.0, true);
+
+ // incompatible types
+ OperatorTest.assertSuccess(Operator.NOT_BETWEEN, true, 1, 3, false);
+ OperatorTest.assertSuccess(Operator.NOT_BETWEEN, null, null, 3, null);
+ }
+
+ public void test_IN() throws Exception
+ {
+ HashSet<SimpleString> set = new HashSet<SimpleString>();
+ set.add(new SimpleString("foo"));
+ set.add(new SimpleString("bar"));
+ set.add(new SimpleString("baz"));
+
+ SimpleString foo = new SimpleString("foo");
+
+ OperatorTest.assertSuccess(Operator.IN, foo, set, true);
+ OperatorTest.assertSuccess(Operator.IN, foo, new HashSet<SimpleString>(),
false);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.IN, true, set);
+ }
+
+ public void test_NOT_IN() throws Exception
+ {
+ HashSet<SimpleString> set = new HashSet<SimpleString>();
+ set.add(new SimpleString("foo"));
+ set.add(new SimpleString("bar"));
+ set.add(new SimpleString("baz"));
+
+ SimpleString foo = new SimpleString("foo");
+
+ OperatorTest.assertSuccess(Operator.NOT_IN, foo, set, false);
+ OperatorTest.assertSuccess(Operator.NOT_IN, foo, new HashSet<SimpleString>(),
true);
+
+ // incompatible types
+ OperatorTest.assertFailure(Operator.NOT_IN, true, set);
+ }
+
+ public void test_LIKE() throws Exception
+ {
+ SimpleString pattern = new SimpleString("12%3");
+ OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("123"),
pattern, true);
+ OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("12993"),
pattern, true);
+ OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("1234"),
pattern, false);
+
+ pattern = new SimpleString("l_se");
+ OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("lose"),
pattern, true);
+ OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("loose"),
pattern, false);
+
+ OperatorTest.assertSuccess(Operator.LIKE, null, pattern, null);
+ }
+
+ public void test_LIKE_ESCAPE() throws Exception
+ {
+ SimpleString pattern = new SimpleString("\\_%");
+ SimpleString escapeChar = new SimpleString("\\");
+ OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, new
SimpleString("_foo"), pattern, escapeChar, true);
+ OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, new SimpleString("bar"),
pattern, escapeChar, false);
+ OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, null, pattern, escapeChar, null);
+
+ OperatorTest.assertFailure(Operator.LIKE_ESCAPE,
+ new SimpleString("_foo"),
+ pattern,
+ new SimpleString("must be a single char"));
+ }
+
+ public void test_NOT_LIKE() throws Exception
+ {
+ SimpleString pattern = new SimpleString("12%3");
+ OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("123"),
pattern, false);
+ OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("12993"),
pattern, false);
+ OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("1234"),
pattern, true);
+ OperatorTest.assertSuccess(Operator.NOT_LIKE, null, pattern, null);
+ }
+
+ public void test_NOT_LIKE_ESCAPE() throws Exception
+ {
+ SimpleString pattern = new SimpleString("\\_%");
+ SimpleString escapeChar = new SimpleString("\\");
+ OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, new
SimpleString("_foo"), pattern, escapeChar, false);
+ OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, new
SimpleString("bar"), pattern, escapeChar, true);
+ OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, null, pattern, escapeChar,
null);
+
+ OperatorTest.assertFailure(Operator.NOT_LIKE_ESCAPE,
+ new SimpleString("_foo"),
+ pattern,
+ new SimpleString("must be a single char"));
+ }
+}
Copied: trunk/hornetq-core/src/test/java/org/hornetq/util/CompressionUtilTest.java (from
rev 12016,
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/CompressionUtilTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/util/CompressionUtilTest.java
(rev 0)
+++ trunk/hornetq-core/src/test/java/org/hornetq/util/CompressionUtilTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.zip.Deflater;
+
+import junit.framework.TestCase;
+
+import org.hornetq.utils.DeflaterReader;
+import org.hornetq.utils.InflaterReader;
+import org.hornetq.utils.InflaterWriter;
+
+/**
+ * A CompressionUtilTest
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ *
+ */
+public class CompressionUtilTest extends TestCase
+{
+
+ public void testDeflaterReader() throws Exception
+ {
+ String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
+
+ AtomicLong counter = new AtomicLong(0);
+ DeflaterReader reader = new DeflaterReader(inputStream, counter);
+
+ ArrayList<Integer> zipHolder = new ArrayList<Integer>();
+ int b = reader.read();
+
+ while (b != -1)
+ {
+ zipHolder.add(b);
+ b = reader.read();
+ }
+
+ assertEquals(input.length, counter.get());
+
+ byte[] allCompressed = new byte[zipHolder.size()];
+ for (int i = 0; i < allCompressed.length; i++)
+ {
+ allCompressed[i] = (byte) zipHolder.get(i).intValue();
+ }
+
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ compareByteArray(allCompressed, output, compressedDataLength);
+ }
+
+ public void testDeflaterReader2() throws Exception
+ {
+ String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
+ AtomicLong counter = new AtomicLong(0);
+
+ DeflaterReader reader = new DeflaterReader(inputStream, counter);
+
+ byte[] buffer = new byte[7];
+ ArrayList<Integer> zipHolder = new ArrayList<Integer>();
+
+ int n = reader.read(buffer);
+ while (n != -1)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ zipHolder.add((int)buffer[i]);
+ }
+ n = reader.read(buffer);
+ }
+
+ assertEquals(input.length, counter.get());
+
+ byte[] allCompressed = new byte[zipHolder.size()];
+ for (int i = 0; i < allCompressed.length; i++)
+ {
+ allCompressed[i] = (byte) zipHolder.get(i).intValue();
+ }
+
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ compareByteArray(allCompressed, output, compressedDataLength);
+ }
+
+ public void testInflaterReader() throws Exception
+ {
+ String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ byte[] zipBytes = new byte[compressedDataLength];
+
+ System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
+ ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
+
+ InflaterReader inflater = new InflaterReader(byteInput);
+ ArrayList<Integer> holder = new ArrayList<Integer>();
+ int read = inflater.read();
+
+ while (read != -1)
+ {
+ holder.add(read);
+ read = inflater.read();
+ }
+
+ byte[] result = new byte[holder.size()];
+
+ for (int i = 0; i < result.length; i++)
+ {
+ result[i] = holder.get(i).byteValue();
+ }
+
+ String txt = new String(result);
+
+ assertEquals(inputString, txt);
+
+ }
+
+ public void testInflaterWriter() throws Exception
+ {
+ String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ byte[] zipBytes = new byte[compressedDataLength];
+
+ System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
+ ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
+
+ ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
+ InflaterWriter writer = new InflaterWriter(byteOutput);
+
+ byte[] zipBuffer = new byte[12];
+
+ int n = byteInput.read(zipBuffer);
+ while (n > 0)
+ {
+ writer.write(zipBuffer, 0, n);
+ n = byteInput.read(zipBuffer);
+ }
+
+ writer.close();
+
+ byte[] outcome = byteOutput.toByteArray();
+ String outStr = new String(outcome);
+
+ assertEquals(inputString, outStr);
+ }
+
+ private void compareByteArray(byte[] first, byte[] second, int length)
+ {
+ for (int i = 0; i < length; i++)
+ {
+ assertEquals(first[i], second[i]);
+ }
+ }
+}
Copied: trunk/hornetq-core/src/test/java/org/hornetq/util/ConcurrentHashSetTest.java (from
rev 12016,
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/ConcurrentHashSetTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/util/ConcurrentHashSetTest.java
(rev 0)
+++
trunk/hornetq-core/src/test/java/org/hornetq/util/ConcurrentHashSetTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.util;
+
+import java.util.Iterator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hornetq.tests.util.RandomUtil;
+import org.hornetq.utils.ConcurrentHashSet;
+import org.hornetq.utils.ConcurrentSet;
+
+/**
+ * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class ConcurrentHashSetTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private ConcurrentSet<String> set;
+
+ private String element;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testAdd() throws Exception
+ {
+ Assert.assertTrue(set.add(element));
+ Assert.assertFalse(set.add(element));
+ }
+
+ public void testAddIfAbsent() throws Exception
+ {
+ Assert.assertTrue(set.addIfAbsent(element));
+ Assert.assertFalse(set.addIfAbsent(element));
+ }
+
+ public void testRemove() throws Exception
+ {
+ Assert.assertTrue(set.add(element));
+
+ Assert.assertTrue(set.remove(element));
+ Assert.assertFalse(set.remove(element));
+ }
+
+ public void testContains() throws Exception
+ {
+ Assert.assertFalse(set.contains(element));
+
+ Assert.assertTrue(set.add(element));
+ Assert.assertTrue(set.contains(element));
+
+ Assert.assertTrue(set.remove(element));
+ Assert.assertFalse(set.contains(element));
+ }
+
+ public void testSize() throws Exception
+ {
+ Assert.assertEquals(0, set.size());
+
+ Assert.assertTrue(set.add(element));
+ Assert.assertEquals(1, set.size());
+
+ Assert.assertTrue(set.remove(element));
+ Assert.assertEquals(0, set.size());
+ }
+
+ public void testClear() throws Exception
+ {
+ Assert.assertTrue(set.add(element));
+
+ Assert.assertTrue(set.contains(element));
+ set.clear();
+ Assert.assertFalse(set.contains(element));
+ }
+
+ public void testIsEmpty() throws Exception
+ {
+ Assert.assertTrue(set.isEmpty());
+
+ Assert.assertTrue(set.add(element));
+ Assert.assertFalse(set.isEmpty());
+
+ set.clear();
+ Assert.assertTrue(set.isEmpty());
+ }
+
+ public void testIterator() throws Exception
+ {
+ set.add(element);
+
+ Iterator<String> iterator = set.iterator();
+ while (iterator.hasNext())
+ {
+ String e = iterator.next();
+ Assert.assertEquals(element, e);
+ }
+ }
+
+ // TestCase overrides --------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ set = new ConcurrentHashSet<String>();
+ element = RandomUtil.randomString();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ set = null;
+ element = null;
+
+ super.tearDown();
+ }
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Copied:
trunk/hornetq-core/src/test/java/org/hornetq/util/TimeAndCounterIDGeneratorTest.java (from
rev 12016,
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TimeAndCounterIDGeneratorTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/util/TimeAndCounterIDGeneratorTest.java
(rev 0)
+++
trunk/hornetq-core/src/test/java/org/hornetq/util/TimeAndCounterIDGeneratorTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.util;
+
+import java.util.concurrent.CountDownLatch;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hornetq.utils.ConcurrentHashSet;
+import org.hornetq.utils.TimeAndCounterIDGenerator;
+
+/**
+ * A TimeAndCounterIDGeneratorTest
+ *
+ * @author <a href="mailto:clebert.suconic@jboss.org">Clebert
Suconic</a> Created 24-Sep-08 3:42:25 PM
+ */
+public class TimeAndCounterIDGeneratorTest extends TestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testCalculation()
+ {
+ TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
+ long max = 11000;
+
+ long lastNr = 0;
+
+ for (long i = 0; i < max; i++)
+ {
+ long seqNr = seq.generateID();
+
+ Assert.assertTrue("The sequence generator should aways generate crescent
numbers", seqNr > lastNr);
+
+ lastNr = seqNr;
+ }
+
+ }
+
+ public void testCalculationRefresh()
+ {
+ TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
+
+ long id1 = seq.generateID();
+ Assert.assertEquals(1, id1 & 0xffff);
+ Assert.assertEquals(2, seq.generateID() & 0xffff);
+
+ seq.refresh();
+
+ long id2 = seq.generateID();
+
+ Assert.assertTrue(id2 > id1);
+
+ Assert.assertEquals(1, id2 & 0xffff);
+
+ }
+
+ public void testCalculationOnMultiThread() throws Throwable
+ {
+ final ConcurrentHashSet<Long> hashSet = new ConcurrentHashSet<Long>();
+
+ final TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
+
+ System.out.println("Time = " +
TimeAndCounterIDGeneratorTest.hex(System.currentTimeMillis()) + ", " + seq);
+
+ final int NUMBER_OF_THREADS = 100;
+
+ final int NUMBER_OF_IDS = 10;
+
+ final CountDownLatch latchAlign = new CountDownLatch(NUMBER_OF_THREADS);
+
+ final CountDownLatch latchStart = new CountDownLatch(1);
+
+ class T1 extends Thread
+ {
+ Throwable e;
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ latchAlign.countDown();
+ latchStart.await();
+
+ long lastValue = 0l;
+ for (int i = 0; i < NUMBER_OF_IDS; i++)
+ {
+ long value = seq.generateID();
+ Assert.assertTrue(TimeAndCounterIDGeneratorTest.hex(value) + "
should be greater than " +
+ TimeAndCounterIDGeneratorTest.hex(lastValue) +
+ " on seq " +
+ seq.toString(), value > lastValue);
+ lastValue = value;
+
+ hashSet.add(value);
+ }
+ }
+ catch (Throwable e)
+ {
+ this.e = e;
+ }
+ }
+
+ };
+
+ T1[] arrays = new T1[NUMBER_OF_THREADS];
+
+ for (int i = 0; i < arrays.length; i++)
+ {
+ arrays[i] = new T1();
+ arrays[i].start();
+ }
+
+ latchAlign.await();
+
+ latchStart.countDown();
+
+ for (T1 t : arrays)
+ {
+ t.join();
+ if (t.e != null)
+ {
+ throw t.e;
+ }
+ }
+
+ Assert.assertEquals(NUMBER_OF_THREADS * NUMBER_OF_IDS, hashSet.size());
+
+ hashSet.clear();
+
+ }
+
+ public void testWrapID() throws Throwable
+ {
+ final ConcurrentHashSet<Long> hashSet = new
org.hornetq.utils.ConcurrentHashSet<Long>();
+
+ TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
+
+ System.out.println("Current Time = " +
TimeAndCounterIDGeneratorTest.hex(System.currentTimeMillis()) + " " + seq);
+
+ seq.setInternalDate(System.currentTimeMillis() + 10000l); // 10 seconds in the
future
+
+ seq.setInternalID(TimeAndCounterIDGenerator.ID_MASK); // 1 ID about to explode
+
+ try
+ {
+ // This is simulating a situation where we generated more than 268 million
messages on the same time interval
+ seq.generateID();
+ Assert.fail("It was supposed to throw an exception, as the counter was set
to explode on this test");
+ }
+ catch (Exception e)
+ {
+ }
+
+ seq = new TimeAndCounterIDGenerator();
+
+ seq.setInternalDate(System.currentTimeMillis() - 10000l); // 10 seconds in the
past
+
+ long timeMark = seq.getInternalTimeMark();
+
+ seq.setInternalID(TimeAndCounterIDGenerator.ID_MASK); // 1 ID about to explode
+
+ // This is ok... the time portion would be added to the next one generated 10
seconds ago
+ seq.generateID();
+
+ Assert.assertTrue(TimeAndCounterIDGeneratorTest.hex(timeMark) + " < "
+
+
TimeAndCounterIDGeneratorTest.hex(seq.getInternalTimeMark()),
+ timeMark < seq.getInternalTimeMark());
+ }
+
+ private static String hex(final long value)
+ {
+ return String.format("%1$X", value);
+ }
+
+}
Copied:
trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesConversionTest.java (from
rev 12016,
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesConversionTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesConversionTest.java
(rev 0)
+++
trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesConversionTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.util;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hornetq.api.core.PropertyConversionException;
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.tests.util.RandomUtil;
+import org.hornetq.tests.util.UnitTestCase;
+import org.hornetq.utils.TypedProperties;
+
+/**
+ * A TypedPropertiesConversionTest
+ *
+ * @author jmesnil
+ *
+ *
+ */
+public class TypedPropertiesConversionTest extends TestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private TypedProperties props;
+
+ private SimpleString key;
+
+ private final SimpleString unknownKey = new
SimpleString("this.key.is.never.used");
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ key = RandomUtil.randomSimpleString();
+ props = new TypedProperties();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ key = null;
+ props = null;
+
+ super.tearDown();
+ }
+
+ public void testBooleanProperty() throws Exception
+ {
+ Boolean val = RandomUtil.randomBoolean();
+ props.putBooleanProperty(key, val);
+
+ Assert.assertEquals(val, props.getBooleanProperty(key));
+ Assert.assertEquals(new SimpleString(Boolean.toString(val)),
props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Boolean.toString(val)));
+ Assert.assertEquals(val, props.getBooleanProperty(key));
+
+ try
+ {
+ props.putByteProperty(key, RandomUtil.randomByte());
+ props.getBooleanProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ Assert.assertFalse(props.getBooleanProperty(unknownKey));
+ }
+
+ public void testCharProperty() throws Exception
+ {
+ Character val = RandomUtil.randomChar();
+ props.putCharProperty(key, val);
+
+ Assert.assertEquals(val, props.getCharProperty(key));
+ Assert.assertEquals(new SimpleString(Character.toString(val)),
props.getSimpleStringProperty(key));
+
+ try
+ {
+ props.putByteProperty(key, RandomUtil.randomByte());
+ props.getCharProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ try
+ {
+ props.getCharProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NullPointerException e)
+ {
+ }
+ }
+
+ public void testByteProperty() throws Exception
+ {
+ Byte val = RandomUtil.randomByte();
+ props.putByteProperty(key, val);
+
+ Assert.assertEquals(val, props.getByteProperty(key));
+ Assert.assertEquals(new SimpleString(Byte.toString(val)),
props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Byte.toString(val)));
+ Assert.assertEquals(val, props.getByteProperty(key));
+
+ try
+ {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getByteProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ try
+ {
+ props.getByteProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ }
+
+ public void testIntProperty() throws Exception
+ {
+ Integer val = RandomUtil.randomInt();
+ props.putIntProperty(key, val);
+
+ Assert.assertEquals(val, props.getIntProperty(key));
+ Assert.assertEquals(new SimpleString(Integer.toString(val)),
props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Integer.toString(val)));
+ Assert.assertEquals(val, props.getIntProperty(key));
+
+ Byte byteVal = RandomUtil.randomByte();
+ props.putByteProperty(key, byteVal);
+ Assert.assertEquals(Integer.valueOf(byteVal), props.getIntProperty(key));
+
+ try
+ {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getIntProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ try
+ {
+ props.getIntProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ }
+
+ public void testLongProperty() throws Exception
+ {
+ Long val = RandomUtil.randomLong();
+ props.putLongProperty(key, val);
+
+ Assert.assertEquals(val, props.getLongProperty(key));
+ Assert.assertEquals(new SimpleString(Long.toString(val)),
props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Long.toString(val)));
+ Assert.assertEquals(val, props.getLongProperty(key));
+
+ Byte byteVal = RandomUtil.randomByte();
+ props.putByteProperty(key, byteVal);
+ Assert.assertEquals(Long.valueOf(byteVal), props.getLongProperty(key));
+
+ Short shortVal = RandomUtil.randomShort();
+ props.putShortProperty(key, shortVal);
+ Assert.assertEquals(Long.valueOf(shortVal), props.getLongProperty(key));
+
+ Integer intVal = RandomUtil.randomInt();
+ props.putIntProperty(key, intVal);
+ Assert.assertEquals(Long.valueOf(intVal), props.getLongProperty(key));
+
+ try
+ {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getLongProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ try
+ {
+ props.getLongProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ }
+
+ public void testDoubleProperty() throws Exception
+ {
+ Double val = RandomUtil.randomDouble();
+ props.putDoubleProperty(key, val);
+
+ Assert.assertEquals(val, props.getDoubleProperty(key));
+ Assert.assertEquals(new SimpleString(Double.toString(val)),
props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Double.toString(val)));
+ Assert.assertEquals(val, props.getDoubleProperty(key));
+
+ try
+ {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getDoubleProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ try
+ {
+ props.getDoubleProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ public void testFloatProperty() throws Exception
+ {
+ Float val = RandomUtil.randomFloat();
+ props.putFloatProperty(key, val);
+
+ Assert.assertEquals(val, props.getFloatProperty(key));
+ Assert.assertEquals(Double.valueOf(val), props.getDoubleProperty(key));
+ Assert.assertEquals(new SimpleString(Float.toString(val)),
props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Float.toString(val)));
+ Assert.assertEquals(val, props.getFloatProperty(key));
+
+ try
+ {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getFloatProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ try
+ {
+ props.getFloatProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ public void testShortProperty() throws Exception
+ {
+ Short val = RandomUtil.randomShort();
+ props.putShortProperty(key, val);
+
+ Assert.assertEquals(val, props.getShortProperty(key));
+ Assert.assertEquals(Integer.valueOf(val), props.getIntProperty(key));
+ Assert.assertEquals(new SimpleString(Short.toString(val)),
props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Short.toString(val)));
+ Assert.assertEquals(val, props.getShortProperty(key));
+
+ Byte byteVal = RandomUtil.randomByte();
+ props.putByteProperty(key, byteVal);
+ Assert.assertEquals(Short.valueOf(byteVal), props.getShortProperty(key));
+
+ try
+ {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getShortProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ try
+ {
+ props.getShortProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ }
+
+ public void testSimpleStringProperty() throws Exception
+ {
+ SimpleString strVal = RandomUtil.randomSimpleString();
+ props.putSimpleStringProperty(key, strVal);
+ Assert.assertEquals(strVal, props.getSimpleStringProperty(key));
+ }
+
+ public void testBytesProperty() throws Exception
+ {
+ byte[] val = RandomUtil.randomBytes();
+ props.putBytesProperty(key, val);
+
+ UnitTestCase.assertEqualsByteArrays(val, props.getBytesProperty(key));
+
+ try
+ {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getBytesProperty(key);
+ Assert.fail();
+ }
+ catch (PropertyConversionException e)
+ {
+ }
+
+ Assert.assertNull(props.getBytesProperty(unknownKey));
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Copied: trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesTest.java (from
rev 12016,
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesTest.java
(rev 0)
+++ trunk/hornetq-core/src/test/java/org/hornetq/util/TypedPropertiesTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -0,0 +1,248 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.util;
+import java.util.Iterator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hornetq.api.core.HornetQBuffer;
+import org.hornetq.api.core.HornetQBuffers;
+import org.hornetq.api.core.SimpleString;
+import org.hornetq.tests.util.RandomUtil;
+import org.hornetq.tests.util.UnitTestCase;
+import org.hornetq.utils.TypedProperties;
+
+/**
+ * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
+ */
+public class TypedPropertiesTest extends TestCase
+{
+
+ private static void assertEqualsTypeProperties(final TypedProperties expected, final
TypedProperties actual)
+ {
+ Assert.assertNotNull(expected);
+ Assert.assertNotNull(actual);
+ Assert.assertEquals(expected.getEncodeSize(), actual.getEncodeSize());
+ Assert.assertEquals(expected.getPropertyNames(), actual.getPropertyNames());
+ Iterator<SimpleString> iterator = actual.getPropertyNames().iterator();
+ while (iterator.hasNext())
+ {
+ SimpleString key = iterator.next();
+ Object expectedValue = expected.getProperty(key);
+ Object actualValue = actual.getProperty(key);
+ if (expectedValue instanceof byte[] && actualValue instanceof byte[])
+ {
+ byte[] expectedBytes = (byte[])expectedValue;
+ byte[] actualBytes = (byte[])actualValue;
+ UnitTestCase.assertEqualsByteArrays(expectedBytes, actualBytes);
+ }
+ else
+ {
+ Assert.assertEquals(expectedValue, actualValue);
+ }
+ }
+ }
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ private TypedProperties props;
+
+ private SimpleString key;
+
+ public void testCopyContructor() throws Exception
+ {
+ props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
+
+ TypedProperties copy = new TypedProperties(props);
+
+ Assert.assertEquals(props.getEncodeSize(), copy.getEncodeSize());
+ Assert.assertEquals(props.getPropertyNames(), copy.getPropertyNames());
+
+ Assert.assertTrue(copy.containsProperty(key));
+ Assert.assertEquals(props.getProperty(key), copy.getProperty(key));
+ }
+
+ public void testRemove() throws Exception
+ {
+ props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
+
+ Assert.assertTrue(props.containsProperty(key));
+ Assert.assertNotNull(props.getProperty(key));
+
+ props.removeProperty(key);
+
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ public void testClear() throws Exception
+ {
+ props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
+
+ Assert.assertTrue(props.containsProperty(key));
+ Assert.assertNotNull(props.getProperty(key));
+
+ props.clear();
+
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ public void testKey() throws Exception
+ {
+ props.putBooleanProperty(key, true);
+ boolean bool = (Boolean)props.getProperty(key);
+ Assert.assertEquals(true, bool);
+
+ props.putCharProperty(key, 'a');
+ char c = (Character)props.getProperty(key);
+ Assert.assertEquals('a', c);
+ }
+
+ public void testGetPropertyOnEmptyProperties() throws Exception
+ {
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ public void testRemovePropertyOnEmptyProperties() throws Exception
+ {
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.removeProperty(key));
+ }
+
+ public void testNullProperty() throws Exception
+ {
+ props.putSimpleStringProperty(key, null);
+ Assert.assertTrue(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ public void testBytesPropertyWithNull() throws Exception
+ {
+ props.putBytesProperty(key, null);
+
+ Assert.assertTrue(props.containsProperty(key));
+ byte[] bb = (byte[])props.getProperty(key);
+ Assert.assertNull(bb);
+ }
+
+ public void testTypedProperties() throws Exception
+ {
+ SimpleString longKey = RandomUtil.randomSimpleString();
+ long longValue = RandomUtil.randomLong();
+ SimpleString simpleStringKey = RandomUtil.randomSimpleString();
+ SimpleString simpleStringValue = RandomUtil.randomSimpleString();
+ TypedProperties otherProps = new TypedProperties();
+ otherProps.putLongProperty(longKey, longValue);
+ otherProps.putSimpleStringProperty(simpleStringKey, simpleStringValue);
+
+ props.putTypedProperties(otherProps);
+
+ long ll = props.getLongProperty(longKey);
+ Assert.assertEquals(longValue, ll);
+ SimpleString ss = props.getSimpleStringProperty(simpleStringKey);
+ Assert.assertEquals(simpleStringValue, ss);
+ }
+
+ public void testEmptyTypedProperties() throws Exception
+ {
+ Assert.assertEquals(0, props.getPropertyNames().size());
+
+ props.putTypedProperties(new TypedProperties());
+
+ Assert.assertEquals(0, props.getPropertyNames().size());
+ }
+
+ public void testNullTypedProperties() throws Exception
+ {
+ Assert.assertEquals(0, props.getPropertyNames().size());
+
+ props.putTypedProperties(null);
+
+ Assert.assertEquals(0, props.getPropertyNames().size());
+ }
+
+ public void testEncodeDecode() throws Exception
+ {
+ props.putByteProperty(RandomUtil.randomSimpleString(), RandomUtil.randomByte());
+ props.putBytesProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBytes());
+ props.putBytesProperty(RandomUtil.randomSimpleString(), null);
+ props.putBooleanProperty(RandomUtil.randomSimpleString(),
RandomUtil.randomBoolean());
+ props.putShortProperty(RandomUtil.randomSimpleString(), RandomUtil.randomShort());
+ props.putIntProperty(RandomUtil.randomSimpleString(), RandomUtil.randomInt());
+ props.putLongProperty(RandomUtil.randomSimpleString(), RandomUtil.randomLong());
+ props.putFloatProperty(RandomUtil.randomSimpleString(), RandomUtil.randomFloat());
+ props.putDoubleProperty(RandomUtil.randomSimpleString(),
RandomUtil.randomDouble());
+ props.putCharProperty(RandomUtil.randomSimpleString(), RandomUtil.randomChar());
+ props.putSimpleStringProperty(RandomUtil.randomSimpleString(),
RandomUtil.randomSimpleString());
+ props.putSimpleStringProperty(RandomUtil.randomSimpleString(), null);
+ SimpleString keyToRemove = RandomUtil.randomSimpleString();
+ props.putSimpleStringProperty(keyToRemove, RandomUtil.randomSimpleString());
+
+ HornetQBuffer buffer = HornetQBuffers.dynamicBuffer(1024);
+ props.encode(buffer);
+
+ Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
+
+ TypedProperties decodedProps = new TypedProperties();
+ decodedProps.decode(buffer);
+
+ TypedPropertiesTest.assertEqualsTypeProperties(props, decodedProps);
+
+ buffer.clear();
+
+ // After removing a property, you should still be able to encode the Property
+ props.removeProperty(keyToRemove);
+ props.encode(buffer);
+
+ Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
+ }
+
+ public void testEncodeDecodeEmpty() throws Exception
+ {
+ TypedProperties emptyProps = new TypedProperties();
+
+ HornetQBuffer buffer = HornetQBuffers.dynamicBuffer(1024);
+ emptyProps.encode(buffer);
+
+ Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
+
+ TypedProperties decodedProps = new TypedProperties();
+ decodedProps.decode(buffer);
+
+ TypedPropertiesTest.assertEqualsTypeProperties(emptyProps, decodedProps);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ props = new TypedProperties();
+ key = RandomUtil.randomSimpleString();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ key = null;
+ props = null;
+
+ super.tearDown();
+ }
+}
Copied: trunk/hornetq-core/src/test/java/org/hornetq/util/XMLUtilTest.java (from rev
12016, trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/XMLUtilTest.java)
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/util/XMLUtilTest.java
(rev 0)
+++ trunk/hornetq-core/src/test/java/org/hornetq/util/XMLUtilTest.java 2012-01-12 12:10:54
UTC (rev 12017)
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat 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.hornetq.util;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.hornetq.utils.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author <a href="mailto:ovidiu@feodorov.com">Ovidiu
Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ */
+public class XMLUtilTest extends TestCase
+{
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testGetTextContext_1() throws Exception
+ {
+ String document = "<blah>foo</blah>";
+
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
+
+ Assert.assertEquals("foo", org.hornetq.utils.XMLUtil.getTextContent(e));
+ }
+
+ public void testGetTextContext_2() throws Exception
+ {
+ String document = "<blah
someattribute=\"somevalue\">foo</blah>";
+
+ Element e = XMLUtil.stringToElement(document);
+
+ Assert.assertEquals("foo", org.hornetq.utils.XMLUtil.getTextContent(e));
+ }
+
+ public void testGetTextContext_3() throws Exception
+ {
+ String document = "<blah
someattribute=\"somevalue\"><a/></blah>";
+
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
+
+ String s = org.hornetq.utils.XMLUtil.getTextContent(e);
+
+ Element subelement = org.hornetq.utils.XMLUtil.stringToElement(s);
+
+ Assert.assertEquals("a", subelement.getNodeName());
+ }
+
+ public void testGetTextContext_4() throws Exception
+ {
+ String document = "<blah
someattribute=\"somevalue\"><a></a></blah>";
+
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
+
+ String s = org.hornetq.utils.XMLUtil.getTextContent(e);
+
+ Element subelement = org.hornetq.utils.XMLUtil.stringToElement(s);
+
+ Assert.assertEquals("a", subelement.getNodeName());
+ }
+
+ public void testGetTextContext_5() throws Exception
+ {
+ String document = "<blah
someattribute=\"somevalue\"><a><b/></a></blah>";
+
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
+
+ String s = org.hornetq.utils.XMLUtil.getTextContent(e);
+
+ Element subelement = org.hornetq.utils.XMLUtil.stringToElement(s);
+
+ Assert.assertEquals("a", subelement.getNodeName());
+ NodeList nl = subelement.getChildNodes();
+
+ // try to find <b>
+ boolean found = false;
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node n = nl.item(i);
+ if ("b".equals(n.getNodeName()))
+ {
+ found = true;
+ }
+ }
+ Assert.assertTrue(found);
+ }
+
+ public void testEquivalent_1() throws Exception
+ {
+ String s = "<a/>";
+ String s2 = "<a/>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
org.hornetq.utils.XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_2() throws Exception
+ {
+ String s = "<a></a>";
+ String s2 = "<a/>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
org.hornetq.utils.XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_3() throws Exception
+ {
+ String s = "<a attr1=\"val1\"
attr2=\"val2\"/>";
+ String s2 = "<a attr2=\"val2\"/>";
+
+ try
+ {
+
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
+ XMLUtil.stringToElement(s2));
+ Assert.fail("this should throw exception");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // OK
+ }
+ }
+
+ public void testEquivalent_4() throws Exception
+ {
+ String s = "<a attr1=\"val1\"
attr2=\"val2\"/>";
+ String s2 = "<a attr2=\"val2\"
attr1=\"val1\"/>";
+
+
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
+
org.hornetq.utils.XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_5() throws Exception
+ {
+ String s = "<a><b/></a>";
+ String s2 = "<a><b/></a>";
+
+
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
+
org.hornetq.utils.XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_6() throws Exception
+ {
+ String s = "<enclosing><a attr1=\"val1\"
attr2=\"val2\"/></enclosing>";
+ String s2 = "<enclosing><a attr2=\"val2\"
attr1=\"val1\"/></enclosing>";
+
+ org.hornetq.utils.XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
+
org.hornetq.utils.XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_7() throws Exception
+ {
+ String s = "<a><b/><c/></a>";
+ String s2 = "<a><c/><b/></a>";
+
+ try
+ {
+
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
+
org.hornetq.utils.XMLUtil.stringToElement(s2));
+ Assert.fail("this should throw exception");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // OK
+ }
+ }
+
+ public void testEquivalent_8() throws Exception
+ {
+ String s = "<a><!-- some comment --><b/><!--some other
comment --><c/><!-- blah --></a>";
+ String s2 = "<a><b/><!--blah
blah--><c/></a>";
+
+ org.hornetq.utils.XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
+
org.hornetq.utils.XMLUtil.stringToElement(s2));
+ }
+
+ public void testElementToString_1() throws Exception
+ {
+ String s = "<a b=\"something\">somethingelse</a>";
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
+ String tostring = org.hornetq.utils.XMLUtil.elementToString(e);
+ Element convertedAgain = org.hornetq.utils.XMLUtil.stringToElement(tostring);
+ org.hornetq.utils.XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testElementToString_2() throws Exception
+ {
+ String s = "<a b=\"something\"></a>";
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
+ String tostring = XMLUtil.elementToString(e);
+ Element convertedAgain = XMLUtil.stringToElement(tostring);
+ XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testElementToString_3() throws Exception
+ {
+ String s = "<a b=\"something\"/>";
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
+ String tostring = XMLUtil.elementToString(e);
+ Element convertedAgain = org.hornetq.utils.XMLUtil.stringToElement(tostring);
+ org.hornetq.utils.XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testElementToString_4() throws Exception
+ {
+ String s = "<a><![CDATA[somedata]]></a>";
+ Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
+ String tostring = XMLUtil.elementToString(e);
+ Element convertedAgain = org.hornetq.utils.XMLUtil.stringToElement(tostring);
+ org.hornetq.utils.XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testReplaceSystemProperties()
+ {
+ String before = "<configuration>\n" + " <test
name=\"${sysprop1}\">content1</test>\n"
+ + " <test
name=\"test2\">content2</test>\n"
+ + " <test
name=\"test3\">content3</test>\n"
+ + " <test
name=\"test4\">${sysprop2}</test>\n"
+ + " <test
name=\"test5\">content5</test>\n"
+ + " <test
name=\"test6\">content6</test>\n"
+ + "</configuration>";
+ String after = "<configuration>\n" + " <test
name=\"test1\">content1</test>\n"
+ + " <test
name=\"test2\">content2</test>\n"
+ + " <test
name=\"test3\">content3</test>\n"
+ + " <test
name=\"test4\">content4</test>\n"
+ + " <test
name=\"test5\">content5</test>\n"
+ + " <test
name=\"test6\">content6</test>\n"
+ + "</configuration>";
+ System.setProperty("sysprop1", "test1");
+ System.setProperty("sysprop2", "content4");
+ String replaced = org.hornetq.utils.XMLUtil.replaceSystemProps(before);
+ Assert.assertEquals(after, replaced);
+ }
+
+ public void testStripCDATA() throws Exception
+ {
+ String xml = "<![CDATA[somedata]]>";
+ String stripped = XMLUtil.stripCDATA(xml);
+
+ Assert.assertEquals("somedata", stripped);
+ }
+
+}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/FilterTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/FilterTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/FilterTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,703 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.core.filter.impl;
-
-import junit.framework.Assert;
-
-import org.hornetq.api.core.HornetQException;
-import org.hornetq.api.core.SimpleString;
-import org.hornetq.core.filter.Filter;
-import org.hornetq.core.filter.impl.FilterImpl;
-import org.hornetq.core.logging.Logger;
-import org.hornetq.core.server.ServerMessage;
-import org.hornetq.core.server.impl.ServerMessageImpl;
-import org.hornetq.tests.util.RandomUtil;
-import org.hornetq.tests.util.UnitTestCase;
-
-/**
- * Tests the compliance with the HornetQ Filter syntax.
- *
- * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
- * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- * @version $Revision: 3514 $
- */
-public class FilterTest extends UnitTestCase
-{
- private static final Logger log = Logger.getLogger(FilterTest.class);
-
- private Filter filter;
-
- private ServerMessage message;
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- message = new ServerMessageImpl(1, 1000);
- }
-
- public void testFilterForgets() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("color =
'RED'"));
-
- message.putStringProperty(new SimpleString("color"), new
SimpleString("RED"));
- Assert.assertTrue(filter.match(message));
- message = new ServerMessageImpl();
- Assert.assertFalse(filter.match(message));
- }
-
- public void testInvalidString() throws Exception
- {
- testInvalidFilter("color = 'red");
- testInvalidFilter(new SimpleString("color = 'red"));
-
- testInvalidFilter("3");
- testInvalidFilter(new SimpleString("3"));
- }
-
- public void testNullFilter() throws Exception
- {
- Assert.assertNull(FilterImpl.createFilter((String)null));
- Assert.assertNull(FilterImpl.createFilter(""));
- Assert.assertNull(FilterImpl.createFilter((SimpleString)null));
- Assert.assertNull(FilterImpl.createFilter(new SimpleString("")));
- }
-
- public void testHQDurable() throws Exception
- {
- filter = FilterImpl.createFilter(new
SimpleString("HQDurable='DURABLE'"));
-
- message.setDurable(true);
-
- Assert.assertTrue(filter.match(message));
-
- message.setDurable(false);
-
- Assert.assertFalse(filter.match(message));
-
- filter = FilterImpl.createFilter(new
SimpleString("HQDurable='NON_DURABLE'"));
-
- message = new ServerMessageImpl();
- message.setDurable(true);
-
- Assert.assertFalse(filter.match(message));
-
- message.setDurable(false);
-
- Assert.assertTrue(filter.match(message));
-
- }
-
- public void testHQSize() throws Exception
- {
- message.setAddress(RandomUtil.randomSimpleString());
-
- int encodeSize = message.getEncodeSize();
-
- Filter moreThanSmall = FilterImpl.createFilter(new SimpleString("HQSize >
" + (encodeSize - 1)));
- Filter lessThanLarge = FilterImpl.createFilter(new SimpleString("HQSize <
" + (encodeSize + 1)));
-
- Filter lessThanSmall = FilterImpl.createFilter(new SimpleString("HQSize <
" + encodeSize));
- Filter moreThanLarge = FilterImpl.createFilter(new SimpleString("HQSize >
" + encodeSize));
-
- Assert.assertTrue(moreThanSmall.match(message));
- Assert.assertTrue(lessThanLarge.match(message));
-
- Assert.assertFalse(lessThanSmall.match(message));
- Assert.assertFalse(moreThanLarge.match(message));
-
- }
-
- public void testHQPriority() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("HQPriority=3"));
-
- for (int i = 0; i < 10; i++)
- {
- message.setPriority((byte)i);
-
- if (i == 3)
- {
- Assert.assertTrue(filter.match(message));
- }
- else
- {
- Assert.assertFalse(filter.match(message));
- }
- }
- }
-
- public void testHQTimestamp() throws Exception
- {
- filter = FilterImpl.createFilter(new
SimpleString("HQTimestamp=12345678"));
-
- message.setTimestamp(87654321);
-
- Assert.assertFalse(filter.match(message));
-
- message.setTimestamp(12345678);
-
- Assert.assertTrue(filter.match(message));
- }
-
- public void testBooleanTrue() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("MyBoolean=true"));
-
- testBoolean("MyBoolean", true);
- }
-
- public void testIdentifier() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("MyBoolean"));
-
- testBoolean("MyBoolean", true);
- }
-
- public void testDifferentNullString() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("prop <>
'foo'"));
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("NOT (prop =
'foo')"));
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("prop <>
'foo'"));
- doPutStringProperty("prop", "bar");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("prop <>
'foo'"));
- doPutStringProperty("prop", "foo");
- Assert.assertFalse(filter.match(message));
- }
-
- public void testBooleanFalse() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("MyBoolean=false"));
- testBoolean("MyBoolean", false);
- }
-
- private void testBoolean(final String name, final boolean flag) throws Exception
- {
- message.putBooleanProperty(new SimpleString(name), flag);
- Assert.assertTrue(filter.match(message));
-
- message.putBooleanProperty(new SimpleString(name), !flag);
- Assert.assertTrue(!filter.match(message));
- }
-
- public void testStringEquals() throws Exception
- {
- // First, simple test of string equality and inequality
- filter = FilterImpl.createFilter(new
SimpleString("MyString='astring'"));
-
- doPutStringProperty("MyString", "astring");
- Assert.assertTrue(filter.match(message));
-
- doPutStringProperty("MyString", "NOTastring");
- Assert.assertTrue(!filter.match(message));
-
- // test empty string
- filter = FilterImpl.createFilter(new
SimpleString("MyString=''"));
-
- doPutStringProperty("MyString", "");
- Assert.assertTrue("test 1", filter.match(message));
-
- doPutStringProperty("MyString", "NOTastring");
- Assert.assertTrue("test 2", !filter.match(message));
-
- // test literal apostrophes (which are escaped using two apostrophes
- // in selectors)
- filter = FilterImpl.createFilter(new SimpleString("MyString='test
JBoss''s filter'"));
-
- // note: apostrophes are not escaped in string properties
- doPutStringProperty("MyString", "test JBoss's filter");
- // this test fails -- bug 530120
- // assertTrue("test 3", filter.match(message));
-
- doPutStringProperty("MyString", "NOTastring");
- Assert.assertTrue("test 4", !filter.match(message));
-
- }
-
- public void testNOT_INWithNullProperty() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("myNullProp NOT IN
('foo','jms','test')"));
-
- assertFalse(filter.match(message));
-
- message.putStringProperty("myNullProp", "JMS");
- assertTrue(filter.match(message));
- }
-
- public void testNOT_LIKEWithNullProperty() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("myNullProp NOT LIKE
'1_3'"));
-
- assertFalse(filter.match(message));
-
- message.putStringProperty("myNullProp", "JMS");
- assertTrue(filter.match(message));
- }
-
- public void testIS_NOT_NULLWithNullProperty() throws Exception
- {
- filter = FilterImpl.createFilter(new SimpleString("myNullProp IS NOT
NULL"));
-
- assertFalse(filter.match(message));
-
- message.putStringProperty("myNullProp", "JMS");
- assertTrue(filter.match(message));
- }
-
- public void testStringLike() throws Exception
- {
- // test LIKE operator with no wildcards
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'astring'"));
- Assert.assertFalse(filter.match(message));
-
- // test where LIKE operand matches
- doPutStringProperty("MyString", "astring");
- Assert.assertTrue(filter.match(message));
-
- // test one character string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a'"));
- doPutStringProperty("MyString", "a");
- Assert.assertTrue(filter.match(message));
-
- // test empty string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
''"));
- doPutStringProperty("MyString", "");
- Assert.assertTrue(filter.match(message));
-
- // tests where operand does not match
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'astring'"));
-
- // test with extra characters at beginning
- doPutStringProperty("MyString", "NOTastring");
- Assert.assertTrue(!filter.match(message));
-
- // test with extra characters at end
- doPutStringProperty("MyString", "astringNOT");
- Assert.assertTrue(!filter.match(message));
-
- // test with extra characters in the middle
- doPutStringProperty("MyString", "astNOTring");
- Assert.assertTrue(!filter.match(message));
-
- // test where operand is entirely different
- doPutStringProperty("MyString", "totally different");
- Assert.assertTrue(!filter.match(message));
-
- // test case sensitivity
- doPutStringProperty("MyString", "ASTRING");
- Assert.assertTrue(!filter.match(message));
-
- // test empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // test lower-case 'like' operator?
- }
-
- public void testStringLikeUnderbarWildcard() throws Exception
- {
- // test LIKE operator with the _ wildcard, which
- // matches any single character
-
- // first, some tests with the wildcard by itself
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'_'"));
- Assert.assertFalse(filter.match(message));
-
- // test match against single character
- doPutStringProperty("MyString", "a");
- Assert.assertTrue(filter.match(message));
-
- // test match failure against multiple characters
- doPutStringProperty("MyString", "aaaaa");
- Assert.assertTrue(!filter.match(message));
-
- // test match failure against the empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // next, tests with wildcard at the beginning of the string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'_bcdf'"));
-
- // test match at beginning of string
- doPutStringProperty("MyString", "abcdf");
- Assert.assertTrue(filter.match(message));
-
- // match failure in first character after wildcard
- doPutStringProperty("MyString", "aXcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in middle character
- doPutStringProperty("MyString", "abXdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in last character
- doPutStringProperty("MyString", "abcdX");
- Assert.assertTrue(!filter.match(message));
-
- // match failure with empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at beginning
- doPutStringProperty("MyString", "XXXabcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at the end
- doPutStringProperty("MyString", "abcdfXXX");
- Assert.assertTrue(!filter.match(message));
-
- // test that the _ wildcard does not match the 'empty' character
- doPutStringProperty("MyString", "bcdf");
- Assert.assertTrue(!filter.match(message));
-
- // next, tests with wildcard at the end of the string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'abcd_'"));
-
- // test match at end of string
- doPutStringProperty("MyString", "abcdf");
- Assert.assertTrue(filter.match(message));
-
- // match failure in first character before wildcard
- doPutStringProperty("MyString", "abcXf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in middle character
- doPutStringProperty("MyString", "abXdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in first character
- doPutStringProperty("MyString", "Xbcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure with empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at beginning
- doPutStringProperty("MyString", "XXXabcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at the end
- doPutStringProperty("MyString", "abcdfXXX");
- Assert.assertTrue(!filter.match(message));
-
- // test that the _ wildcard does not match the 'empty' character
- doPutStringProperty("MyString", "abcd");
- Assert.assertTrue(!filter.match(message));
-
- // test match in middle of string
-
- // next, tests with wildcard in the middle of the string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'ab_df'"));
-
- // test match in the middle of string
- doPutStringProperty("MyString", "abcdf");
- Assert.assertTrue(filter.match(message));
-
- // match failure in first character before wildcard
- doPutStringProperty("MyString", "aXcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in first character after wildcard
- doPutStringProperty("MyString", "abcXf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in last character
- doPutStringProperty("MyString", "abcdX");
- Assert.assertTrue(!filter.match(message));
-
- // match failure with empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at beginning
- doPutStringProperty("MyString", "XXXabcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at the end
- doPutStringProperty("MyString", "abcdfXXX");
- Assert.assertTrue(!filter.match(message));
-
- // test that the _ wildcard does not match the 'empty' character
- doPutStringProperty("MyString", "abdf");
- Assert.assertTrue(!filter.match(message));
-
- // test match failures
- }
-
- public void testNotLikeExpression() throws Exception
- {
- // Should evaluate to false when the property MyString is not set
- filter = FilterImpl.createFilter(new SimpleString("NOT (MyString LIKE
'%')"));
-
- Assert.assertFalse(filter.match(message));
- }
-
- public void testStringLikePercentWildcard() throws Exception
- {
- // test LIKE operator with the % wildcard, which
- // matches any sequence of characters
- // note many of the tests are similar to those for _
-
- // first, some tests with the wildcard by itself
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'%'"));
- Assert.assertFalse(filter.match(message));
-
- // test match against single character
- doPutStringProperty("MyString", "a");
- Assert.assertTrue(filter.match(message));
-
- // test match against multiple characters
- doPutStringProperty("MyString", "aaaaa");
- Assert.assertTrue(filter.match(message));
-
- doPutStringProperty("MyString", "abcdf");
- Assert.assertTrue(filter.match(message));
-
- // test match against the empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(filter.match(message));
-
- // next, tests with wildcard at the beginning of the string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'%bcdf'"));
-
- // test match with single character at beginning of string
- doPutStringProperty("MyString", "Xbcdf");
- Assert.assertTrue(filter.match(message));
-
- // match with multiple characters at beginning
- doPutStringProperty("MyString", "XXbcdf");
- Assert.assertTrue(filter.match(message));
-
- // match failure in middle character
- doPutStringProperty("MyString", "abXdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in last character
- doPutStringProperty("MyString", "abcdX");
- Assert.assertTrue(!filter.match(message));
-
- // match failure with empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at the end
- doPutStringProperty("MyString", "abcdfXXX");
- Assert.assertTrue(!filter.match(message));
-
- // test that the % wildcard matches the empty string
- doPutStringProperty("MyString", "bcdf");
- Assert.assertTrue(filter.match(message));
-
- // next, tests with wildcard at the end of the string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'abcd%'"));
-
- // test match of single character at end of string
- doPutStringProperty("MyString", "abcdf");
- Assert.assertTrue(filter.match(message));
-
- // test match of multiple characters at end of string
- doPutStringProperty("MyString", "abcdfgh");
- Assert.assertTrue(filter.match(message));
-
- // match failure in first character before wildcard
- doPutStringProperty("MyString", "abcXf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in middle character
- doPutStringProperty("MyString", "abXdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in first character
- doPutStringProperty("MyString", "Xbcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure with empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at beginning
- doPutStringProperty("MyString", "XXXabcdf");
- Assert.assertTrue(!filter.match(message));
-
- // test that the % wildcard matches the empty string
- doPutStringProperty("MyString", "abcd");
- Assert.assertTrue(filter.match(message));
-
- // next, tests with wildcard in the middle of the string
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'ab%df'"));
-
- // test match with single character in the middle of string
- doPutStringProperty("MyString", "abXdf");
- Assert.assertTrue(filter.match(message));
-
- // test match with multiple characters in the middle of string
- doPutStringProperty("MyString", "abXXXdf");
- Assert.assertTrue(filter.match(message));
-
- // match failure in first character before wildcard
- doPutStringProperty("MyString", "aXcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in first character after wildcard
- doPutStringProperty("MyString", "abcXf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure in last character
- doPutStringProperty("MyString", "abcdX");
- Assert.assertTrue(!filter.match(message));
-
- // match failure with empty string
- doPutStringProperty("MyString", "");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at beginning
- doPutStringProperty("MyString", "XXXabcdf");
- Assert.assertTrue(!filter.match(message));
-
- // match failure due to extra characters at the end
- doPutStringProperty("MyString", "abcdfXXX");
- Assert.assertTrue(!filter.match(message));
-
- // test that the % wildcard matches the empty string
- doPutStringProperty("MyString", "abdf");
- Assert.assertTrue(filter.match(message));
-
- }
-
- public void testStringLikePunctuation() throws Exception
- {
- // test proper handling of some punctuation characters.
- // non-trivial since the underlying implementation might
- // (and in fact currently does) use a general-purpose
- // RE library, which has a different notion of which
- // characters are wildcards
-
- // the particular tests here are motivated by the
- // wildcards of the current underlying RE engine,
- // GNU regexp.
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a^$b'"));
- Assert.assertFalse(filter.match(message));
-
- doPutStringProperty("MyString", "a^$b");
- Assert.assertTrue(filter.match(message));
-
- // this one has a double backslash since backslash
- // is interpreted specially by Java
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a\\dc'"));
- doPutStringProperty("MyString", "a\\dc");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a.c'"));
- doPutStringProperty("MyString", "abc");
- Assert.assertTrue(!filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[abc]'"));
- doPutStringProperty("MyString", "[abc]");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[^abc]'"));
- doPutStringProperty("MyString", "[^abc]");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[a-c]'"));
- doPutStringProperty("MyString", "[a-c]");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'[:alpha]'"));
- doPutStringProperty("MyString", "[:alpha]");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)'"));
- doPutStringProperty("MyString", "(abc)");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'a|bc'"));
- doPutStringProperty("MyString", "a|bc");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)?'"));
- doPutStringProperty("MyString", "(abc)?");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)*'"));
- doPutStringProperty("MyString", "(abc)*");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc)+'"));
- doPutStringProperty("MyString", "(abc)+");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc){3}'"));
- doPutStringProperty("MyString", "(abc){3}");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc){3,5}'"));
- doPutStringProperty("MyString", "(abc){3,5}");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(abc){3,}'"));
- doPutStringProperty("MyString", "(abc){3,}");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(?=abc)'"));
- doPutStringProperty("MyString", "(?=abc)");
- Assert.assertTrue(filter.match(message));
-
- filter = FilterImpl.createFilter(new SimpleString("MyString LIKE
'(?!abc)'"));
- doPutStringProperty("MyString", "(?!abc)");
- Assert.assertTrue(filter.match(message));
- }
-
- // Private
-----------------------------------------------------------------------------------
-
- private void doPutStringProperty(final String key, final String value)
- {
- message.putStringProperty(new SimpleString(key), new SimpleString(value));
- }
-
- private void testInvalidFilter(final String filterString) throws Exception
- {
- try
- {
- filter = FilterImpl.createFilter(filterString);
- Assert.fail("Should throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.INVALID_FILTER_EXPRESSION, e.getCode());
- }
- }
-
- private void testInvalidFilter(final SimpleString filterString) throws Exception
- {
- try
- {
- filter = FilterImpl.createFilter(filterString);
- Assert.fail("Should throw exception");
- }
- catch (HornetQException e)
- {
- Assert.assertEquals(HornetQException.INVALID_FILTER_EXPRESSION, e.getCode());
- }
- }
-
-}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/core/filter/impl/OperatorTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,468 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.core.filter.impl;
-
-import java.util.HashSet;
-
-import junit.framework.Assert;
-
-import org.hornetq.api.core.SimpleString;
-import org.hornetq.core.filter.impl.Operator;
-import org.hornetq.tests.util.UnitTestCase;
-
-/**
- * A OperatorTest
- *
- * @author <a href="jmesnil(a)redhat.com">Jeff Mesnil</a>
- *
- * Created 3 nov. 2008 17:22:22
- *
- *
- */
-public class OperatorTest extends UnitTestCase
-{
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
- private static void assertSuccess(final int op, final Object arg1, final Object
expectedResult) throws Exception
- {
- OperatorTest.assertOperationSuccess(new Operator(op, arg1), expectedResult);
- }
-
- private static void assertSuccess(final int op, final Object arg1, final Object arg2,
final Object expectedResult) throws Exception
- {
- OperatorTest.assertOperationSuccess(new Operator(op, arg1, arg2), expectedResult);
- }
-
- private static void assertSuccess(final int op,
- final Object arg1,
- final Object arg2,
- final Object arg3,
- final Object expectedResult) throws Exception
- {
- OperatorTest.assertOperationSuccess(new Operator(op, arg1, arg2, arg3),
expectedResult);
- }
-
- private static void assertOperationSuccess(final Operator operator, final Object
expectedResult) throws Exception
- {
- Assert.assertEquals(expectedResult, operator.apply());
- }
-
- private static void assertFailure(final int op, final Object arg1) throws Exception
- {
- OperatorTest.assertOperationFailure(new Operator(op, arg1));
- }
-
- private static void assertFailure(final int op, final Object arg1, final Object arg2)
throws Exception
- {
- OperatorTest.assertOperationFailure(new Operator(op, arg1, arg2));
- }
-
- private static void assertFailure(final int op, final Object arg1, final Object arg2,
final Object arg3) throws Exception
- {
- OperatorTest.assertOperationFailure(new Operator(op, arg1, arg2, arg3));
- }
-
- private static void assertOperationFailure(final Operator operator)
- {
- try
- {
- operator.apply();
- Assert.fail("expected to throw an exception");
- }
- catch (Exception e)
- {
- }
- }
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void test_EQUAL() throws Exception
- {
- OperatorTest.assertSuccess(Operator.EQUAL, 1, 1, true);
- OperatorTest.assertSuccess(Operator.EQUAL, 1, 1.0, true);
- OperatorTest.assertSuccess(Operator.EQUAL, 1, null, null);
- OperatorTest.assertSuccess(Operator.EQUAL, 1.0, 1, true);
- OperatorTest.assertSuccess(Operator.EQUAL, 1.0, 1.0, true);
- OperatorTest.assertSuccess(Operator.EQUAL, 1.0, null, null);
-
- OperatorTest.assertSuccess(Operator.EQUAL, false, false, true);
- OperatorTest.assertSuccess(Operator.EQUAL, true, false, false);
- OperatorTest.assertSuccess(Operator.EQUAL, false, true, false);
- OperatorTest.assertSuccess(Operator.EQUAL, true, true, true);
-
- SimpleString foo = new SimpleString("foo");
- SimpleString foo2 = new SimpleString("foo");
- SimpleString bar = new SimpleString("bar");
- OperatorTest.assertSuccess(Operator.EQUAL, foo, foo, true);
- OperatorTest.assertSuccess(Operator.EQUAL, foo, foo2, true);
- OperatorTest.assertSuccess(Operator.EQUAL, foo, bar, false);
- OperatorTest.assertSuccess(Operator.EQUAL, foo, null, false);
-
- OperatorTest.assertSuccess(Operator.EQUAL, null, 1.0, false);
- }
-
- public void test_DIFFERENT() throws Exception
- {
- OperatorTest.assertSuccess(Operator.DIFFERENT, 2, 1, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, 2, 1.0, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, 2, null, null);
- OperatorTest.assertSuccess(Operator.DIFFERENT, 2.0, 1, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, 2.0, 1.0, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, 2.0, null, null);
-
- OperatorTest.assertSuccess(Operator.DIFFERENT, false, false, false);
- OperatorTest.assertSuccess(Operator.DIFFERENT, true, false, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, false, true, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, true, true, false);
-
- SimpleString foo = new SimpleString("foo");
- SimpleString foo2 = new SimpleString("foo");
- SimpleString bar = new SimpleString("bar");
- OperatorTest.assertSuccess(Operator.DIFFERENT, foo, foo, false);
- OperatorTest.assertSuccess(Operator.DIFFERENT, foo, foo2, false);
- OperatorTest.assertSuccess(Operator.DIFFERENT, foo, bar, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, foo, null, null);
-
- OperatorTest.assertSuccess(Operator.DIFFERENT, null, 1.0, true);
- OperatorTest.assertSuccess(Operator.DIFFERENT, null, null, false);
- }
-
- public void test_IS_NULL() throws Exception
- {
- OperatorTest.assertSuccess(Operator.IS_NULL, null, true);
- OperatorTest.assertSuccess(Operator.IS_NULL, 1, false);
- }
-
- public void test_IS_NOT_NULL() throws Exception
- {
- OperatorTest.assertSuccess(Operator.IS_NOT_NULL, null, false);
- OperatorTest.assertSuccess(Operator.IS_NOT_NULL, 1, true);
- }
-
- public void test_ADD() throws Exception
- {
- OperatorTest.assertSuccess(Operator.ADD, 1, 1, 2L);
- OperatorTest.assertSuccess(Operator.ADD, 1.0, 1, 2.0);
- OperatorTest.assertSuccess(Operator.ADD, 1, 1.0, 2.0);
- OperatorTest.assertSuccess(Operator.ADD, 1.0, 1.0, 2.0);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.ADD, true, 1.0);
- OperatorTest.assertFailure(Operator.ADD, 1, true);
- }
-
- public void test_SUB() throws Exception
- {
- OperatorTest.assertSuccess(Operator.SUB, 2, 1, 1L);
- OperatorTest.assertSuccess(Operator.SUB, 2.0, 1, 1.0);
- OperatorTest.assertSuccess(Operator.SUB, 2, 1.0, 1.0);
- OperatorTest.assertSuccess(Operator.SUB, 2.0, 1.0, 1.0);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.SUB, true, 1.0);
- OperatorTest.assertFailure(Operator.SUB, 1, true);
- }
-
- public void test_MUL() throws Exception
- {
- OperatorTest.assertSuccess(Operator.MUL, 2, 1, 2L);
- OperatorTest.assertSuccess(Operator.MUL, 2.0, 1, 2.0);
- OperatorTest.assertSuccess(Operator.MUL, 2, 1.0, 2.0);
- OperatorTest.assertSuccess(Operator.MUL, 2.0, 1.0, 2.0);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.MUL, 2, null, null);
- OperatorTest.assertSuccess(Operator.MUL, null, 1.0, null);
- OperatorTest.assertFailure(Operator.MUL, true, 1.0);
- OperatorTest.assertFailure(Operator.MUL, 1, true);
- }
-
- public void test_DIV() throws Exception
- {
- OperatorTest.assertSuccess(Operator.DIV, 2, 2, 1L);
- OperatorTest.assertSuccess(Operator.DIV, 2.0, 2, 1.0);
- OperatorTest.assertSuccess(Operator.DIV, 2, 2.0, 1.0);
- OperatorTest.assertSuccess(Operator.DIV, 2.0, 2.0, 1.0);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.DIV, 2, null, null);
- OperatorTest.assertSuccess(Operator.DIV, null, 1.0, null);
- OperatorTest.assertFailure(Operator.DIV, true, 1.0);
- OperatorTest.assertFailure(Operator.DIV, 1, true);
- }
-
- public void test_NEG() throws Exception
- {
- OperatorTest.assertSuccess(Operator.NEG, 1, -1L);
- OperatorTest.assertSuccess(Operator.NEG, -1.0, 1.0);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.NEG, true);
- }
-
- public void test_AND() throws Exception
- {
- // NULL and NULL -> NULL
- OperatorTest.assertSuccess(Operator.AND, null, null, null);
- // NULL and F -> F
- OperatorTest.assertSuccess(Operator.AND, null, false, false);
- // NULL and T -> NULL
- OperatorTest.assertSuccess(Operator.AND, null, true, null);
-
- // F and NULL -> F
- OperatorTest.assertSuccess(Operator.AND, false, null, false);
- // F and F -> F
- OperatorTest.assertSuccess(Operator.AND, false, false, false);
- // F and T -> F
- OperatorTest.assertSuccess(Operator.AND, false, true, false);
-
- // T and NULL -> NULL
- OperatorTest.assertSuccess(Operator.AND, true, null, null);
- // T and F -> F
- OperatorTest.assertSuccess(Operator.AND, true, false, false);
- // T and T -> T
- OperatorTest.assertSuccess(Operator.AND, true, true, true);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.AND, 1.0, true);
- OperatorTest.assertFailure(Operator.AND, true, 1.0);
- OperatorTest.assertFailure(Operator.AND, null, 1.0);
- }
-
- public void test_OR() throws Exception
- {
- // NULL OR NULL -> NULL
- OperatorTest.assertSuccess(Operator.OR, null, null, null);
- // NULL OR F -> NULL
- OperatorTest.assertSuccess(Operator.OR, null, false, null);
- // NULL OR T -> T
- OperatorTest.assertSuccess(Operator.OR, null, true, true);
-
- // F or NULL -> NULL
- OperatorTest.assertSuccess(Operator.OR, false, null, null);
- // F or F -> F
- OperatorTest.assertSuccess(Operator.OR, false, false, false);
- // F or T -> F
- OperatorTest.assertSuccess(Operator.OR, false, true, true);
-
- // T or NULL -> T
- OperatorTest.assertSuccess(Operator.OR, true, null, true);
- // T or F -> T
- OperatorTest.assertSuccess(Operator.OR, true, false, true);
- // T or T -> T
- OperatorTest.assertSuccess(Operator.OR, true, true, true);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.OR, 1.0, true);
- OperatorTest.assertFailure(Operator.OR, false, 1.0);
- OperatorTest.assertFailure(Operator.OR, null, 1.0);
- }
-
- public void test_NOT() throws Exception
- {
- // NOT NULL -> NULL
- OperatorTest.assertSuccess(Operator.NOT, null, null);
- // NOT F -> T
- OperatorTest.assertSuccess(Operator.NOT, false, true);
- // NOT T -> F
- OperatorTest.assertSuccess(Operator.NOT, true, false);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.NOT, 1.0);
- }
-
- public void test_GT() throws Exception
- {
- OperatorTest.assertSuccess(Operator.GT, 2, 1, true);
- OperatorTest.assertSuccess(Operator.GT, 2.0, 1, true);
- OperatorTest.assertSuccess(Operator.GT, 2, 1.0, true);
- OperatorTest.assertSuccess(Operator.GT, 2.0, 1.0, true);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.GT, 2.0, true, false);
- OperatorTest.assertSuccess(Operator.GT, 2, null, null);
- OperatorTest.assertSuccess(Operator.GT, true, 1.0, false);
- OperatorTest.assertSuccess(Operator.GT, null, 1, null);
- OperatorTest.assertSuccess(Operator.GT, true, true, false);
- OperatorTest.assertSuccess(Operator.GT, null, null, null);
- }
-
- public void test_GE() throws Exception
- {
- OperatorTest.assertSuccess(Operator.GE, 1, 1, true);
- OperatorTest.assertSuccess(Operator.GE, 1.0, 1, true);
- OperatorTest.assertSuccess(Operator.GE, 1, 1.0, true);
- OperatorTest.assertSuccess(Operator.GE, 1.0, 1.0, true);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.GE, 2.0, true, false);
- OperatorTest.assertSuccess(Operator.GE, 2, null, null);
- OperatorTest.assertSuccess(Operator.GE, true, 1.0, false);
- OperatorTest.assertSuccess(Operator.GE, null, 1, null);
- OperatorTest.assertSuccess(Operator.GE, true, true, false);
- OperatorTest.assertSuccess(Operator.GE, null, null, null);
- }
-
- public void test_LT() throws Exception
- {
- OperatorTest.assertSuccess(Operator.LT, 1, 2, true);
- OperatorTest.assertSuccess(Operator.LT, 1.0, 2, true);
- OperatorTest.assertSuccess(Operator.LT, 1, 2.0, true);
- OperatorTest.assertSuccess(Operator.LT, 1.0, 2.0, true);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.LT, 1.0, true, false);
- OperatorTest.assertSuccess(Operator.LT, 1, null, null);
- OperatorTest.assertSuccess(Operator.LT, true, 2.0, false);
- OperatorTest.assertSuccess(Operator.LT, null, 2, null);
- OperatorTest.assertSuccess(Operator.LT, true, true, false);
- OperatorTest.assertSuccess(Operator.LT, null, null, null);
- }
-
- public void test_LE() throws Exception
- {
- OperatorTest.assertSuccess(Operator.LE, 1, 1, true);
- OperatorTest.assertSuccess(Operator.LE, 1.0, 1, true);
- OperatorTest.assertSuccess(Operator.LE, 1, 1.0, true);
- OperatorTest.assertSuccess(Operator.LE, 1.0, 1.0, true);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.LE, 1.0, true, false);
- OperatorTest.assertSuccess(Operator.LE, 1, null, null);
- OperatorTest.assertSuccess(Operator.LE, true, 1.0, false);
- OperatorTest.assertSuccess(Operator.LE, null, 1, null);
- OperatorTest.assertSuccess(Operator.LE, true, true, false);
- OperatorTest.assertSuccess(Operator.LE, null, null, null);
- }
-
- public void test_BETWEEN() throws Exception
- {
- // 2 BETWEEN 1 AND 3
- OperatorTest.assertSuccess(Operator.BETWEEN, 2, 1, 3, true);
- OperatorTest.assertSuccess(Operator.BETWEEN, 2.0, 1.0, 3.0, true);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.BETWEEN, true, 1, 3, false);
- OperatorTest.assertSuccess(Operator.BETWEEN, null, null, 3, null);
- }
-
- public void test_NOT_BETWEEN() throws Exception
- {
- // 2 NOT BETWEEN 3 AND 4
- OperatorTest.assertSuccess(Operator.NOT_BETWEEN, 2, 3, 4, true);
- OperatorTest.assertSuccess(Operator.NOT_BETWEEN, 2.0, 3.0, 4.0, true);
-
- // incompatible types
- OperatorTest.assertSuccess(Operator.NOT_BETWEEN, true, 1, 3, false);
- OperatorTest.assertSuccess(Operator.NOT_BETWEEN, null, null, 3, null);
- }
-
- public void test_IN() throws Exception
- {
- HashSet set = new HashSet();
- set.add(new SimpleString("foo"));
- set.add(new SimpleString("bar"));
- set.add(new SimpleString("baz"));
-
- SimpleString foo = new SimpleString("foo");
-
- OperatorTest.assertSuccess(Operator.IN, foo, set, true);
- OperatorTest.assertSuccess(Operator.IN, foo, new HashSet(), false);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.IN, true, set);
- }
-
- public void test_NOT_IN() throws Exception
- {
- HashSet set = new HashSet();
- set.add(new SimpleString("foo"));
- set.add(new SimpleString("bar"));
- set.add(new SimpleString("baz"));
-
- SimpleString foo = new SimpleString("foo");
-
- OperatorTest.assertSuccess(Operator.NOT_IN, foo, set, false);
- OperatorTest.assertSuccess(Operator.NOT_IN, foo, new HashSet(), true);
-
- // incompatible types
- OperatorTest.assertFailure(Operator.NOT_IN, true, set);
- }
-
- public void test_LIKE() throws Exception
- {
- SimpleString pattern = new SimpleString("12%3");
- OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("123"),
pattern, true);
- OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("12993"),
pattern, true);
- OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("1234"),
pattern, false);
-
- pattern = new SimpleString("l_se");
- OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("lose"),
pattern, true);
- OperatorTest.assertSuccess(Operator.LIKE, new SimpleString("loose"),
pattern, false);
-
- OperatorTest.assertSuccess(Operator.LIKE, null, pattern, null);
- }
-
- public void test_LIKE_ESCAPE() throws Exception
- {
- SimpleString pattern = new SimpleString("\\_%");
- SimpleString escapeChar = new SimpleString("\\");
- OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, new
SimpleString("_foo"), pattern, escapeChar, true);
- OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, new SimpleString("bar"),
pattern, escapeChar, false);
- OperatorTest.assertSuccess(Operator.LIKE_ESCAPE, null, pattern, escapeChar, null);
-
- OperatorTest.assertFailure(Operator.LIKE_ESCAPE,
- new SimpleString("_foo"),
- pattern,
- new SimpleString("must be a single char"));
- }
-
- public void test_NOT_LIKE() throws Exception
- {
- SimpleString pattern = new SimpleString("12%3");
- OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("123"),
pattern, false);
- OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("12993"),
pattern, false);
- OperatorTest.assertSuccess(Operator.NOT_LIKE, new SimpleString("1234"),
pattern, true);
- OperatorTest.assertSuccess(Operator.NOT_LIKE, null, pattern, null);
- }
-
- public void test_NOT_LIKE_ESCAPE() throws Exception
- {
- SimpleString pattern = new SimpleString("\\_%");
- SimpleString escapeChar = new SimpleString("\\");
- OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, new
SimpleString("_foo"), pattern, escapeChar, false);
- OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, new
SimpleString("bar"), pattern, escapeChar, true);
- OperatorTest.assertSuccess(Operator.NOT_LIKE_ESCAPE, null, pattern, escapeChar,
null);
-
- OperatorTest.assertFailure(Operator.NOT_LIKE_ESCAPE,
- new SimpleString("_foo"),
- pattern,
- new SimpleString("must be a single char"));
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/CompressionUtilTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/CompressionUtilTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/CompressionUtilTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,192 +0,0 @@
-/*
- * Copyright 2010 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.ArrayList;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.zip.Deflater;
-
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.DeflaterReader;
-import org.hornetq.utils.InflaterReader;
-import org.hornetq.utils.InflaterWriter;
-
-/**
- * A CompressionUtilTest
- *
- * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
- *
- */
-public class CompressionUtilTest extends UnitTestCase
-{
-
- public void testDeflaterReader() throws Exception
- {
- String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
- byte[] input = inputString.getBytes("UTF-8");
-
- ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
-
- AtomicLong counter = new AtomicLong(0);
- DeflaterReader reader = new DeflaterReader(inputStream, counter);
-
- ArrayList<Integer> zipHolder = new ArrayList<Integer>();
- int b = reader.read();
-
- while (b != -1)
- {
- zipHolder.add(b);
- b = reader.read();
- }
-
- assertEquals(input.length, counter.get());
-
- byte[] allCompressed = new byte[zipHolder.size()];
- for (int i = 0; i < allCompressed.length; i++)
- {
- allCompressed[i] = (byte) zipHolder.get(i).intValue();
- }
-
- byte[] output = new byte[30];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
-
- compareByteArray(allCompressed, output, compressedDataLength);
- }
-
- public void testDeflaterReader2() throws Exception
- {
- String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
- byte[] input = inputString.getBytes("UTF-8");
-
- ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
- AtomicLong counter = new AtomicLong(0);
-
- DeflaterReader reader = new DeflaterReader(inputStream, counter);
-
- byte[] buffer = new byte[7];
- ArrayList<Integer> zipHolder = new ArrayList<Integer>();
-
- int n = reader.read(buffer);
- while (n != -1)
- {
- for (int i = 0; i < n; i++)
- {
- zipHolder.add((int)buffer[i]);
- }
- n = reader.read(buffer);
- }
-
- assertEquals(input.length, counter.get());
-
- byte[] allCompressed = new byte[zipHolder.size()];
- for (int i = 0; i < allCompressed.length; i++)
- {
- allCompressed[i] = (byte) zipHolder.get(i).intValue();
- }
-
- byte[] output = new byte[30];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
-
- compareByteArray(allCompressed, output, compressedDataLength);
- }
-
- public void testInflaterReader() throws Exception
- {
- String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
- byte[] input = inputString.getBytes("UTF-8");
- byte[] output = new byte[30];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
-
- byte[] zipBytes = new byte[compressedDataLength];
-
- System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
- ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
-
- InflaterReader inflater = new InflaterReader(byteInput);
- ArrayList<Integer> holder = new ArrayList<Integer>();
- int read = inflater.read();
-
- while (read != -1)
- {
- holder.add(read);
- read = inflater.read();
- }
-
- byte[] result = new byte[holder.size()];
-
- for (int i = 0; i < result.length; i++)
- {
- result[i] = holder.get(i).byteValue();
- }
-
- String txt = new String(result);
-
- assertEquals(inputString, txt);
-
- }
-
- public void testInflaterWriter() throws Exception
- {
- String inputString =
"blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
- byte[] input = inputString.getBytes("UTF-8");
- byte[] output = new byte[30];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
-
- byte[] zipBytes = new byte[compressedDataLength];
-
- System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
- ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
-
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
- InflaterWriter writer = new InflaterWriter(byteOutput);
-
- byte[] zipBuffer = new byte[12];
-
- int n = byteInput.read(zipBuffer);
- while (n > 0)
- {
- writer.write(zipBuffer, 0, n);
- n = byteInput.read(zipBuffer);
- }
-
- writer.close();
-
- byte[] outcome = byteOutput.toByteArray();
- String outStr = new String(outcome);
-
- assertEquals(inputString, outStr);
- }
-
- private void compareByteArray(byte[] first, byte[] second, int length)
- {
- for (int i = 0; i < length; i++)
- {
- assertEquals(first[i], second[i]);
- }
- }
-}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/ConcurrentHashSetTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/ConcurrentHashSetTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/ConcurrentHashSetTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,147 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.util;
-
-import java.util.Iterator;
-
-import junit.framework.Assert;
-
-import org.hornetq.tests.util.RandomUtil;
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.ConcurrentHashSet;
-import org.hornetq.utils.ConcurrentSet;
-
-/**
- * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class ConcurrentHashSetTest extends UnitTestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private ConcurrentSet<String> set;
-
- private String element;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testAdd() throws Exception
- {
- Assert.assertTrue(set.add(element));
- Assert.assertFalse(set.add(element));
- }
-
- public void testAddIfAbsent() throws Exception
- {
- Assert.assertTrue(set.addIfAbsent(element));
- Assert.assertFalse(set.addIfAbsent(element));
- }
-
- public void testRemove() throws Exception
- {
- Assert.assertTrue(set.add(element));
-
- Assert.assertTrue(set.remove(element));
- Assert.assertFalse(set.remove(element));
- }
-
- public void testContains() throws Exception
- {
- Assert.assertFalse(set.contains(element));
-
- Assert.assertTrue(set.add(element));
- Assert.assertTrue(set.contains(element));
-
- Assert.assertTrue(set.remove(element));
- Assert.assertFalse(set.contains(element));
- }
-
- public void testSize() throws Exception
- {
- Assert.assertEquals(0, set.size());
-
- Assert.assertTrue(set.add(element));
- Assert.assertEquals(1, set.size());
-
- Assert.assertTrue(set.remove(element));
- Assert.assertEquals(0, set.size());
- }
-
- public void testClear() throws Exception
- {
- Assert.assertTrue(set.add(element));
-
- Assert.assertTrue(set.contains(element));
- set.clear();
- Assert.assertFalse(set.contains(element));
- }
-
- public void testIsEmpty() throws Exception
- {
- Assert.assertTrue(set.isEmpty());
-
- Assert.assertTrue(set.add(element));
- Assert.assertFalse(set.isEmpty());
-
- set.clear();
- Assert.assertTrue(set.isEmpty());
- }
-
- public void testIterator() throws Exception
- {
- set.add(element);
-
- Iterator<String> iterator = set.iterator();
- while (iterator.hasNext())
- {
- String e = iterator.next();
- Assert.assertEquals(element, e);
- }
- }
-
- // TestCase overrides --------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- set = new ConcurrentHashSet<String>();
- element = RandomUtil.randomString();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- set = null;
- element = null;
-
- super.tearDown();
- }
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TimeAndCounterIDGeneratorTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TimeAndCounterIDGeneratorTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TimeAndCounterIDGeneratorTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,197 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.util;
-
-import java.util.concurrent.CountDownLatch;
-
-import junit.framework.Assert;
-
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.ConcurrentHashSet;
-import org.hornetq.utils.TimeAndCounterIDGenerator;
-
-/**
- * A TimeAndCounterIDGeneratorTest
- *
- * @author <a href="mailto:clebert.suconic@jboss.org">Clebert
Suconic</a> Created 24-Sep-08 3:42:25 PM
- */
-public class TimeAndCounterIDGeneratorTest extends UnitTestCase
-{
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testCalculation()
- {
- TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
- long max = 11000;
-
- long lastNr = 0;
-
- for (long i = 0; i < max; i++)
- {
- long seqNr = seq.generateID();
-
- Assert.assertTrue("The sequence generator should aways generate crescent
numbers", seqNr > lastNr);
-
- lastNr = seqNr;
- }
-
- }
-
- public void testCalculationRefresh()
- {
- TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
-
- long id1 = seq.generateID();
- Assert.assertEquals(1, id1 & 0xffff);
- Assert.assertEquals(2, seq.generateID() & 0xffff);
-
- seq.refresh();
-
- long id2 = seq.generateID();
-
- Assert.assertTrue(id2 > id1);
-
- Assert.assertEquals(1, id2 & 0xffff);
-
- }
-
- public void testCalculationOnMultiThread() throws Throwable
- {
- final ConcurrentHashSet<Long> hashSet = new ConcurrentHashSet<Long>();
-
- final TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
-
- System.out.println("Time = " +
TimeAndCounterIDGeneratorTest.hex(System.currentTimeMillis()) + ", " + seq);
-
- final int NUMBER_OF_THREADS = 100;
-
- final int NUMBER_OF_IDS = 10;
-
- final CountDownLatch latchAlign = new CountDownLatch(NUMBER_OF_THREADS);
-
- final CountDownLatch latchStart = new CountDownLatch(1);
-
- class T1 extends Thread
- {
- Throwable e;
-
- @Override
- public void run()
- {
- try
- {
- latchAlign.countDown();
- latchStart.await();
-
- long lastValue = 0l;
- for (int i = 0; i < NUMBER_OF_IDS; i++)
- {
- long value = seq.generateID();
- Assert.assertTrue(TimeAndCounterIDGeneratorTest.hex(value) + "
should be greater than " +
- TimeAndCounterIDGeneratorTest.hex(lastValue) +
- " on seq " +
- seq.toString(), value > lastValue);
- lastValue = value;
-
- hashSet.add(value);
- }
- }
- catch (Throwable e)
- {
- this.e = e;
- }
- }
-
- };
-
- T1[] arrays = new T1[NUMBER_OF_THREADS];
-
- for (int i = 0; i < arrays.length; i++)
- {
- arrays[i] = new T1();
- arrays[i].start();
- }
-
- latchAlign.await();
-
- latchStart.countDown();
-
- for (T1 t : arrays)
- {
- t.join();
- if (t.e != null)
- {
- throw t.e;
- }
- }
-
- Assert.assertEquals(NUMBER_OF_THREADS * NUMBER_OF_IDS, hashSet.size());
-
- hashSet.clear();
-
- }
-
- public void testWrapID() throws Throwable
- {
- final ConcurrentHashSet<Long> hashSet = new
org.hornetq.utils.ConcurrentHashSet<Long>();
-
- TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
-
- System.out.println("Current Time = " +
TimeAndCounterIDGeneratorTest.hex(System.currentTimeMillis()) + " " + seq);
-
- seq.setInternalDate(System.currentTimeMillis() + 10000l); // 10 seconds in the
future
-
- seq.setInternalID(TimeAndCounterIDGenerator.ID_MASK); // 1 ID about to explode
-
- try
- {
- // This is simulating a situation where we generated more than 268 million
messages on the same time interval
- seq.generateID();
- Assert.fail("It was supposed to throw an exception, as the counter was set
to explode on this test");
- }
- catch (Exception e)
- {
- }
-
- seq = new TimeAndCounterIDGenerator();
-
- seq.setInternalDate(System.currentTimeMillis() - 10000l); // 10 seconds in the
past
-
- long timeMark = seq.getInternalTimeMark();
-
- seq.setInternalID(TimeAndCounterIDGenerator.ID_MASK); // 1 ID about to explode
-
- // This is ok... the time portion would be added to the next one generated 10
seconds ago
- seq.generateID();
-
- Assert.assertTrue(TimeAndCounterIDGeneratorTest.hex(timeMark) + " < "
+
-
TimeAndCounterIDGeneratorTest.hex(seq.getInternalTimeMark()),
- timeMark < seq.getInternalTimeMark());
- }
-
- private static String hex(final long value)
- {
- return String.format("%1$X", value);
- }
-
-}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesConversionTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesConversionTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesConversionTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,364 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.util;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.hornetq.api.core.PropertyConversionException;
-import org.hornetq.api.core.SimpleString;
-import org.hornetq.tests.util.RandomUtil;
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.TypedProperties;
-
-/**
- * A TypedPropertiesConversionTest
- *
- * @author jmesnil
- *
- *
- */
-public class TypedPropertiesConversionTest extends TestCase
-{
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private TypedProperties props;
-
- private SimpleString key;
-
- private final SimpleString unknownKey = new
SimpleString("this.key.is.never.used");
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- key = RandomUtil.randomSimpleString();
- props = new TypedProperties();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- key = null;
- props = null;
-
- super.tearDown();
- }
-
- public void testBooleanProperty() throws Exception
- {
- Boolean val = RandomUtil.randomBoolean();
- props.putBooleanProperty(key, val);
-
- Assert.assertEquals(val, props.getBooleanProperty(key));
- Assert.assertEquals(new SimpleString(Boolean.toString(val)),
props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Boolean.toString(val)));
- Assert.assertEquals(val, props.getBooleanProperty(key));
-
- try
- {
- props.putByteProperty(key, RandomUtil.randomByte());
- props.getBooleanProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- Assert.assertFalse(props.getBooleanProperty(unknownKey));
- }
-
- public void testCharProperty() throws Exception
- {
- Character val = RandomUtil.randomChar();
- props.putCharProperty(key, val);
-
- Assert.assertEquals(val, props.getCharProperty(key));
- Assert.assertEquals(new SimpleString(Character.toString(val)),
props.getSimpleStringProperty(key));
-
- try
- {
- props.putByteProperty(key, RandomUtil.randomByte());
- props.getCharProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- try
- {
- props.getCharProperty(unknownKey);
- Assert.fail();
- }
- catch (NullPointerException e)
- {
- }
- }
-
- public void testByteProperty() throws Exception
- {
- Byte val = RandomUtil.randomByte();
- props.putByteProperty(key, val);
-
- Assert.assertEquals(val, props.getByteProperty(key));
- Assert.assertEquals(new SimpleString(Byte.toString(val)),
props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Byte.toString(val)));
- Assert.assertEquals(val, props.getByteProperty(key));
-
- try
- {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getByteProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- try
- {
- props.getByteProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e)
- {
- }
- }
-
- public void testIntProperty() throws Exception
- {
- Integer val = RandomUtil.randomInt();
- props.putIntProperty(key, val);
-
- Assert.assertEquals(val, props.getIntProperty(key));
- Assert.assertEquals(new SimpleString(Integer.toString(val)),
props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Integer.toString(val)));
- Assert.assertEquals(val, props.getIntProperty(key));
-
- Byte byteVal = RandomUtil.randomByte();
- props.putByteProperty(key, byteVal);
- Assert.assertEquals(Integer.valueOf(byteVal), props.getIntProperty(key));
-
- try
- {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getIntProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- try
- {
- props.getIntProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e)
- {
- }
- }
-
- public void testLongProperty() throws Exception
- {
- Long val = RandomUtil.randomLong();
- props.putLongProperty(key, val);
-
- Assert.assertEquals(val, props.getLongProperty(key));
- Assert.assertEquals(new SimpleString(Long.toString(val)),
props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Long.toString(val)));
- Assert.assertEquals(val, props.getLongProperty(key));
-
- Byte byteVal = RandomUtil.randomByte();
- props.putByteProperty(key, byteVal);
- Assert.assertEquals(Long.valueOf(byteVal), props.getLongProperty(key));
-
- Short shortVal = RandomUtil.randomShort();
- props.putShortProperty(key, shortVal);
- Assert.assertEquals(Long.valueOf(shortVal), props.getLongProperty(key));
-
- Integer intVal = RandomUtil.randomInt();
- props.putIntProperty(key, intVal);
- Assert.assertEquals(Long.valueOf(intVal), props.getLongProperty(key));
-
- try
- {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getLongProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- try
- {
- props.getLongProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e)
- {
- }
- }
-
- public void testDoubleProperty() throws Exception
- {
- Double val = RandomUtil.randomDouble();
- props.putDoubleProperty(key, val);
-
- Assert.assertEquals(val, props.getDoubleProperty(key));
- Assert.assertEquals(new SimpleString(Double.toString(val)),
props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Double.toString(val)));
- Assert.assertEquals(val, props.getDoubleProperty(key));
-
- try
- {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getDoubleProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- try
- {
- props.getDoubleProperty(unknownKey);
- Assert.fail();
- }
- catch (Exception e)
- {
- }
- }
-
- public void testFloatProperty() throws Exception
- {
- Float val = RandomUtil.randomFloat();
- props.putFloatProperty(key, val);
-
- Assert.assertEquals(val, props.getFloatProperty(key));
- Assert.assertEquals(Double.valueOf(val), props.getDoubleProperty(key));
- Assert.assertEquals(new SimpleString(Float.toString(val)),
props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Float.toString(val)));
- Assert.assertEquals(val, props.getFloatProperty(key));
-
- try
- {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getFloatProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- try
- {
- props.getFloatProperty(unknownKey);
- Assert.fail();
- }
- catch (Exception e)
- {
- }
- }
-
- public void testShortProperty() throws Exception
- {
- Short val = RandomUtil.randomShort();
- props.putShortProperty(key, val);
-
- Assert.assertEquals(val, props.getShortProperty(key));
- Assert.assertEquals(Integer.valueOf(val), props.getIntProperty(key));
- Assert.assertEquals(new SimpleString(Short.toString(val)),
props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Short.toString(val)));
- Assert.assertEquals(val, props.getShortProperty(key));
-
- Byte byteVal = RandomUtil.randomByte();
- props.putByteProperty(key, byteVal);
- Assert.assertEquals(Short.valueOf(byteVal), props.getShortProperty(key));
-
- try
- {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getShortProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- try
- {
- props.getShortProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e)
- {
- }
- }
-
- public void testSimpleStringProperty() throws Exception
- {
- SimpleString strVal = RandomUtil.randomSimpleString();
- props.putSimpleStringProperty(key, strVal);
- Assert.assertEquals(strVal, props.getSimpleStringProperty(key));
- }
-
- public void testBytesProperty() throws Exception
- {
- byte[] val = RandomUtil.randomBytes();
- props.putBytesProperty(key, val);
-
- UnitTestCase.assertEqualsByteArrays(val, props.getBytesProperty(key));
-
- try
- {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getBytesProperty(key);
- Assert.fail();
- }
- catch (PropertyConversionException e)
- {
- }
-
- Assert.assertNull(props.getBytesProperty(unknownKey));
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/TypedPropertiesTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,264 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.util;
-
-import java.util.Iterator;
-
-import junit.framework.Assert;
-
-import org.hornetq.api.core.HornetQBuffer;
-import org.hornetq.api.core.HornetQBuffers;
-import org.hornetq.api.core.SimpleString;
-import org.hornetq.tests.util.RandomUtil;
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.TypedProperties;
-
-/**
- * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class TypedPropertiesTest extends UnitTestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- private static void assertEqualsTypeProperties(final TypedProperties expected, final
TypedProperties actual)
- {
- Assert.assertNotNull(expected);
- Assert.assertNotNull(actual);
- Assert.assertEquals(expected.getEncodeSize(), actual.getEncodeSize());
- Assert.assertEquals(expected.getPropertyNames(), actual.getPropertyNames());
- Iterator<SimpleString> iterator = actual.getPropertyNames().iterator();
- while (iterator.hasNext())
- {
- SimpleString key = iterator.next();
- Object expectedValue = expected.getProperty(key);
- Object actualValue = actual.getProperty(key);
- if (expectedValue instanceof byte[] && actualValue instanceof byte[])
- {
- byte[] expectedBytes = (byte[])expectedValue;
- byte[] actualBytes = (byte[])actualValue;
- UnitTestCase.assertEqualsByteArrays(expectedBytes, actualBytes);
- }
- else
- {
- Assert.assertEquals(expectedValue, actualValue);
- }
- }
- }
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- private TypedProperties props;
-
- private SimpleString key;
-
- public void testCopyContructor() throws Exception
- {
- props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
-
- TypedProperties copy = new TypedProperties(props);
-
- Assert.assertEquals(props.getEncodeSize(), copy.getEncodeSize());
- Assert.assertEquals(props.getPropertyNames(), copy.getPropertyNames());
-
- Assert.assertTrue(copy.containsProperty(key));
- Assert.assertEquals(props.getProperty(key), copy.getProperty(key));
- }
-
- public void testRemove() throws Exception
- {
- props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
-
- Assert.assertTrue(props.containsProperty(key));
- Assert.assertNotNull(props.getProperty(key));
-
- props.removeProperty(key);
-
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- public void testClear() throws Exception
- {
- props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
-
- Assert.assertTrue(props.containsProperty(key));
- Assert.assertNotNull(props.getProperty(key));
-
- props.clear();
-
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- public void testKey() throws Exception
- {
- props.putBooleanProperty(key, true);
- boolean bool = (Boolean)props.getProperty(key);
- Assert.assertEquals(true, bool);
-
- props.putCharProperty(key, 'a');
- char c = (Character)props.getProperty(key);
- Assert.assertEquals('a', c);
- }
-
- public void testGetPropertyOnEmptyProperties() throws Exception
- {
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- public void testRemovePropertyOnEmptyProperties() throws Exception
- {
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.removeProperty(key));
- }
-
- public void testNullProperty() throws Exception
- {
- props.putSimpleStringProperty(key, null);
- Assert.assertTrue(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- public void testBytesPropertyWithNull() throws Exception
- {
- props.putBytesProperty(key, null);
-
- Assert.assertTrue(props.containsProperty(key));
- byte[] bb = (byte[])props.getProperty(key);
- Assert.assertNull(bb);
- }
-
- public void testTypedProperties() throws Exception
- {
- SimpleString longKey = RandomUtil.randomSimpleString();
- long longValue = RandomUtil.randomLong();
- SimpleString simpleStringKey = RandomUtil.randomSimpleString();
- SimpleString simpleStringValue = RandomUtil.randomSimpleString();
- TypedProperties otherProps = new TypedProperties();
- otherProps.putLongProperty(longKey, longValue);
- otherProps.putSimpleStringProperty(simpleStringKey, simpleStringValue);
-
- props.putTypedProperties(otherProps);
-
- long ll = props.getLongProperty(longKey);
- Assert.assertEquals(longValue, ll);
- SimpleString ss = props.getSimpleStringProperty(simpleStringKey);
- Assert.assertEquals(simpleStringValue, ss);
- }
-
- public void testEmptyTypedProperties() throws Exception
- {
- Assert.assertEquals(0, props.getPropertyNames().size());
-
- props.putTypedProperties(new TypedProperties());
-
- Assert.assertEquals(0, props.getPropertyNames().size());
- }
-
- public void testNullTypedProperties() throws Exception
- {
- Assert.assertEquals(0, props.getPropertyNames().size());
-
- props.putTypedProperties(null);
-
- Assert.assertEquals(0, props.getPropertyNames().size());
- }
-
- public void testEncodeDecode() throws Exception
- {
- props.putByteProperty(RandomUtil.randomSimpleString(), RandomUtil.randomByte());
- props.putBytesProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBytes());
- props.putBytesProperty(RandomUtil.randomSimpleString(), null);
- props.putBooleanProperty(RandomUtil.randomSimpleString(),
RandomUtil.randomBoolean());
- props.putShortProperty(RandomUtil.randomSimpleString(), RandomUtil.randomShort());
- props.putIntProperty(RandomUtil.randomSimpleString(), RandomUtil.randomInt());
- props.putLongProperty(RandomUtil.randomSimpleString(), RandomUtil.randomLong());
- props.putFloatProperty(RandomUtil.randomSimpleString(), RandomUtil.randomFloat());
- props.putDoubleProperty(RandomUtil.randomSimpleString(),
RandomUtil.randomDouble());
- props.putCharProperty(RandomUtil.randomSimpleString(), RandomUtil.randomChar());
- props.putSimpleStringProperty(RandomUtil.randomSimpleString(),
RandomUtil.randomSimpleString());
- props.putSimpleStringProperty(RandomUtil.randomSimpleString(), null);
- SimpleString keyToRemove = RandomUtil.randomSimpleString();
- props.putSimpleStringProperty(keyToRemove, RandomUtil.randomSimpleString());
-
- HornetQBuffer buffer = HornetQBuffers.dynamicBuffer(1024);
- props.encode(buffer);
-
- Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
-
- TypedProperties decodedProps = new TypedProperties();
- decodedProps.decode(buffer);
-
- TypedPropertiesTest.assertEqualsTypeProperties(props, decodedProps);
-
- buffer.clear();
-
- // After removing a property, you should still be able to encode the Property
- props.removeProperty(keyToRemove);
- props.encode(buffer);
-
- Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
- }
-
- public void testEncodeDecodeEmpty() throws Exception
- {
- TypedProperties emptyProps = new TypedProperties();
-
- HornetQBuffer buffer = HornetQBuffers.dynamicBuffer(1024);
- emptyProps.encode(buffer);
-
- Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
-
- TypedProperties decodedProps = new TypedProperties();
- decodedProps.decode(buffer);
-
- TypedPropertiesTest.assertEqualsTypeProperties(emptyProps, decodedProps);
- }
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- props = new TypedProperties();
- key = RandomUtil.randomSimpleString();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- key = null;
- props = null;
-
- super.tearDown();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/XMLUtilTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/XMLUtilTest.java 2012-01-12
12:10:11 UTC (rev 12016)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/XMLUtilTest.java 2012-01-12
12:10:54 UTC (rev 12017)
@@ -1,258 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat 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.hornetq.tests.unit.util;
-
-import junit.framework.Assert;
-
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.XMLUtil;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * @author <a href="mailto:ovidiu@feodorov.com">Ovidiu
Feodorov</a>
- * @version <tt>$Revision$</tt>
- */
-public class XMLUtilTest extends UnitTestCase
-{
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testGetTextContext_1() throws Exception
- {
- String document = "<blah>foo</blah>";
-
- Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
-
- Assert.assertEquals("foo", org.hornetq.utils.XMLUtil.getTextContent(e));
- }
-
- public void testGetTextContext_2() throws Exception
- {
- String document = "<blah
someattribute=\"somevalue\">foo</blah>";
-
- Element e = XMLUtil.stringToElement(document);
-
- Assert.assertEquals("foo", org.hornetq.utils.XMLUtil.getTextContent(e));
- }
-
- public void testGetTextContext_3() throws Exception
- {
- String document = "<blah
someattribute=\"somevalue\"><a/></blah>";
-
- Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
-
- String s = org.hornetq.utils.XMLUtil.getTextContent(e);
-
- Element subelement = org.hornetq.utils.XMLUtil.stringToElement(s);
-
- Assert.assertEquals("a", subelement.getNodeName());
- }
-
- public void testGetTextContext_4() throws Exception
- {
- String document = "<blah
someattribute=\"somevalue\"><a></a></blah>";
-
- Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
-
- String s = org.hornetq.utils.XMLUtil.getTextContent(e);
-
- Element subelement = org.hornetq.utils.XMLUtil.stringToElement(s);
-
- Assert.assertEquals("a", subelement.getNodeName());
- }
-
- public void testGetTextContext_5() throws Exception
- {
- String document = "<blah
someattribute=\"somevalue\"><a><b/></a></blah>";
-
- Element e = org.hornetq.utils.XMLUtil.stringToElement(document);
-
- String s = org.hornetq.utils.XMLUtil.getTextContent(e);
-
- Element subelement = org.hornetq.utils.XMLUtil.stringToElement(s);
-
- Assert.assertEquals("a", subelement.getNodeName());
- NodeList nl = subelement.getChildNodes();
-
- // try to find <b>
- boolean found = false;
- for (int i = 0; i < nl.getLength(); i++)
- {
- Node n = nl.item(i);
- if ("b".equals(n.getNodeName()))
- {
- found = true;
- }
- }
- Assert.assertTrue(found);
- }
-
- public void testEquivalent_1() throws Exception
- {
- String s = "<a/>";
- String s2 = "<a/>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
org.hornetq.utils.XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_2() throws Exception
- {
- String s = "<a></a>";
- String s2 = "<a/>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
org.hornetq.utils.XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_3() throws Exception
- {
- String s = "<a attr1=\"val1\"
attr2=\"val2\"/>";
- String s2 = "<a attr2=\"val2\"/>";
-
- try
- {
-
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
- XMLUtil.stringToElement(s2));
- Assert.fail("this should throw exception");
- }
- catch (IllegalArgumentException e)
- {
- // OK
- e.printStackTrace();
- }
- }
-
- public void testEquivalent_4() throws Exception
- {
- String s = "<a attr1=\"val1\"
attr2=\"val2\"/>";
- String s2 = "<a attr2=\"val2\"
attr1=\"val1\"/>";
-
-
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
-
org.hornetq.utils.XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_5() throws Exception
- {
- String s = "<a><b/></a>";
- String s2 = "<a><b/></a>";
-
-
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
-
org.hornetq.utils.XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_6() throws Exception
- {
- String s = "<enclosing><a attr1=\"val1\"
attr2=\"val2\"/></enclosing>";
- String s2 = "<enclosing><a attr2=\"val2\"
attr1=\"val1\"/></enclosing>";
-
- org.hornetq.utils.XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
-
org.hornetq.utils.XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_7() throws Exception
- {
- String s = "<a><b/><c/></a>";
- String s2 = "<a><c/><b/></a>";
-
- try
- {
-
org.hornetq.utils.XMLUtil.assertEquivalent(org.hornetq.utils.XMLUtil.stringToElement(s),
-
org.hornetq.utils.XMLUtil.stringToElement(s2));
- Assert.fail("this should throw exception");
- }
- catch (IllegalArgumentException e)
- {
- // OK
- e.printStackTrace();
- }
- }
-
- public void testEquivalent_8() throws Exception
- {
- String s = "<a><!-- some comment --><b/><!--some other
comment --><c/><!-- blah --></a>";
- String s2 = "<a><b/><!--blah
blah--><c/></a>";
-
- org.hornetq.utils.XMLUtil.assertEquivalent(XMLUtil.stringToElement(s),
-
org.hornetq.utils.XMLUtil.stringToElement(s2));
- }
-
- public void testElementToString_1() throws Exception
- {
- String s = "<a b=\"something\">somethingelse</a>";
- Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
- String tostring = org.hornetq.utils.XMLUtil.elementToString(e);
- Element convertedAgain = org.hornetq.utils.XMLUtil.stringToElement(tostring);
- org.hornetq.utils.XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testElementToString_2() throws Exception
- {
- String s = "<a b=\"something\"></a>";
- Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
- String tostring = XMLUtil.elementToString(e);
- Element convertedAgain = XMLUtil.stringToElement(tostring);
- XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testElementToString_3() throws Exception
- {
- String s = "<a b=\"something\"/>";
- Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
- String tostring = XMLUtil.elementToString(e);
- Element convertedAgain = org.hornetq.utils.XMLUtil.stringToElement(tostring);
- org.hornetq.utils.XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testElementToString_4() throws Exception
- {
- String s = "<a><![CDATA[somedata]]></a>";
- Element e = org.hornetq.utils.XMLUtil.stringToElement(s);
- String tostring = XMLUtil.elementToString(e);
- Element convertedAgain = org.hornetq.utils.XMLUtil.stringToElement(tostring);
- org.hornetq.utils.XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testReplaceSystemProperties()
- {
- String before = "<configuration>\n" + " <test
name=\"${sysprop1}\">content1</test>\n"
- + " <test
name=\"test2\">content2</test>\n"
- + " <test
name=\"test3\">content3</test>\n"
- + " <test
name=\"test4\">${sysprop2}</test>\n"
- + " <test
name=\"test5\">content5</test>\n"
- + " <test
name=\"test6\">content6</test>\n"
- + "</configuration>";
- String after = "<configuration>\n" + " <test
name=\"test1\">content1</test>\n"
- + " <test
name=\"test2\">content2</test>\n"
- + " <test
name=\"test3\">content3</test>\n"
- + " <test
name=\"test4\">content4</test>\n"
- + " <test
name=\"test5\">content5</test>\n"
- + " <test
name=\"test6\">content6</test>\n"
- + "</configuration>";
- System.setProperty("sysprop1", "test1");
- System.setProperty("sysprop2", "content4");
- String replaced = org.hornetq.utils.XMLUtil.replaceSystemProps(before);
- Assert.assertEquals(after, replaced);
- }
-
- public void testStripCDATA() throws Exception
- {
- String xml = "<![CDATA[somedata]]>";
- String stripped = XMLUtil.stripCDATA(xml);
-
- Assert.assertEquals("somedata", stripped);
- }
-
-}