Skip to content

Commit a9f0bcf

Browse files
author
Pedro González Marcos
committed
feat: migrate positive test suite
- Some test were disable to pass ci (need a look) - Add some new test cases - Remove legacy tests
1 parent ec9d79f commit a9f0bcf

47 files changed

Lines changed: 1013 additions & 487 deletions

Some content is hidden

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

src/test/java/io/github/isagroup/parsing/AddOnParserTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/test/java/io/github/isagroup/parsing/FeatureParserTest.java

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/test/java/io/github/isagroup/parsing/PricingManagerParserTest.java

Lines changed: 0 additions & 122 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.github.isagroup.parsing.negative;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.fail;
5+
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.CsvFileSource;
8+
9+
import io.github.isagroup.exceptions.InvalidPlanException;
10+
import io.github.isagroup.exceptions.PricingParsingException;
11+
import io.github.isagroup.exceptions.VersionException;
12+
import io.github.isagroup.services.yaml.YamlUtils;
13+
14+
class NegativeParsingTests {
15+
16+
@ParameterizedTest(name = "{0} - {1}")
17+
@CsvFileSource(resources = "/negative-parsing-tests.csv", delimiter = ';')
18+
void negativeTests(String testDescription, String fileName, String expectedErrorMessage) {
19+
20+
try {
21+
YamlUtils.retrieveManagerFromYaml(fileName);
22+
fail();
23+
} catch (PricingParsingException | InvalidPlanException | VersionException e) {
24+
assertEquals(expectedErrorMessage, e.getMessage());
25+
}
26+
}
27+
28+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.github.isagroup.parsing.positive;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import io.github.isagroup.models.PricingManager;
6+
import io.github.isagroup.services.yaml.YamlUtils;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
import org.junit.jupiter.api.DisplayName;
11+
12+
public class AddOnParserTest {
13+
14+
private static final String TEST_CASES = "parsing/positive/addOn/";
15+
16+
@Test
17+
@DisplayName(value = "'dependsOn': In order to purchase an add-on you have to previosly purchase other add-on.")
18+
void givenAnAddOnInDependsOnShouldParse() {
19+
20+
PricingManager pricingManager = YamlUtils.retrieveManagerFromYaml(TEST_CASES + "dependsOn/dependent-addOn.yml");
21+
assertEquals(2, pricingManager.getAddOns().size());
22+
assertTrue(pricingManager.getAddOns().get("baz").getDependsOn().contains("bar"));
23+
24+
}
25+
26+
@Test
27+
@DisplayName(value = "When 'private' is true, add-on should parse")
28+
void givenEnablePrivateInAddOnShouldParse() {
29+
30+
String addOnName = "addon1";
31+
PricingManager pricingManager = YamlUtils.retrieveManagerFromYaml(TEST_CASES + "private/is-private.yml");
32+
assertTrue(pricingManager.getAddOns().get(addOnName).getIsPrivate());
33+
34+
}
35+
36+
@Test
37+
@DisplayName(value = "When 'private' is false, add-on should parse")
38+
void givenDisablePrivateInAddOnShouldParse() {
39+
40+
String addOnName = "addon1";
41+
PricingManager pricingManager = YamlUtils.retrieveManagerFromYaml(TEST_CASES + "private/is-not-private.yml");
42+
assertFalse(pricingManager.getAddOns().get(addOnName).getIsPrivate());
43+
44+
}
45+
46+
@Test
47+
@DisplayName(value = "When add-on 'private' is not provided by default is false")
48+
void givenNullPrivateShouldParse() {
49+
50+
String addOnName = "addon1";
51+
PricingManager pricingManager = YamlUtils.retrieveManagerFromYaml(TEST_CASES + "private/no-private.yml");
52+
assertFalse(pricingManager.getAddOns().get(addOnName).getIsPrivate());
53+
54+
}
55+
56+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package io.github.isagroup.parsing.positive;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5+
import static org.junit.jupiter.api.Assertions.assertNull;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
import org.junit.jupiter.api.DisplayName;
11+
import org.junit.jupiter.api.Test;
12+
13+
import io.github.isagroup.models.PricingManager;
14+
import io.github.isagroup.services.yaml.YamlUtils;
15+
16+
public class FeatureParserTest {
17+
18+
private static final String POSITIVE_CASES = "parsing/positive/feature/";
19+
20+
@Test
21+
@DisplayName(value = "Given a list of payment methods in 'defaultValue' should parse it")
22+
void givenPaymentFeatureDefaultValueShouldBeListOfPaymentMethods() {
23+
24+
List<String> expectedPaymentMethods = new ArrayList<>();
25+
expectedPaymentMethods.add("CARD");
26+
String paymentFeatName = "payment";
27+
28+
PricingManager pricingManager = YamlUtils
29+
.retrieveManagerFromYaml(POSITIVE_CASES + "type/payment-feature.yml");
30+
31+
assertNotNull(pricingManager.getFeatures().get(paymentFeatName));
32+
List<String> actualPaymentMethods = (List<String>) pricingManager.getFeatures().get(paymentFeatName)
33+
.getDefaultValue();
34+
assertEquals(expectedPaymentMethods, actualPaymentMethods,
35+
"Payment methods should be a list of payment methods");
36+
37+
}
38+
39+
@Test
40+
@DisplayName(value = "A feature 'expression' should be optional")
41+
void givenAFeatureExpressionShouldBeOptional() {
42+
43+
String featName = "foo";
44+
PricingManager pricingManager = YamlUtils
45+
.retrieveManagerFromYaml(POSITIVE_CASES + "expression/expression-is-null.yml");
46+
47+
assertNotNull(pricingManager.getFeatures().get(featName));
48+
assertNull(pricingManager.getFeatures().get(featName).getExpression());
49+
50+
}
51+
}

0 commit comments

Comments
 (0)