2 * BodyTubeHandlerTest.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.Stage;
14 import net.sf.openrocket.rocketcomponent.ExternalComponent;
16 import java.util.HashMap;
19 * BodyTubeHandler Tester.
22 public class BodyTubeHandlerTest extends RocksimTestBase {
25 * The class under test.
27 public static final Class classUT = BodyTubeHandler.class;
30 * The test class (this class).
32 public static final Class testClass = BodyTubeHandlerTest.class;
35 * Create a test suite of all tests within this test class.
37 * @return a suite of tests
39 public static Test suite() {
40 return new TestSuite(BodyTubeHandlerTest.class);
46 * @param name the name of the test to run.
48 public BodyTubeHandlerTest(String name) {
55 public void setUp() throws Exception {
60 * Teardown the fixture.
62 public void tearDown() throws Exception {
70 * @throws Exception thrown if something goes awry
72 public void testConstructor() throws Exception {
75 new BodyTubeHandler(null);
76 fail("Should have thrown IllegalArgumentException");
78 catch (IllegalArgumentException iae) {
82 Stage stage = new Stage();
83 BodyTubeHandler handler = new BodyTubeHandler(stage);
84 BodyTube component = (BodyTube) getField(handler, "bodyTube");
85 assertContains(component, stage.getChildren());
89 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
91 * @throws Exception thrown if something goes awry
93 public void testOpenElement() throws Exception {
94 assertEquals(PlainTextHandler.INSTANCE, new BodyTubeHandler(new Stage()).openElement(null, null, null));
95 assertNotNull(new BodyTubeHandler(new Stage()).openElement("AttachedParts", null, null));
100 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
102 * @throws Exception thrown if something goes awry
104 public void testCloseElement() throws Exception {
105 Stage stage = new Stage();
106 BodyTubeHandler handler = new BodyTubeHandler(stage);
107 BodyTube component = (BodyTube) getField(handler, "bodyTube");
108 HashMap<String, String> attributes = new HashMap<String, String>();
109 WarningSet warnings = new WarningSet();
111 handler.closeElement("OD", attributes, "-1", warnings);
112 assertEquals(0d, component.getInnerRadius());
113 handler.closeElement("OD", attributes, "0", warnings);
114 assertEquals(0d, component.getInnerRadius());
115 handler.closeElement("OD", attributes, "75", warnings);
116 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
117 handler.closeElement("OD", attributes, "foo", warnings);
118 assertEquals(1, warnings.size());
121 handler.closeElement("ID", attributes, "-1", warnings);
122 assertEquals(0d, component.getInnerRadius());
123 handler.closeElement("ID", attributes, "0", warnings);
124 assertEquals(0d, component.getInnerRadius());
125 handler.closeElement("ID", attributes, "75", warnings);
126 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
127 handler.closeElement("ID", attributes, "foo", warnings);
128 assertEquals(1, warnings.size());
131 handler.closeElement("Len", attributes, "-1", warnings);
132 assertEquals(0d, component.getLength());
133 handler.closeElement("Len", attributes, "10", warnings);
134 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
135 handler.closeElement("Len", attributes, "10.0", warnings);
136 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
137 handler.closeElement("Len", attributes, "foo", warnings);
138 assertEquals(1, warnings.size());
141 handler.closeElement("IsMotorMount", attributes, "1", warnings);
142 assertTrue(component.isMotorMount());
143 handler.closeElement("IsMotorMount", attributes, "0", warnings);
144 assertFalse(component.isMotorMount());
145 handler.closeElement("IsMotorMount", attributes, "foo", warnings);
146 assertFalse(component.isMotorMount());
148 handler.closeElement("EngineOverhang", attributes, "-1", warnings);
149 assertEquals(-1d/RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
150 handler.closeElement("EngineOverhang", attributes, "10", warnings);
151 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
152 handler.closeElement("EngineOverhang", attributes, "10.0", warnings);
153 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
154 handler.closeElement("EngineOverhang", attributes, "foo", warnings);
155 assertEquals(1, warnings.size());
158 handler.closeElement("FinishCode", attributes, "-1", warnings);
159 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
160 handler.closeElement("FinishCode", attributes, "100", warnings);
161 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
162 handler.closeElement("FinishCode", attributes, "foo", warnings);
163 assertEquals(1, warnings.size());
166 handler.closeElement("Name", attributes, "Test Name", warnings);
167 assertEquals("Test Name", component.getName());
171 * Method: getComponent()
173 * @throws Exception thrown if something goes awry
175 public void testGetComponent() throws Exception {
176 assertTrue(new BodyTubeHandler(new Stage()).getComponent() instanceof BodyTube);
180 * Method: getMaterialType()
182 * @throws Exception thrown if something goes awry
184 public void testGetMaterialType() throws Exception {
185 assertEquals(Material.Type.BULK, new BodyTubeHandler(new Stage()).getMaterialType());