notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r1555 - in development/laboratory/planet/components/fsm: . api/src/main/net/dpml/fsm basic/src/main/net/dpml/fsm/basic basic/src/test/net/dpml/fsm basic/src/test/net/dpml/fsm/basic/test demo/trafficlight/src/main/net/dpml/fsm/trafficlight
- From: niclas AT netcompartner.com
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r1555 - in development/laboratory/planet/components/fsm: . api/src/main/net/dpml/fsm basic/src/main/net/dpml/fsm/basic basic/src/test/net/dpml/fsm basic/src/test/net/dpml/fsm/basic/test demo/trafficlight/src/main/net/dpml/fsm/trafficlight
- Date: Sat, 22 Jan 2005 10:36:26 +0100
Author: niclas
Date: Sat Jan 22 10:36:25 2005
New Revision: 1555
Added:
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/Resources.properties
(contents, props changed)
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/Resources_sv.properties
(contents, props changed)
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/basic/test/CommandRuleTestCase.java
(contents, props changed)
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/basic/test/StateTestCase.java
(contents, props changed)
Removed:
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/basic/test/CommandRuleImplTestCase.java
Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java
development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
development/laboratory/planet/components/fsm/index.xml
Log:
Added some more testcases, and realized I need the ClassLoader in Locale
related method calls.
Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java
Sat Jan 22 10:36:25 2005
@@ -58,21 +58,23 @@
* Return the human-readable name of this State.
*
* @param locale The java.util.Locale to return the name in.
+ * @param classloader the ClassLoader to use to load the Locale
resources with.
*
* @return A human-readable name in the requested Locale, or the default
Locale if null is
* passed in as the locale argument.
*/
- String getName( Locale locale );
+ String getName( Locale locale, ClassLoader classloader );
/**
* Return the human-readable description of this State.
*
* @param locale The java.util.Locale to return the description in.
+ * @param classloader the ClassLoader to use to load the Locale
resources with.
*
* @return A human-readable description in the requested Locale, or the
default Locale if null
* is passed in as the locale argument.
*/
- String getDescription( Locale locale );
+ String getDescription( Locale locale, ClassLoader classloader );
/** Called by the StateMachine when this State is entered.
* exit() on the "end" State is always called before entry() on the
Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java
Sat Jan 22 10:36:25 2005
@@ -73,15 +73,23 @@
String getIdentity();
/** Return the Name of the Transition in the provided Locale.
+ *
+ * @param locale The java.util.Locale to return the name in.
+ * @param classloader the ClassLoader to use to load the Locale
resources with.
+ *
* @return the human-readable Name of the Transition in the provided
Locale.
*/
- String getName( Locale locale );
+ String getName( Locale locale, ClassLoader classloader );
/** Return the Description of the Transition in the provided Locale.
+ *
+ * @param locale The java.util.Locale to return the description in.
+ * @param classloader the ClassLoader to use to load the Locale
resources with.
+ *
* @return the human-readable Description of the Transition in the
provided
* Locale.
*/
- String getDescription( Locale locale );
+ String getDescription( Locale locale, ClassLoader classloader );
/** Add a TransitionListener to the Transition.
* <p/>
Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java
Sat Jan 22 10:36:25 2005
@@ -19,6 +19,9 @@
package net.dpml.fsm.basic;
import net.dpml.fsm.TransitionRule;
+
+import net.dpml.lang.NullArgumentException;
+
import net.dpml.parameters.Parameters;
import net.dpml.parameters.ParameterException;
@@ -35,15 +38,31 @@
public class CommandRuleComponent extends CommandRuleImpl
implements TransitionRule
{
- private String m_command;
- private int m_priority;
- private boolean m_ignoreCase;
-
+ /** Constructor for Metro component.
+ * The expected parameters in the params argument are;
+ * <ul>
+ * <li>
+ * <strong>command</strong> - Required. The command string that this
rule
+ * should respond to
+ * </li>
+ * <li>
+ * <strong>priority</strong> - Optional. Default=100. The Priority of
this
+ * rule.
+ * </li>
+ * <li>
+ * <strong>ignore-case</strong> - Optional. Default=false. If true,
command
+ * strings of different case will still considered a match.
+ * </li>
+ * </ul>
+ * @param params The Parameters instance.
+ * @exception NullArgumentException if the params instance does not
contain
+ * a <strong><code>command</code></strong> parameter.
+ */
public CommandRuleComponent( Parameters params )
- throws ParameterException
+ throws NullArgumentException
{
super(
- params.getParameter( "command" ),
+ params.getParameter( "command", null ),
params.getParameterAsInteger( "priority", 100 ),
params.getParameterAsBoolean( "ignore-case", false )
);
Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java
Sat Jan 22 10:36:25 2005
@@ -27,6 +27,8 @@
* <p/>
* The generic CommandRule should be enough for most situations, unless
dynamically user
* re-programmable statemachines are needed.
+ * Both the command match argument (passed in constructor) and the
commandString
+ * (passed in the isTransition()) are trimmed from leading and trailing
whitespace.
*/
public class CommandRuleImpl
implements TransitionRule
@@ -42,7 +44,7 @@
{
throw new NullArgumentException( "command" );
}
- m_command = command;
+ m_command = command.trim();
m_priority = priority;
m_ignoreCase = ignoreCase;
}
@@ -64,11 +66,21 @@
return m_command.equals( commandString );
}
+ public String getCommand()
+ {
+ return m_command;
+ }
+
public int getPriority()
{
return m_priority;
}
+ public boolean isIgnoringCase()
+ {
+ return m_ignoreCase;
+ }
+
/**
* Compares this object with the specified object for order. Returns a
negative integer, zero,
* or a positive integer as this object is less than, equal to, or
greater than the specified
@@ -117,4 +129,41 @@
}
return -1;
}
+
+ public String toString()
+ {
+ String c = "";
+ if( m_ignoreCase )
+ c = ", ignore-case";
+ String s = "CommandRule[" + m_command + ", " + m_priority + c + "]";
+ return s;
+ }
+
+ public int hashCode()
+ {
+ int hash = m_command.hashCode();
+ hash = hash >>> m_priority;
+ if( m_ignoreCase )
+ hash = hash >>> 19;
+ else
+ hash = hash >>> 7;
+ return hash;
+ }
+
+ public boolean equals( Object o )
+ {
+ if( o == null )
+ return false;
+ if( ! ( o instanceof CommandRuleImpl ) )
+ return false;
+ CommandRuleImpl other = (CommandRuleImpl) o;
+
+ if( m_priority != other.m_priority )
+ return false;
+
+ if( m_ignoreCase ^ other.m_ignoreCase )
+ return false;
+
+ return m_command.equals( other.m_command );
+ }
}
Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java
Sat Jan 22 10:36:25 2005
@@ -20,11 +20,14 @@
import java.util.Locale;
import java.util.ResourceBundle;
-import net.dpml.parameters.ParameterException;
-import net.dpml.parameters.Parameters;
+
import net.dpml.fsm.State;
import net.dpml.fsm.StateMachine;
+import net.dpml.lang.NullArgumentException;
+
+import net.dpml.parameters.Parameters;
+
/**
* This class represents each State internal in the StateMachine.
* <p/>
@@ -52,9 +55,9 @@
implements State
{
public StateComponent( Parameters params )
- throws ParameterException
+ throws NullArgumentException
{
- super( params.getParameter( "identity" ) );
+ super( params.getParameter( "identity", null ) );
}
}
Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java
Sat Jan 22 10:36:25 2005
@@ -20,12 +20,13 @@
import java.util.Locale;
import java.util.ResourceBundle;
-import net.dpml.lang.NullArgumentException;
-import net.dpml.parameters.ParameterException;
-import net.dpml.parameters.Parameters;
+
import net.dpml.fsm.State;
import net.dpml.fsm.StateMachine;
+import net.dpml.lang.NullArgumentException;
+
+
/**
* This class represents each State internal in the StateMachine.
* <p/>
@@ -52,7 +53,7 @@
private String m_identity;
public StateImpl( String identity )
- throws ParameterException, NullArgumentException
+ throws NullArgumentException
{
if( identity == null )
{
@@ -67,15 +68,17 @@
return m_identity;
}
- public String getName( Locale locale )
+ public String getName( Locale locale, ClassLoader cl )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
+ String name = StateMachine.BUNDLE_NAME;
+ ResourceBundle bundle = ResourceBundle.getBundle( name , locale, cl
);
return bundle.getString( m_identity + ".name" );
}
- public String getDescription( Locale locale )
+ public String getDescription( Locale locale, ClassLoader cl )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
+ String name = StateMachine.BUNDLE_NAME;
+ ResourceBundle bundle = ResourceBundle.getBundle( name, locale, cl );
return bundle.getString( m_identity + ".description" );
}
@@ -88,4 +91,26 @@
{
// default: No action.
}
+
+ public String toString()
+ {
+ return "State[" + m_identity + "]";
+ }
+
+ public boolean equals( Object o )
+ {
+ if( o == null )
+ return false;
+ if( ! (o instanceof StateImpl) )
+ return false;
+ StateImpl other = (StateImpl) o;
+ return m_identity.equals( other.m_identity );
+ }
+
+ public int hashCode()
+ {
+ int hash = m_identity.hashCode();
+ return hash;
+ }
+
}
Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java
Sat Jan 22 10:36:25 2005
@@ -106,15 +106,17 @@
return m_identity;
}
- public String getName( Locale locale )
+ public String getName( Locale locale, ClassLoader classloader )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
+ String name = StateMachine.BUNDLE_NAME;
+ ResourceBundle bundle = ResourceBundle.getBundle( name, locale,
classloader );
return bundle.getString( m_identity + ".name" );
}
- public String getDescription( Locale locale )
+ public String getDescription( Locale locale, ClassLoader classloader )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
+ String name = StateMachine.BUNDLE_NAME;
+ ResourceBundle bundle = ResourceBundle.getBundle( name, locale,
classloader );
return bundle.getString( m_identity + ".description" );
}
Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java
Sat Jan 22 10:36:25 2005
@@ -97,15 +97,17 @@
return m_identity;
}
- public String getName( Locale locale )
+ public String getName( Locale locale, ClassLoader classloader )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
+ String name = StateMachine.BUNDLE_NAME;
+ ResourceBundle bundle = ResourceBundle.getBundle( name, locale,
classloader );
return bundle.getString( m_identity + ".name" );
}
- public String getDescription( Locale locale )
+ public String getDescription( Locale locale, ClassLoader classloader )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
+ String name = StateMachine.BUNDLE_NAME;
+ ResourceBundle bundle = ResourceBundle.getBundle( name, locale,
classloader );
return bundle.getString( m_identity + ".description" );
}
Added:
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/Resources.properties
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/Resources.properties
Sat Jan 22 10:36:25 2005
@@ -0,0 +1,6 @@
+
+test.name=SomeName
+test.description=SomeDescription
+
+test2.name=SomeOtherName
+test2.description = Some Other Descriptription
Added:
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/Resources_sv.properties
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/Resources_sv.properties
Sat Jan 22 10:36:25 2005
@@ -0,0 +1,6 @@
+
+test.name=EttNamn
+test.description=EnBeskrivning
+
+test2.name=Ett Annat Namn
+test2.description = En annan beskrivning.
Added:
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/basic/test/CommandRuleTestCase.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/basic/test/CommandRuleTestCase.java
Sat Jan 22 10:36:25 2005
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2004-2005 Niclas Hedhman.
+ *
+ * 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 net.dpml.fsm.basic.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import junit.framework.TestCase;
+
+import net.dpml.fsm.basic.CommandRuleImpl;
+import net.dpml.fsm.basic.CommandRuleComponent;
+
+import net.dpml.lang.NullArgumentException;
+
+import net.dpml.parameters.impl.DefaultParameters;
+
+public class CommandRuleTestCase extends TestCase
+{
+ public CommandRuleTestCase( String name )
+ {
+ super( name );
+ }
+
+ public void testConstructor()
+ {
+ CommandRuleImpl rule = new CommandRuleImpl( "test-command", 200,
true );
+ assertEquals( "command invalid", "test-command", rule.getCommand() );
+ assertTrue( "ignoreCase invalid", rule.isIgnoringCase() );
+ assertEquals( "priority invalid", 200, rule.getPriority() );
+ }
+
+ public void testComponentConstructor()
+ throws Exception
+ {
+ DefaultParameters params = new DefaultParameters();
+ params.setParameter( "command", "test-command" );
+ params.setParameter( "priority", "200" );
+ params.setParameter( "ignore-case", "true" );
+
+ CommandRuleComponent rule1 = new CommandRuleComponent( params );
+ CommandRuleImpl rule2 = new CommandRuleImpl( "test-command", 200,
true );
+ assertEquals( "equals not same for Component", rule1, rule2 );
+
+ params = new DefaultParameters();
+ params.setParameter( "command", "test-command" );
+ rule1 = new CommandRuleComponent( params );
+ rule2 = new CommandRuleImpl( "test-command", 100, false );
+ assertEquals( "equals not same for Component with default values",
rule1, rule2 );
+
+ }
+
+ public void testConstructorWithNullArgument()
+ throws Exception
+ {
+ try
+ {
+ new CommandRuleImpl( null, 0, false );
+ fail( "NullArgumentException was expected for Impl constructor,
but not thrown." );
+
+ } catch( NullArgumentException e )
+ {
+ // expected !
+ }
+
+ try
+ {
+ DefaultParameters params = new DefaultParameters();
+ CommandRuleComponent rule1 = new CommandRuleComponent( params );
+ fail( "NullArgumentException was expected for Component
constructor, but not thrown." );
+ } catch( NullArgumentException e )
+ {
+ // expected !
+ }
+ }
+
+ public void testTransitionTestCaseSensitive()
+ {
+ CommandRuleImpl rule = new CommandRuleImpl( "test-command", 100,
false );
+ assertTrue( "Rule indicating no transition for exact match.",
rule.isTransition( "test-command" ) );
+ assertTrue( "Rule indicating transition for wrong command.", !
rule.isTransition( "test2-command" ) );
+ assertTrue( "Rule indicating transition for wrong case.", !
rule.isTransition( "tEst-command" ) );
+ }
+
+ public void testTransitionTestCaseIgnore()
+ {
+ CommandRuleImpl rule = new CommandRuleImpl( "test-command", 100,
true );
+ assertTrue( "Rule indicating no transition for exact match.",
rule.isTransition( "test-command" ) );
+ assertTrue( "Rule indicating transition for wrong command.", !
rule.isTransition( "test2-command" ) );
+ assertTrue( "Rule indicating no transition for mixed case.",
rule.isTransition( "tEst-commanD" ) );
+ }
+
+ public void testPriority()
+ {
+ CommandRuleImpl rule1 = new CommandRuleImpl( "test-command", 100,
true );
+ CommandRuleImpl rule2 = new CommandRuleImpl( "test2-command", 100,
true );
+ CommandRuleImpl rule3 = new CommandRuleImpl( "test3-command", 101,
true );
+ assertEquals( 0, rule1.compareTo( rule2 ) );
+ assertEquals( 0, rule2.compareTo( rule1 ) );
+ SortedSet list = new TreeSet();
+ list.add( rule3 );
+ list.add( rule1 );
+ assertEquals( rule1, list.first() );
+ assertEquals( rule3, list.last() );
+ }
+
+ public void testEquals()
+ {
+ CommandRuleImpl rule1 = new CommandRuleImpl( "test-command", 100,
true );
+ CommandRuleImpl rule2 = new CommandRuleImpl( "test-command", 100,
true );
+ assertEquals( "equals not same", rule1, rule2 );
+
+ rule1 = new CommandRuleImpl( "test-command", 100, true );
+ rule2 = new CommandRuleImpl( "test-command", 100, false );
+ assertTrue( "equals true (ignore case)", ! rule1.equals( rule2 ) );
+
+ rule1 = new CommandRuleImpl( "test-command", 100, true );
+ rule2 = new CommandRuleImpl( "test-command", 101, true );
+ assertTrue( "equals true (priority)", ! rule1.equals( rule2 ) );
+
+ rule1 = new CommandRuleImpl( "tst-command", 100, true );
+ rule2 = new CommandRuleImpl( "test-command", 100, true );
+ assertTrue( "equals true (command)", ! rule1.equals( rule2 ) );
+ }
+
+ public void testHashCode()
+ {
+ CommandRuleImpl rule1 = new CommandRuleImpl( "test-command", 100,
true );
+ CommandRuleImpl rule2 = new CommandRuleImpl( "test-command", 100,
true );
+ assertEquals( "hashCode not same", rule1.hashCode(),
rule2.hashCode() );
+
+ rule1 = new CommandRuleImpl( "test-command", 100, true );
+ rule2 = new CommandRuleImpl( "test-command", 100, false );
+ assertTrue( "hashCode same (ignore case)", rule1.hashCode() !=
rule2.hashCode() );
+
+ rule1 = new CommandRuleImpl( "test-command", 100, true );
+ rule2 = new CommandRuleImpl( "test-command", 101, true );
+ assertTrue( "hashCode same (priority)", rule1.hashCode() !=
rule2.hashCode() );
+
+ rule1 = new CommandRuleImpl( "tst-command", 100, true );
+ rule2 = new CommandRuleImpl( "test-command", 100, true );
+ assertTrue( "hashCode same (command)", rule1.hashCode() !=
rule2.hashCode() );
+ }
+
+ public void testSerialization()
+ throws Exception
+ {
+ CommandRuleImpl rule1 = new CommandRuleImpl( "test-command", 100,
true );
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream( baos );
+ oos.writeObject( rule1 );
+ oos.flush();
+ oos.close();
+ baos.close();
+ byte[] ba = baos.toByteArray();
+ ByteArrayInputStream bais = new ByteArrayInputStream( ba );
+ ObjectInputStream ois = new ObjectInputStream( bais );
+ CommandRuleImpl rule2 = (CommandRuleImpl) ois.readObject();
+ ois.close();
+ assertEquals( "serialization", rule1, rule2 );
+ }
+
+ public void testToString()
+ {
+ CommandRuleImpl rule2 = new CommandRuleImpl( "test2-command", 101,
false );
+ assertEquals( "toString", "CommandRule[test2-command, 101]",
rule2.toString() );
+ CommandRuleImpl rule1 = new CommandRuleImpl( "test-command", 100,
true );
+ assertEquals( "toString", "CommandRule[test-command, 100,
ignore-case]", rule1.toString() );
+ }
+}
Added:
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/basic/test/StateTestCase.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/fsm/basic/src/test/net/dpml/fsm/basic/test/StateTestCase.java
Sat Jan 22 10:36:25 2005
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2004-2005 Niclas Hedhman.
+ *
+ * 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 net.dpml.fsm.basic.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import net.dpml.fsm.basic.StateImpl;
+import net.dpml.fsm.basic.StateComponent;
+
+import net.dpml.lang.NullArgumentException;
+
+import net.dpml.parameters.impl.DefaultParameters;
+
+public class StateTestCase extends TestCase
+{
+ public StateTestCase( String name )
+ {
+ super( name );
+ }
+
+ public void testConstructor()
+ {
+ StateImpl state = new StateImpl( "test" );
+ String identity = state.getIdentity();
+ assertEquals( "Indentity invalid.", "test", identity );
+ }
+
+ public void testComponentConstructor()
+ throws Exception
+ {
+ DefaultParameters params = new DefaultParameters();
+ params.setParameter( "identity", "test-identity" );
+
+ StateComponent state1 = new StateComponent( params );
+ StateImpl state2 = new StateImpl( "test-identity" );
+ assertEquals( "equals not same for Component", state1, state2 );
+ }
+
+ public void testConstructorWithNullArgument()
+ {
+ try
+ {
+ StateImpl state = new StateImpl( null );
+ fail( "NullArgumentException was expected." );
+ } catch( NullArgumentException e )
+ {
+ // expected!
+ }
+
+ try
+ {
+ DefaultParameters params = new DefaultParameters();
+ StateComponent state1 = new StateComponent( params );
+ fail( "NullArgumentException was expected for Component
constructor, but not thrown." );
+ } catch( NullArgumentException e )
+ {
+ // expected !
+ }
+ }
+
+ public void testLocale()
+ {
+ ClassLoader cl = getClass().getClassLoader();
+
+ Locale[] all = Locale.getAvailableLocales();
+ for( int i = 0; i < all.length ; i++ )
+ {
+ if( i != 0 )
+ System.out.print( ", " );
+ System.out.print( all[i] );
+ }
+ System.out.println();
+
+ Locale en = Locale.US;
+ Locale sv = new Locale( "sv" );
+ System.out.println( sv.getDisplayName() );
+
+ StateImpl state1 = new StateImpl( "test" );
+ StateImpl state2 = new StateImpl( "test2" );
+
+ assertEquals( "name_en", "SomeName", state1.getName( en, cl ) );
+ assertEquals( "description_en", "SomeDescription",
state1.getDescription( en, cl ) );
+ assertEquals( "name_en", "SomeOtherName", state2.getName( en, cl ) );
+ assertEquals( "description_en", "Some Other Descriptription",
state2.getDescription( en, cl ) );
+
+ assertEquals( "name_sv", "EttNamn", state1.getName( sv, cl ) );
+ assertEquals( "description_sv", "EnBeskrivning",
state1.getDescription( sv, cl ) );
+ assertEquals( "name_sv", "Ett Annat Namn", state2.getName( sv, cl )
);
+ assertEquals( "description_sv", "En annan beskrivning.",
state2.getDescription( sv, cl ) );
+ }
+
+ public void testToString()
+ {
+ StateImpl state = new StateImpl( "test2" );
+ assertEquals( "toString", "State[test2]", state.toString() );
+ }
+
+ public void testEquals()
+ {
+ StateImpl state1 = new StateImpl( "test-state" );
+ StateImpl state2 = new StateImpl( "test-state" );
+ assertEquals( "equals not true", state1, state2 );
+
+ state1 = new StateImpl( "test-state" );
+ state2 = new StateImpl( "test-stat" );
+ assertTrue( "equals true (ignore case)", ! state1.equals( state2 ) );
+ }
+
+ public void testHashCode()
+ {
+ StateImpl state1 = new StateImpl( "test-state" );
+ StateImpl state2 = new StateImpl( "test-state" );
+ assertEquals( "hashCode not same", state1.hashCode(),
state2.hashCode() );
+
+ state1 = new StateImpl( "test-state" );
+ state2 = new StateImpl( "test-stat" );
+ assertTrue( "hashCode same (ignore case)", state1.hashCode() !=
state2.hashCode() );
+ }
+
+ public void testSerialization()
+ throws Exception
+ {
+ StateImpl state1 = new StateImpl( "test-state" );
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream( baos );
+ oos.writeObject( state1 );
+ oos.flush();
+ oos.close();
+ baos.close();
+ byte[] ba = baos.toByteArray();
+ ByteArrayInputStream bais = new ByteArrayInputStream( ba );
+ ObjectInputStream ois = new ObjectInputStream( bais );
+ StateImpl state2 = (StateImpl) ois.readObject();
+ ois.close();
+ assertEquals( "serialization", state1, state2 );
+ }
+}
Modified:
development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
==============================================================================
---
development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
(original)
+++
development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
Sat Jan 22 10:36:25 2005
@@ -180,6 +180,7 @@
Date date = event.getTransitionDate();
State state = transition.getEndState();
SimpleDateFormat sdf = new SimpleDateFormat( "HH:mm:ss" );
- System.out.println( sdf.format( date ) + " : " + state.getName(
Locale.getDefault() ) );
+ ClassLoader cl = getClass().getClassLoader();
+ System.out.println( sdf.format( date ) + " : " + state.getName(
Locale.getDefault(), cl ) );
}
}
Modified: development/laboratory/planet/components/fsm/index.xml
==============================================================================
--- development/laboratory/planet/components/fsm/index.xml (original)
+++ development/laboratory/planet/components/fsm/index.xml Sat Jan 22
10:36:25 2005
@@ -65,6 +65,7 @@
<include key="dpml-context-api" />
<include key="dpml-logging-api" />
<include key="dpml-parameters-api" />
+ <include key="dpml-parameters-impl" build="false" runtime="false"
test="true" />
<include key="dpml-service-api" />
<include key="dpml-transitionmachine-api" />
<include key="dpml-transit" />
- svn commit: r1555 - in development/laboratory/planet/components/fsm: . api/src/main/net/dpml/fsm basic/src/main/net/dpml/fsm/basic basic/src/test/net/dpml/fsm basic/src/test/net/dpml/fsm/basic/test demo/trafficlight/src/main/net/dpml/fsm/trafficlight, niclas, 01/22/2005
Archive powered by MHonArc 2.6.24.