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 static org.junit.Assert.assertTrue;
8 import net.sf.openrocket.material.Material;
9 import net.sf.openrocket.motor.Manufacturer;
10 import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
11 import net.sf.openrocket.rocketcomponent.Transition;
12 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
14 import org.junit.Before;
15 import org.junit.Test;
18 * Test application of ComponentPresets to Transition RocketComponents through
19 * the Transition.loadFromPreset mechanism.
21 * Test Transition is well defined.
23 * Test calling setters on Transition will clear the ComponentPreset.
26 public class TransitionComponentTests extends BaseTestCase {
28 ComponentPreset preset;
31 public void createPreset() throws Exception {
32 TypedPropertyMap presetspec = new TypedPropertyMap();
33 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
34 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
35 presetspec.put( ComponentPreset.PARTNO, "partno");
36 presetspec.put( ComponentPreset.LENGTH, 2.0);
37 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
38 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
39 presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0);
40 presetspec.put( ComponentPreset.AFT_SHOULDER_LENGTH, 1.0);
41 presetspec.put( ComponentPreset.AFT_SHOULDER_DIAMETER, 1.0);
42 presetspec.put( ComponentPreset.FORE_SHOULDER_LENGTH, 1.0);
43 presetspec.put( ComponentPreset.FORE_SHOULDER_DIAMETER, 0.5);
44 presetspec.put( ComponentPreset.FILLED, true);
45 presetspec.put( ComponentPreset.MASS, 100.0);
46 presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0));
47 preset = ComponentPresetFactory.create(presetspec);
51 public void testComponentType() {
52 Transition tr = new Transition();
54 assertSame( ComponentPreset.Type.TRANSITION, tr.getPresetType() );
58 public void testLoadFromPresetIsSane() {
59 Transition tr = new Transition();
61 tr.loadPreset(preset);
63 assertEquals( 2.0, tr.getLength(), 0.0 );
64 assertSame( Transition.Shape.CONICAL, tr.getType() );
65 assertEquals( 1.0, tr.getAftRadius(), 0.0 );
66 assertEquals( 1.0, tr.getForeShoulderLength(), 0.0 );
67 assertEquals( 0.25, tr.getForeShoulderRadius(), 0.0 );
68 assertEquals( 0.25, tr.getForeShoulderThickness(), 0.0 );
69 assertEquals( 1.0, tr.getAftShoulderLength(), 0.0 );
70 assertEquals( 0.5, tr.getAftShoulderRadius(), 0.0 );
71 assertEquals( 0.5, tr.getAftShoulderThickness(), 0.0 );
73 assertFalse( tr.isForeRadiusAutomatic() );
74 assertFalse( tr.isAftRadiusAutomatic() );
75 assertTrue( tr.isFilled() );
77 assertSame( preset.get( ComponentPreset.MATERIAL), tr.getMaterial() );
78 assertEquals( 100.0, tr.getMass(), 1.0);
82 public void changeLengthClearsPreset() {
83 Transition tr = new Transition();
85 tr.loadPreset(preset);
89 assertNull( tr.getPresetComponent() );
93 public void changeAftRadiusClearsPreset() {
94 Transition tr = new Transition();
96 tr.loadPreset(preset);
100 assertNull( tr.getPresetComponent() );
104 public void changeAftRadiusAutomaticClearsPreset() {
105 Transition tr = new Transition();
107 tr.loadPreset(preset);
109 tr.setAftRadiusAutomatic(true);
111 assertNull( tr.getPresetComponent() );
115 public void changeForeRadiusClearsPreset() {
116 Transition tr = new Transition();
118 tr.loadPreset(preset);
120 tr.setForeRadius(2.0);
122 assertNull( tr.getPresetComponent() );
126 public void changeForeRadiusAutomaticClearsPreset() {
127 Transition tr = new Transition();
129 tr.loadPreset(preset);
131 tr.setForeRadiusAutomatic(true);
133 assertNull( tr.getPresetComponent() );
137 public void changeForeShoulderRadiusClearsPreset() {
138 Transition tr = new Transition();
140 tr.loadPreset(preset);
142 tr.setForeShoulderRadius(2.0);
144 assertNull( tr.getPresetComponent() );
148 public void changeAftShoulderRadiusClearsPreset() {
149 Transition tr = new Transition();
151 tr.loadPreset(preset);
153 tr.setAftShoulderRadius(2.0);
155 assertNull( tr.getPresetComponent() );
159 public void changeAftSholderLengthLeavesPreset() {
160 Transition tr = new Transition();
162 tr.loadPreset(preset);
164 tr.setAftShoulderLength(2.0);
166 assertSame( preset, tr.getPresetComponent() );
170 public void changeThicknessClearsPreset() {
171 Transition tr = new Transition();
173 tr.loadPreset(preset);
175 tr.setThickness(0.1);
177 assertNull( tr.getPresetComponent() );
182 public void changeFilledClearsPreset() {
183 Transition tr = new Transition();
185 tr.loadPreset(preset);
189 assertNull( tr.getPresetComponent() );
193 public void changeMaterialClearsPreset() {
194 Transition tr = new Transition();
196 tr.loadPreset(preset);
198 tr.setMaterial( Material.newUserMaterial(Material.Type.BULK,"new", 1.0));
200 assertNull( tr.getPresetComponent() );
204 public void changeFinishLeavesPreset() {
205 Transition tr = new Transition();
207 tr.loadPreset(preset);
209 tr.setFinish( Finish.POLISHED );
211 assertSame( preset, tr.getPresetComponent() );