4d9734c897ee7a39e27d4df3d6fa489174a5d0af
[debian/openrocket] / core / test / net / sf / openrocket / preset / BulkHeadComponentTests.java
1 package net.sf.openrocket.preset;
2
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;
11
12 import org.junit.Before;
13 import org.junit.Test;
14
15 /**
16  * Test application of ComponentPresets to Bulkhead RocketComponents through
17  * the Bulkhead.loadFromPreset mechanism.
18  * 
19  * Test Bulkhead is well defined.
20  * 
21  * Test calling setters on Bulkhead will clear the ComponentPreset.
22  * 
23  */
24 public class BulkHeadComponentTests extends BaseTestCase {
25
26         ComponentPreset preset;
27         
28         @Before
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);
38         }
39
40         @Test
41         public void testComponentType() {
42                 Bulkhead bt = new Bulkhead();
43                 
44                 assertSame( ComponentPreset.Type.BULK_HEAD, bt.getPresetType() );
45         }
46         
47         @Test
48         public void testLoadFromPresetIsSane() {
49                 Bulkhead bt = new Bulkhead();
50                 
51                 bt.loadPreset(preset);
52                 
53                 assertEquals( 2.0, bt.getLength(), 0.0 );
54                 assertEquals( 1.0, bt.getOuterRadius(), 0.0 );
55                 
56                 assertFalse( bt.isOuterRadiusAutomatic() );
57                 
58                 assertSame( preset.get( ComponentPreset.MATERIAL), bt.getMaterial() );
59                 assertEquals( 100.0, bt.getMass(), 0.05);
60         }
61         
62         @Test
63         public void changeLengthLeavesPreset() {
64                 Bulkhead bt = new Bulkhead();
65                 
66                 bt.loadPreset(preset);
67
68                 bt.setLength(1.0);
69                 
70                 assertSame( preset, bt.getPresetComponent() );
71         }
72
73         @Test
74         public void changeODClearsPreset() {
75                 Bulkhead bt = new Bulkhead();
76                 
77                 bt.loadPreset(preset);
78
79                 bt.setOuterRadius(2.0);
80                 
81                 assertNull( bt.getPresetComponent() );
82         }
83
84         @Test
85         public void changeODAutomaticClearsPreset() {
86                 Bulkhead bt = new Bulkhead();
87                 
88                 bt.loadPreset(preset);
89                 
90                 bt.setOuterRadiusAutomatic(true);
91         
92                 assertNull( bt.getPresetComponent() );
93         }
94
95         @Test
96         public void changeMaterialClearsPreset() {
97                 Bulkhead bt = new Bulkhead();
98                 
99                 bt.loadPreset(preset);
100
101                 bt.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0));
102                 
103                 assertNull( bt.getPresetComponent() );
104         }
105
106 }