1 package net.sf.openrocket.preset;
3 import static org.junit.Assert.*;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.motor.Manufacturer;
6 import net.sf.openrocket.rocketcomponent.Bulkhead;
7 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
9 import org.junit.Before;
10 import org.junit.Test;
13 * Test application of ComponentPresets to Bulkhead RocketComponents through
14 * the Bulkhead.loadFromPreset mechanism.
16 * Test Bulkhead is well defined.
18 * Test calling setters on Bulkhead will clear the ComponentPreset.
21 public class BulkHeadComponentTests extends BaseTestCase {
23 ComponentPreset preset;
26 public void createPreset() throws Exception {
27 TypedPropertyMap presetspec = new TypedPropertyMap();
28 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD);
29 presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
30 presetspec.put(ComponentPreset.PARTNO, "partno");
31 presetspec.put(ComponentPreset.LENGTH, 2.0);
32 presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0);
33 presetspec.put(ComponentPreset.MASS, 100.0);
34 preset = ComponentPresetFactory.create(presetspec);
38 public void testComponentType() {
39 Bulkhead bt = new Bulkhead();
41 assertSame(ComponentPreset.Type.BULK_HEAD, bt.getPresetType());
45 public void testLoadFromPresetIsSane() {
46 Bulkhead bt = new Bulkhead();
48 bt.loadPreset(preset);
50 assertEquals(2.0, bt.getLength(), 0.0);
51 assertEquals(1.0, bt.getOuterRadius(), 0.0);
53 assertFalse(bt.isOuterRadiusAutomatic());
55 assertSame(preset.get(ComponentPreset.MATERIAL), bt.getMaterial());
56 assertEquals(100.0, bt.getMass(), 0.05);
60 public void changeLengthLeavesPreset() {
61 Bulkhead bt = new Bulkhead();
63 bt.loadPreset(preset);
67 assertSame(preset, bt.getPresetComponent());
71 public void changeODClearsPreset() {
72 Bulkhead bt = new Bulkhead();
74 bt.loadPreset(preset);
76 bt.setOuterRadius(2.0);
78 assertNull(bt.getPresetComponent());
82 public void changeODAutomaticClearsPreset() {
83 Bulkhead bt = new Bulkhead();
85 bt.loadPreset(preset);
87 bt.setOuterRadiusAutomatic(true);
89 assertNull(bt.getPresetComponent());
93 public void changeMaterialClearsPreset() {
94 Bulkhead bt = new Bulkhead();
96 bt.loadPreset(preset);
98 bt.setMaterial(Material.newMaterial(Material.Type.BULK, "new", 1.0, true));
100 assertNull(bt.getPresetComponent());