2 * InnerBodyTubeHandlerTest.java
4 package net.sf.openrocket.file.rocksim.importt;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
8 import net.sf.openrocket.file.simplesax.PlainTextHandler;
9 import net.sf.openrocket.material.Material;
10 import net.sf.openrocket.rocketcomponent.BodyTube;
11 import net.sf.openrocket.rocketcomponent.InnerTube;
12 import net.sf.openrocket.rocketcomponent.RocketComponent;
13 import org.junit.Assert;
15 import java.util.HashMap;
18 * InnerBodyTubeHandler Tester.
21 public class InnerBodyTubeHandlerTest extends RocksimTestBase {
26 * @throws Exception thrown if something goes awry
29 public void testConstructor() throws Exception {
32 new InnerBodyTubeHandler(null, new WarningSet());
33 Assert.fail("Should have thrown IllegalArgumentException");
35 catch (IllegalArgumentException iae) {
39 BodyTube tube = new BodyTube();
40 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
41 InnerTube component = (InnerTube) getField(handler, "bodyTube");
42 assertContains(component, tube.getChildren());
46 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
48 * @throws Exception thrown if something goes awry
51 public void testOpenElement() throws Exception {
52 Assert.assertEquals(PlainTextHandler.INSTANCE, new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
53 Assert.assertNotNull(new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).openElement("AttachedParts", null, null));
58 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
60 * @throws Exception thrown if something goes awry
63 public void testCloseElement() throws Exception {
64 BodyTube tube = new BodyTube();
65 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
66 InnerTube component = (InnerTube) getField(handler, "bodyTube");
67 HashMap<String, String> attributes = new HashMap<String, String>();
68 WarningSet warnings = new WarningSet();
70 handler.closeElement("OD", attributes, "-1", warnings);
71 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
72 handler.closeElement("OD", attributes, "0", warnings);
73 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
74 handler.closeElement("OD", attributes, "75", warnings);
75 Assert.assertEquals(75d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
76 handler.closeElement("OD", attributes, "foo", warnings);
77 Assert.assertEquals(1, warnings.size());
80 handler.closeElement("ID", attributes, "-1", warnings);
81 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
82 handler.closeElement("ID", attributes, "0", warnings);
83 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
84 handler.closeElement("ID", attributes, "75", warnings);
85 Assert.assertEquals(75d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
86 handler.closeElement("ID", attributes, "foo", warnings);
87 Assert.assertEquals(1, warnings.size());
90 handler.closeElement("Len", attributes, "-1", warnings);
91 Assert.assertEquals(0d, component.getLength(), 0.001);
92 handler.closeElement("Len", attributes, "10", warnings);
93 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
94 handler.closeElement("Len", attributes, "10.0", warnings);
95 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
96 handler.closeElement("Len", attributes, "foo", warnings);
97 Assert.assertEquals(1, warnings.size());
100 handler.closeElement("IsMotorMount", attributes, "1", warnings);
101 Assert.assertTrue(component.isMotorMount());
102 handler.closeElement("IsMotorMount", attributes, "0", warnings);
103 Assert.assertFalse(component.isMotorMount());
104 handler.closeElement("IsMotorMount", attributes, "foo", warnings);
105 Assert.assertFalse(component.isMotorMount());
107 handler.closeElement("EngineOverhang", attributes, "-1", warnings);
108 Assert.assertEquals(-1d/ RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
109 handler.closeElement("EngineOverhang", attributes, "10", warnings);
110 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
111 handler.closeElement("EngineOverhang", attributes, "10.0", warnings);
112 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
113 handler.closeElement("EngineOverhang", attributes, "foo", warnings);
114 Assert.assertEquals(1, warnings.size());
117 handler.closeElement("Name", attributes, "Test Name", warnings);
118 Assert.assertEquals("Test Name", component.getName());
122 * Method: setRelativePosition(RocketComponent.Position position)
124 * @throws Exception thrown if something goes awry
127 public void testSetRelativePosition() throws Exception {
128 BodyTube tube = new BodyTube();
129 InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
130 InnerTube component = (InnerTube) getField(handler, "bodyTube");
131 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
132 Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
136 * Method: getComponent()
138 * @throws Exception thrown if something goes awry
141 public void testGetComponent() throws Exception {
142 Assert.assertTrue(new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).getComponent() instanceof InnerTube);
146 * Method: getMaterialType()
148 * @throws Exception thrown if something goes awry
151 public void testGetMaterialType() throws Exception {
152 Assert.assertEquals(Material.Type.BULK, new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).getMaterialType());