You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pubscribe-dev@ws.apache.org by ip...@apache.org on 2005/05/05 01:18:16 UTC

svn commit: r168210 - in /incubator/hermes/trunk/src: java/org/apache/ws/notification/topics/impl/ test/org/apache/ws/notification/topics/impl/

Author: ips
Date: Wed May  4 16:18:16 2005
New Revision: 168210

URL: http://svn.apache.org/viewcvs?rev=168210&view=rev
Log:
new/expanded unit tests

Added:
    incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluatorTestCase.java
    incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluatorTestCase.java
Modified:
    incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java
    incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java

Modified: incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java?rev=168210&r1=168209&r2=168210&view=diff
==============================================================================
--- incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java (original)
+++ incubator/hermes/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java Wed May  4 16:18:16 2005
@@ -33,10 +33,9 @@
     private String m_name = "TopicSpace";
     private Map m_rootTopicMap = new HashMap();
 
-
     public TopicSpaceImpl( String targetNs )
     {
-        m_targetNs = targetNs;
+        m_targetNs = targetNs != null ? targetNs : "";
     }
 
     public String getTargetNamespace()

Added: incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluatorTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluatorTestCase.java?rev=168210&view=auto
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluatorTestCase.java (added)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/ConcreteTopicExpressionEvaluatorTestCase.java Wed May  4 16:18:16 2005
@@ -0,0 +1,142 @@
+/*=============================================================================*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.notification.topics.impl;
+
+import junit.framework.TestCase;
+import org.apache.ws.notification.base.impl.XmlBeansTopicExpression;
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
+import org.apache.ws.notification.topics.TopicExpressionEvaluator;
+import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
+import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+
+/**
+ * TODO
+ */
+public class ConcreteTopicExpressionEvaluatorTestCase extends TestCase
+{
+
+    private static final String NSURI1 = "http://ns1.com/";
+    private static final String NSPREFIX1 = "ns1";
+    private static final String NSURI2 = "http://ns2.com/";
+    private static final String NSPREFIX2 = "ns2";
+
+    private TopicExpressionEvaluator m_evaluator;
+    private TopicSpaceSet m_topicSpaceSet;
+
+    protected void setUp() throws Exception
+    {
+        m_evaluator = new ConcreteTopicExpressionEvaluator();
+        m_topicSpaceSet = new TopicSpaceSetImpl( true );
+        TopicSpace topicSpace0 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( "" ) );
+        topicSpace0.addTopic( "celebs" );
+        TopicSpace topicSpace1 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( NSURI1 ) );
+        Topic sportsTopic = topicSpace1.addTopic( "sports" );
+        Topic tennisTopic = sportsTopic.addTopic( "tennis" );
+        tennisTopic.addTopic( "college" );
+        Topic footballTopic = sportsTopic.addTopic( "football" );
+        footballTopic.addTopic( "college" );
+        Topic gamesTopic = topicSpace1.addTopic( "games" );
+        gamesTopic.addTopic( "monopoly" );
+        gamesTopic.addTopic( "chess" );
+    }
+
+    public void testEvaluateValid() throws Exception
+    {
+        Topic[] resultTopics = evaluate( "celebs" );
+        assertEquals( 1, resultTopics.length );
+
+        resultTopics = evaluate( NSPREFIX1 + ":sports" );
+        assertEquals( 1, resultTopics.length );
+        assertContainsTopic( resultTopics, "sports" );
+
+        resultTopics = evaluate( NSPREFIX1 + ":bands" );
+        assertEquals( 0, resultTopics.length );
+
+        resultTopics = evaluate( NSPREFIX1 + ":sports/tennis" );
+        assertEquals( 1, resultTopics.length );
+        assertContainsTopic( resultTopics, "tennis" );
+
+        resultTopics = evaluate( NSPREFIX1 + ":sports/baseball" );
+        assertEquals( 0, resultTopics.length );
+
+        ((TopicSpaceSetImpl)m_topicSpaceSet).setFixed( false );
+        resultTopics = evaluate( NSPREFIX1 + ":sports/baseball" );
+        assertEquals( 0, resultTopics.length );
+    }
+
+    public void testEvaluateInvalid() throws Exception
+    {
+        // check expressions that do not conform to the Concrete Topic Expression grammar defined by the WS-Topics spec
+        assertExpressionIsInvalid( NSPREFIX1 + ":" );
+        assertExpressionIsInvalid( ":sports" );
+        assertExpressionIsInvalid( NSPREFIX1 + "::sports" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports:tennis" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports/*" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports/." );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports//tennis" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports|" + NSPREFIX2 + ":bands" );
+    }
+
+    private void assertExpressionIsInvalid( String expr )
+            throws Exception
+    {
+        try
+        {
+            evaluate( expr );
+            fail();
+        }
+        catch ( InvalidTopicExpressionException itee )
+        {
+            // success!
+        }
+    }
+
+    private void assertContainsTopic( Topic[] topics, String name )
+    {
+        boolean foundIt = false;
+        for ( int i = 0; i < topics.length; i++ )
+        {
+            if ( topics[i].getName().equals( name ) )
+            {
+                foundIt = true;
+            }
+        }
+        assertTrue( foundIt );
+    }
+
+    private Topic[] evaluate( String expr ) throws Exception
+    {
+        TopicExpressionType topicExpr = ( (TopicExpressionDocument) XmlObject.Factory.parse(
+                "<wsnt:TopicExpression xmlns:wsnt='http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd' " +
+                "xmlns:" +
+                NSPREFIX1 +
+                "='" +
+                NSURI1 +
+                "' xmlns:" +
+                NSPREFIX2 +
+                "='" +
+                NSURI2 +
+                "' Dialect='http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Full'>" +
+                expr +
+                "</wsnt:TopicExpression>" ) ).getTopicExpression();
+        return m_evaluator.evaluate( m_topicSpaceSet, new XmlBeansTopicExpression( topicExpr ) );
+    }
+
+}

Modified: incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java?rev=168210&r1=168209&r2=168210&view=diff
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java (original)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/FullTopicExpressionEvaluatorTestCase.java Wed May  4 16:18:16 2005
@@ -44,6 +44,8 @@
     {
         m_evaluator = new FullTopicExpressionEvaluator();
         m_topicSpaceSet = new TopicSpaceSetImpl( true );
+        TopicSpace topicSpace0 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( "" ) );
+        topicSpace0.addTopic( "celebs" );
         TopicSpace topicSpace1 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( NSURI1 ) );
         Topic sportsTopic = topicSpace1.addTopic( "sports" );
         Topic tennisTopic = sportsTopic.addTopic( "tennis" );
@@ -61,7 +63,10 @@
 
     public void testEvaluateSimple() throws Exception
     {
-        Topic[] resultTopics = evaluate( NSPREFIX1 + ":sports" );
+        Topic[] resultTopics = evaluate( "celebs" );
+        assertEquals( 1, resultTopics.length );
+
+        resultTopics = evaluate( NSPREFIX1 + ":sports" );
         assertEquals( 1, resultTopics.length );
         assertContainsTopic( resultTopics, "sports" );
 
@@ -157,13 +162,17 @@
 
     public void testEvaluateInvalid() throws Exception
     {
-        // first check expressions do not conform to the Full Topic Expression grammar defined by the WS-Topics spec
+        // first check expressions that do not conform to the Full Topic Expression grammar defined by the WS-Topics spec
+        assertExpressionIsInvalid( NSPREFIX1 + ":" );
+        assertExpressionIsInvalid( ":sports" );
+        assertExpressionIsInvalid( NSPREFIX1 + "::sports" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports:tennis" );
         assertExpressionIsInvalid( NSPREFIX1 + ":." );
         assertExpressionIsInvalid( NSPREFIX1 + "://." );
         assertExpressionIsInvalid( NSPREFIX1 + ":sports///tennis" );
         // now check expressions that violate other validity constraints defined by the spec
-        assertExpressionIsInvalid( NSPREFIX1 + ":sports/baseball" );
-        assertExpressionIsInvalid( NSPREFIX1 + ":bands|" + NSPREFIX2 + ":bands" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports/baseball" ); // fixed topic set but empty result set
+        assertExpressionIsInvalid( NSPREFIX1 + ":bands|" + NSPREFIX2 + ":bands" ); // undefined root topic
     }
 
     private void assertExpressionIsInvalid( String expr )
@@ -196,7 +205,7 @@
     private Topic[] evaluate( String expr ) throws Exception
     {
         TopicExpressionType topicExpr = ( (TopicExpressionDocument) XmlObject.Factory.parse(
-                "<TopicExpression xmlns='http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd' " +
+                "<wsnt:TopicExpression xmlns:wsnt='http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd' " +
                 "xmlns:" +
                 NSPREFIX1 +
                 "='" +
@@ -207,7 +216,7 @@
                 NSURI2 +
                 "' Dialect='http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Full'>" +
                 expr +
-                "</TopicExpression>" ) ).getTopicExpression();
+                "</wsnt:TopicExpression>" ) ).getTopicExpression();
         return m_evaluator.evaluate( m_topicSpaceSet, new XmlBeansTopicExpression( topicExpr ) );
     }
 

Added: incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluatorTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluatorTestCase.java?rev=168210&view=auto
==============================================================================
--- incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluatorTestCase.java (added)
+++ incubator/hermes/trunk/src/test/org/apache/ws/notification/topics/impl/SimpleTopicExpressionEvaluatorTestCase.java Wed May  4 16:18:16 2005
@@ -0,0 +1,132 @@
+/*=============================================================================*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+package org.apache.ws.notification.topics.impl;
+
+import junit.framework.TestCase;
+import org.apache.ws.notification.base.impl.XmlBeansTopicExpression;
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
+import org.apache.ws.notification.topics.TopicExpressionEvaluator;
+import org.apache.ws.notification.topics.topicexpression.impl.InvalidTopicExpressionException;
+import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+
+/**
+ * TODO
+ */
+public class SimpleTopicExpressionEvaluatorTestCase extends TestCase
+{
+
+    private static final String NSURI1 = "http://ns1.com/";
+    private static final String NSPREFIX1 = "ns1";
+    private static final String NSURI2 = "http://ns2.com/";
+    private static final String NSPREFIX2 = "ns2";
+
+    private TopicExpressionEvaluator m_evaluator;
+    private TopicSpaceSet m_topicSpaceSet;
+
+    protected void setUp() throws Exception
+    {
+        m_evaluator = new SimpleTopicExpressionEvaluator();
+        m_topicSpaceSet = new TopicSpaceSetImpl( true );
+        TopicSpace topicSpace0 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( "" ) );
+        topicSpace0.addTopic( "celebs" );
+        TopicSpace topicSpace1 = m_topicSpaceSet.addTopicSpace( new TopicSpaceImpl( NSURI1 ) );
+        Topic sportsTopic = topicSpace1.addTopic( "sports" );
+        Topic tennisTopic = sportsTopic.addTopic( "tennis" );
+        tennisTopic.addTopic( "college" );
+        Topic footballTopic = sportsTopic.addTopic( "football" );
+        footballTopic.addTopic( "college" );
+        Topic gamesTopic = topicSpace1.addTopic( "games" );
+        gamesTopic.addTopic( "monopoly" );
+        gamesTopic.addTopic( "chess" );
+    }
+
+    public void testEvaluateValid() throws Exception
+    {
+        Topic[] resultTopics = evaluate( "celebs" );
+        assertEquals( 1, resultTopics.length );
+
+        resultTopics = evaluate( NSPREFIX1 + ":sports" );
+        assertEquals( 1, resultTopics.length );
+        assertContainsTopic( resultTopics, "sports" );
+
+        resultTopics = evaluate( NSPREFIX1 + ":bands" );
+        assertEquals( 0, resultTopics.length );
+    }
+
+    public void testEvaluateInvalid() throws Exception
+    {
+        // check expressions that do not conform to the Simple Topic Expression grammar defined by the WS-Topics spec
+        assertExpressionIsInvalid( NSPREFIX1 + ":" );
+        assertExpressionIsInvalid( ":sports" );
+        assertExpressionIsInvalid( NSPREFIX1 + "::sports" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports:tennis" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports/tennis" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports/*" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports/." );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports//tennis" );
+        assertExpressionIsInvalid( NSPREFIX1 + ":sports|" + NSPREFIX2 + ":bands" );
+    }
+
+    private void assertExpressionIsInvalid( String expr )
+            throws Exception
+    {
+        try
+        {
+            evaluate( expr );
+            fail();
+        }
+        catch ( InvalidTopicExpressionException itee )
+        {
+            // success!
+        }
+    }
+
+    private void assertContainsTopic( Topic[] topics, String name )
+    {
+        boolean foundIt = false;
+        for ( int i = 0; i < topics.length; i++ )
+        {
+            if ( topics[i].getName().equals( name ) )
+            {
+                foundIt = true;
+            }
+        }
+        assertTrue( foundIt );
+    }
+
+    private Topic[] evaluate( String expr ) throws Exception
+    {
+        TopicExpressionType topicExpr = ( (TopicExpressionDocument) XmlObject.Factory.parse(
+                "<wsnt:TopicExpression xmlns:wsnt='http://docs.oasis-open.org/wsn/2004/06/wsn-WS-BaseNotification-1.2-draft-01.xsd' " +
+                "xmlns:" +
+                NSPREFIX1 +
+                "='" +
+                NSURI1 +
+                "' xmlns:" +
+                NSPREFIX2 +
+                "='" +
+                NSURI2 +
+                "' Dialect='http://docs.oasis-open.org/wsn/2004/06/TopicExpression/Full'>" +
+                expr +
+                "</wsnt:TopicExpression>" ) ).getTopicExpression();
+        return m_evaluator.evaluate( m_topicSpaceSet, new XmlBeansTopicExpression( topicExpr ) );
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: hermes-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: hermes-dev-help@ws.apache.org