Author: veithen
Date: Fri Aug 15 10:35:48 2008
New Revision: 686289

URL: http://svn.apache.org/viewvc?rev=686289&view=rev
Log:
Transport test kit: Added feature to exclude individual or groups of test cases.

Added:
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/AndExpression.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/EqualityExpression.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpression.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpressionParser.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/NotExpression.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/OrExpression.java
Removed:
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/listener/NameBuilder.java
Modified:
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MimeClient.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MultipartClient.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuite.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/name/NameUtils.java
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/tests/TransportTestCase.java

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java?rev=686289&r1=686288&r2=686289&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
 Fri Aug 15 10:35:48 2008
@@ -27,6 +27,7 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.synapse.transport.testkit.AdapterUtils;
 import org.apache.synapse.transport.testkit.SimpleTransportDescriptionFactory;
 import org.apache.synapse.transport.testkit.TestEnvironment;
 import org.apache.synapse.transport.testkit.TransportDescriptionFactory;
@@ -38,8 +39,18 @@
 import org.apache.synapse.transport.testkit.server.axis2.AxisServer;
 
 public class MailTransportListenerTest extends TestCase {
-    public static TestSuite suite() {
+    public static TestSuite suite() throws Exception {
         TransportTestSuite<TestEnvironment> suite = new 
TransportTestSuite<TestEnvironment>();
+        
+        // TODO: these test don't work; need more analysis why this is so
+        suite.addExclude("(&(messageType=SOAP12)(data=Latin1))");
+        suite.addExclude("(&(messageType=POX)(data=Latin1))");
+        suite.addExclude("(&(client=multipart)(data=Latin1))");
+        suite.addExclude("(&(client=multipart)(messageType=POX))");
+        suite.addExclude("(test=AsyncSwA)");
+        suite.addExclude("(test=AsyncBinary)");
+        suite.addExclude("(&(test=AsyncTextPlain)(!(data=ASCII)))");
+        
         TransportDescriptionFactory tdf =
             new SimpleTransportDescriptionFactory(MailConstants.TRANSPORT_NAME,
                     MailTransportListener.class, MailTransportSender.class);
@@ -50,21 +61,11 @@
         clients.add(new MultipartClient());
         for (MailClient client : clients) {
             AsyncTestClient<TestEnvironment,MailChannel,XMLMessage> xmlClient 
= adapt(client, MessageConverter.XML_TO_BYTE);
-            // TODO: SOAP 1.2 tests don't work yet for mail transport
-            suite.addSOAP11Test(null, channel, xmlClient, axisServer, 
ContentTypeMode.TRANSPORT, TransportTestSuite.ASCII_TEST_DATA);
-            suite.addSOAP11Test(null, channel, xmlClient, axisServer, 
ContentTypeMode.TRANSPORT, TransportTestSuite.UTF8_TEST_DATA);
-            // TODO: this test fails when using multipart
-            if (client instanceof MimeClient) {
-                suite.addSOAP11Test(null, channel, xmlClient, axisServer, 
ContentTypeMode.TRANSPORT, TransportTestSuite.LATIN1_TEST_DATA);
-            }
-            // addSOAPTests(strategy, suite);
-            // TODO: POX tests don't work yet for mail transport
-            // addPOXTests(strategy, suite);
-            // Temporarily skip this test until we know why it fails.
-            // addSwATests(strategy, suite);
-            // Temporarily skip the following tests until SYNAPSE-359 is solved
-            // addTextPlainTests(strategy, suite);
-            // addBinaryTest(strategy, suite);
+            suite.addSOAPTests(null, channel, xmlClient, axisServer, 
ContentTypeMode.TRANSPORT);
+            suite.addPOXTests(null, channel, xmlClient, axisServer, 
ContentTypeMode.TRANSPORT);
+            suite.addSwATests(null, channel, client, axisServer);
+            suite.addTextPlainTests(null, channel, AdapterUtils.adapt(client, 
MessageConverter.STRING_TO_BYTE), AdapterUtils.adapt(axisServer, 
MessageConverter.AXIS_TO_STRING), ContentTypeMode.TRANSPORT);
+            suite.addBinaryTest(null, channel, client, 
AdapterUtils.adapt(axisServer, MessageConverter.AXIS_TO_BYTE), 
ContentTypeMode.TRANSPORT);
         }
         return suite;
     }

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MimeClient.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MimeClient.java?rev=686289&r1=686288&r2=686289&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MimeClient.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MimeClient.java
 Fri Aug 15 10:35:48 2008
@@ -22,6 +22,9 @@
 import javax.activation.DataHandler;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.synapse.transport.testkit.name.DisplayName;
+
[EMAIL PROTECTED]("mime")
 public class MimeClient extends MailClient {
     @Override
     protected void setupMessage(MimeMessage msg, DataHandler dh) throws 
Exception {

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MultipartClient.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MultipartClient.java?rev=686289&r1=686288&r2=686289&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MultipartClient.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MultipartClient.java
 Fri Aug 15 10:35:48 2008
@@ -24,6 +24,9 @@
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 
+import org.apache.synapse.transport.testkit.name.DisplayName;
+
[EMAIL PROTECTED]("multipart")
 public class MultipartClient extends MailClient {
     @Override
     protected void setupMessage(MimeMessage msg, DataHandler dh) throws 
Exception {

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuite.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuite.java?rev=686289&r1=686288&r2=686289&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuite.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/TransportTestSuite.java
 Fri Aug 15 10:35:48 2008
@@ -19,12 +19,20 @@
 
 package org.apache.synapse.transport.testkit;
 
+import java.text.ParseException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.synapse.transport.testkit.client.AsyncTestClient;
 import 
org.apache.synapse.transport.testkit.client.XMLRequestResponseTestClient;
+import org.apache.synapse.transport.testkit.filter.FilterExpression;
+import org.apache.synapse.transport.testkit.filter.FilterExpressionParser;
 import org.apache.synapse.transport.testkit.listener.AsyncChannel;
 import org.apache.synapse.transport.testkit.listener.ContentTypeMode;
 import org.apache.synapse.transport.testkit.listener.MessageTestData;
@@ -38,6 +46,7 @@
 import org.apache.synapse.transport.testkit.message.RESTMessage.Parameter;
 import org.apache.synapse.transport.testkit.server.AsyncEndpointFactory;
 import org.apache.synapse.transport.testkit.server.EndpointFactory;
+import org.apache.synapse.transport.testkit.tests.TransportTestCase;
 import org.apache.synapse.transport.testkit.tests.async.BinaryTestCase;
 import org.apache.synapse.transport.testkit.tests.async.RESTTestCase;
 import org.apache.synapse.transport.testkit.tests.async.SwATestCase;
@@ -68,6 +77,7 @@
             new Parameter("param", "value2"),
         });
         
+    private final List<FilterExpression> excludes = new 
LinkedList<FilterExpression>();
     private final boolean reuseServer;
     
     public TransportTestSuite(boolean reuseServer) {
@@ -78,6 +88,10 @@
         this(true);
     }
 
+    public void addExclude(String filter) throws ParseException {
+        excludes.add(FilterExpressionParser.parse(filter));
+    }
+
     public <C extends AsyncChannel<? super E>> void addSOAP11Test(E env, C 
channel, AsyncTestClient<? super E,? super C,XMLMessage> client, 
AsyncEndpointFactory<? super E,? super C,MessageData> endpointFactory, 
ContentTypeMode contentTypeMode, MessageTestData data) {
         addTest(new XMLAsyncMessageTestCase<E,C>(env, channel, client, 
endpointFactory, XMLMessageType.SOAP11, contentTypeMode, 
SOAP11Constants.SOAP_11_CONTENT_TYPE, data));
     }
@@ -143,6 +157,20 @@
 //        addTest(new RESTTestCase<E,C>(env, channel, client, endpointFactory, 
restTestMessage2));
     }
 
+    @Override
+    public void addTest(Test test) {
+        if (test instanceof TransportTestCase) {
+            TransportTestCase<?,?,?> ttest = (TransportTestCase<?,?,?>)test;
+            Map<String,String> map = ttest.getNameComponents();
+            for (FilterExpression exclude : excludes) {
+                if (exclude.matches(map)) {
+                    return;
+                }
+            }
+        }
+        super.addTest(test);
+    }
+
 /*
     @Override
     public void run(TestResult result) {

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/AndExpression.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/AndExpression.java?rev=686289&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/AndExpression.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/AndExpression.java
 Fri Aug 15 10:35:48 2008
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.testkit.filter;
+
+import java.util.Map;
+
+public class AndExpression implements FilterExpression {
+    private final FilterExpression[] operands;
+
+    public AndExpression(FilterExpression[] operands) {
+        this.operands = operands;
+    }
+
+    public boolean matches(Map<String,String> map) {
+        for (FilterExpression operand : operands) {
+            if (!operand.matches(map)) {
+                return false;
+            }
+        }
+        return true;
+    }
+}

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/EqualityExpression.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/EqualityExpression.java?rev=686289&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/EqualityExpression.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/EqualityExpression.java
 Fri Aug 15 10:35:48 2008
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.testkit.filter;
+
+import java.util.Map;
+
+public class EqualityExpression implements FilterExpression {
+    private final String key;
+    private final String value;
+    
+    public EqualityExpression(String key, String value) {
+        this.key = key;
+        this.value = value;
+    }
+
+    public boolean matches(Map<String,String> map) {
+        return value.equals(map.get(key));
+    }
+}

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpression.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpression.java?rev=686289&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpression.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpression.java
 Fri Aug 15 10:35:48 2008
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.testkit.filter;
+
+import java.util.Map;
+
+public interface FilterExpression {
+    boolean matches(Map<String,String> map);
+}

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpressionParser.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpressionParser.java?rev=686289&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpressionParser.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/FilterExpressionParser.java
 Fri Aug 15 10:35:48 2008
@@ -0,0 +1,62 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.testkit.filter;
+
+import java.text.ParseException;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.filter.AndNode;
+import org.apache.directory.shared.ldap.filter.EqualityNode;
+import org.apache.directory.shared.ldap.filter.ExprNode;
+import org.apache.directory.shared.ldap.filter.FilterParser;
+import org.apache.directory.shared.ldap.filter.NotNode;
+import org.apache.directory.shared.ldap.filter.OrNode;
+
+public class FilterExpressionParser {
+    private FilterExpressionParser() {}
+    
+    private static FilterExpression[] buildExpressions(List<ExprNode> nodes) {
+        FilterExpression[] result = new FilterExpression[nodes.size()];
+        int i = 0;
+        for (ExprNode node : nodes) {
+            result[i++] = buildExpression(node);
+        }
+        return result;
+    }
+    
+    private static FilterExpression buildExpression(ExprNode node) {
+        if (node instanceof AndNode) {
+            return new 
AndExpression(buildExpressions(((AndNode)node).getChildren()));
+        } else if (node instanceof OrNode) {
+            return new 
OrExpression(buildExpressions(((AndNode)node).getChildren()));
+        } else if (node instanceof NotNode) {
+            return new 
NotExpression(buildExpression(((NotNode)node).getFirstChild()));
+        } else if (node instanceof EqualityNode) {
+            EqualityNode equalityNode = (EqualityNode)node;
+            return new EqualityExpression(equalityNode.getAttribute(), 
equalityNode.getValue().toString());
+        } else {
+            throw new UnsupportedOperationException();
+        }
+    }
+    
+    public static FilterExpression parse(String filter) throws ParseException {
+        return buildExpression(FilterParser.parse(filter));
+    }
+}

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/NotExpression.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/NotExpression.java?rev=686289&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/NotExpression.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/NotExpression.java
 Fri Aug 15 10:35:48 2008
@@ -0,0 +1,34 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.testkit.filter;
+
+import java.util.Map;
+
+public class NotExpression implements FilterExpression {
+    private final FilterExpression operand;
+    
+    public NotExpression(FilterExpression operand) {
+        this.operand = operand;
+    }
+
+    public boolean matches(Map<String,String> map) {
+        return !operand.matches(map);
+    }
+}

Added: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/OrExpression.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/OrExpression.java?rev=686289&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/OrExpression.java
 (added)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/filter/OrExpression.java
 Fri Aug 15 10:35:48 2008
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.transport.testkit.filter;
+
+import java.util.Map;
+
+public class OrExpression implements FilterExpression {
+    private final FilterExpression[] operands;
+
+    public OrExpression(FilterExpression[] operands) {
+        this.operands = operands;
+    }
+
+    public boolean matches(Map<String,String> map) {
+        for (FilterExpression operand : operands) {
+            if (!operand.matches(map)) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/name/NameUtils.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/name/NameUtils.java?rev=686289&r1=686288&r2=686289&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/name/NameUtils.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/name/NameUtils.java
 Fri Aug 15 10:35:48 2008
@@ -20,9 +20,10 @@
 package org.apache.synapse.transport.testkit.name;
 
 import java.lang.reflect.Method;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 import org.apache.synapse.transport.testkit.Adapter;
-import org.apache.synapse.transport.testkit.listener.NameBuilder;
 
 public class NameUtils {
     public static String getName(Object object) {
@@ -36,7 +37,28 @@
         }
     }
     
-    public static void getNameComponents(NameBuilder nameBuilder, Object 
object) {
+    public static Map<String,String> getNameComponents(String rootKey, Object 
object) {
+        Map<String,String> result = new LinkedHashMap<String,String>();
+        collectNameComponents(result, rootKey, object);
+        return result;
+    }
+    
+    private static void collectNameComponents(Map<String,String> map, String 
key, Object component) {
+        while (component instanceof Adapter) {
+            component = ((Adapter)component).getTarget();
+        }
+        if (component instanceof String) {
+            map.put(key, (String)component);
+        } else {
+            DisplayName displayName = 
component.getClass().getAnnotation(DisplayName.class);
+            if (displayName != null) {
+                map.put(key, displayName.value());
+            }
+            collectNameComponents(map, component);
+        }
+    }
+    
+    private static void collectNameComponents(Map<String,String> map, Object 
object) {
         Class<?> clazz = object.getClass();
         for (Method method : clazz.getMethods()) {
             NameComponent ann = method.getAnnotation(NameComponent.class);
@@ -49,18 +71,7 @@
                     throw new Error("Error invoking " + method, ex);
                 }
                 if (component != null) {
-                    while (component instanceof Adapter) {
-                        component = ((Adapter)component).getTarget();
-                    }
-                    if (component instanceof String) {
-                        nameBuilder.addComponent(ann.value(), 
(String)component);
-                    } else {
-                        DisplayName displayName = 
component.getClass().getAnnotation(DisplayName.class);
-                        if (displayName != null) {
-                            nameBuilder.addComponent(ann.value(), 
displayName.value());
-                        }
-                        getNameComponents(nameBuilder, component);
-                    }
+                    collectNameComponents(map, ann.value(), component);
                 }
             }
         }

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/tests/TransportTestCase.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/tests/TransportTestCase.java?rev=686289&r1=686288&r2=686289&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/tests/TransportTestCase.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/tests/TransportTestCase.java
 Fri Aug 15 10:35:48 2008
@@ -19,17 +19,18 @@
 
 package org.apache.synapse.transport.testkit.tests;
 
+import java.util.Map;
+
+import junit.framework.TestCase;
+
 import org.apache.synapse.transport.testkit.TestEnvironment;
 import org.apache.synapse.transport.testkit.client.TestClient;
 import org.apache.synapse.transport.testkit.listener.Channel;
 import org.apache.synapse.transport.testkit.listener.ContentTypeMode;
-import org.apache.synapse.transport.testkit.listener.NameBuilder;
 import org.apache.synapse.transport.testkit.name.NameComponent;
 import org.apache.synapse.transport.testkit.name.NameUtils;
 import org.apache.synapse.transport.testkit.server.Server;
 
-import junit.framework.TestCase;
-
 public abstract class TransportTestCase<E extends TestEnvironment,C extends 
Channel<? super E>,L extends TestClient<? super E,? super C>> extends TestCase {
     protected final E env;
     protected final C channel;
@@ -38,6 +39,8 @@
     protected final ContentTypeMode contentTypeMode;
     protected final String contentType;
     
+    private Map<String,String> nameComponents;
+    
     private boolean manageServer = true;
 
     public TransportTestCase(E env, C channel, L client, Server<? super E> 
server, ContentTypeMode contentTypeMode, String contentType) {
@@ -49,15 +52,28 @@
         this.contentType = contentType;
     }
 
+    public Map<String,String> getNameComponents() {
+        if (nameComponents == null) {
+            nameComponents = NameUtils.getNameComponents("test", this);
+            nameComponents.put("contentTypeMode", 
contentTypeMode.toString().toLowerCase());
+        }
+        return nameComponents;
+    }
+    
     @Override
     public String getName() {
         String testName = super.getName();
         if (testName == null) {
-            NameBuilder nameBuilder = new NameBuilder();
-            nameBuilder.addComponent("test", NameUtils.getName(this));
-            NameUtils.getNameComponents(nameBuilder, this);
-            nameBuilder.addComponent("contentTypeMode", 
contentTypeMode.toString().toLowerCase());
-            testName = nameBuilder.toString();
+            StringBuilder buffer = new StringBuilder();
+            for (Map.Entry<String,String> entry : 
getNameComponents().entrySet()) {
+                if (buffer.length() > 0) {
+                    buffer.append(',');
+                }
+                buffer.append(entry.getKey());
+                buffer.append('=');
+                buffer.append(entry.getValue());
+            }
+            testName = buffer.toString();
             setName(testName);
         }
         return testName;


Reply via email to