donaldp 02/04/25 20:18:23 Added: aut/src/test/org/apache/aut/jprocess/test DemuxTestCase.java Log: Add unit test for DemuxProperties Revision Changes Path 1.1 jakarta-ant-myrmidon/aut/src/test/org/apache/aut/jprocess/test/DemuxTestCase.java Index: DemuxTestCase.java =================================================================== /* * Copyright The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.aut.jprocess.test; import java.util.HashMap; import java.util.Iterator; import java.util.Properties; import junit.framework.TestCase; import org.apache.aut.jprocess.DemuxProperties; /** * Basic unit tests for the multiplexing streams. * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a> */ public final class DemuxTestCase extends TestCase { private static final String T1 = "Thread1"; private static final String T2 = "Thread2"; private static final String T3 = "Thread3"; private static final String T4 = "Thread4"; private static final String KEY1 = "Key1"; private static final String KEY2 = "Key2"; private static final String KEY3 = "Key3"; private static final String KEY4 = "Key4"; private static final String DATA1 = "Data1"; private static final String DATA2 = "Data2"; private static final String DATA3 = "Data3"; private static final String DATA4 = "Data4"; private final HashMap m_threadMap = new HashMap(); public DemuxTestCase( final String name ) { super( name ); } private void doStart() throws Exception { final Iterator iterator = m_threadMap.keySet().iterator(); while( iterator.hasNext() ) { final String name = (String)iterator.next(); final Thread thread = (Thread)m_threadMap.get( name ); thread.start(); } } private void doJoin() throws Exception { final Iterator iterator = m_threadMap.keySet().iterator(); while( iterator.hasNext() ) { final String name = (String)iterator.next(); final Thread thread = (Thread)m_threadMap.get( name ); thread.join(); } } private void startThread( final String name, final DemuxProperties demux ) throws Exception { final PropertyThread thread = new PropertyThread( name, new Properties(), demux ); m_threadMap.put( name, thread ); } public void testProperties() throws Exception { final DemuxProperties properties = new DemuxProperties( new Properties() ); startThread( T1, properties ); startThread( T2, properties ); startThread( T3, properties ); startThread( T4, properties ); doStart(); doJoin(); final Properties properties1 = getProperties( T1 ); assertEquals( "Data1/1", T1 + DATA1, properties1.getProperty( KEY1 ) ); assertEquals( "Data1/2", T1 + DATA2, properties1.getProperty( KEY2 ) ); assertEquals( "Data1/3", T1 + DATA3, properties1.getProperty( KEY3 ) ); assertEquals( "Data1/4", T1 + DATA4, properties1.getProperty( KEY4 ) ); final Properties properties2 = getProperties( T2 ); assertEquals( "Data2/1", T2 + DATA1, properties2.getProperty( KEY1 ) ); assertEquals( "Data2/2", T2 + DATA2, properties2.getProperty( KEY2 ) ); assertEquals( "Data2/3", T2 + DATA3, properties2.getProperty( KEY3 ) ); assertEquals( "Data2/4", T2 + DATA4, properties2.getProperty( KEY4 ) ); final Properties properties3 = getProperties( T3 ); assertEquals( "Data3/1", T3 + DATA1, properties3.getProperty( KEY1 ) ); assertEquals( "Data3/2", T3 + DATA2, properties3.getProperty( KEY2 ) ); assertEquals( "Data3/3", T3 + DATA3, properties3.getProperty( KEY3 ) ); assertEquals( "Data3/4", T3 + DATA4, properties3.getProperty( KEY4 ) ); final Properties properties4 = getProperties( T4 ); assertEquals( "Data4/1", T4 + DATA1, properties4.getProperty( KEY1 ) ); assertEquals( "Data4/2", T4 + DATA2, properties4.getProperty( KEY2 ) ); assertEquals( "Data4/3", T4 + DATA3, properties4.getProperty( KEY3 ) ); assertEquals( "Data4/4", T4 + DATA4, properties4.getProperty( KEY4 ) ); } private Properties getProperties( final String threadName ) { final PropertyThread thread = (PropertyThread)m_threadMap.get( threadName ); assertNotNull( "getProperties()", thread ); return thread.getProperties(); } private static class PropertyThread extends Thread { private final Properties m_properties; private final DemuxProperties m_demux; PropertyThread( final String name, final Properties properties, final DemuxProperties demux ) { super( name ); m_properties = properties; m_demux = demux; } Properties getProperties() { return m_properties; } public void run() { m_demux.bindProperties( m_properties ); m_demux.setProperty( KEY1, getName() + DATA1 ); m_demux.setProperty( KEY2, getName() + DATA2 ); m_demux.setProperty( KEY3, getName() + DATA3 ); m_demux.setProperty( KEY4, getName() + DATA4 ); } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
