1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.qualitytest.blueprint.configuration;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import net.sf.qualitytest.blueprint.CycleHandlingStrategy;
22 import net.sf.qualitytest.blueprint.strategy.creation.BlueprintCreationStrategy;
23 import net.sf.qualitytest.blueprint.strategy.creation.BlueprintStringCreationStrategy;
24 import net.sf.qualitytest.blueprint.strategy.creation.RandomBooleanValueCreationStrategy;
25 import net.sf.qualitytest.blueprint.strategy.creation.RandomByteValueCreationStrategy;
26 import net.sf.qualitytest.blueprint.strategy.creation.RandomCharValueCreationStrategy;
27 import net.sf.qualitytest.blueprint.strategy.creation.RandomDoubleValueCreationStrategy;
28 import net.sf.qualitytest.blueprint.strategy.creation.RandomEnumCreationStrategy;
29 import net.sf.qualitytest.blueprint.strategy.creation.RandomFloatValueCreationStrategy;
30 import net.sf.qualitytest.blueprint.strategy.creation.RandomIntValueCreationStrategy;
31 import net.sf.qualitytest.blueprint.strategy.creation.RandomLongValueCreationStrategy;
32 import net.sf.qualitytest.blueprint.strategy.creation.RandomShortValueCreationStrategy;
33 import net.sf.qualitytest.blueprint.strategy.creation.ValueCreationStrategy;
34 import net.sf.qualitytest.blueprint.strategy.matching.InstanceOfTypeMatchingStrategy;
35 import net.sf.qualitytest.blueprint.strategy.matching.SetterMethodMatchingStrategy;
36 import net.sf.qualitytest.blueprint.strategy.matching.TypeMatchingStrategy;
37
38 import com.google.common.collect.ImmutableList;
39
40
41
42
43
44
45
46
47
48
49
50 public final class RandomBlueprintConfiguration extends ImmutableBlueprintConfiguration {
51
52 private static final ValueCreationStrategy<Long> LONG_DEFAULT = new RandomLongValueCreationStrategy();
53 private static final ValueCreationStrategy<Integer> INTEGER_DEFAULT = new RandomIntValueCreationStrategy();
54 private static final ValueCreationStrategy<Boolean> BOOLEAN_DEFAULT = new RandomBooleanValueCreationStrategy();
55 private static final ValueCreationStrategy<Character> CHARACTER_DEFAULT = new RandomCharValueCreationStrategy();
56 private static final ValueCreationStrategy<Short> SHORT_DEFAULT = new RandomShortValueCreationStrategy();
57 private static final ValueCreationStrategy<Byte> BYTE_DEFAULT = new RandomByteValueCreationStrategy();
58 private static final ValueCreationStrategy<Float> FLOAT_DEFAULT = new RandomFloatValueCreationStrategy();
59 private static final ValueCreationStrategy<Double> DOUBLE_DEFAULT = new RandomDoubleValueCreationStrategy();
60
61
62
63
64
65
66 public static void addRandomEnumStrategy(final List<StrategyPair> list) {
67 list.add(new StrategyPair(new InstanceOfTypeMatchingStrategy(Enum.class), new RandomEnumCreationStrategy()));
68 }
69
70 private static List<StrategyPair> createDefaultAttributeMapping() {
71 final List<StrategyPair> list = new ArrayList<StrategyPair>();
72 list.add(new StrategyPair(new TypeMatchingStrategy(String.class), new BlueprintStringCreationStrategy()));
73 list.add(new StrategyPair(new TypeMatchingStrategy(Long.class), LONG_DEFAULT));
74 list.add(new StrategyPair(new TypeMatchingStrategy(long.class), LONG_DEFAULT));
75 list.add(new StrategyPair(new TypeMatchingStrategy(Integer.class), INTEGER_DEFAULT));
76 list.add(new StrategyPair(new TypeMatchingStrategy(int.class), INTEGER_DEFAULT));
77 list.add(new StrategyPair(new TypeMatchingStrategy(Boolean.class), BOOLEAN_DEFAULT));
78 list.add(new StrategyPair(new TypeMatchingStrategy(boolean.class), BOOLEAN_DEFAULT));
79 list.add(new StrategyPair(new TypeMatchingStrategy(Character.class), CHARACTER_DEFAULT));
80 list.add(new StrategyPair(new TypeMatchingStrategy(char.class), CHARACTER_DEFAULT));
81 list.add(new StrategyPair(new TypeMatchingStrategy(Short.class), SHORT_DEFAULT));
82 list.add(new StrategyPair(new TypeMatchingStrategy(short.class), SHORT_DEFAULT));
83 list.add(new StrategyPair(new TypeMatchingStrategy(Byte.class), BYTE_DEFAULT));
84 list.add(new StrategyPair(new TypeMatchingStrategy(byte.class), BYTE_DEFAULT));
85 list.add(new StrategyPair(new TypeMatchingStrategy(Float.class), FLOAT_DEFAULT));
86 list.add(new StrategyPair(new TypeMatchingStrategy(float.class), FLOAT_DEFAULT));
87 list.add(new StrategyPair(new TypeMatchingStrategy(Double.class), DOUBLE_DEFAULT));
88 list.add(new StrategyPair(new TypeMatchingStrategy(double.class), DOUBLE_DEFAULT));
89
90 addRandomEnumStrategy(list);
91 DefaultBlueprintConfiguration.addDefaultArrayStrategy(list);
92 DefaultBlueprintConfiguration.addDefaultCollections(list);
93 list.add(new StrategyPair(new SetterMethodMatchingStrategy(), new BlueprintCreationStrategy()));
94
95 return list;
96 }
97
98 public RandomBlueprintConfiguration() {
99 super(createDefaultAttributeMapping(), ImmutableList.<CycleHandlingStrategy<?>> of(), false);
100 }
101 }