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.CenteringRing;
14 import net.sf.openrocket.rocketcomponent.RocketComponent;
16 import java.util.HashMap;
21 public class RingHandlerTest extends RocksimTestBase {
24 * The class under test.
26 public static final Class classUT = RingHandler.class;
29 * The test class (this class).
31 public static final Class testClass = RingHandlerTest.class;
34 * Create a test suite of all tests within this test class.
36 * @return a suite of tests
38 public static Test suite() {
39 return new TestSuite(RingHandlerTest.class);
45 * @param name the name of the test to run.
47 public RingHandlerTest(String name) {
54 public void setUp() throws Exception {
59 * Teardown the fixture.
61 public void tearDown() throws Exception {
66 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
68 * @throws Exception thrown if something goes awry
70 public void testOpenElement() throws Exception {
71 assertEquals(PlainTextHandler.INSTANCE, new RingHandler(new BodyTube()).openElement(null, null, null));
75 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
77 * @throws Exception thrown if something goes awry
79 public void testCloseElement() throws Exception {
81 BodyTube tube = new BodyTube();
82 RingHandler handler = new RingHandler(tube);
83 CenteringRing component = (CenteringRing) getField(handler, "ring");
84 HashMap<String, String> attributes = new HashMap<String, String>();
85 WarningSet warnings = new WarningSet();
87 handler.closeElement("OD", attributes, "0", warnings);
88 assertEquals(0d, component.getOuterRadius());
89 handler.closeElement("OD", attributes, "75", warnings);
90 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getOuterRadius());
91 handler.closeElement("OD", attributes, "foo", warnings);
92 assertEquals(1, warnings.size());
95 handler.closeElement("ID", attributes, "0", warnings);
96 assertEquals(0d, component.getInnerRadius());
97 handler.closeElement("ID", attributes, "75", warnings);
98 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
99 handler.closeElement("ID", attributes, "foo", warnings);
100 assertEquals(1, warnings.size());
103 handler.closeElement("Len", attributes, "-1", warnings);
104 assertEquals(0d, component.getLength());
105 handler.closeElement("Len", attributes, "10", warnings);
106 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
107 handler.closeElement("Len", attributes, "10.0", warnings);
108 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
109 handler.closeElement("Len", attributes, "foo", warnings);
110 assertEquals(1, warnings.size());
113 handler.closeElement("Name", attributes, "Test Name", warnings);
114 assertEquals("Test Name", component.getName());
119 * Method: constructor
121 * @throws Exception thrown if something goes awry
123 public void testConstructor() throws Exception {
126 new RingHandler(null);
127 fail("Should have thrown IllegalArgumentException");
129 catch (IllegalArgumentException iae) {
133 BodyTube tube = new BodyTube();
134 RingHandler handler = new RingHandler(tube);
135 CenteringRing component = (CenteringRing) getField(handler, "ring");
136 assertContains(component, tube.getChildren());
140 * Method: setRelativePosition(RocketComponent.Position position)
142 * @throws Exception thrown if something goes awry
144 public void testSetRelativePosition() throws Exception {
145 BodyTube tube = new BodyTube();
146 RingHandler handler = new RingHandler(tube);
147 CenteringRing component = (CenteringRing) getField(handler, "ring");
148 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
149 assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
153 * Method: getComponent()
155 * @throws Exception thrown if something goes awry
157 public void testGetComponent() throws Exception {
158 assertTrue(new RingHandler(new BodyTube()).getComponent() instanceof CenteringRing);
162 * Method: getMaterialType()
164 * @throws Exception thrown if something goes awry
166 public void testGetMaterialType() throws Exception {
167 assertEquals(Material.Type.BULK, new RingHandler(new BodyTube()).getMaterialType());