1 package net.sf.openrocket.preset;
3 import static org.junit.Assert.assertEquals;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.motor.Manufacturer;
6 import net.sf.openrocket.rocketcomponent.Transition;
7 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
12 * Test construction of NOSE_CONE type ComponentPresets based on TypedPropertyMap through the
13 * ComponentPresetFactory.create() method.
15 * Ensure required properties are populated
17 * Ensure any computed values are correctly computed.
20 public class NoseConePresetTests extends BaseTestCase {
23 public void testManufacturerRequired() {
25 TypedPropertyMap presetspec = new TypedPropertyMap();
26 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
27 ComponentPresetFactory.create(presetspec);
28 } catch (InvalidComponentPresetException ex) {
29 PresetAssertHelper.assertInvalidPresetException(ex,
31 ComponentPreset.MANUFACTURER,
32 ComponentPreset.PARTNO,
33 ComponentPreset.LENGTH,
34 ComponentPreset.AFT_OUTER_DIAMETER,
38 "No Manufacturer specified",
39 "No PartNo specified",
40 "No Length specified",
41 "No AftOuterDiameter specified",
49 public void testPartNoRequired() {
51 TypedPropertyMap presetspec = new TypedPropertyMap();
52 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
53 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
54 ComponentPresetFactory.create(presetspec);
55 } catch (InvalidComponentPresetException ex) {
56 PresetAssertHelper.assertInvalidPresetException(ex,
58 ComponentPreset.PARTNO,
59 ComponentPreset.LENGTH,
60 ComponentPreset.AFT_OUTER_DIAMETER,
64 "No PartNo specified",
65 "No Length specified",
66 "No AftOuterDiameter specified",
74 public void testLengthRequired() {
76 TypedPropertyMap presetspec = new TypedPropertyMap();
77 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
78 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
79 presetspec.put(ComponentPreset.PARTNO, "partno");
80 ComponentPresetFactory.create(presetspec);
81 } catch (InvalidComponentPresetException ex) {
82 PresetAssertHelper.assertInvalidPresetException(ex,
84 ComponentPreset.LENGTH,
85 ComponentPreset.AFT_OUTER_DIAMETER,
89 "No Length specified",
90 "No AftOuterDiameter specified",
98 public void testShapeRequired() {
100 TypedPropertyMap presetspec = new TypedPropertyMap();
101 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
102 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
103 presetspec.put(ComponentPreset.PARTNO, "partno");
104 presetspec.put(ComponentPreset.LENGTH, 2.0);
105 ComponentPresetFactory.create(presetspec);
106 } catch (InvalidComponentPresetException ex) {
107 PresetAssertHelper.assertInvalidPresetException(ex,
109 ComponentPreset.AFT_OUTER_DIAMETER,
110 ComponentPreset.SHAPE
113 "No AftOuterDiameter specified",
121 public void testAftOuterDiameterRequired() {
123 TypedPropertyMap presetspec = new TypedPropertyMap();
124 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
125 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
126 presetspec.put(ComponentPreset.PARTNO, "partno");
127 presetspec.put(ComponentPreset.LENGTH, 2.0);
128 presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL);
129 ComponentPresetFactory.create(presetspec);
130 } catch (InvalidComponentPresetException ex) {
131 PresetAssertHelper.assertInvalidPresetException(ex,
133 ComponentPreset.AFT_OUTER_DIAMETER
136 "No AftOuterDiameter specified"
143 public void testComputeDensityNoMaterial() throws Exception {
144 TypedPropertyMap presetspec = new TypedPropertyMap();
145 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
146 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
147 presetspec.put(ComponentPreset.PARTNO, "partno");
148 presetspec.put(ComponentPreset.LENGTH, 2.0);
149 presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL);
150 presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
151 presetspec.put(ComponentPreset.FILLED, true);
152 presetspec.put(ComponentPreset.MASS, 100.0);
153 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
155 // constants put into the presetspec above.
156 double volume = /*base area*/Math.PI;
157 volume *= 2.0 /* times height *// 3.0; /* one third */
159 double density = 100.0 / volume;
161 assertEquals("NoseConeCustom", preset.get(ComponentPreset.MATERIAL).getName());
162 // note - epsilon is 1% of the simple computation of density
163 assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.01 * density);
167 public void testMaterial() throws Exception {
168 TypedPropertyMap presetspec = new TypedPropertyMap();
169 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
170 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
171 presetspec.put(ComponentPreset.PARTNO, "partno");
172 presetspec.put(ComponentPreset.LENGTH, 2.0);
173 presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL);
174 presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
175 presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true));
176 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
178 assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName());
179 assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005);
184 public void testComputeDensityWithMaterial() throws Exception {
185 TypedPropertyMap presetspec = new TypedPropertyMap();
186 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
187 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
188 presetspec.put(ComponentPreset.PARTNO, "partno");
189 presetspec.put(ComponentPreset.LENGTH, 2.0);
190 presetspec.put(ComponentPreset.SHAPE, Transition.Shape.CONICAL);
191 presetspec.put(ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
192 presetspec.put(ComponentPreset.FILLED, true);
193 presetspec.put(ComponentPreset.MASS, 100.0);
194 presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true));
195 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
197 // constants put into the presetspec above.
198 double volume = /*base area*/Math.PI;
199 volume *= 2.0 /* times height *// 3.0; /* one third */
201 double density = 100.0 / volume;
203 assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName());
204 // note - epsilon is 1% of the simple computation of density
205 assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.01 * density);