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 TRANSITION 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 TransitionPresetTests extends BaseTestCase {
24 public void testManufacturerRequired() {
26 TypedPropertyMap presetspec = new TypedPropertyMap();
27 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
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.TRANSITION);
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.TRANSITION);
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 testAftOuterDiameterRequired() {
62 TypedPropertyMap presetspec = new TypedPropertyMap();
63 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
64 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
65 presetspec.put( ComponentPreset.PARTNO, "partno");
66 presetspec.put( ComponentPreset.LENGTH, 2.0);
67 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
68 ComponentPresetFactory.create(presetspec);
69 } catch ( InvalidComponentPresetException ex ) {
70 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter"));
76 public void testForeOuterDiameterRequired() {
78 TypedPropertyMap presetspec = new TypedPropertyMap();
79 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
80 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
81 presetspec.put( ComponentPreset.PARTNO, "partno");
82 presetspec.put( ComponentPreset.LENGTH, 2.0);
83 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
84 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
85 ComponentPresetFactory.create(presetspec);
86 } catch ( InvalidComponentPresetException ex ) {
87 assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No ForeOuterDiameter"));
92 public void testComputeDensityNoMaterial() throws Exception {
93 TypedPropertyMap presetspec = new TypedPropertyMap();
94 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
95 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
96 presetspec.put( ComponentPreset.PARTNO, "partno");
97 presetspec.put( ComponentPreset.LENGTH, 2.0);
98 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
99 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
100 presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0);
101 presetspec.put( ComponentPreset.FILLED, true);
102 presetspec.put( ComponentPreset.MASS, 100.0);
103 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
105 // constants put into the presetspec above.
106 double volume = /*base area*/ Math.PI * ( 1.0 * 1.0 + 1.0 * 0.5 + 0.5 * 0.5);
108 volume *= 2.0 /* times height */ / 3.0; /* one third */
110 double density = 100.0 / volume;
112 assertEquals("TransitionCustom",preset.get(ComponentPreset.MATERIAL).getName());
114 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density);
118 public void testMaterial() throws Exception {
119 TypedPropertyMap presetspec = new TypedPropertyMap();
120 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
121 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
122 presetspec.put( ComponentPreset.PARTNO, "partno");
123 presetspec.put( ComponentPreset.LENGTH, 2.0);
124 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
125 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
126 presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0);
127 presetspec.put( ComponentPreset.FILLED, true);
128 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
129 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
131 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
132 assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
137 public void testComputeDensityWithMaterial() throws Exception {
138 TypedPropertyMap presetspec = new TypedPropertyMap();
139 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
140 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
141 presetspec.put( ComponentPreset.PARTNO, "partno");
142 presetspec.put( ComponentPreset.LENGTH, 2.0);
143 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
144 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
145 presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0);
146 presetspec.put( ComponentPreset.FILLED, true);
147 presetspec.put( ComponentPreset.MASS, 100.0);
148 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
149 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
151 // constants put into the presetspec above.
152 double totvolume = /*base area*/ Math.PI;
154 totvolume *= 4.0 /* times height */ / 3.0; /* one third */
156 double uppervolume = /*fore area*/ Math.PI * 0.5 * 0.5;
157 uppervolume *= 2.0 /* times height */ / 3.0; /* one third */
159 double volume = totvolume-uppervolume;
161 double density = 100.0 / volume;
163 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
165 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density);