2 * InnerBodyTubeHandlerTest.java
4 package net.sf.openrocket.file.rocksim;
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8 import net.sf.openrocket.aerodynamics.WarningSet;
9 import net.sf.openrocket.database.Databases;
10 import net.sf.openrocket.file.simplesax.PlainTextHandler;
11 import net.sf.openrocket.material.Material;
12 import net.sf.openrocket.rocketcomponent.BodyTube;
13 import net.sf.openrocket.rocketcomponent.InnerTube;
14 import net.sf.openrocket.rocketcomponent.RocketComponent;
15 import net.sf.openrocket.rocketcomponent.Stage;
17 import java.util.HashMap;
20 * InnerBodyTubeHandler Tester.
23 public class InnerBodyTubeHandlerTest extends RocksimTestBase {
26 * The class under test.
28 public static final Class classUT = InnerBodyTubeHandler.class;
31 * The test class (this class).
33 public static final Class testClass = InnerBodyTubeHandlerTest.class;
36 * Create a test suite of all tests within this test class.
38 * @return a suite of tests
40 public static Test suite() {
41 return new TestSuite(InnerBodyTubeHandlerTest.class);
47 * @param name the name of the test to run.
49 public InnerBodyTubeHandlerTest(String name) {
56 public void setUp() throws Exception {
61 * Teardown the fixture.
63 public void tearDown() throws Exception {
71 * @throws Exception thrown if something goes awry
73 public void testConstructor() throws Exception {
76 new InnerBodyTubeHandler(null);
77 fail("Should have thrown IllegalArgumentException");
79 catch (IllegalArgumentException iae) {
83 BodyTube tube = new BodyTube();
84 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube);
85 InnerTube component = (InnerTube) getField(handler, "bodyTube");
86 assertContains(component, tube.getChildren());
90 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
92 * @throws Exception thrown if something goes awry
94 public void testOpenElement() throws Exception {
95 assertEquals(PlainTextHandler.INSTANCE, new InnerBodyTubeHandler(new BodyTube()).openElement(null, null, null));
96 assertNotNull(new InnerBodyTubeHandler(new BodyTube()).openElement("AttachedParts", null, null));
101 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
103 * @throws Exception thrown if something goes awry
105 public void testCloseElement() throws Exception {
106 BodyTube tube = new BodyTube();
107 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube);
108 InnerTube component = (InnerTube) getField(handler, "bodyTube");
109 HashMap<String, String> attributes = new HashMap<String, String>();
110 WarningSet warnings = new WarningSet();
112 handler.closeElement("OD", attributes, "-1", warnings);
113 assertEquals(0d, component.getInnerRadius());
114 handler.closeElement("OD", attributes, "0", warnings);
115 assertEquals(0d, component.getInnerRadius());
116 handler.closeElement("OD", attributes, "75", warnings);
117 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
118 handler.closeElement("OD", attributes, "foo", warnings);
119 assertEquals(1, warnings.size());
122 handler.closeElement("ID", attributes, "-1", warnings);
123 assertEquals(0d, component.getInnerRadius());
124 handler.closeElement("ID", attributes, "0", warnings);
125 assertEquals(0d, component.getInnerRadius());
126 handler.closeElement("ID", attributes, "75", warnings);
127 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
128 handler.closeElement("ID", attributes, "foo", warnings);
129 assertEquals(1, warnings.size());
132 handler.closeElement("Len", attributes, "-1", warnings);
133 assertEquals(0d, component.getLength());
134 handler.closeElement("Len", attributes, "10", warnings);
135 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
136 handler.closeElement("Len", attributes, "10.0", warnings);
137 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
138 handler.closeElement("Len", attributes, "foo", warnings);
139 assertEquals(1, warnings.size());
142 handler.closeElement("IsMotorMount", attributes, "1", warnings);
143 assertTrue(component.isMotorMount());
144 handler.closeElement("IsMotorMount", attributes, "0", warnings);
145 assertFalse(component.isMotorMount());
146 handler.closeElement("IsMotorMount", attributes, "foo", warnings);
147 assertFalse(component.isMotorMount());
149 handler.closeElement("EngineOverhang", attributes, "-1", warnings);
150 assertEquals(-1d/RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
151 handler.closeElement("EngineOverhang", attributes, "10", warnings);
152 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
153 handler.closeElement("EngineOverhang", attributes, "10.0", warnings);
154 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
155 handler.closeElement("EngineOverhang", attributes, "foo", warnings);
156 assertEquals(1, warnings.size());
159 handler.closeElement("Name", attributes, "Test Name", warnings);
160 assertEquals("Test Name", component.getName());
164 * Method: setRelativePosition(RocketComponent.Position position)
166 * @throws Exception thrown if something goes awry
168 public void testSetRelativePosition() throws Exception {
169 BodyTube tube = new BodyTube();
170 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube);
171 InnerTube component = (InnerTube) getField(handler, "bodyTube");
172 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
173 assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
177 * Method: getComponent()
179 * @throws Exception thrown if something goes awry
181 public void testGetComponent() throws Exception {
182 assertTrue(new InnerBodyTubeHandler(new BodyTube()).getComponent() instanceof InnerTube);
186 * Method: getMaterialType()
188 * @throws Exception thrown if something goes awry
190 public void testGetMaterialType() throws Exception {
191 assertEquals(Material.Type.BULK, new InnerBodyTubeHandler(new BodyTube()).getMaterialType());