public static ComponentPreset create( TypedPropertyMap props ) throws InvalidComponentPresetException {
+ InvalidComponentPresetException exceptions = new InvalidComponentPresetException("Invalid preset specification.");
+
ComponentPreset preset = new ComponentPreset();
// First do validation.
- if ( !props.containsKey(TYPE)) {
- throw new InvalidComponentPresetException("No Type specified " + props.toString() );
- }
-
if (!props.containsKey(MANUFACTURER)) {
- throw new InvalidComponentPresetException("No Manufacturer specified " + props.toString() );
+ exceptions.addInvalidParameter(MANUFACTURER, "No Manufacturer specified");
}
-
if (!props.containsKey(PARTNO)) {
- throw new InvalidComponentPresetException("No PartNo specified " + props.toString() );
+ exceptions.addInvalidParameter(PARTNO,"No PartNo specified");
}
+ if ( !props.containsKey(TYPE)) {
+ exceptions.addInvalidParameter(TYPE, "No Type specified" );
+ // We can't do anything else without TYPE so throw immediately.
+ throw exceptions;
+ }
+
preset.putAll(props);
Type t = props.get(TYPE);
switch ( t ) {
case BODY_TUBE: {
- makeBodyTube(preset);
+ makeBodyTube(exceptions,preset);
break;
}
case NOSE_CONE: {
- makeNoseCone(preset);
+ makeNoseCone(exceptions,preset);
break;
}
case TRANSITION: {
- makeTransition(preset);
+ makeTransition(exceptions,preset);
break;
}
case BULK_HEAD: {
- makeBulkHead(preset);
+ makeBulkHead(exceptions,preset);
break;
}
case TUBE_COUPLER: {
// For now TUBE_COUPLER is the same as BODY_TUBE
- makeBodyTube(preset);
+ makeBodyTube(exceptions,preset);
break;
}
case CENTERING_RING: {
- makeCenteringRing(preset);
+ makeCenteringRing(exceptions,preset);
break;
}
case ENGINE_BLOCK: {
- makeEngineBlock(preset);
+ makeEngineBlock(exceptions,preset);
break;
}
case LAUNCH_LUG: {
// Same processing as BODY_TUBE
- makeBodyTube(preset);
+ makeBodyTube(exceptions,preset);
break;
}
case STREAMER: {
- makeStreamer(preset);
+ makeStreamer(exceptions,preset);
break;
}
case PARACHUTE: {
- makeParachute(preset);
+ makeParachute(exceptions,preset);
break;
}
}
+ if ( exceptions.hasProblems() ) {
+ throw exceptions;
+ }
+
preset.computeDigest();
return preset;
}
- private static void makeBodyTube( ComponentPreset preset ) throws InvalidComponentPresetException {
+ private static void makeBodyTube( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
- checkRequiredFields( preset, LENGTH );
+ checkRequiredFields( exceptions, preset, LENGTH );
- checkDiametersAndThickness(preset);
+ checkDiametersAndThickness(exceptions, preset);
double volume = computeVolumeOfTube( preset );
}
- private static void makeNoseCone( ComponentPreset preset ) throws InvalidComponentPresetException {
+ private static void makeNoseCone( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
- checkRequiredFields( preset, LENGTH, SHAPE, AFT_OUTER_DIAMETER );
+ checkRequiredFields( exceptions, preset, LENGTH, SHAPE, AFT_OUTER_DIAMETER );
if ( preset.has(MASS) ) {
// compute a density for this component
}
- private static void makeTransition( ComponentPreset preset ) throws InvalidComponentPresetException {
- checkRequiredFields(preset, LENGTH, AFT_OUTER_DIAMETER, FORE_OUTER_DIAMETER);
+ private static void makeTransition( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+ checkRequiredFields(exceptions, preset, LENGTH, AFT_OUTER_DIAMETER, FORE_OUTER_DIAMETER);
if ( preset.has(MASS) ) {
// compute a density for this component
}
- private static void makeBulkHead( ComponentPreset preset ) throws InvalidComponentPresetException {
- checkRequiredFields(preset, LENGTH, OUTER_DIAMETER );
+ private static void makeBulkHead( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+ checkRequiredFields(exceptions, preset, LENGTH, OUTER_DIAMETER );
if ( preset.has(MASS) ) {
// compute a density for this component
}
- private static void makeCenteringRing( ComponentPreset preset ) throws InvalidComponentPresetException {
- checkRequiredFields( preset, LENGTH );
+ private static void makeCenteringRing( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
+ checkRequiredFields( exceptions, preset, LENGTH );
- checkDiametersAndThickness( preset );
+ checkDiametersAndThickness( exceptions, preset );
double volume = computeVolumeOfTube( preset );
}
- private static void makeEngineBlock( ComponentPreset preset ) throws InvalidComponentPresetException {
- checkRequiredFields( preset, LENGTH );
+ private static void makeEngineBlock( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
+ checkRequiredFields( exceptions, preset, LENGTH );
- checkDiametersAndThickness( preset );
+ checkDiametersAndThickness( exceptions, preset );
double volume = computeVolumeOfTube( preset );
}
- private static void makeStreamer( ComponentPreset preset ) throws InvalidComponentPresetException {
- checkRequiredFields( preset, LENGTH, WIDTH );
+ private static void makeStreamer( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+ checkRequiredFields( exceptions, preset, LENGTH, WIDTH );
}
- private static void makeParachute( ComponentPreset preset ) throws InvalidComponentPresetException {
- checkRequiredFields( preset, DIAMETER, LINE_COUNT, LINE_LENGTH );
+ private static void makeParachute( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+ checkRequiredFields( exceptions, preset, DIAMETER, LINE_COUNT, LINE_LENGTH );
}
- private static void checkRequiredFields( ComponentPreset preset, TypedKey<?> ... keys ) throws InvalidComponentPresetException {
+ private static void checkRequiredFields( InvalidComponentPresetException exceptions, ComponentPreset preset, TypedKey<?> ... keys ) {
for( TypedKey<?> key: keys ) {
if (! preset.has(key) ) {
- throw new InvalidComponentPresetException( "No " + key.getName() + " specified for " + preset.getType().name() + " preset " + preset.toString());
+ exceptions.addInvalidParameter(key, "No " + key.getName() + " specified");
}
}
}
- private static void checkDiametersAndThickness( ComponentPreset preset ) throws InvalidComponentPresetException {
+ private static void checkDiametersAndThickness( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
// Need to verify contains 2 of OD, thickness, ID. Compute the third.
boolean hasOd = preset.has(OUTER_DIAMETER);
boolean hasId = preset.has(INNER_DIAMETER);
thickness = preset.get(THICKNESS);
innerRadius = outerRadius - thickness;
} else {
- throw new InvalidComponentPresetException("Preset underspecified " + preset.toString());
+ exceptions.addMessage("Preset dimensions underspecified");
+ throw exceptions;
}
} else {
if ( ! hasId || ! hasThickness ) {
- throw new InvalidComponentPresetException("Preset underspecified " + preset.toString());
+ exceptions.addMessage("Preset dimensions underspecified");
+ throw exceptions;
}
innerRadius = preset.get(INNER_DIAMETER)/2.0;
thickness = preset.get(THICKNESS);
package net.sf.openrocket.preset;
+import java.util.ArrayList;
+import java.util.List;
+
public class InvalidComponentPresetException extends Exception {
+ private List<String> errors = new ArrayList<String>();
+ private List<TypedKey<?>> invalidParameters = new ArrayList<TypedKey<?>>();
+
public InvalidComponentPresetException() {
super();
- // TODO Auto-generated constructor stub
}
public InvalidComponentPresetException(String message, Throwable cause) {
super(message, cause);
- // TODO Auto-generated constructor stub
}
public InvalidComponentPresetException(String message) {
super(message);
- // TODO Auto-generated constructor stub
}
public InvalidComponentPresetException(Throwable cause) {
super(cause);
- // TODO Auto-generated constructor stub
+ }
+
+ void addInvalidParameter(TypedKey<?> key ) {
+ invalidParameters.add(key);
+ }
+
+ void addInvalidParameter(TypedKey<?> key, String message ) {
+ invalidParameters.add(key);
+ errors.add(message);
+ }
+
+ void addMessage( String message ) {
+ errors.add(message);
}
+ boolean hasProblems() {
+ return (invalidParameters.size() + errors.size()) > 0;
+ }
+
+ public int problemCount() {
+ return Math.max( invalidParameters.size(), errors.size() );
+ }
+
+ public List<String> getErrors() {
+ return errors;
+ }
+
+ public List<TypedKey<?>> getInvalidParameters() {
+ return invalidParameters;
+ }
+
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
// constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */
-
+
double density = 100.0 / volume;
-
+
assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
}
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
-
+
}
@Test
// constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */
-
+
double density = 100.0 / volume;
-
+
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.OUTER_DIAMETER
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "No OuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.OUTER_DIAMETER
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "No OuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH,
+ ComponentPreset.OUTER_DIAMETER
+ },
+ new String[] {
+ "No Length specified",
+ "No OuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.LENGTH, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No OuterDiameter specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.OUTER_DIAMETER
+ },
+ new String[] {
+ "No OuterDiameter specified"
+ }
+ );
}
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
// constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */
-
+
double density = 100.0 / volume;
-
+
assertEquals("CenteringRingCustom",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
}
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
-
+
}
@Test
// constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */
-
+
double density = 100.0 / volume;
-
+
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.rocketcomponent.Transition;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.SHAPE
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "No AftOuterDiameter specified",
+ "No Shape specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.SHAPE
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "No AftOuterDiameter specified",
+ "No Shape specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH,
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.SHAPE
+ },
+ new String[] {
+ "No Length specified",
+ "No AftOuterDiameter specified",
+ "No Shape specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.LENGTH, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Shape"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.SHAPE
+ },
+ new String[] {
+ "No AftOuterDiameter specified",
+ "No Shape specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.AFT_OUTER_DIAMETER
+ },
+ new String[] {
+ "No AftOuterDiameter specified"
+ }
+ );
}
}
package net.sf.openrocket.preset;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.motor.Manufacturer;
import org.junit.Test;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.PARACHUTE);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.DIAMETER,
+ ComponentPreset.LINE_COUNT,
+ ComponentPreset.LINE_LENGTH
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Diameter specified",
+ "No LineCount specified",
+ "No LineLength specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.DIAMETER,
+ ComponentPreset.LINE_COUNT,
+ ComponentPreset.LINE_LENGTH
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Diameter specified",
+ "No LineCount specified",
+ "No LineLength specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Diameter specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.DIAMETER,
+ ComponentPreset.LINE_COUNT,
+ ComponentPreset.LINE_LENGTH
+ },
+ new String[] {
+ "No Diameter specified",
+ "No LineCount specified",
+ "No LineLength specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No LineCount specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LINE_COUNT,
+ ComponentPreset.LINE_LENGTH
+ },
+ new String[] {
+ "No LineCount specified",
+ "No LineLength specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.LINE_COUNT, 6);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No LineLength specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LINE_LENGTH
+ },
+ new String[] {
+ "No LineLength specified"
+ }
+ );
}
}
--- /dev/null
+package net.sf.openrocket.preset;
+
+import static org.junit.Assert.*;
+
+public abstract class PresetTest {
+
+ public static void assertInvalidPresetException( InvalidComponentPresetException exceptions, TypedKey<?>[] keys, String[] messages ) {
+ if ( keys != null ) {
+ assertEquals( keys.length, exceptions.getInvalidParameters().size() );
+ for( TypedKey<?> expectedKey : keys ) {
+ boolean keyFound = false;
+ for( TypedKey<?> k : exceptions.getInvalidParameters() ) {
+ if ( expectedKey == k ) {
+ keyFound = true;
+ break;
+ }
+ }
+ if ( ! keyFound ) {
+ fail( "Expected key " + expectedKey + " not in exception");
+ }
+ }
+ } else {
+ assertEquals(0, exceptions.getInvalidParameters().size() );
+ }
+ if ( messages != null ) {
+ assertEquals( messages.length, exceptions.getErrors().size() );
+ for( String expectedMessage : messages ) {
+ boolean stringMatched = false;
+ for ( String s : exceptions.getErrors() ) {
+ if ( s.contains( expectedMessage ) ) {
+ stringMatched = true;
+ break;
+ }
+ }
+ if( !stringMatched ) {
+ fail( "Expected string \"" + expectedMessage + "\" not reported in errors");
+ }
+ }
+ } else {
+ assertEquals(0, exceptions.getErrors().size() );
+ }
+ }
+}
package net.sf.openrocket.preset;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.motor.Manufacturer;
import org.junit.Test;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.STREAMER);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.WIDTH
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "No Width specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.WIDTH
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "No Width specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH,
+ ComponentPreset.WIDTH
+ },
+ new String[] {
+ "No Length specified",
+ "No Width specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.LENGTH, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Width specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.WIDTH
+ },
+ new String[] {
+ "No Width specified"
+ }
+ );
}
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.rocketcomponent.Transition;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.FORE_OUTER_DIAMETER
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "No AftOuterDiameter specified",
+ "No ForeOuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH,
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.FORE_OUTER_DIAMETER
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "No AftOuterDiameter specified",
+ "No ForeOuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH,
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.FORE_OUTER_DIAMETER
+ },
+ new String[] {
+ "No Length specified",
+ "No AftOuterDiameter specified",
+ "No ForeOuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.FORE_OUTER_DIAMETER
+ },
+ new String[] {
+ "No AftOuterDiameter specified",
+ "No ForeOuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No ForeOuterDiameter"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.FORE_OUTER_DIAMETER
+ },
+ new String[] {
+ "No ForeOuterDiameter specified"
+ }
+ );
}
}
package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.MANUFACTURER,
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Manufacturer specified",
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.PARTNO,
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No PartNo specified",
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetTest.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.LENGTH
+ },
+ new String[] {
+ "No Length specified",
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+ PresetTest.assertInvalidPresetException( ex,
+ null,
+ new String[] {
+ "Preset dimensions underspecified"
+ }
+ );
}
}