1 package net.sf.openrocket.preset;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNull;
6 import static org.junit.Assert.assertSame;
7 import net.sf.openrocket.material.Material;
8 import net.sf.openrocket.motor.Manufacturer;
9 import net.sf.openrocket.rocketcomponent.Bulkhead;
10 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
12 import org.junit.Before;
13 import org.junit.Test;
16 * Test application of ComponentPresets to Bulkhead RocketComponents through
17 * the Bulkhead.loadFromPreset mechanism.
19 * Test Bulkhead is well defined.
21 * Test calling setters on Bulkhead will clear the ComponentPreset.
24 public class BulkHeadComponentTests extends BaseTestCase {
26 ComponentPreset preset;
29 public void createPreset() throws Exception {
30 TypedPropertyMap presetspec = new TypedPropertyMap();
31 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD);
32 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
33 presetspec.put( ComponentPreset.PARTNO, "partno");
34 presetspec.put( ComponentPreset.LENGTH, 2.0);
35 presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
36 presetspec.put( ComponentPreset.MASS, 100.0);
37 preset = ComponentPresetFactory.create(presetspec);
41 public void testComponentType() {
42 Bulkhead bt = new Bulkhead();
44 assertSame( ComponentPreset.Type.BULK_HEAD, bt.getPresetType() );
48 public void testLoadFromPresetIsSane() {
49 Bulkhead bt = new Bulkhead();
51 bt.loadPreset(preset);
53 assertEquals( 2.0, bt.getLength(), 0.0 );
54 assertEquals( 1.0, bt.getOuterRadius(), 0.0 );
56 assertFalse( bt.isOuterRadiusAutomatic() );
58 assertSame( preset.get( ComponentPreset.MATERIAL), bt.getMaterial() );
59 assertEquals( 100.0, bt.getMass(), 0.05);
63 public void changeLengthLeavesPreset() {
64 Bulkhead bt = new Bulkhead();
66 bt.loadPreset(preset);
70 assertSame( preset, bt.getPresetComponent() );
74 public void changeODClearsPreset() {
75 Bulkhead bt = new Bulkhead();
77 bt.loadPreset(preset);
79 bt.setOuterRadius(2.0);
81 assertNull( bt.getPresetComponent() );
85 public void changeODAutomaticClearsPreset() {
86 Bulkhead bt = new Bulkhead();
88 bt.loadPreset(preset);
90 bt.setOuterRadiusAutomatic(true);
92 assertNull( bt.getPresetComponent() );
96 public void changeMaterialClearsPreset() {
97 Bulkhead bt = new Bulkhead();
99 bt.loadPreset(preset);
101 bt.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0));
103 assertNull( bt.getPresetComponent() );