1 package net.sf.openrocket.preset;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import net.sf.openrocket.material.Material;
6 import net.sf.openrocket.motor.Manufacturer;
11 * Test construction of TUBE_COUPLER type ComponentPresets based on TypedPropertyMap through the
12 * ComponentPresetFactory.create() method.
14 * Ensure required properties are populated
16 * Ensure any computed values are correctly computed.
19 public class TubeCouplerPresetTests {
22 public void testManufacturerRequired() {
24 TypedPropertyMap presetspec = new TypedPropertyMap();
25 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
26 ComponentPresetFactory.create(presetspec);
27 } catch ( InvalidComponentPresetException ex ) {
28 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
33 public void testPartNoRequired() {
35 TypedPropertyMap presetspec = new TypedPropertyMap();
36 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
37 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
38 ComponentPresetFactory.create(presetspec);
39 } catch ( InvalidComponentPresetException ex ) {
40 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
45 public void testLengthRequired() {
47 TypedPropertyMap presetspec = new TypedPropertyMap();
48 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
49 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
50 presetspec.put( ComponentPreset.PARTNO, "partno");
51 ComponentPresetFactory.create(presetspec);
52 } catch ( InvalidComponentPresetException ex ) {
53 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
58 public void testOnlyOuterDiameter() {
60 TypedPropertyMap presetspec = new TypedPropertyMap();
61 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
62 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
63 presetspec.put( ComponentPreset.PARTNO, "partno");
64 presetspec.put( ComponentPreset.LENGTH, 2.0);
65 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
66 ComponentPresetFactory.create(presetspec);
67 } catch ( InvalidComponentPresetException ex ) {
68 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
73 public void testOnlyInnerDiameter() {
75 TypedPropertyMap presetspec = new TypedPropertyMap();
76 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
77 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
78 presetspec.put( ComponentPreset.PARTNO, "partno");
79 presetspec.put( ComponentPreset.LENGTH, 2.0);
80 presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
81 ComponentPresetFactory.create(presetspec);
82 } catch ( InvalidComponentPresetException ex ) {
83 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
88 public void testOnlyThicknessDiameter() {
90 TypedPropertyMap presetspec = new TypedPropertyMap();
91 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
92 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
93 presetspec.put( ComponentPreset.PARTNO, "partno");
94 presetspec.put( ComponentPreset.LENGTH, 2.0);
95 presetspec.put( ComponentPreset.THICKNESS, 2.0);
96 ComponentPresetFactory.create(presetspec);
97 } catch ( InvalidComponentPresetException ex ) {
98 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
103 public void testComputeInnerDiameter() throws Exception {
104 TypedPropertyMap presetspec = new TypedPropertyMap();
105 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
106 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
107 presetspec.put( ComponentPreset.PARTNO, "partno");
108 presetspec.put( ComponentPreset.LENGTH, 2.0);
109 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
110 presetspec.put( ComponentPreset.THICKNESS, 0.5);
111 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
113 assertEquals(1.0,preset.get(ComponentPreset.INNER_DIAMETER).doubleValue(),0.0);
117 public void testComputeOuterDiameter() throws Exception {
118 TypedPropertyMap presetspec = new TypedPropertyMap();
119 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
120 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
121 presetspec.put( ComponentPreset.PARTNO, "partno");
122 presetspec.put( ComponentPreset.LENGTH, 2.0);
123 presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0);
124 presetspec.put( ComponentPreset.THICKNESS, 0.5);
125 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
127 assertEquals(2.0,preset.get(ComponentPreset.OUTER_DIAMETER).doubleValue(),0.0);
131 public void testComputeThickness() throws Exception {
132 TypedPropertyMap presetspec = new TypedPropertyMap();
133 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
134 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
135 presetspec.put( ComponentPreset.PARTNO, "partno");
136 presetspec.put( ComponentPreset.LENGTH, 2.0);
137 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
138 presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0);
139 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
141 assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0);
145 public void testComputeThicknessLooses() throws Exception {
146 // If all OUTER_DIAMETER, INNER_DIAMETER and THICKNESS are
147 // specified, THICKNESS is recomputed.
148 TypedPropertyMap presetspec = new TypedPropertyMap();
149 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
150 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
151 presetspec.put( ComponentPreset.PARTNO, "partno");
152 presetspec.put( ComponentPreset.LENGTH, 2.0);
153 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
154 presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0);
155 presetspec.put( ComponentPreset.THICKNESS, 15.0);
156 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
158 assertEquals(0.5,preset.get(ComponentPreset.THICKNESS).doubleValue(),0.0);
162 public void testComputeDensityNoMaterial() throws Exception {
163 TypedPropertyMap presetspec = new TypedPropertyMap();
164 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
165 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
166 presetspec.put( ComponentPreset.PARTNO, "partno");
167 presetspec.put( ComponentPreset.LENGTH, 2.0);
168 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
169 presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0);
170 presetspec.put( ComponentPreset.MASS, 100.0);
171 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
173 // Compute the volume by hand here using a slightly different formula from
174 // the real implementation. The magic numbers are based on the
175 // constants put into the presetspec above.
176 double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
177 volume *= 2.0; /* times length */
179 double density = 100.0 / volume;
181 assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName());
182 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
186 public void testMaterial() throws Exception {
187 TypedPropertyMap presetspec = new TypedPropertyMap();
188 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
189 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
190 presetspec.put( ComponentPreset.PARTNO, "partno");
191 presetspec.put( ComponentPreset.LENGTH, 2.0);
192 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
193 presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0);
194 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
195 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
197 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
198 assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
203 public void testComputeDensityWithMaterial() throws Exception {
204 TypedPropertyMap presetspec = new TypedPropertyMap();
205 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
206 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
207 presetspec.put( ComponentPreset.PARTNO, "partno");
208 presetspec.put( ComponentPreset.LENGTH, 2.0);
209 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
210 presetspec.put( ComponentPreset.INNER_DIAMETER, 1.0);
211 presetspec.put( ComponentPreset.MASS, 100.0);
212 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
213 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
215 // Compute the volume by hand here using a slightly different formula from
216 // the real implementation. The magic numbers are based on the
217 // constants put into the presetspec above.
218 double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
219 volume *= 2.0; /* times length */
221 double density = 100.0 / volume;
223 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
224 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);