2 * InnerBodyTubeHandlerTest.java
4 package net.sf.openrocket.file.rocksim;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.simplesax.PlainTextHandler;
8 import net.sf.openrocket.material.Material;
9 import net.sf.openrocket.rocketcomponent.BodyTube;
10 import net.sf.openrocket.rocketcomponent.InnerTube;
11 import net.sf.openrocket.rocketcomponent.RocketComponent;
12 import org.junit.Assert;
14 import java.util.HashMap;
17 * InnerBodyTubeHandler Tester.
20 public class InnerBodyTubeHandlerTest extends RocksimTestBase {
25 * @throws Exception thrown if something goes awry
28 public void testConstructor() throws Exception {
31 new InnerBodyTubeHandler(null, new WarningSet());
32 Assert.fail("Should have thrown IllegalArgumentException");
34 catch (IllegalArgumentException iae) {
38 BodyTube tube = new BodyTube();
39 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
40 InnerTube component = (InnerTube) getField(handler, "bodyTube");
41 assertContains(component, tube.getChildren());
45 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
47 * @throws Exception thrown if something goes awry
50 public void testOpenElement() throws Exception {
51 Assert.assertEquals(PlainTextHandler.INSTANCE, new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
52 Assert.assertNotNull(new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).openElement("AttachedParts", null, null));
57 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
59 * @throws Exception thrown if something goes awry
62 public void testCloseElement() throws Exception {
63 BodyTube tube = new BodyTube();
64 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
65 InnerTube component = (InnerTube) getField(handler, "bodyTube");
66 HashMap<String, String> attributes = new HashMap<String, String>();
67 WarningSet warnings = new WarningSet();
69 handler.closeElement("OD", attributes, "-1", warnings);
70 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
71 handler.closeElement("OD", attributes, "0", warnings);
72 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
73 handler.closeElement("OD", attributes, "75", warnings);
74 Assert.assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
75 handler.closeElement("OD", attributes, "foo", warnings);
76 Assert.assertEquals(1, warnings.size());
79 handler.closeElement("ID", attributes, "-1", warnings);
80 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
81 handler.closeElement("ID", attributes, "0", warnings);
82 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
83 handler.closeElement("ID", attributes, "75", warnings);
84 Assert.assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
85 handler.closeElement("ID", attributes, "foo", warnings);
86 Assert.assertEquals(1, warnings.size());
89 handler.closeElement("Len", attributes, "-1", warnings);
90 Assert.assertEquals(0d, component.getLength(), 0.001);
91 handler.closeElement("Len", attributes, "10", warnings);
92 Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
93 handler.closeElement("Len", attributes, "10.0", warnings);
94 Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
95 handler.closeElement("Len", attributes, "foo", warnings);
96 Assert.assertEquals(1, warnings.size());
99 handler.closeElement("IsMotorMount", attributes, "1", warnings);
100 Assert.assertTrue(component.isMotorMount());
101 handler.closeElement("IsMotorMount", attributes, "0", warnings);
102 Assert.assertFalse(component.isMotorMount());
103 handler.closeElement("IsMotorMount", attributes, "foo", warnings);
104 Assert.assertFalse(component.isMotorMount());
106 handler.closeElement("EngineOverhang", attributes, "-1", warnings);
107 Assert.assertEquals(-1d/RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
108 handler.closeElement("EngineOverhang", attributes, "10", warnings);
109 Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
110 handler.closeElement("EngineOverhang", attributes, "10.0", warnings);
111 Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
112 handler.closeElement("EngineOverhang", attributes, "foo", warnings);
113 Assert.assertEquals(1, warnings.size());
116 handler.closeElement("Name", attributes, "Test Name", warnings);
117 Assert.assertEquals("Test Name", component.getName());
121 * Method: setRelativePosition(RocketComponent.Position position)
123 * @throws Exception thrown if something goes awry
126 public void testSetRelativePosition() throws Exception {
127 BodyTube tube = new BodyTube();
128 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
129 InnerTube component = (InnerTube) getField(handler, "bodyTube");
130 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
131 Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
135 * Method: getComponent()
137 * @throws Exception thrown if something goes awry
140 public void testGetComponent() throws Exception {
141 Assert.assertTrue(new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).getComponent() instanceof InnerTube);
145 * Method: getMaterialType()
147 * @throws Exception thrown if something goes awry
150 public void testGetMaterialType() throws Exception {
151 Assert.assertEquals(Material.Type.BULK, new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).getMaterialType());