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.file.simplesax.PlainTextHandler;
10 import net.sf.openrocket.material.Material;
11 import net.sf.openrocket.rocketcomponent.BodyTube;
12 import net.sf.openrocket.rocketcomponent.CenteringRing;
13 import net.sf.openrocket.rocketcomponent.RocketComponent;
15 import java.util.HashMap;
20 public class RingHandlerTest extends RocksimTestBase {
23 * The class under test.
25 public static final Class classUT = RingHandler.class;
28 * The test class (this class).
30 public static final Class testClass = RingHandlerTest.class;
33 * Create a test suite of all tests within this test class.
35 * @return a suite of tests
37 public static Test suite() {
38 return new TestSuite(RingHandlerTest.class);
44 * @param name the name of the test to run.
46 public RingHandlerTest(String name) {
53 public void setUp() throws Exception {
58 * Teardown the fixture.
60 public void tearDown() throws Exception {
65 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
67 * @throws Exception thrown if something goes awry
69 public void testOpenElement() throws Exception {
70 assertEquals(PlainTextHandler.INSTANCE, new RingHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
74 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
76 * @throws Exception thrown if something goes awry
78 public void testCloseElement() throws Exception {
80 BodyTube tube = new BodyTube();
81 RingHandler handler = new RingHandler(tube, new WarningSet());
82 CenteringRing component = (CenteringRing) getField(handler, "ring");
83 HashMap<String, String> attributes = new HashMap<String, String>();
84 WarningSet warnings = new WarningSet();
86 handler.closeElement("OD", attributes, "0", warnings);
87 assertEquals(0d, component.getOuterRadius());
88 handler.closeElement("OD", attributes, "75", warnings);
89 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getOuterRadius());
90 handler.closeElement("OD", attributes, "foo", warnings);
91 assertEquals(1, warnings.size());
94 handler.closeElement("ID", attributes, "0", warnings);
95 assertEquals(0d, component.getInnerRadius());
96 handler.closeElement("ID", attributes, "75", warnings);
97 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
98 handler.closeElement("ID", attributes, "foo", warnings);
99 assertEquals(1, warnings.size());
102 handler.closeElement("Len", attributes, "-1", warnings);
103 assertEquals(0d, component.getLength());
104 handler.closeElement("Len", attributes, "10", warnings);
105 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
106 handler.closeElement("Len", attributes, "10.0", warnings);
107 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
108 handler.closeElement("Len", attributes, "foo", warnings);
109 assertEquals(1, warnings.size());
112 handler.closeElement("Name", attributes, "Test Name", warnings);
113 assertEquals("Test Name", component.getName());
118 * Method: constructor
120 * @throws Exception thrown if something goes awry
122 public void testConstructor() throws Exception {
125 new RingHandler(null, new WarningSet());
126 fail("Should have thrown IllegalArgumentException");
128 catch (IllegalArgumentException iae) {
132 BodyTube tube = new BodyTube();
133 RingHandler handler = new RingHandler(tube, new WarningSet());
134 CenteringRing component = (CenteringRing) getField(handler, "ring");
135 assertContains(component, tube.getChildren());
139 * Method: setRelativePosition(RocketComponent.Position position)
141 * @throws Exception thrown if something goes awry
143 public void testSetRelativePosition() throws Exception {
144 BodyTube tube = new BodyTube();
145 RingHandler handler = new RingHandler(tube, new WarningSet());
146 CenteringRing component = (CenteringRing) getField(handler, "ring");
147 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
148 assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
152 * Method: getComponent()
154 * @throws Exception thrown if something goes awry
156 public void testGetComponent() throws Exception {
157 assertTrue(new RingHandler(new BodyTube(), new WarningSet()).getComponent() instanceof CenteringRing);
161 * Method: getMaterialType()
163 * @throws Exception thrown if something goes awry
165 public void testGetMaterialType() throws Exception {
166 assertEquals(Material.Type.BULK, new RingHandler(new BodyTube(), new WarningSet()).getMaterialType());