Skip to content

Commit a221886

Browse files
authored
test: negative & positive parsing tests
Also cleaned up all legacy and unnecessary tests
2 parents 89ca759 + a9f0bcf commit a221886

285 files changed

Lines changed: 37503 additions & 14078 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.HashMap;
44
import java.util.List;
55
import java.util.Map;
6+
import java.util.Set;
67

78
import io.github.isagroup.exceptions.FeatureNotFoundException;
89
import io.github.isagroup.exceptions.InvalidDefaultValueException;
@@ -96,6 +97,11 @@ private static void setAvailableFor(Map<String, Object> addOnMap, PricingManager
9697

9798
List<String> plansAvailable = (List<String>) addOnMap.get("availableFor");
9899

100+
if (plansAvailable == null) {
101+
List<String> allPlans = pricingManager.getPlans().keySet().stream().toList();
102+
addOn.setAvailableFor(allPlans);
103+
}
104+
99105
for (String planName : plansAvailable) {
100106
if (!pricingManager.getPlans().containsKey(planName)
101107
&& !pricingManager.getAddOns().containsKey(planName)) {

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.github.isagroup.exceptions.PricingParsingException;
1111
import io.github.isagroup.models.Feature;
1212
import io.github.isagroup.models.FeatureType;
13+
import io.github.isagroup.models.PricingManager;
1314
import io.github.isagroup.models.ValueType;
1415
import io.github.isagroup.models.featuretypes.Automation;
1516
import io.github.isagroup.models.featuretypes.AutomationType;
@@ -28,7 +29,7 @@ public class FeatureParser {
2829
private FeatureParser() {
2930
}
3031

31-
public static Feature parseMapToFeature(String featureName, Map<String, Object> featureMap) {
32+
public static Feature parseMapToFeature(String featureName, Map<String, Object> featureMap, PricingManager pricingManager) {
3233

3334
if (featureMap.get("type") == null) {
3435
throw new PricingParsingException("feature 'type' is mandatory");
@@ -39,28 +40,28 @@ public static Feature parseMapToFeature(String featureName, Map<String, Object>
3940
switch (FeatureType.valueOf((String) featureMap.get("type"))) {
4041

4142
case INFORMATION:
42-
return parseMapToInformation(featureName, featureMap);
43+
return parseMapToInformation(featureName, featureMap, pricingManager);
4344

4445
case INTEGRATION:
45-
return parseMapToIntegration(featureName, featureMap);
46+
return parseMapToIntegration(featureName, featureMap, pricingManager);
4647

4748
case DOMAIN:
48-
return parseMapToDomain(featureName, featureMap);
49+
return parseMapToDomain(featureName, featureMap, pricingManager);
4950

5051
case AUTOMATION:
51-
return parseMapToAutomation(featureName, featureMap);
52+
return parseMapToAutomation(featureName, featureMap, pricingManager);
5253

5354
case MANAGEMENT:
54-
return parseMapToManagement(featureName, featureMap);
55+
return parseMapToManagement(featureName, featureMap, pricingManager);
5556

5657
case GUARANTEE:
57-
return parseMapToGuarantee(featureName, featureMap);
58+
return parseMapToGuarantee(featureName, featureMap, pricingManager);
5859

5960
case SUPPORT:
60-
return parseMapToSupport(featureName, featureMap);
61+
return parseMapToSupport(featureName, featureMap, pricingManager);
6162

6263
case PAYMENT:
63-
return parseMapToPayment(featureName, featureMap);
64+
return parseMapToPayment(featureName, featureMap, pricingManager);
6465

6566
default:
6667
return null;
@@ -71,18 +72,18 @@ public static Feature parseMapToFeature(String featureName, Map<String, Object>
7172
}
7273
}
7374

74-
private static Information parseMapToInformation(String featureName, Map<String, Object> map) {
75+
private static Information parseMapToInformation(String featureName, Map<String, Object> map, PricingManager pricingManager) {
7576
Information information = new Information();
7677

77-
loadBasicAttributes(information, featureName, map);
78+
loadBasicAttributes(information, featureName, map, pricingManager);
7879

7980
return information;
8081
}
8182

82-
private static Integration parseMapToIntegration(String featureName, Map<String, Object> map) {
83+
private static Integration parseMapToIntegration(String featureName, Map<String, Object> map, PricingManager pricingManager) {
8384
Integration integration = new Integration();
8485

85-
loadBasicAttributes(integration, featureName, map);
86+
loadBasicAttributes(integration, featureName, map, pricingManager);
8687

8788
try {
8889
integration.setIntegrationType(IntegrationType.valueOf((String) map.get("integrationType")));
@@ -99,18 +100,18 @@ private static Integration parseMapToIntegration(String featureName, Map<String,
99100
return integration;
100101
}
101102

102-
private static Domain parseMapToDomain(String featureName, Map<String, Object> map) {
103+
private static Domain parseMapToDomain(String featureName, Map<String, Object> map, PricingManager pricingManager) {
103104
Domain domain = new Domain();
104105

105-
loadBasicAttributes(domain, featureName, map);
106+
loadBasicAttributes(domain, featureName, map, pricingManager);
106107

107108
return domain;
108109
}
109110

110-
private static Automation parseMapToAutomation(String featureName, Map<String, Object> map) {
111+
private static Automation parseMapToAutomation(String featureName, Map<String, Object> map, PricingManager pricingManager) {
111112
Automation automation = new Automation();
112113

113-
loadBasicAttributes(automation, featureName, map);
114+
loadBasicAttributes(automation, featureName, map, pricingManager);
114115

115116
try {
116117
automation.setAutomationType(AutomationType.valueOf((String) map.get("automationType")));
@@ -123,41 +124,41 @@ private static Automation parseMapToAutomation(String featureName, Map<String, O
123124
return automation;
124125
}
125126

126-
private static Management parseMapToManagement(String featureName, Map<String, Object> map) {
127+
private static Management parseMapToManagement(String featureName, Map<String, Object> map, PricingManager pricingManager) {
127128
Management management = new Management();
128129

129-
loadBasicAttributes(management, featureName, map);
130+
loadBasicAttributes(management, featureName, map, pricingManager);
130131

131132
return management;
132133
}
133134

134-
private static Guarantee parseMapToGuarantee(String featureName, Map<String, Object> map) {
135+
private static Guarantee parseMapToGuarantee(String featureName, Map<String, Object> map, PricingManager pricingManager) {
135136
Guarantee guarantee = new Guarantee();
136137

137-
loadBasicAttributes(guarantee, featureName, map);
138+
loadBasicAttributes(guarantee, featureName, map, pricingManager);
138139

139140
guarantee.setDocURL((String) map.get("docURL"));
140141

141142
return guarantee;
142143
}
143144

144-
private static Support parseMapToSupport(String featureName, Map<String, Object> map) {
145+
private static Support parseMapToSupport(String featureName, Map<String, Object> map, PricingManager pricingManager) {
145146
Support support = new Support();
146147

147-
loadBasicAttributes(support, featureName, map);
148+
loadBasicAttributes(support, featureName, map, pricingManager);
148149

149150
return support;
150151
}
151152

152-
private static Payment parseMapToPayment(String featureName, Map<String, Object> map) {
153+
private static Payment parseMapToPayment(String featureName, Map<String, Object> map, PricingManager pricingManager) {
153154
Payment payment = new Payment();
154155

155-
loadBasicAttributes(payment, featureName, map);
156+
loadBasicAttributes(payment, featureName, map, pricingManager);
156157

157158
return payment;
158159
}
159160

160-
private static void loadBasicAttributes(Feature feature, String featureName, Map<String, Object> map) {
161+
private static void loadBasicAttributes(Feature feature, String featureName, Map<String, Object> map, PricingManager pricingManager) {
161162

162163
if (featureName == null) {
163164
throw new PricingParsingException("A feature cannot have the name null");
@@ -214,10 +215,15 @@ private static void loadBasicAttributes(Feature feature, String featureName, Map
214215
+ " does not have either an evaluation expression or serverExpression.");
215216
}
216217

217-
try {
218-
feature.setTag((String) map.get("tag"));
219-
} catch (NoSuchElementException e) {
220-
feature.setTag(null);
218+
219+
String featureTag = (String) map.get("tag");
220+
221+
if (featureTag != null) {
222+
if (pricingManager.getTags().contains(featureTag)){
223+
feature.setTag((String) featureTag);
224+
}else{
225+
throw new PricingParsingException("The tag " + featureTag + " is not defined in the global tags.");
226+
}
221227
}
222228
}
223229

0 commit comments

Comments
 (0)