create changelog entry
[debian/openrocket] / core / test / net / sf / openrocket / file / rocksim / importt / LaunchLugHandlerTest.java
1 /*
2  * LaunchLugHandlerTest.java
3  */
4 package net.sf.openrocket.file.rocksim.importt;
5
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.LaunchLug;
13 import net.sf.openrocket.rocketcomponent.RocketComponent;
14 import org.junit.Assert;
15
16 import java.util.HashMap;
17
18 /**
19  * LaunchLugHandler Tester.
20  *
21  */
22 public class LaunchLugHandlerTest extends RocksimTestBase {
23
24     /**
25      * Method: constructor
26      *
27      * @throws Exception thrown if something goes awry
28      */
29     @org.junit.Test
30     public void testConstructor() throws Exception {
31
32         try {
33             new LaunchLugHandler(null, new WarningSet());
34             Assert.fail("Should have thrown IllegalArgumentException");
35         }
36         catch (IllegalArgumentException iae) {
37             //success
38         }
39
40         BodyTube tube = new BodyTube();
41         LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
42         LaunchLug component = (LaunchLug) getField(handler, "lug");
43         assertContains(component, tube.getChildren());
44     }
45
46     /**
47      * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
48      *
49      * @throws Exception thrown if something goes awry
50      */
51     @org.junit.Test
52     public void testOpenElement() throws Exception {
53         Assert.assertEquals(PlainTextHandler.INSTANCE, new LaunchLugHandler(new BodyTube(), new WarningSet()).openElement(null, 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     @org.junit.Test
63     public void testCloseElement() throws Exception {
64         BodyTube tube = new BodyTube();
65         LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
66         LaunchLug component = (LaunchLug) getField(handler, "lug");
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.getOuterRadius(), 0.001);
72         handler.closeElement("OD", attributes, "0", warnings);
73         Assert.assertEquals(0d, component.getOuterRadius(), 0.001);
74         handler.closeElement("OD", attributes, "75", warnings);
75         Assert.assertEquals(75d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS, component.getOuterRadius(), 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 / RocksimCommonConstants.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 / 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());
98         warnings.clear();
99
100         handler.closeElement("FinishCode", attributes, "-1", warnings);
101         Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
102         handler.closeElement("FinishCode", attributes, "100", warnings);
103         Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
104         handler.closeElement("FinishCode", attributes, "foo", warnings);
105         Assert.assertEquals(1, warnings.size());
106         warnings.clear();
107
108         handler.closeElement("Name", attributes, "Test Name", warnings);
109         Assert.assertEquals("Test Name", component.getName());
110     }
111     
112     /**
113      * Method: setRelativePosition(RocketComponent.Position position)
114      *
115      * @throws Exception thrown if something goes awry
116      */
117     @org.junit.Test
118     public void testSetRelativePosition() throws Exception {
119         BodyTube tube = new BodyTube();
120         LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
121         LaunchLug component = (LaunchLug) getField(handler, "lug");
122         handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
123         Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
124     }
125
126     /**
127      * Method: getComponent()
128      *
129      * @throws Exception thrown if something goes awry
130      */
131     @org.junit.Test
132     public void testGetComponent() throws Exception {
133         Assert.assertTrue(new LaunchLugHandler(new BodyTube(), new WarningSet()).getComponent() instanceof LaunchLug);
134     }
135
136     /**
137      * Method: getMaterialType()
138      *
139      * @throws Exception thrown if something goes awry
140      */
141     @org.junit.Test
142     public void testGetMaterialType() throws Exception {
143         Assert.assertEquals(Material.Type.BULK, new LaunchLugHandler(new BodyTube(), new WarningSet()).getMaterialType());
144     }
145
146
147 }