2 * BodyTubeHandlerTest.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.ExternalComponent;
12 import net.sf.openrocket.rocketcomponent.Stage;
13 import org.junit.Assert;
14 import org.junit.Test;
16 import java.util.HashMap;
19 * BodyTubeHandler Tester.
22 public class BodyTubeHandlerTest extends RocksimTestBase {
27 * @throws Exception thrown if something goes awry
30 public void testConstructor() throws Exception {
33 new BodyTubeHandler(null, new WarningSet());
34 Assert.fail("Should have thrown IllegalArgumentException");
36 catch (IllegalArgumentException iae) {
40 Stage stage = new Stage();
41 BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
42 BodyTube component = (BodyTube) getField(handler, "bodyTube");
43 assertContains(component, stage.getChildren());
47 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
49 * @throws Exception thrown if something goes awry
52 public void testOpenElement() throws Exception {
53 Assert.assertEquals(PlainTextHandler.INSTANCE, new BodyTubeHandler(new Stage(), new WarningSet()).openElement(null, null, null));
54 Assert.assertNotNull(new BodyTubeHandler(new Stage(), new WarningSet()).openElement("AttachedParts", null, null));
59 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
61 * @throws Exception thrown if something goes awry
64 public void testCloseElement() throws Exception {
65 Stage stage = new Stage();
66 BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
67 BodyTube component = (BodyTube) getField(handler, "bodyTube");
68 HashMap<String, String> attributes = new HashMap<String, String>();
69 WarningSet warnings = new WarningSet();
71 handler.closeElement("OD", attributes, "-1", warnings);
72 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
73 handler.closeElement("OD", attributes, "0", warnings);
74 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
75 handler.closeElement("OD", attributes, "75", warnings);
76 Assert.assertEquals(75d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
77 handler.closeElement("OD", attributes, "foo", warnings);
78 Assert.assertEquals(1, warnings.size());
81 handler.closeElement("ID", attributes, "-1", warnings);
82 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
83 handler.closeElement("ID", attributes, "0", warnings);
84 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
85 handler.closeElement("ID", attributes, "75", warnings);
86 Assert.assertEquals(75d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
87 handler.closeElement("ID", attributes, "foo", warnings);
88 Assert.assertEquals(1, warnings.size());
91 handler.closeElement("Len", attributes, "-1", warnings);
92 Assert.assertEquals(0d, component.getLength(), 0.001);
93 handler.closeElement("Len", attributes, "10", warnings);
94 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
95 handler.closeElement("Len", attributes, "10.0", warnings);
96 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
97 handler.closeElement("Len", attributes, "foo", warnings);
98 Assert.assertEquals(1, warnings.size());
101 handler.closeElement("IsMotorMount", attributes, "1", warnings);
102 Assert.assertTrue(component.isMotorMount());
103 handler.closeElement("IsMotorMount", attributes, "0", warnings);
104 Assert.assertFalse(component.isMotorMount());
105 handler.closeElement("IsMotorMount", attributes, "foo", warnings);
106 Assert.assertFalse(component.isMotorMount());
108 handler.closeElement("EngineOverhang", attributes, "-1", warnings);
109 Assert.assertEquals(-1d/ RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
110 handler.closeElement("EngineOverhang", attributes, "10", warnings);
111 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
112 handler.closeElement("EngineOverhang", attributes, "10.0", warnings);
113 Assert.assertEquals(10d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
114 handler.closeElement("EngineOverhang", attributes, "foo", warnings);
115 Assert.assertEquals(1, warnings.size());
118 handler.closeElement("FinishCode", attributes, "-1", warnings);
119 Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
120 handler.closeElement("FinishCode", attributes, "100", warnings);
121 Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
122 handler.closeElement("FinishCode", attributes, "foo", warnings);
123 Assert.assertEquals(1, warnings.size());
126 handler.closeElement("Name", attributes, "Test Name", warnings);
127 Assert.assertEquals("Test Name", component.getName());
131 * Method: getComponent()
133 * @throws Exception thrown if something goes awry
136 public void testGetComponent() throws Exception {
137 Assert.assertTrue(new BodyTubeHandler(new Stage(), new WarningSet()).getComponent() instanceof BodyTube);
141 * Method: getMaterialType()
143 * @throws Exception thrown if something goes awry
146 public void testGetMaterialType() throws Exception {
147 Assert.assertEquals(Material.Type.BULK, new BodyTubeHandler(new Stage(), new WarningSet()).getMaterialType());