Changeset 96 for java/main/src/test
- Timestamp:
- 07/04/13 20:29:50 (11 years ago)
- Location:
- java/main/src/test
- Files:
-
- 11 added
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/test/java/com/framsticks/core/FramsticksTest.java
r88 r96 20 20 Framsticks framsticks = Framsticks.loadConfiguration(stream); 21 21 assertThat(framsticks).isNotNull(); 22 assertThat(framsticks. getObservables().size()).isEqualTo(1);23 assertThat(framsticks.get Observables().get("browser")).isInstanceOf(Browser.class);22 assertThat(framsticks.size()).isEqualTo(1); 23 assertThat(framsticks.get("browser")).isInstanceOf(Browser.class); 24 24 } 25 25 -
java/main/src/test/java/com/framsticks/core/ObjectInstanceTest.java
r90 r96 19 19 import com.framsticks.params.ReflectionAccess; 20 20 import com.framsticks.params.types.FloatParam; 21 22 import static com.framsticks.core.InstanceUtils.*; 23 21 24 22 25 import static org.fest.assertions.Assertions.*; … … 48 51 public void startInstance() { 49 52 instance = new ObjectInstance(); 50 instance. getRegistry().takeAllFrom(schema.getRegistry());53 instance.takeAllFrom(schema.getRegistry()); 51 54 52 55 instance.setRootObject(model); … … 62 65 })).isEqualTo("bla"); 63 66 64 assertDispatch(instance,new RunAt<Instance>() {67 instance.dispatch(new RunAt<Instance>() { 65 68 @Override 66 69 public void run() { 67 70 assertThat(instance.getRootObject(Model.class).getNeuroDefinitions().get(2).details).isEqualTo("G"); 68 71 69 Path path = instance.getPath("/");72 Path path = Path.to(instance, "/"); 70 73 assertThat(path.isResolved()); 71 AccessInterface access = instance.bindAccess(path);74 AccessInterface access = InstanceUtils.bindAccess(path); 72 75 assertThat(access.get("se", Double.class)).isEqualTo(1.0); 73 76 74 assertThat( instance.bindAccess("/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getDef(Double.class)).isEqualTo(1.0);75 assertThat( instance.bindAccess("/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0);76 assertThat( instance.bindAccess("/parts/2")).isInstanceOf(ReflectionAccess.class);77 assertThat( instance.getPath("/neurodefs").getTopObject()).isInstanceOf(ArrayList.class);78 assertThat( instance.getPath("/joints/1").getTopObject()).isInstanceOf(Joint.class);79 assertThat( instance.bindAccess("/parts/2").get("i", String.class)).isEqualTo("bla");77 assertThat(bindAccess(instance, "/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getDef(Double.class)).isEqualTo(1.0); 78 assertThat(bindAccess(instance, "/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0); 79 assertThat(bindAccess(instance, "/parts/2")).isInstanceOf(ReflectionAccess.class); 80 assertThat(Path.to(instance, "/neurodefs").getTopObject()).isInstanceOf(ArrayList.class); 81 assertThat(Path.to(instance, "/joints/1").getTopObject()).isInstanceOf(Joint.class); 82 assertThat(bindAccess(instance, "/parts/2").get("i", String.class)).isEqualTo("bla"); 80 83 } 81 84 }); -
java/main/src/test/java/com/framsticks/gui/BrowserBaseTest.java
r90 r96 9 9 import org.fest.swing.fixture.FrameFixture; 10 10 import org.fest.swing.fixture.JTreeFixture; 11 import org.testng.annotations.AfterClass;12 import org.testng.annotations.BeforeClass;13 11 import org.testng.annotations.Test; 14 12 15 import com.framsticks.test. TestConfiguration;16 import com.framsticks.util.dispatching. Monitor;13 import com.framsticks.test.MonitorBasedTest; 14 import com.framsticks.util.dispatching.Joinable; 17 15 18 16 import static org.fest.assertions.Assertions.assertThat; … … 22 20 23 21 @Test 24 public abstract class BrowserBaseTest extends TestConfiguration{22 public abstract class BrowserBaseTest extends MonitorBasedTest { 25 23 26 24 private static final Logger log = Logger.getLogger(BrowserTest.class); 27 25 28 protected Monitor monitor;29 26 protected Browser browser; 30 27 protected static Robot robot; … … 39 36 } 40 37 41 @BeforeClass(timeOut = 5000) 42 public void setUp() { 38 @Override 39 protected Joinable createSubject() { 40 configureBrowser(); 41 return browser; 42 } 43 43 44 configureBrowser(); 45 46 monitor = new Monitor(browser); 47 48 monitor.use(); 49 44 protected void setUpAfterUse() { 50 45 frame = new FrameFixture(robot, 51 46 GuiActionRunner.execute(new GuiQuery<JFrame>() { … … 57 52 58 53 tree = frame.tree("tree"); 54 59 55 log.debug("frame fixture done"); 60 56 } 57 61 58 62 59 protected abstract void configureBrowser(); … … 71 68 } 72 69 73 @AfterClass(timeOut = 5000)74 public void tearDown() {75 monitor.drop().join();76 }77 78 70 } -
java/main/src/test/java/com/framsticks/gui/BrowserTest.java
r90 r96 10 10 11 11 import com.framsticks.model.ModelPackage; 12 import com.framsticks.remote. RemoteInstance;12 import com.framsticks.remote.SimulatorInstance; 13 13 14 14 public class BrowserTest extends BrowserBaseTest { … … 16 16 private static final Logger log = Logger.getLogger(BrowserTest.class); 17 17 18 RemoteInstance localhost;18 SimulatorInstance localhost; 19 19 20 20 @Override … … 22 22 browser = new Browser(); 23 23 24 localhost = new RemoteInstance();24 localhost = new SimulatorInstance(); 25 25 localhost.setName("localhost"); 26 26 localhost.setAddress("localhost:9009"); -
java/main/src/test/java/com/framsticks/gui/ObjectInstanceBrowserTest.java
r90 r96 11 11 import com.framsticks.parsers.XmlLoader; 12 12 import com.framsticks.util.dispatching.RunAt; 13 14 import static com.framsticks.core.InstanceUtils.*; 13 15 14 16 @Test … … 29 31 @Test(timeOut = 10000) 30 32 public void testShow() { 31 assertDispatch(instance,new RunAt<Instance>() {33 instance.dispatch(new RunAt<Instance>() { 32 34 @Override 33 35 public void run() { … … 40 42 clickAndExpandPath("model/parts/2"); 41 43 42 assertDispatch(instance,new RunAt<Instance>() {44 instance.dispatch(new RunAt<Instance>() { 43 45 @Override 44 46 public void run() { 45 assertThat( instance.bindAccess("/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0);47 assertThat(bindAccess(instance, "/parts/2").getFramsClass().getParamEntry("m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0); 46 48 } 47 49 }); -
java/main/src/test/java/com/framsticks/gui/ProcedureBrowserTest.java
r90 r96 16 16 import com.framsticks.test.TestClass; 17 17 import com.framsticks.util.dispatching.RunAt; 18 import static com.framsticks.core.InstanceUtils.*; 18 19 19 20 @Test … … 34 35 @Test(timeOut = 10000) 35 36 public void testShow() { 36 assertDispatch(instance,new RunAt<Instance>() {37 instance.dispatch(new RunAt<Instance>() { 37 38 @Override 38 39 public void run() { … … 43 44 clickAndExpandPath("test"); 44 45 45 assertDispatch(instance,new RunAt<Instance>() {46 instance.dispatch(new RunAt<Instance>() { 46 47 @Override 47 48 public void run() { 48 assertThat( instance.bindAccess("/").getFramsClass().getParam("history")).isInstanceOf(StringParam.class);49 assertThat(bindAccess(instance, "/").getFramsClass().getParam("history")).isInstanceOf(StringParam.class); 49 50 } 50 51 }); … … 52 53 // monitor.useFor(4.0); 53 54 54 assertDispatch(instance,new RunAt<Instance>() {55 instance.dispatch(new RunAt<Instance>() { 55 56 @Override 56 57 public void run() { 57 AccessInterface access = instance.bindAccess("/");58 AccessInterface access = bindAccess(instance, "/"); 58 59 assertThat(access).isInstanceOf(ReflectionAccess.class); 59 60 FramsClass framsClass = access.getFramsClass(); … … 74 75 waitForIdle(); 75 76 76 assertDispatch(instance,new RunAt<Instance>() {77 instance.dispatch(new RunAt<Instance>() { 77 78 @Override 78 79 public void run() { 79 assertThat( instance.bindAccess("/").get("history", String.class)).isEqualTo("argument|");80 assertThat(bindAccess(instance, "/").get("history", String.class)).isEqualTo("argument|"); 80 81 } 81 82 }); … … 84 85 waitForIdle(); 85 86 86 assertDispatch(instance,new RunAt<Instance>() {87 instance.dispatch(new RunAt<Instance>() { 87 88 @Override 88 89 public void run() { 89 assertThat( instance.bindAccess("/").get("history", String.class)).isEqualTo("");90 assertThat(bindAccess(instance, "/").get("history", String.class)).isEqualTo(""); 90 91 } 91 92 }); -
java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java
r90 r96 1 1 package com.framsticks.params; 2 2 3 import java.util.Arrays; 3 4 4 5 import org.testng.annotations.BeforeClass; … … 7 8 import com.framsticks.params.types.ProcedureParam; 8 9 import com.framsticks.params.types.StringParam; 10 import com.framsticks.parsers.Savers; 9 11 import com.framsticks.test.TestClass; 10 12 import com.framsticks.test.TestConfiguration; … … 17 19 ReflectionAccess access; 18 20 TestClass test; 19 20 21 21 22 @BeforeClass … … 36 37 assertThat(framsClass.getParam("appendHistory")).isInstanceOf(ProcedureParam.class); 37 38 assertThat(framsClass.getParam("resetHistory")).isInstanceOf(ProcedureParam.class); 39 38 40 ProcedureParam appendHistory = framsClass.getParamEntry("appendHistory", ProcedureParam.class); 39 41 assertThat(appendHistory.getArgumentsType().size()).isEqualTo(1); … … 42 44 43 45 @Test(dependsOnMethods = "checkProcedureParams") 46 public void print() { 47 assertThat(Savers.saveFramsClass(new ListSink(), framsClass).getOut()).isEqualTo( 48 Arrays.asList( 49 "class:", 50 "name:TestClass", 51 "id:TestClass", 52 "", 53 "prop:", 54 "id:name", 55 "name:Name", 56 "type:s", 57 "", 58 "prop:", 59 "id:history", 60 "name:History", 61 "type:s", 62 "", 63 "prop:", 64 "id:appendHistory", 65 "name:AppendHistory", 66 "type:p d(s arg0)", 67 "", 68 "prop:", 69 "id:resetHistory", 70 "name:ResetHistory", 71 "type:p()", 72 "" 73 ) 74 ); 75 } 76 77 78 @Test(dependsOnMethods = "print") 44 79 public void callProcedures() { 45 80 access = new ReflectionAccess(TestClass.class, framsClass); -
java/main/src/test/java/com/framsticks/params/ParamBuilderTest.java
r88 r96 23 23 assertThat(builderFramsClass.getName()).isEqualTo("prop"); 24 24 assertThat(builderFramsClass.getId()).isEqualTo("prop"); 25 assertThat(builderFramsClass.getParamEntry("flags", ValueParam.class).getDef(Object.class)).isEqualTo(new Integer(0)); 25 26 assertThat(builderFramsClass.getParamEntry("id", Param.class)).isInstanceOf(StringParam.class); 26 27 } -
java/main/src/test/java/com/framsticks/running/FramsServerTest.java
r90 r96 3 3 import org.testng.annotations.Test; 4 4 5 import com.framsticks.core.Framsticks; 6 import com.framsticks.test.TestConfiguration; 7 import com.framsticks.util.dispatching.Monitor; 5 import com.framsticks.core.XmlBasedTest; 8 6 9 7 import static org.fest.assertions.Assertions.*; 10 8 11 9 @Test 12 public class FramsServerTest extends TestConfiguration { 10 public class FramsServerTest extends XmlBasedTest { 11 12 @Override 13 protected String getConfigurationName() { 14 return "FramsServerTest.xml"; 15 } 13 16 14 17 @Test(timeOut = 3000) 15 18 public void runServer() { 16 Framsticks framsticks = Framsticks.loadConfiguration(FramsServerTest.class.getResourceAsStream("/configs/FramsServerTest.xml")); 19 assertThat(framsticks.size()).isEqualTo(1); 20 assertThat(framsticks.get("frams")).isInstanceOf(FramsServer.class); 17 21 18 assertThat(framsticks.getObservables().size()).isEqualTo(1); 19 assertThat(framsticks.getObservables().get("frams")).isInstanceOf(FramsServer.class); 20 // assertThat(framsticks.getObservables().get("remote")).isInstanceOf(RemoteInstance.class); 21 22 new Monitor(framsticks).use().useFor(1.0).drop().join(); 23 24 // monitor.use(); 25 26 // Dispatching.sleep(1000); 27 28 // // monitor.waitFor(); 29 // monitor.drop(); 30 // monitor.join(); 31 32 // framsticks.start(); 33 34 // framsticks.waitForObservables(); 35 22 monitor.useFor(1.0); 36 23 } 37 24 25 38 26 } -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r90 r96 1 1 package com.framsticks.test; 2 2 3 import java.util.HashSet; 3 4 import java.util.LinkedList; 4 5 import java.util.List; 6 import java.util.Set; 5 7 6 8 import org.apache.log4j.Logger; … … 8 10 import org.testng.annotations.*; 9 11 12 import com.framsticks.util.FramsticksException; 10 13 import com.framsticks.util.dispatching.Dispatcher; 11 import com.framsticks.util.dispatching.RunAt; 14 import com.framsticks.util.dispatching.Dispatching; 15 import com.framsticks.util.dispatching.Dispatching.Waiter; 16 import com.framsticks.util.dispatching.ExceptionHandler; 17 import com.framsticks.util.dispatching.ExceptionResultHandler; 18 19 import static org.fest.assertions.Assertions.*; 12 20 13 21 public class TestConfiguration { … … 21 29 } 22 30 23 private final List<As yncAssert<?>> asyncAssertions = new LinkedList<AsyncAssert<?>>();31 private final List<AssertionError> asyncAssertions = new LinkedList<>(); 24 32 25 public class AsyncAssert<C> extends RunAt<C> { 26 final RunAt<? extends C> runnable; 27 boolean done = false; 28 AssertionError assertion; 33 public ExceptionHandler createExceptionHandler() { 34 return new ExceptionHandler() { 35 @Override 36 public boolean handle(Dispatcher<?> dispatcher, Throwable throwable) { 37 AssertionError ae; 38 if (AssertionError.class.isInstance(throwable)) { 39 ae = AssertionError.class.cast(throwable); 40 } else { 41 ae = new AssertionError(); 42 ae.initCause(throwable); 43 } 44 synchronized (asyncAssertions) { 45 asyncAssertions.add(ae); 46 } 47 return true; 48 } 49 }; 50 } 29 51 30 /** 31 * @param runnable 32 */ 33 public AsyncAssert(RunAt<? extends C> runnable) { 34 this.runnable = runnable; 35 } 36 37 @Override 38 public void run() { 52 @AfterMethod 53 public void waitForWaiters() { 54 for (Waiter w : waiters) { 39 55 try { 40 runnable.run(); 41 } catch (AssertionError e) { 42 assertion = e; 43 } 44 synchronized (this) { 45 done = true; 46 this.notifyAll(); 56 w.waitFor(); 57 } catch (FramsticksException e) { 58 AssertionError ae = new AssertionError(); 59 ae.initCause(e); 60 asyncAssertions.add(ae); 47 61 } 48 62 } 49 63 } 50 64 51 public <C> void assertDispatch(Dispatcher<C> dispatcher, RunAt<? extends C> runnable) {52 AsyncAssert<C> assertion = new AsyncAssert<C>(runnable);65 @AfterMethod(timeOut = 1000, dependsOnMethods = "waitForWaiters") 66 public void processAsyncAssertions() { 53 67 synchronized (asyncAssertions) { 54 asyncAssertions.add(assertion); 55 } 56 dispatcher.dispatch(assertion); 57 } 58 59 @BeforeMethod 60 public void clearAsyncAsserts() { 61 synchronized (asyncAssertions) { 62 asyncAssertions.clear(); 68 if (asyncAssertions.isEmpty()) { 69 return; 70 } 71 AssertionError a = asyncAssertions.get(0); 72 asyncAssertions.remove(0); 73 throw a; 63 74 } 64 75 } 65 76 66 @AfterMethod(timeOut = 5000) 67 public void waitForAsyncAsserts() { 68 while (true) { 69 AsyncAssert<?> assertion; 70 synchronized (asyncAssertions) { 71 if (asyncAssertions.isEmpty()) { 72 return; 73 } 74 assertion = asyncAssertions.get(0); 75 asyncAssertions.remove(0); 77 final Set<Waiter> waiters = new HashSet<>(); 78 79 @BeforeMethod 80 public void clearWaiters() { 81 waiters.clear(); 82 } 83 84 protected Dispatching.Waiter produceWaiter(double timeOut) { 85 Waiter waiter = new Waiter(timeOut); 86 waiters.add(waiter); 87 return waiter; 88 } 89 90 public static ExceptionResultHandler failOnException() { 91 return new ExceptionResultHandler() { 92 @Override 93 public void handle(FramsticksException e) { 94 assertThat(e).isNull(); 76 95 } 77 synchronized (assertion) { 78 while (!assertion.done) { 79 try { 80 assertion.wait(); 81 } catch (InterruptedException ignored) { 82 } 83 } 84 if (assertion.assertion != null) { 85 throw assertion.assertion; 86 } 87 } 88 } 96 }; 97 89 98 } 90 99 } -
java/main/src/test/resources/configs/test.xml
r88 r96 2 2 <Framsticks> 3 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks.remote. RemoteInstance" />4 <import class="com.framsticks.remote.SimulatorInstance" /> 5 5 <Browser name="browser"> 6 < RemoteInstance name="localhost:9009" address="localhost:9009" />6 <SimulatorInstance name="localhost:9009" address="localhost:9009" /> 7 7 </Browser> 8 8 </Framsticks> -
java/main/src/test/resources/log4j.properties
r90 r96 27 27 28 28 log4j.logger.com.framsticks=INFO 29 # log4j.logger.com.framsticks.hosting.Server=DEBUG 30 # log4j.logger.com.framsticks.communication.ServerConnection=TRACE 31 # log4j.logger.com.framsticks.util.dispatching.AbstractJoinable=DEBUG 29 32 # log4j.logger.com.framsticks.parsers.F0Writer=TRACE 30 33 # log4j.logger.com.framsticks.core.ObjectInstance=DEBUG
Note: See TracChangeset
for help on using the changeset viewer.