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;
7 import net.sf.openrocket.rocketcomponent.Transition;
8 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
10 import org.junit.Test;
13 * Test construction of NOSE_CONE type ComponentPresets based on TypedPropertyMap through the
14 * ComponentPresetFactory.create() method.
16 * Ensure required properties are populated
18 * Ensure any computed values are correctly computed.
21 public class NoseConePresetTests extends BaseTestCase {
24 public void testManufacturerRequired() {
26 TypedPropertyMap presetspec = new TypedPropertyMap();
27 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
28 ComponentPresetFactory.create(presetspec);
29 } catch ( InvalidComponentPresetException ex ) {
30 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
35 public void testPartNoRequired() {
37 TypedPropertyMap presetspec = new TypedPropertyMap();
38 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
39 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
40 ComponentPresetFactory.create(presetspec);
41 } catch ( InvalidComponentPresetException ex ) {
42 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
47 public void testLengthRequired() {
49 TypedPropertyMap presetspec = new TypedPropertyMap();
50 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
51 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
52 presetspec.put( ComponentPreset.PARTNO, "partno");
53 ComponentPresetFactory.create(presetspec);
54 } catch ( InvalidComponentPresetException ex ) {
55 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
60 public void testShapeRequired() {
62 TypedPropertyMap presetspec = new TypedPropertyMap();
63 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
64 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
65 presetspec.put( ComponentPreset.PARTNO, "partno");
66 presetspec.put( ComponentPreset.LENGTH, 2.0);
67 ComponentPresetFactory.create(presetspec);
68 } catch ( InvalidComponentPresetException ex ) {
69 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Shape"));
74 public void testAftOuterDiameterRequired() {
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 presetspec.put( ComponentPreset.LENGTH, 2.0);
81 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
82 ComponentPresetFactory.create(presetspec);
83 } catch ( InvalidComponentPresetException ex ) {
84 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter"));
89 public void testComputeDensityNoMaterial() throws Exception {
90 TypedPropertyMap presetspec = new TypedPropertyMap();
91 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
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.SHAPE, Transition.Shape.CONICAL);
96 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
97 presetspec.put( ComponentPreset.FILLED, true);
98 presetspec.put( ComponentPreset.MASS, 100.0);
99 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
101 // constants put into the presetspec above.
102 double volume = /*base area*/ Math.PI;
103 volume *= 2.0 /* times height */ / 3.0; /* one third */
105 double density = 100.0 / volume;
107 assertEquals("NoseConeCustom",preset.get(ComponentPreset.MATERIAL).getName());
108 // FIXME - I would expect the nc volume computation to be closer for such a simple shape.
109 // simple math yields 47.74648
110 // 100.0/nc.getComponentVolume yields 48.7159
111 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),1.0);
115 public void testMaterial() throws Exception {
116 TypedPropertyMap presetspec = new TypedPropertyMap();
117 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
118 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
119 presetspec.put( ComponentPreset.PARTNO, "partno");
120 presetspec.put( ComponentPreset.LENGTH, 2.0);
121 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
122 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
123 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
124 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
126 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
127 assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
132 public void testComputeDensityWithMaterial() throws Exception {
133 TypedPropertyMap presetspec = new TypedPropertyMap();
134 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
135 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
136 presetspec.put( ComponentPreset.PARTNO, "partno");
137 presetspec.put( ComponentPreset.LENGTH, 2.0);
138 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
139 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
140 presetspec.put( ComponentPreset.FILLED, true);
141 presetspec.put( ComponentPreset.MASS, 100.0);
142 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
143 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
145 // constants put into the presetspec above.
146 double volume = /*base area*/ Math.PI;
147 volume *= 2.0 /* times height */ / 3.0; /* one third */
149 double density = 100.0 / volume;
151 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
152 // FIXME - I would expect the nc volume computation to be closer for such a simple shape.
153 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),1.5);