Skip to content

Commit d30a1b8

Browse files
authored
5.3.1
FEAT: - New validations for payment types
2 parents 563387d + f00dda0 commit d30a1b8

4 files changed

Lines changed: 36 additions & 15 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>io.github.isa-group</groupId>
99
<artifactId>Pricing4Java</artifactId>
10-
<version>5.3.0</version>
10+
<version>5.4.0</version>
1111

1212
<name>${project.groupId}:${project.artifactId}</name>
1313
<description>A pricing driven feature toggling library for java</description>

src/main/java/io/github/isagroup/services/parsing/FeatureParser.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ private static Integration parseMapToIntegration(String featureName, Map<String,
8989

9090
loadBasicAttributes(integration, featureName, map, pricingManager);
9191

92+
String integrationType = "";
93+
try{
94+
integrationType = (String) map.get("integrationType");
95+
} catch (NullPointerException e) {
96+
throw new InvalidIntegrationTypeException("The feature " + featureName + " is from type INTEGRATION but does not have an integrationType attribute");
97+
}
98+
9299
try {
93-
integration.setIntegrationType(IntegrationType.valueOf((String) map.get("integrationType")));
100+
integration.setIntegrationType(IntegrationType.valueOf(integrationType));
94101
} catch (NullPointerException | IllegalArgumentException e) {
95102
throw new InvalidIntegrationTypeException(
96103
"The feature " + featureName + " does not have a supported integrationType (" + Arrays.toString(IntegrationType.values()) + "). Current value: "
97-
+ (String) map.get("integrationType"));
104+
+ integrationType);
98105
}
99106

100107
if (integration.getIntegrationType().equals(IntegrationType.WEB_SAAS)) {
@@ -118,12 +125,19 @@ private static Automation parseMapToAutomation(String featureName, Map<String, O
118125

119126
loadBasicAttributes(automation, featureName, map, pricingManager);
120127

128+
String automationType = "";
129+
try{
130+
automationType = (String) map.get("automationType");
131+
} catch (NullPointerException e) {
132+
throw new InvalidAutomationTypeException("The feature " + featureName + " is from type AUTOMATION but does not have an automationType attribute");
133+
}
134+
121135
try {
122-
automation.setAutomationType(AutomationType.valueOf((String) map.get("automationType")));
136+
automation.setAutomationType(AutomationType.valueOf(automationType));
123137
} catch (IllegalArgumentException e) {
124138
throw new InvalidAutomationTypeException(
125139
"The feature " + featureName + " does not have a supported automationType (" + Arrays.toString(AutomationType.values()) + "). Current value: "
126-
+ (String) map.get("automationType"));
140+
+ automationType);
127141
}
128142

129143
return automation;
@@ -190,7 +204,7 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
190204
feature.setValueType(ValueType.valueOf((String) map.get("valueType")));
191205
} catch (IllegalArgumentException e) {
192206
throw new PricingParsingException("The feature " + featureName
193-
+ " does not have a supported valueType. Current valueType: " + (String) map.get("valueType"));
207+
+ " does not have a supported valueType (" + Arrays.toString(ValueType.values()) + "). Current valueType: " + (String) map.get("valueType"));
194208
}
195209
try {
196210
Object defaultValue = map.get("defaultValue");
@@ -204,6 +218,10 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
204218

205219
switch (feature.getValueType()) {
206220
case NUMERIC:
221+
if (feature instanceof Payment) {
222+
throw new InvalidDefaultValueException("The feature " + featureName
223+
+ " is from type PAYMENT but has a valueType of NUMERIC. It should be TEXT.");
224+
}
207225
feature.setDefaultValue(map.get("defaultValue"));
208226
if (!(feature.getDefaultValue() instanceof Integer || feature.getDefaultValue() instanceof Double
209227
|| feature.getDefaultValue() instanceof Long)) {
@@ -251,18 +269,21 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
251269
}
252270

253271
private static void parsePaymentValue(Feature feature, String featureName, Map<String, Object> map) {
254-
255-
List<String> allowedPaymentTypes = (List<String>) map.get("defaultValue");
256-
for (String type : allowedPaymentTypes) {
272+
List<String> allowedPaymentTypes;
273+
try{
274+
allowedPaymentTypes = (List<String>) map.get("defaultValue");
275+
} catch (ClassCastException e) {
276+
throw new InvalidDefaultValueException("The feature " + featureName
277+
+ " is from type PAYMENT but has a valueType of TEXT. It should be a list of supported paymentType ("+Arrays.toString(PaymentType.values())+"). To specify a list, use a dash (-) before each value. The defaultValue that generates the issue: " + map.get("defaultValue"));
278+
}
279+
for (String paymentType : allowedPaymentTypes) {
257280
try {
258-
PaymentType.valueOf(type);
281+
PaymentType.valueOf(paymentType);
259282
} catch (IllegalArgumentException e) {
260283
throw new InvalidDefaultValueException("The feature " + featureName
261-
+ " does not have a supported paymentType. PaymentType that generates the issue: " + type);
284+
+ " does not have a valid defaultValue consisting on a list of supported paymentType ("+Arrays.toString(PaymentType.values())+"). PaymentType that generates the issue: " + paymentType);
262285
}
263286
}
264-
265287
feature.setDefaultValue(allowedPaymentTypes);
266-
267288
}
268289
}

src/main/java/io/github/isagroup/services/parsing/UsageLimitParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static void loadBasicAttributes(UsageLimit limit, String limitName, Map<
9898
limit.setValueType(ValueType.valueOf((String) map.get("valueType")));
9999
} catch (IllegalArgumentException e) {
100100
throw new InvalidValueTypeException("The feature " + limitName
101-
+ " does not have a supported valueType. Current valueType: " + (String) map.get("valueType"));
101+
+ " does not have a supported valueType (" + Arrays.toString(ValueType.values()) + "). Current valueType: " + (String) map.get("valueType"));
102102
}
103103
try {
104104
Object defaultValue = map.get("defaultValue");

src/test/resources/negative-parsing-tests.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Throw an error if feature 'docUrl' is not a string;parsing/negative/feature/docU
3636
Throw an error if feature 'type' is missing or null;parsing/negative/feature/type/null-type.yml;feature 'type' is mandatory
3737
# feature.valueType
3838
Throw an error if feature 'type' is missing or null;parsing/negative/feature/valueType/null-valueType.yml;Feature value type is null
39-
Throw an error if feature 'type' is not a supported feature type;parsing/negative/feature/valueType/unsupported-valueType.yml;The feature foo does not have a supported valueType. Current valueType: foo
39+
Throw an error if feature 'type' is not a supported feature type;parsing/negative/feature/valueType/unsupported-valueType.yml;The feature foo does not have a supported valueType ([NUMERIC, TEXT, BOOLEAN]). Current valueType: foo
4040
# features
4141
Throw an error if 'features' is not a map;parsing/negative/features/features-is-boolean.yml;'features' must be a Map but found Boolean instead
4242
Throw an error if 'features' is not a map;parsing/negative/features/features-is-float.yml;'features' must be a Map but found Double instead

0 commit comments

Comments
 (0)