]> git.gag.com Git - debian/openrocket/blob - core/test/net/sf/openrocket/file/rocksim/importt/BodyTubeHandlerTest.java
moving to core/
[debian/openrocket] / core / test / net / sf / openrocket / file / rocksim / importt / BodyTubeHandlerTest.java
1 /*
2  * BodyTubeHandlerTest.java
3  */
4 package net.sf.openrocket.file.rocksim.importt;
5
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.simplesax.PlainTextHandler;
8 import net.sf.openrocket.material.Material;
9 import net.sf.openrocket.rocketcomponent.BodyTube;
10 import net.sf.openrocket.rocketcomponent.ExternalComponent;
11 import net.sf.openrocket.rocketcomponent.Stage;
12 import org.junit.Assert;
13 import org.junit.Test;
14
15 import java.util.HashMap;
16
17 /**
18  * BodyTubeHandler Tester.
19  *
20  */
21 public class BodyTubeHandlerTest extends RocksimTestBase {
22
23     /**
24      * Method: constructor
25      *
26      * @throws Exception thrown if something goes awry
27      */
28     @Test
29     public void testConstructor() throws Exception {
30
31         try {
32             new BodyTubeHandler(null, new WarningSet());
33             Assert.fail("Should have thrown IllegalArgumentException");
34         }
35         catch (IllegalArgumentException iae) {
36             //success
37         }
38
39         Stage stage = new Stage();
40         BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
41         BodyTube component = (BodyTube) getField(handler, "bodyTube");
42         assertContains(component, stage.getChildren());
43     }
44
45     /**
46      * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
47      *
48      * @throws Exception thrown if something goes awry
49      */
50     @Test
51     public void testOpenElement() throws Exception {
52         Assert.assertEquals(PlainTextHandler.INSTANCE, new BodyTubeHandler(new Stage(), new WarningSet()).openElement(null, null, null));
53         Assert.assertNotNull(new BodyTubeHandler(new Stage(), new WarningSet()).openElement("AttachedParts", null, null));
54     }
55
56     /**
57      *
58      * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
59      *
60      * @throws Exception  thrown if something goes awry
61      */
62     @Test
63     public void testCloseElement() throws Exception {
64         Stage stage = new Stage();
65         BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
66         BodyTube component = (BodyTube) getField(handler, "bodyTube");
67         HashMap<String, String> attributes = new HashMap<String, String>();
68         WarningSet warnings = new WarningSet();
69
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 / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
76         handler.closeElement("OD", attributes, "foo", warnings);
77         Assert.assertEquals(1, warnings.size());
78         warnings.clear();
79
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 / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
86         handler.closeElement("ID", attributes, "foo", warnings);
87         Assert.assertEquals(1, warnings.size());
88         warnings.clear();
89
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 / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
94         handler.closeElement("Len", attributes, "10.0", warnings);
95         Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
96         handler.closeElement("Len", attributes, "foo", warnings);
97         Assert.assertEquals(1, warnings.size());
98         warnings.clear();
99
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());
106
107         handler.closeElement("EngineOverhang", attributes, "-1", warnings);
108         Assert.assertEquals(-1d/RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
109         handler.closeElement("EngineOverhang", attributes, "10", warnings);
110         Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
111         handler.closeElement("EngineOverhang", attributes, "10.0", warnings);
112         Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang(), 0.001);
113         handler.closeElement("EngineOverhang", attributes, "foo", warnings);
114         Assert.assertEquals(1, warnings.size());
115         warnings.clear();
116
117         handler.closeElement("FinishCode", attributes, "-1", warnings);
118         Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
119         handler.closeElement("FinishCode", attributes, "100", warnings);
120         Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
121         handler.closeElement("FinishCode", attributes, "foo", warnings);
122         Assert.assertEquals(1, warnings.size());
123         warnings.clear();
124
125         handler.closeElement("Name", attributes, "Test Name", warnings);
126         Assert.assertEquals("Test Name", component.getName());
127     }
128     
129     /**
130      * Method: getComponent()
131      *
132      * @throws Exception thrown if something goes awry
133      */
134     @Test
135     public void testGetComponent() throws Exception {
136         Assert.assertTrue(new BodyTubeHandler(new Stage(), new WarningSet()).getComponent() instanceof BodyTube);
137     }
138
139     /**
140      * Method: getMaterialType()
141      *
142      * @throws Exception thrown if something goes awry
143      */
144     @Test
145     public void testGetMaterialType() throws Exception {
146         Assert.assertEquals(Material.Type.BULK, new BodyTubeHandler(new Stage(), new WarningSet()).getMaterialType());
147     }
148
149 }