[overlord-commits] Overlord SVN: r113 - in sam/trunk: src/test/java/org/jboss/test/sam/simulation and 1 other directory.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Fri Jul 4 05:43:48 EDT 2008


Author: heiko.braun at jboss.com
Date: 2008-07-04 05:43:48 -0400 (Fri, 04 Jul 2008)
New Revision: 113

Added:
   sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java
Modified:
   sam/trunk/SAM.iws
   sam/trunk/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java
   sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java
Log:
Add simlation API unit test

Modified: sam/trunk/SAM.iws
===================================================================
--- sam/trunk/SAM.iws	2008-07-03 20:29:27 UTC (rev 112)
+++ sam/trunk/SAM.iws	2008-07-04 09:43:48 UTC (rev 113)
@@ -19,7 +19,8 @@
     <list default="true" name="Default" comment="">
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/SAM.iws" afterPath="$PROJECT_DIR$/SAM.iws" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java" afterPath="$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/main/java/org/jboss/sam/simulation/EventSimulation.java" afterPath="$PROJECT_DIR$/src/main/java/org/jboss/sam/simulation/EventSimulation.java" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java" afterPath="$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java" />
+      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java" />
     </list>
   </component>
   <component name="ChangeListSynchronizer" />
@@ -137,8 +138,8 @@
       <property name="field_breakpoints_groupByClasses" value="true" />
       <property name="method_breakpoints_groupByClasses" value="true" />
       <property name="exception_breakpoints_viewId" value="TABLE" />
-      <property name="field_breakpoints_viewId" value="TABLE" />
       <property name="exception_breakpoints_groupByClasses" value="true" />
+      <property name="field_breakpoints_viewId" value="TABLE" />
       <property name="method_breakpoints_groupByMethods" value="false" />
     </ui_properties>
   </component>
@@ -161,10 +162,19 @@
   </component>
   <component name="FileEditorManager">
     <leaf>
-      <file leaf-file-name="EventSimulation.java" pinned="false" current="true" current-in-tab="true">
-        <entry file="file://$PROJECT_DIR$/src/main/java/org/jboss/sam/simulation/EventSimulation.java">
+      <file leaf-file-name="SimulationMain.java" pinned="false" current="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="57" column="28" selection-start="2531" selection-end="2531" vertical-scroll-proportion="0.5041322">
+            <state line="87" column="40" selection-start="1389" selection-end="3318" vertical-scroll-proportion="0.86540735">
+              <folding />
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <file leaf-file-name="SimulationTestCase.java" pinned="false" current="true" current-in-tab="true">
+        <entry file="file://$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java">
+          <provider selected="true" editor-type-id="text-editor">
+            <state line="91" column="30" selection-start="3145" selection-end="3145" vertical-scroll-proportion="0.95513576">
               <folding>
                 <element signature="imports" expanded="true" />
               </folding>
@@ -172,10 +182,10 @@
           </provider>
         </entry>
       </file>
-      <file leaf-file-name="SimulationMain.java" pinned="false" current="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java">
+      <file leaf-file-name="SensorEventMessage.java" pinned="false" current="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="42" column="61" selection-start="1521" selection-end="1576" vertical-scroll-proportion="0.38134593">
+            <state line="32" column="62" selection-start="1308" selection-end="1308" vertical-scroll-proportion="0.26918536">
               <folding />
             </state>
           </provider>
@@ -490,41 +500,7 @@
           <option name="myItemId" value="SAM.ipr" />
           <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
         </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="sam-trunk" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewModuleNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src/main" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src/main/java" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src/main/java/org/jboss/sam" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="PsiDirectory:$PROJECT_DIR$/src/main/java/org/jboss/sam/simulation" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
-        </PATH_ELEMENT>
       </PATH>
-      <PATH>
-        <PATH_ELEMENT>
-          <option name="myItemId" value="SAM.ipr" />
-          <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
-        </PATH_ELEMENT>
-      </PATH>
     </subPane>
   </component>
   <component name="ProjectReloadState">
@@ -538,7 +514,7 @@
       <showLibraryContents />
       <hideEmptyPackages />
       <abbreviatePackageNames />
-      <showStructure Favorites="false" PackagesPane="false" Scope="false" ProjectPane="false" />
+      <showStructure ProjectPane="false" PackagesPane="false" Scope="false" Favorites="false" />
       <autoscrollToSource />
       <autoscrollFromSource />
       <sortByType />
@@ -548,13 +524,13 @@
     <property name="GenerateAntBuildDialog.enableUiFormCompile" value="true" />
     <property name="GoToFile.includeJavaFiles" value="false" />
     <property name="GoToClass.toSaveIncludeLibraries" value="false" />
-    <property name="RunManagerConfig.showSettingsBeforeRunnig" value="false" />
     <property name="RunManagerConfig.compileBeforeRunning" value="false" />
+    <property name="RunManagerConfig.showSettingsBeforeRunnig" value="false" />
     <property name="GenerateAntBuildDialog.generateSingleFile" value="false" />
     <property name="MemberChooser.sorted" value="false" />
     <property name="MemberChooser.showClasses" value="true" />
-    <property name="GenerateAntBuildDialog.forceTargetJdk" value="true" />
     <property name="GenerateAntBuildDialog.backupFiles" value="true" />
+    <property name="GenerateAntBuildDialog.forceTargetJdk" value="true" />
     <property name="GoToClass.includeLibraries" value="false" />
     <property name="MemberChooser.copyJavadoc" value="false" />
   </component>
@@ -611,21 +587,15 @@
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
       <option name="ALTERNATIVE_JRE_PATH" />
     </configuration>
-    <configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
-      <module name="" />
-      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
-      <option name="ALTERNATIVE_JRE_PATH" />
-      <option name="PACKAGE_NAME" />
+    <configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
       <option name="MAIN_CLASS_NAME" />
-      <option name="METHOD_NAME" />
-      <option name="TEST_OBJECT" value="class" />
       <option name="VM_PARAMETERS" />
-      <option name="PARAMETERS" />
+      <option name="PROGRAM_PARAMETERS" />
       <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
-      <option name="ADDITIONAL_CLASS_PATH" />
-      <option name="TEST_SEARCH_SCOPE">
-        <value defaultName="wholeProject" />
-      </option>
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+      <option name="ALTERNATIVE_JRE_PATH" />
+      <option name="ENABLE_SWING_INSPECTOR" value="false" />
+      <module name="" />
       <method>
         <option name="Make" value="true" />
       </method>
@@ -637,36 +607,21 @@
       <option name="HOST" value="localhost" />
       <option name="PORT" value="5005" />
     </configuration>
-    <configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
-      <option name="MAIN_CLASS_NAME" />
-      <option name="VM_PARAMETERS" />
-      <option name="PROGRAM_PARAMETERS" />
-      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+    <configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
+      <module name="" />
       <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
       <option name="ALTERNATIVE_JRE_PATH" />
-      <option name="ENABLE_SWING_INSPECTOR" value="false" />
-      <module name="" />
-      <method>
-        <option name="Make" value="true" />
-      </method>
-    </configuration>
-    <configuration default="false" name="SimulationMain" type="Application" factoryName="Application" enabled="false" merge="false">
-      <option name="MAIN_CLASS_NAME" value="org.jboss.test.sam.simulation.SimulationMain" />
+      <option name="PACKAGE_NAME" />
+      <option name="MAIN_CLASS_NAME" />
+      <option name="METHOD_NAME" />
+      <option name="TEST_OBJECT" value="class" />
       <option name="VM_PARAMETERS" />
-      <option name="PROGRAM_PARAMETERS" />
+      <option name="PARAMETERS" />
       <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
-      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
-      <option name="ALTERNATIVE_JRE_PATH" />
-      <option name="ENABLE_SWING_INSPECTOR" value="false" />
-      <module name="sam-trunk" />
-      <RunnerSettings RunnerId="Debug">
-        <option name="DEBUG_PORT" value="32888" />
-        <option name="TRANSPORT" value="0" />
-        <option name="LOCAL" value="true" />
-      </RunnerSettings>
-      <RunnerSettings RunnerId="Run" />
-      <ConfigurationWrapper RunnerId="Debug" />
-      <ConfigurationWrapper RunnerId="Run" />
+      <option name="ADDITIONAL_CLASS_PATH" />
+      <option name="TEST_SEARCH_SCOPE">
+        <value defaultName="wholeProject" />
+      </option>
       <method>
         <option name="Make" value="true" />
       </method>
@@ -878,20 +833,6 @@
     <option name="myLastEditedConfigurable" value="IDE Profiles" />
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/src/main/java/org/jboss/sam/internal/esper/EsperRuntimeImpl.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="121" column="16" selection-start="4154" selection-end="4154" vertical-scroll-proportion="0.2545825">
-          <folding />
-        </state>
-      </provider>
-    </entry>
-    <entry file="file://$PROJECT_DIR$/src/main/java/org/jboss/sam/internal/esper/StreamOutputAdapter.java">
-      <provider selected="true" editor-type-id="text-editor">
-        <state line="34" column="6" selection-start="1420" selection-end="1420" vertical-scroll-proportion="0.33197555">
-          <folding />
-        </state>
-      </provider>
-    </entry>
     <entry file="file://$PROJECT_DIR$/src/main/java/org/jboss/sam/simulation/EventSinkEntity.java">
       <provider selected="true" editor-type-id="text-editor">
         <state line="59" column="13" selection-start="2120" selection-end="2120" vertical-scroll-proportion="0.33293125">
@@ -966,16 +907,39 @@
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/src/main/java/org/jboss/sam/simulation/EventSimulation.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="57" column="28" selection-start="2531" selection-end="2531" vertical-scroll-proportion="0.5041322">
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
     <entry file="file://$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="42" column="61" selection-start="1521" selection-end="1576" vertical-scroll-proportion="0.38134593">
+        <state line="87" column="40" selection-start="1389" selection-end="3318" vertical-scroll-proportion="0.86540735">
           <folding />
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/src/main/java/org/jboss/sam/simulation/EventSimulation.java">
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="57" column="28" selection-start="2531" selection-end="2531" vertical-scroll-proportion="0.5041322">
+        <state line="32" column="62" selection-start="1308" selection-end="1308" vertical-scroll-proportion="0.26918536">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/pom.xml">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="37" column="73" selection-start="1380" selection-end="1380" vertical-scroll-proportion="0.52884614">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="91" column="30" selection-start="3145" selection-end="3145" vertical-scroll-proportion="0.95513576">
           <folding>
             <element signature="imports" expanded="true" />
           </folding>

Modified: sam/trunk/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java
===================================================================
--- sam/trunk/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java	2008-07-03 20:29:27 UTC (rev 112)
+++ sam/trunk/src/test/java/org/jboss/test/sam/simulation/SensorEventMessage.java	2008-07-04 09:43:48 UTC (rev 113)
@@ -30,10 +30,10 @@
    private double surveyValue;
    private double simTime;
 
-   public SensorEventMessage(String source, double threshold, double simTime)
+   public SensorEventMessage(String source, double surveyValue, double simTime)
    {
       this.source = source;
-      this.surveyValue = threshold;
+      this.surveyValue = surveyValue;
       this.simTime = simTime;
    }
 

Modified: sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java
===================================================================
--- sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java	2008-07-03 20:29:27 UTC (rev 112)
+++ sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationMain.java	2008-07-04 09:43:48 UTC (rev 113)
@@ -47,7 +47,7 @@
 
       // shared between all entities
       SimulationContext context = simulation.getContext();
-
+                                                                                       
       // create an event source and associate a message factory
       EventSourceEntity source = new EventSourceEntity("source-A", 0.10);      
       source.setEventMessageFactory( new SensorMessageFactory() );

Added: sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java
===================================================================
--- sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java	                        (rev 0)
+++ sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java	2008-07-04 09:43:48 UTC (rev 113)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.sam.simulation;
+
+import junit.framework.TestCase;
+import org.jboss.sam.EventMessage;
+import org.jboss.sam.simulation.*;
+
+import java.util.Properties;
+
+/**
+ * A simple test case that shows how to use the simulation API
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class SimulationTestCase extends TestCase
+{
+
+   public void testSimulationAPI()
+   {
+      // config
+      Properties config = new Properties();
+      config.put(EventSimulation.TOTAL_SIM_TIME, 60.00);
+
+      // init
+      EventSimulation simulation = EventSimulation.bootstrap(
+        config,
+        Thread.currentThread().getContextClassLoader().getResource("simulation/esper-cfg.xml")
+      );
+
+      // shared between all entities
+      SimulationContext context = simulation.getContext();
+
+      // create an event source and associate a message factory
+      EventSourceEntity source = new EventSourceEntity("source-A", 0.10);
+      source.setEventMessageFactory(
+         new EventMessageFactory()
+         {
+            public Object createEventMessage(SimulationContext context)
+            {
+               return new SensorEventMessage("source-A", 12.00, context.getCurrentSimulationTime() );  
+            }
+         }
+      );
+      
+      // create an event sink and associate handler
+      EventSinkEntity sink = new EventSinkEntity("sink-B");
+      sink.setEventHandler(
+         new EventSinkHandler()
+         {
+            public void handle(EventMessage[] events, SimulationContext context)
+            {
+               context.addAttachment(EventMessage.class, events[0]);               
+            }
+         }
+      );
+
+      simulation.addSource(source);
+      simulation.addSink(sink);
+
+      // forward single event messages
+      simulation.bindStatement("select * from SensorEventMessage", sink);
+
+      // start simulation
+      simulation.singleRun();
+
+      // evaluate results
+      EventMessage lastEventMessage = context.getAttachment(EventMessage.class);
+      assertNotNull(lastEventMessage);
+      assertEquals(12.00, lastEventMessage.getProperty("surveyValue"));
+   }
+}


Property changes on: sam/trunk/src/test/java/org/jboss/test/sam/simulation/SimulationTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the overlord-commits mailing list