]> git.gag.com Git - debian/openrocket/blob - test/net/sf/openrocket/file/rocksim/LaunchLugHandlerTest.java
DGP - Modified Rocksim import to discriminate between centering ring, tube coupler...
[debian/openrocket] / test / net / sf / openrocket / file / rocksim / LaunchLugHandlerTest.java
1 /*
2  * LaunchLugHandlerTest.java
3  */
4 package net.sf.openrocket.file.rocksim;
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.LaunchLug;
12 import net.sf.openrocket.rocketcomponent.RocketComponent;
13 import org.junit.Assert;
14
15 import java.util.HashMap;
16
17 /**
18  * LaunchLugHandler Tester.
19  *
20  */
21 public class LaunchLugHandlerTest extends RocksimTestBase {
22
23     /**
24      * Method: constructor
25      *
26      * @throws Exception thrown if something goes awry
27      */
28     @org.junit.Test
29     public void testConstructor() throws Exception {
30
31         try {
32             new LaunchLugHandler(null, new WarningSet());
33             Assert.fail("Should have thrown IllegalArgumentException");
34         }
35         catch (IllegalArgumentException iae) {
36             //success
37         }
38
39         BodyTube tube = new BodyTube();
40         LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
41         LaunchLug component = (LaunchLug) getField(handler, "lug");
42         assertContains(component, tube.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     @org.junit.Test
51     public void testOpenElement() throws Exception {
52         Assert.assertEquals(PlainTextHandler.INSTANCE, new LaunchLugHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
53     }
54
55     /**
56      *
57      * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
58      *
59      * @throws Exception  thrown if something goes awry
60      */
61     @org.junit.Test
62     public void testCloseElement() throws Exception {
63         BodyTube tube = new BodyTube();
64         LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
65         LaunchLug component = (LaunchLug) getField(handler, "lug");
66         HashMap<String, String> attributes = new HashMap<String, String>();
67         WarningSet warnings = new WarningSet();
68
69         handler.closeElement("OD", attributes, "-1", warnings);
70         Assert.assertEquals(0d, component.getOuterRadius(), 0.001);
71         handler.closeElement("OD", attributes, "0", warnings);
72         Assert.assertEquals(0d, component.getOuterRadius(), 0.001);
73         handler.closeElement("OD", attributes, "75", warnings);
74         Assert.assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getOuterRadius(), 0.001);
75         handler.closeElement("OD", attributes, "foo", warnings);
76         Assert.assertEquals(1, warnings.size());
77         warnings.clear();
78
79         handler.closeElement("ID", attributes, "-1", warnings);
80         Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
81         handler.closeElement("ID", attributes, "0", warnings);
82         Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
83         handler.closeElement("ID", attributes, "75", warnings);
84         Assert.assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
85         handler.closeElement("ID", attributes, "foo", warnings);
86         Assert.assertEquals(1, warnings.size());
87         warnings.clear();
88
89         handler.closeElement("Len", attributes, "-1", warnings);
90         Assert.assertEquals(0d, component.getLength(), 0.001);
91         handler.closeElement("Len", attributes, "10", warnings);
92         Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
93         handler.closeElement("Len", attributes, "10.0", warnings);
94         Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
95         handler.closeElement("Len", attributes, "foo", warnings);
96         Assert.assertEquals(1, warnings.size());
97         warnings.clear();
98
99         handler.closeElement("FinishCode", attributes, "-1", warnings);
100         Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
101         handler.closeElement("FinishCode", attributes, "100", warnings);
102         Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
103         handler.closeElement("FinishCode", attributes, "foo", warnings);
104         Assert.assertEquals(1, warnings.size());
105         warnings.clear();
106
107         handler.closeElement("Name", attributes, "Test Name", warnings);
108         Assert.assertEquals("Test Name", component.getName());
109     }
110     
111     /**
112      * Method: setRelativePosition(RocketComponent.Position position)
113      *
114      * @throws Exception thrown if something goes awry
115      */
116     @org.junit.Test
117     public void testSetRelativePosition() throws Exception {
118         BodyTube tube = new BodyTube();
119         LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
120         LaunchLug component = (LaunchLug) getField(handler, "lug");
121         handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
122         Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
123     }
124
125     /**
126      * Method: getComponent()
127      *
128      * @throws Exception thrown if something goes awry
129      */
130     @org.junit.Test
131     public void testGetComponent() throws Exception {
132         Assert.assertTrue(new LaunchLugHandler(new BodyTube(), new WarningSet()).getComponent() instanceof LaunchLug);
133     }
134
135     /**
136      * Method: getMaterialType()
137      *
138      * @throws Exception thrown if something goes awry
139      */
140     @org.junit.Test
141     public void testGetMaterialType() throws Exception {
142         Assert.assertEquals(Material.Type.BULK, new LaunchLugHandler(new BodyTube(), new WarningSet()).getMaterialType());
143     }
144
145
146 }