Changeset 90 for java/main/src/test
- Timestamp:
- 07/02/13 16:20:07 (12 years ago)
- Location:
- java/main/src/test
- Files:
-
- 9 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/test/java/com/framsticks/gui/BrowserTest.java
r88 r90 1 1 package com.framsticks.gui; 2 2 3 import javax.swing.JFrame; 3 import static org.fest.assertions.Assertions.assertThat; 4 import static org.fest.swing.edt.GuiActionRunner.execute; 5 4 6 5 7 import org.apache.log4j.Logger; 6 import org.fest.swing.edt.FailOnThreadViolationRepaintManager;7 import org.fest.swing.edt.GuiActionRunner;8 import org.fest.swing.edt.GuiQuery;9 8 import org.fest.swing.edt.GuiTask; 10 import org.fest.swing.fixture.FrameFixture; 11 import org.fest.swing.fixture.JTreeFixture; 12 // import static org.fest.swing.edt.GuiActionRunner.*; 13 import org.testng.annotations.*; 9 import org.testng.annotations.Test; 14 10 11 import com.framsticks.model.ModelPackage; 15 12 import com.framsticks.remote.RemoteInstance; 16 import com.framsticks.test.TestConfiguration;17 import com.framsticks.util.dispatching.Dispatching;18 import com.framsticks.util.dispatching.JoinableMonitor;19 // import com.framsticks.util.dispatching.Dispatching;20 13 21 import static org.fest.assertions.Assertions.*; 22 import static org.fest.swing.core.BasicRobot.robotWithNewAwtHierarchy; 23 import static org.fest.swing.edt.GuiActionRunner.*; 24 import org.fest.swing.core.Robot; 14 public class BrowserTest extends BrowserBaseTest { 25 15 26 public class BrowserTest extends TestConfiguration {27 16 private static final Logger log = Logger.getLogger(BrowserTest.class); 28 17 29 JoinableMonitor monitor; 30 Browser browser; 31 Robot robot; 32 FrameFixture frame; 18 RemoteInstance localhost; 33 19 34 @BeforeClass 35 public void setUp() { 36 FailOnThreadViolationRepaintManager.install(); 37 assertThat(executeInEDT()).isTrue(); 20 @Override 21 protected void configureBrowser() { 22 browser = new Browser(); 38 23 39 robot = robotWithNewAwtHierarchy(); 40 41 browser = new Browser(); 42 monitor = new JoinableMonitor(browser); 43 44 RemoteInstance localhost = new RemoteInstance(); 24 localhost = new RemoteInstance(); 45 25 localhost.setName("localhost"); 46 26 localhost.setAddress("localhost:9009"); 27 localhost.usePackage(new ModelPackage()); 47 28 48 29 browser.addInstance(localhost); 49 30 50 monitor.use();51 // robot.waitForIdle();52 frame = new FrameFixture(robot,53 GuiActionRunner.execute(new GuiQuery<JFrame>() {54 @Override55 protected JFrame executeInEDT() throws Throwable {56 return browser.getMainFrame().getSwing();57 }58 }));59 60 log.info("frame fixture done");61 // frame.show();62 // log.info("frame fixture shown");63 31 } 64 32 65 public void clickAndExpandPath(JTreeFixture tree, String path) { 66 tree.clickPath(path).expandPath(path); 67 robot.waitForIdle(); 68 } 69 70 @Test 33 @Test(timeOut = 10000) 71 34 public void testShow() { 72 35 log.info("testing"); 73 JTreeFixture tree = frame.tree("tree");74 36 tree.clickRow(0).expandRow(0); 75 37 robot.waitForIdle(); … … 81 43 @Override 82 44 protected void executeInEDT() throws Throwable { 83 assertThat(frame.panel("o Simulator").component().isVisible()) 84 .isTrue(); 45 assertThat(frame.panel("Simulator").component().isVisible()).isTrue(); 85 46 } 86 47 }); 87 48 88 clickAndExpandPath(tree, "localhost/simulator/genepools"); 89 clickAndExpandPath(tree, "localhost/simulator/genepools/groups"); 90 clickAndExpandPath(tree, "localhost/simulator/genepools/groups/Genotypes"); 49 clickAndExpandPath("localhost/simulator/genepools"); 50 clickAndExpandPath("localhost/simulator/genepools/groups"); 51 clickAndExpandPath("localhost/simulator/genepools/groups/Genotypes"); 52 } 91 53 92 54 93 55 94 95 96 97 // tree.clickPath("localhost/simulator/genepools/groups/Genotypes/genotypes");98 // robot.waitForIdle();99 // sleep(2);100 // tree.expandPath("localhost/simulator/genepools/groups/Genotypes/genotypes");101 102 // tree.expandRow(tree.component().getLeadSelectionRow() + 1);103 // robot.waitForIdle();104 105 // sleep(2);106 }107 108 109 @AfterClass110 public void tearDown() {111 log.info("before close");112 113 monitor.drop();114 115 Dispatching.joinAbsolutely(browser);116 // frame.cleanUp();117 // log.info("before close");118 // browser.interrupt();119 120 // try {121 // // frame.close();122 // } catch (Throwable t) {123 // log.error("caught ", t);124 // }125 // log.info("after close");126 // // frame.close();127 // // frame.cleanUp();128 129 130 131 // Dispatching.join(browser);132 }133 134 56 } -
java/main/src/test/java/com/framsticks/model/f0/SchemaTest.java
r88 r90 3 3 import org.testng.annotations.*; 4 4 5 import com.framsticks.params.FramsClass; 5 6 import com.framsticks.params.types.FloatParam; 6 7 import com.framsticks.test.TestConfiguration; … … 15 16 @Test 16 17 public void loadSchemaWithXmlLoader() { 17 Schema schema = Schema.load(Schema.getDefaultDefinitionAsStream());18 Schema schema = new SchemaBuilder().stream(Schema.getDefaultDefinitionAsStream()).finish(); 18 19 assertThat(schema.getFramsClasses().size()).isEqualTo(5); 19 20 assertThat(schema.getNeuroClasses().size()).isEqualTo(21); … … 23 24 assertThat(schema.getNeuroClass("VEye").getParamEntry("p", FloatParam.class).getMax(Double.class)).isEqualTo(10.0, delta(0.0)); 24 25 25 assertThat(schema.getFramsClass("p").getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0)); 26 FramsClass partClass = schema.getFramsClass("p"); 27 assertThat(partClass).isNotNull(); 28 assertThat(partClass.getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0)); 29 assertThat(partClass.getGroupCount()).isEqualTo(3); 30 assertThat(partClass.getGroup(1).getName()).isEqualTo("Other properties"); 31 assertThat(partClass.getGroup(1).getCount()).isEqualTo(7); 32 assertThat(partClass.getGroup(1).getParam(2)).isEqualTo(partClass.getParam("dn")); 26 33 } 27 34 -
java/main/src/test/java/com/framsticks/parsers/F0ParserTest.java
r88 r90 4 4 5 5 import com.framsticks.model.*; 6 import com.framsticks.model.Package;7 6 import com.framsticks.model.f0.Schema; 7 import com.framsticks.model.f0.SchemaBuilder; 8 8 import com.framsticks.params.*; 9 9 import com.framsticks.params.types.FloatParam; … … 25 25 private Schema schema; 26 26 private List<AccessInterface> accesses; 27 private List< Object> objects;27 private List<ModelComponent> components; 28 28 private Model model; 29 29 30 30 @BeforeClass 31 31 public void setUp() throws Exception { 32 schema = Schema.load(Schema.getDefaultDefinitionAsStream()); 33 Package.register(schema.getRegistry()); 32 schema = new SchemaBuilder().stream(Schema.getDefaultDefinitionAsStream()).finish(); 34 33 } 35 34 36 35 @Test 36 public void checkFramsClasses() { 37 FramsClass modelClass = schema.getRegistry().getFramsClass("Model"); 38 assertThat(modelClass).isNotNull(); 39 assertThat(modelClass.getParam("se")).isInstanceOf(FloatParam.class); 40 // assertThat(modelClass.getParam("energ0")).isInstanceOf(FloatParam.class); 41 assertThat(modelClass.getParam("Vstyle")).isInstanceOf(StringParam.class); 42 assertThat(modelClass.getParamCount()).isEqualTo(6); 43 // assertThat(); 44 45 } 46 47 @Test(dependsOnMethods = "checkFramsClasses") 37 48 public void primitiveParam() { 38 49 FramsClass joint = schema.getFramsClass("j"); … … 43 54 assertThat(dx.getMin(Double.class)).isEqualTo(-2.0, delta(0.0)); 44 55 45 assertThat(schema.getRegistry().get InfoFromCache("n").getParamEntry("d", StringParam.class).getDef(String.class)).isEqualTo("N");56 assertThat(schema.getRegistry().getFramsClass("n").getParamEntry("d", StringParam.class).getDef(String.class)).isEqualTo("N"); 46 57 } 47 58 48 @Test 59 @Test(dependsOnMethods = "primitiveParam") 49 60 public void readF0() throws IOException, ParseException { 50 61 assertThat(schema.getFramsClass("p")).isInstanceOf(FramsClass.class); 51 assertThat(schema.getRegistry().get InfoFromCache("p").getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0));62 assertThat(schema.getRegistry().getFramsClass("p").getParamEntry("as", FloatParam.class).getDef(Double.class)).isEqualTo(0.25, delta(0.0)); 52 63 53 64 accesses = new F0Parser(schema, F0ParserTest.class.getResourceAsStream("/parsers/f0_example.txt")).parse(); 54 65 55 assertThat(accesses.size()).isEqualTo(1 2);66 assertThat(accesses.size()).isEqualTo(19); 56 67 assertThat(accesses.get(0).getSelected()).isInstanceOf(Model.class); 57 68 assertThat(accesses.get(5).get("i", String.class)).isEqualTo("1,2,3,\"dsadsa,,,,"); … … 62 73 @Test(dependsOnMethods = {"readF0"}) 63 74 public void stripAccessInterface() { 64 objects = Util.stripAccessInterface(accesses);75 components = Util.stripAccessInterface(accesses, ModelComponent.class); 65 76 66 assertThat(objects.get(1)).isInstanceOf(Part.class); 67 assertThat(objects.get(4)).isInstanceOf(Joint.class); 68 assertThat(objects.get(6)).isInstanceOf(NeuroDef.class); 77 assertThat(components.get(1)).isInstanceOf(Part.class); 78 assertThat(components.get(4)).isInstanceOf(Joint.class); 79 assertThat(components.get(6)).isInstanceOf(NeuroDefinition.class); 80 assertThat(components.get(12)).isInstanceOf(NeuroConnection.class); 69 81 } 70 82 71 83 @Test(dependsOnMethods = {"stripAccessInterface"}) 72 84 public void buildModel() { 73 model = Model.build(objects);85 model = new ModelBuilder().addComponents(components).finish(); 74 86 75 87 assertThat(model.getParts().size()).isEqualTo(3); 76 assertThat(model.getNeuroDef s().size()).isEqualTo(6);88 assertThat(model.getNeuroDefinitions().size()).isEqualTo(6); 77 89 assertThat(model.getJoints().size()).isEqualTo(2); 78 79 assertThat(model.getJoints().get(0).part1).isEqualTo(0); 80 assertThat(model.getJoints().get(0).part2).isEqualTo(1); 81 assertThat(model.getNeuroDefs().size()).isEqualTo(6); 82 assertThat(model.getNeuroDefs().get(0).part).isEqualTo(1); 83 assertThat(model.getNeuroDefs().get(0).joint).isEqualTo(-1); 84 assertThat(model.getNeuroDefs().get(1).details).isEqualTo("|:p=0.25,r=1"); 85 assertThat(model.getNeuroDefs().get(3).details).isEqualTo("N"); 86 assertThat(model.getNeuroDefs().get(4).part).isEqualTo(-1); 90 assertThat(model.getNeuroConnections().size()).isEqualTo(7); 87 91 88 92 assertThat(model.getParts().get(1).getPosition().x).isEqualTo(2.0, delta(0.0)); 89 93 assertThat(model.getParts().get(2).getPosition().sub(new Point3d(2.27236, -0.0792596, -0.958924)).length()).isLessThan(0.0001); 90 94 assertThat(model.getParts().get(2).getOrientation().y.sub(new Point3d(0.870277, -0.404792, 0.280644)).length()).isLessThan(0.0001); 95 96 assertThat(model.getJoints().get(0).part1).isEqualTo(0); 97 assertThat(model.getJoints().get(0).part2).isEqualTo(1); 98 99 assertThat(model.getNeuroDefinitions().get(0).part).isEqualTo(1); 100 assertThat(model.getNeuroDefinitions().get(0).joint).isEqualTo(-1); 101 assertThat(model.getNeuroDefinitions().get(1).details).isEqualTo("|:p=0.25,r=1"); 102 assertThat(model.getNeuroDefinitions().get(3).details).isEqualTo("N"); 103 assertThat(model.getNeuroDefinitions().get(4).part).isEqualTo(-1); 104 105 assertThat(model.getNeuroConnections().get(2).connectedNeuro).isEqualTo(0); 106 assertThat(model.getNeuroConnections().get(5).weight).isEqualTo(5.6, delta(0.0)); 107 91 108 } 92 109 … … 94 111 public void print() throws Exception { 95 112 ListSink sink = new ListSink(); 96 97 113 98 114 new F0Writer(schema, model, sink).write(); … … 110 126 "n:j=0,d=@:p=0.25", 111 127 "n:p=1,d=Nu", 128 "c:0,2", 129 "c:0,2,5.4", 130 "c:1,0", 131 "c:2,0,3.4", 132 "c:0,1,4.5", 133 "c:1,0,5.6", 134 "c:2,1", 112 135 "m:" 113 136 ); -
java/main/src/test/java/com/framsticks/running/ExternalProcessTest.java
r88 r90 10 10 11 11 import com.framsticks.test.TestConfiguration; 12 import com.framsticks.util.dispatching. JoinableMonitor;12 import com.framsticks.util.dispatching.Monitor; 13 13 14 14 import static org.fest.assertions.Assertions.*; … … 17 17 public class ExternalProcessTest extends TestConfiguration { 18 18 19 @Test 19 @Test(timeOut = 1000) 20 20 public void runBash() throws InterruptedException { 21 21 final ExternalProcess process = new ExternalProcess(); … … 31 31 } 32 32 }); 33 JoinableMonitor monitor = new JoinableMonitor(process);33 Monitor monitor = new Monitor(process); 34 34 monitor.use(); 35 35 -
java/main/src/test/java/com/framsticks/running/FramsServerTest.java
r88 r90 4 4 5 5 import com.framsticks.core.Framsticks; 6 import com.framsticks.remote.RemoteInstance;7 6 import com.framsticks.test.TestConfiguration; 7 import com.framsticks.util.dispatching.Monitor; 8 8 9 9 import static org.fest.assertions.Assertions.*; … … 12 12 public class FramsServerTest extends TestConfiguration { 13 13 14 @Test 14 @Test(timeOut = 3000) 15 15 public void runServer() { 16 16 Framsticks framsticks = Framsticks.loadConfiguration(FramsServerTest.class.getResourceAsStream("/configs/FramsServerTest.xml")); 17 17 18 assertThat(framsticks.getObservables().size()).isEqualTo( 2);18 assertThat(framsticks.getObservables().size()).isEqualTo(1); 19 19 assertThat(framsticks.getObservables().get("frams")).isInstanceOf(FramsServer.class); 20 assertThat(framsticks.getObservables().get("remote")).isInstanceOf(RemoteInstance.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(); 21 31 22 32 // framsticks.start(); -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r88 r90 1 1 package com.framsticks.test; 2 3 import java.util.LinkedList; 4 import java.util.List; 2 5 3 6 import org.apache.log4j.Logger; … … 5 8 import org.testng.annotations.*; 6 9 10 import com.framsticks.util.dispatching.Dispatcher; 11 import com.framsticks.util.dispatching.RunAt; 12 7 13 public class TestConfiguration { 8 14 9 private static final Logger log = 10 Logger.getLogger(TestConfiguration.class); 15 private static final Logger log = Logger.getLogger(TestConfiguration.class); 11 16 12 17 @BeforeClass … … 16 21 } 17 22 23 private final List<AsyncAssert<?>> asyncAssertions = new LinkedList<AsyncAssert<?>>(); 24 25 public class AsyncAssert<C> extends RunAt<C> { 26 final RunAt<? extends C> runnable; 27 boolean done = false; 28 AssertionError assertion; 29 30 /** 31 * @param runnable 32 */ 33 public AsyncAssert(RunAt<? extends C> runnable) { 34 this.runnable = runnable; 35 } 36 37 @Override 38 public void run() { 39 try { 40 runnable.run(); 41 } catch (AssertionError e) { 42 assertion = e; 43 } 44 synchronized (this) { 45 done = true; 46 this.notifyAll(); 47 } 48 } 49 } 50 51 public <C> void assertDispatch(Dispatcher<C> dispatcher, RunAt<? extends C> runnable) { 52 AsyncAssert<C> assertion = new AsyncAssert<C>(runnable); 53 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(); 63 } 64 } 65 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); 76 } 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 } 89 } 18 90 } -
java/main/src/test/resources/configs/FramsServerTest.xml
r88 r90 3 3 <import class="com.framsticks.running.FramsServer" /> 4 4 <import class="com.framsticks.remote.RemoteInstance" /> 5 <FramsServer name="frams" port="9008" /> 6 <RemoteInstance name="remote" address="localhost:9008" /> 5 <import class="com.framsticks.running.LoggingOutputListener" /> 6 <FramsServer name="frams" port="9008"> 7 <LoggingOutputListener /> 8 </FramsServer> 9 <!-- <RemoteInstance name="remote" address="localhost:9008" /> --> 7 10 </Framsticks> -
java/main/src/test/resources/info/Part.info
r86 r90 3 3 4 4 prop: 5 id:x 5 6 name:position.x 6 id:x7 7 type:f 8 8 flags:1024 9 9 10 10 prop: 11 id:y 11 12 name:position.y 12 id:y13 13 type:f 14 14 flags:1024 15 15 16 16 prop: 17 id:z 17 18 name:position.z 18 id:z19 19 type:f 20 20 flags:1024 21 21 22 22 prop: 23 id:m 23 24 name:mass 24 id:m 25 type:f 26 flags:0 25 type:f 0.1 999.0 1.0 27 26 28 27 prop: 28 id:s 29 29 name:size 30 id:s 31 type:f 32 flags:0 30 type:f 0.1 10.0 1.0 33 31 34 32 prop: 33 id:dn 35 34 name:density 36 id:dn 37 type:f 38 flags:0 35 type:f 0.2 5.0 1.0 39 36 40 37 prop: 38 id:fr 41 39 name:friction 42 id:fr 43 type:f 44 flags:0 40 type:f 0.0 4.0 0.4 45 41 46 42 prop: 43 id:ing 47 44 name:ingestion 48 id:ing 49 type:f 50 flags:0 45 type:f 0.0 1.0 0.25 51 46 52 47 prop: 48 id:as 53 49 name:assimilation 54 id:as 55 type:f 56 flags:0 50 type:f 0.0 1.0 0.25 57 51 58 52 prop: 53 id:rx 59 54 name:rot.x 60 id:rx61 55 type:f 62 flags:063 56 64 57 prop: 58 id:ry 65 59 name:rot.y 66 id:ry67 60 type:f 68 61 flags:1024 69 62 70 63 prop: 64 id:rz 71 65 name:rot.z 72 id:rz73 66 type:f 74 67 flags:1024 75 68 76 69 prop: 70 id:i 77 71 name:info 78 id:i79 72 type:s 80 flags:081 73 82 74 prop: 75 id:Vstyle 83 76 name:vis_style 84 id:Vstyle 85 type:s 86 flags:0 77 type:s 0 -1 part 87 78 88 79 prop: 80 id:vs 89 81 name:visual thickness 90 id:vs 91 type:f 92 flags:0 82 type:f 0.05 0.7 0.3 93 83 94 84 prop: 85 id:vr 95 86 name:red component 96 id:vr 97 type:f 98 flags:0 87 type:f 0.0 1.0 0.5 99 88 100 89 prop: 90 id:vg 101 91 name:green component 102 id:vg 103 type:f 92 type:f 0.0 1.0 0.5 104 93 flags:1024 105 94 106 95 prop: 96 id:vb 107 97 name:blue component 108 id:vb 109 type:f 98 type:f 0.0 1.0 0.5 110 99 flags:1024 111 100 -
java/main/src/test/resources/log4j.properties
r88 r90 27 27 28 28 log4j.logger.com.framsticks=INFO 29 # log4j.logger.com.framsticks.util.dispatching.JoinableMonitor=DEBUG 30 # log4j.logger.com.framsticks.util.dispatching.Dispatching=DEBUG 29 # log4j.logger.com.framsticks.parsers.F0Writer=TRACE 30 # log4j.logger.com.framsticks.core.ObjectInstance=DEBUG 31 # log4j.logger.com.framsticks.core.Instance=DEBUG 32 # log4j.logger.com.framsticks.running=DEBUG 31 33 # log4j.logger.com.framsticks.parsers.XmlLoader=DEBUG 32 34 # log4j.logger.com.framsticks.parsers.MultiParamLoader=TRACE -
java/main/src/test/resources/parsers/f0_example.txt
r78 r90 12 12 n:j=0,d=@:p=0.25 13 13 n:p=1,d=Nu 14 #c:0,215 #c:0,2,5.416 #c:1,017 #c:2,0,3.418 #c:0,1,4.519 #c:1,0,5.620 #c:2,114 c:0,2 15 c:0,2,5.4 16 c:1,0 17 c:2,0,3.4 18 c:0,1,4.5 19 c:1,0,5.6 20 c:2,1
Note: See TracChangeset
for help on using the changeset viewer.