Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO ISSUE: Replaces junit assertions with assertj assertions in kie-dmn-openapi #6057

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import org.kie.dmn.core.impl.SimpleTypeImpl;
import org.kie.dmn.feel.lang.types.BuiltInType;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_STRING;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getSchemaForSimpleType;
Expand All @@ -49,25 +47,23 @@ void populateSchemaWithConstraintsForAllowedValues() {
SimpleTypeImpl toRead = getSimpleType(allowedValuesString, null, FEEL_STRING, BuiltInType.STRING);
AtomicReference<Schema> toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead));
DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead);
assertEquals(enumBase.size(), toPopulate.get().getEnumeration().size());
enumBase.forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en)));
assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES));
assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase);
assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES);
String retrieved =
((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_ALLOWED_VALUES)).replace(" ", "");
assertEquals(allowedValuesString, retrieved);
assertThat(retrieved).isEqualTo(allowedValuesString);

toEnum = Arrays.asList(1, 3, 6, 78);
toEnum = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(3), BigDecimal.valueOf(6), BigDecimal.valueOf(78));
allowedValuesString = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList());

toRead = getSimpleType(allowedValuesString, null, FEEL_NUMBER, BuiltInType.NUMBER);
toPopulate.set(getSchemaForSimpleType(toRead));
DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead);
assertEquals(toEnum.size(), toPopulate.get().getEnumeration().size());
toEnum.stream().map(i -> BigDecimal.valueOf((int) i)).forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en)));
assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES));
assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(toEnum).containsAll(toEnum);
assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES);
retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_ALLOWED_VALUES)).replace(" "
, "");
assertEquals(allowedValuesString, retrieved);
assertThat(retrieved).isEqualTo(allowedValuesString);
}

@Test
Expand All @@ -80,26 +76,24 @@ void populateSchemaWithConstraintsForTypeConstraints() {
SimpleTypeImpl toRead = getSimpleType(null, typeConstraintsString, FEEL_STRING, BuiltInType.STRING);
AtomicReference<Schema> toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead));
DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead);
assertEquals(enumBase.size(), toPopulate.get().getEnumeration().size());
enumBase.forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en)));
assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS));
assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase);
assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS);
String retrieved =
((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).replace(" ",
"");
assertEquals(typeConstraintsString, retrieved);
assertThat(retrieved).isEqualTo(typeConstraintsString);

toEnum = Arrays.asList(1, 3, 6, 78);
toEnum = Arrays.asList(BigDecimal.valueOf(1), BigDecimal.valueOf(3), BigDecimal.valueOf(6), BigDecimal.valueOf(78));
typeConstraintsString = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList());

toRead = getSimpleType(null, typeConstraintsString, FEEL_NUMBER, BuiltInType.NUMBER);
toPopulate.set(getSchemaForSimpleType(toRead));
DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead);
assertEquals(toEnum.size(), toPopulate.get().getEnumeration().size());
toEnum.stream().map(i -> BigDecimal.valueOf((int) i)).forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en)));
assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS));
assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(toEnum).containsAll(toEnum);
assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS);
retrieved = ((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).replace(
" ", "");
assertEquals(typeConstraintsString, retrieved);
assertThat(retrieved).isEqualTo(typeConstraintsString);
}

@Test
Expand All @@ -110,15 +104,15 @@ void populateSchemaWithRangesForAllowedValues() {
SimpleTypeImpl toRead = getSimpleType(allowedValuesString, null, FEEL_STRING, BuiltInType.STRING);
AtomicReference<Schema> toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead));
DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead);
assertEquals(BigDecimal.ONE, toPopulate.get().getMinimum());
assertTrue(toPopulate.get().getExclusiveMinimum());
assertEquals(BigDecimal.TEN, toPopulate.get().getMaximum());
assertFalse(toPopulate.get().getExclusiveMaximum());
assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES));
assertThat(toPopulate.get().getMinimum()).isEqualTo(BigDecimal.ONE);
assertThat(toPopulate.get().getExclusiveMinimum()).isTrue();
assertThat(toPopulate.get().getMaximum()).isEqualTo(BigDecimal.TEN);
assertThat(toPopulate.get().getExclusiveMaximum()).isFalse();
assertThat(toPopulate.get().getExtensions()).containsKey(DMNOASConstants.X_DMN_ALLOWED_VALUES);
String retrieved =
((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_ALLOWED_VALUES)).replace(" ", "");
String expected = allowedValuesString.replace("(", "").replace(")", "");
assertEquals(expected, retrieved);
assertThat(retrieved).isEqualTo(expected);
}

@Test
Expand All @@ -129,15 +123,15 @@ void populateSchemaWithRangesForTypeConstraints() {
SimpleTypeImpl toRead = getSimpleType(null, typeConstraintsString, FEEL_STRING, BuiltInType.STRING);
AtomicReference<Schema> toPopulate = new AtomicReference<>(getSchemaForSimpleType(toRead));
DMNTypeSchemas.populateSchemaWithConstraints(toPopulate.get(), toRead);
assertEquals(BigDecimal.ONE, toPopulate.get().getMinimum());
assertTrue(toPopulate.get().getExclusiveMinimum());
assertEquals(BigDecimal.TEN, toPopulate.get().getMaximum());
assertFalse(toPopulate.get().getExclusiveMaximum());
assertTrue(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS));
assertThat(toPopulate.get().getMinimum()).isEqualTo(BigDecimal.ONE);
assertThat(toPopulate.get().getExclusiveMinimum()).isTrue();
assertThat(toPopulate.get().getMaximum()).isEqualTo(BigDecimal.TEN);
assertThat(toPopulate.get().getExclusiveMaximum()).isFalse();
assertThat(toPopulate.get().getExtensions().containsKey(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).isTrue();
String retrieved =
((String) toPopulate.get().getExtensions().get(DMNOASConstants.X_DMN_TYPE_CONSTRAINTS)).replace(" ",
"");
String expected = typeConstraintsString.replace("(", "").replace(")", "");
assertEquals(expected, retrieved);
assertThat(retrieved).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

Expand All @@ -33,12 +32,8 @@
import org.kie.dmn.feel.lang.ast.BaseNode;
import org.kie.dmn.feel.lang.types.BuiltInType;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.kie.dmn.openapi.impl.DMNUnaryTestsMapper.getUnaryEvaluationNodesFromUnaryTests;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_STRING;
Expand All @@ -56,10 +51,9 @@ void populateSchemaFromUnaryTestsForEnumsWithoutNull() {
expression += ", count (?) > 1";
List<DMNUnaryTest> unaryTests = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList();
DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, unaryTests);
assertFalse(toPopulate.getNullable());
assertNotNull(toPopulate.getEnumeration());
assertEquals(expectedStrings.size(), toPopulate.getEnumeration().size());
expectedStrings.forEach(expectedString -> assertTrue(toPopulate.getEnumeration().contains(expectedString)));
assertThat(toPopulate.getNullable()).isFalse();
assertThat(toPopulate.getEnumeration()).isNotNull();
assertThat(toPopulate.getEnumeration()).hasSameSizeAs(expectedStrings).containsAll(expectedStrings);
}

@Test
Expand All @@ -70,10 +64,9 @@ void populateSchemaFromUnaryTestsForEnumsWithNull() {
String expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap.toString())).toList());
List<DMNUnaryTest> unaryTests = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList();
DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, unaryTests);
assertTrue(toPopulate.getNullable());
assertNotNull(toPopulate.getEnumeration());
assertEquals(expectedStrings.size(), toPopulate.getEnumeration().size());
expectedStrings.stream().filter(Objects::nonNull).forEach(expectedString -> assertTrue(toPopulate.getEnumeration().contains(expectedString)));
assertThat(toPopulate.getNullable()).isTrue();
assertThat(toPopulate.getEnumeration()).isNotNull();
assertThat(toPopulate.getEnumeration()).hasSameSizeAs(expectedStrings).containsAll(expectedStrings);
}

@Test
Expand All @@ -83,19 +76,17 @@ void populateSchemaFromUnaryTestsForEnumSucceed() {
String expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList());
List<DMNUnaryTest> toCheck = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList();
AtomicReference<Schema> toPopulate = new AtomicReference<>(getSchemaForSimpleType(null, expression, FEEL_STRING, BuiltInType.STRING));
assertNull(toPopulate.get().getEnumeration());
assertThat(toPopulate.get().getEnumeration()).isNull();;
DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate.get(), toCheck);
assertEquals(enumBase.size(), toPopulate.get().getEnumeration().size());
enumBase.forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en)));
assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase);

toEnum = Arrays.asList(1, 3, 6, 78);
expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList());
List<BigDecimal>toEnum1 = Arrays.asList(BigDecimal.valueOf(1L), BigDecimal.valueOf(3), BigDecimal.valueOf(6), BigDecimal.valueOf(78));
expression = String.join(",", toEnum1.stream().map(toMap -> String.format("%s", toMap)).toList());
toCheck = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList();
toPopulate.set(getSchemaForSimpleType(null, expression, FEEL_NUMBER, BuiltInType.NUMBER));
assertNull(toPopulate.get().getEnumeration());
assertThat(toPopulate.get().getEnumeration()).isNull();
DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate.get(), toCheck);
assertEquals(toEnum.size(), toPopulate.get().getEnumeration().size());
toEnum.stream().map(i -> BigDecimal.valueOf((int)i)).forEach(en -> assertTrue(toPopulate.get().getEnumeration().contains(en)));
assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(enumBase).extracting(value -> ((BigDecimal)value)).containsAll(toEnum1);

toPopulate.set(OASFactory.createObject(Schema.class));
List<LocalDate> expectedDates = Arrays.asList(LocalDate.of(2022, 1, 1), LocalDate.of(2024, 1, 1));
Expand All @@ -104,11 +95,10 @@ void populateSchemaFromUnaryTestsForEnumSucceed() {
.toList();
expression = String.join(",", formattedDates.stream().map(toMap -> String.format("%s", toMap)).toList());
toCheck = feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList();
assertNull(toPopulate.get().getNullable());
assertThat(toPopulate.get().getNullable()).isNull();
DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate.get(), toCheck);
assertNotNull(toPopulate.get().getEnumeration());
assertEquals(expectedDates.size(), toPopulate.get().getEnumeration().size());
expectedDates.forEach(expectedDate -> assertTrue(toPopulate.get().getEnumeration().contains(expectedDate)));
assertThat(toPopulate.get().getEnumeration()).isNotNull();
assertThat(toPopulate.get().getEnumeration()).hasSameSizeAs(expectedDates).containsAll(expectedDates);
}

@Test
Expand All @@ -117,9 +107,9 @@ void populateSchemaFromUnaryTestsFails() {
String expression = String.join(",", toEnum.stream().map(toMap -> String.format("%s", toMap)).toList());
List<DMNUnaryTest> toCheck =
feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList();
assertEquals(toEnum.size(), toCheck.size());
assertThat(toCheck).hasSameSizeAs(toEnum);
Schema toPopulate = getSchemaForSimpleType(null, expression, FEEL_STRING, BuiltInType.STRING);
assertThrows(IllegalArgumentException.class, () -> DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, toCheck));
assertThatIllegalArgumentException().isThrownBy(() -> DMNUnaryTestsMapper.populateSchemaFromUnaryTests(toPopulate, toCheck));
}

@Test
Expand All @@ -130,11 +120,10 @@ void populateSchemaFromBaseNodeSucceed() {
List<DMNUnaryTest> dmnUnaryTests =
feel.evaluateUnaryTests(expression).stream().map(DMNUnaryTest.class::cast).toList();
AtomicReference<Schema> schemaRef = new AtomicReference<>(getSchemaForSimpleType(null, expression, FEEL_STRING, BuiltInType.STRING));
assertNull(schemaRef.get().getEnumeration());
assertThat(schemaRef.get().getEnumeration()).isNull();
BaseNode toCheck = getUnaryEvaluationNodesFromUnaryTests(dmnUnaryTests).get(0);
DMNUnaryTestsMapper.populateSchemaFromBaseNode(schemaRef.get(), toCheck);
assertEquals(enumBase.size(), schemaRef.get().getEnumeration().size());
enumBase.forEach(en -> assertTrue(schemaRef.get().getEnumeration().contains(en)));
assertThat(schemaRef.get().getEnumeration()).hasSameSizeAs(enumBase).containsAll(enumBase);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.kie.dmn.feel.lang.types.BuiltInType;
import org.kie.dmn.feel.runtime.functions.CountFunction;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getSchemaForSimpleType;

Expand All @@ -55,8 +55,8 @@ void populateSchemaFromFEELFunction(InfixOperator operator) {
expectedMaximum = rightValue;
}
}
assertEquals(expectedMinimum, toPopulate.getMinItems());
assertEquals(expectedMaximum, toPopulate.getMaxItems());
assertThat(toPopulate.getMinItems()).isEqualTo(expectedMinimum);
assertThat(toPopulate.getMaxItems()).isEqualTo(expectedMaximum);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import org.kie.dmn.feel.lang.types.BuiltInType;
import org.kie.dmn.feel.runtime.functions.CountFunction;

import static org.junit.jupiter.api.Assertions.assertEquals;

import static org.assertj.core.api.Assertions.assertThat;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.FEEL_NUMBER;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getBaseNode;
import static org.kie.dmn.openapi.impl.SchemaMapperTestUtils.getSchemaForSimpleType;
Expand Down Expand Up @@ -57,8 +58,8 @@ void populateSchemaFromFunctionInvocationNode(InfixOperator operator) {
expectedMaximum = rightValue;
}
}
assertEquals(expectedMinimum, toPopulate.getMinItems());
assertEquals(expectedMaximum, toPopulate.getMaxItems());
assertThat(toPopulate.getMinItems()).isEqualTo(expectedMinimum);
assertThat(toPopulate.getMaxItems()).isEqualTo(expectedMaximum);
});
}
}
Loading
Loading