Skip to content
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 @@ -65,7 +65,7 @@ public static <Entity_, Value_> RootVariableSource<Entity_, Value_> from(
List<List<MemberAccessor>> chainStartingFromSourceVariableList = new ArrayList<>();
boolean isAfterVariable = false;
Class<?> currentEntity = rootEntityClass;
var factCount = 0;
var factCountSinceLastVariable = 0;

for (var iterator = pathIterator(rootEntityClass, variablePath); iterator.hasNext();) {
var pathPart = iterator.next();
Expand All @@ -87,7 +87,7 @@ public static <Entity_, Value_> RootVariableSource<Entity_, Value_> from(
descriptorPolicy);
listMemberAccessors.add(memberAccessor);
chainToVariable = new ArrayList<>();
factCount = 0;
factCountSinceLastVariable = 0;

currentEntity = ConfigUtils.extractGenericTypeParameterOrFail(ShadowSources.class.getSimpleName(),
currentEntity,
Expand Down Expand Up @@ -115,10 +115,10 @@ public static <Entity_, Value_> RootVariableSource<Entity_, Value_> from(
chainStartingFromSourceVariableList.add(chainStartingFromSourceVariable);

isAfterVariable = true;
factCount = 0;
factCountSinceLastVariable = 0;
} else {
factCount++;
if (factCount == 2) {
factCountSinceLastVariable++;
if (factCountSinceLastVariable == 2) {
throw new IllegalArgumentException(
"The source path (%s) starting from root entity (%s) referencing multiple facts (%s, %s) in a row."
.formatted(variablePath, rootEntityClass.getSimpleName(),
Expand Down Expand Up @@ -156,6 +156,12 @@ public static <Entity_, Value_> RootVariableSource<Entity_, Value_> from(
.formatted(variablePath, rootEntityClass.getSimpleName()));
}

if (factCountSinceLastVariable != 0) {
throw new IllegalArgumentException(
"The source path (%s) starting from root entity class (%s) does not end on a variable."
.formatted(variablePath, rootEntityClass.getSimpleName()));
}

for (var variableSourceReference : variableSourceReferences) {
assertIsValidVariableReference(rootEntityClass, variablePath, variableSourceReference);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ void invalidPathNoVariables() {
" does not reference any variables.");
}

@Test
void invalidPathEndOnFact() {
assertThatCode(() -> RootVariableSource.from(
planningSolutionMetaModel,
TestdataInvalidDeclarativeValue.class,
"shadow",
"previous.fact",
DEFAULT_MEMBER_ACCESSOR_FACTORY,
DEFAULT_DESCRIPTOR_POLICY))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("The source path (previous.fact)" +
" starting from root entity class (TestdataInvalidDeclarativeValue)" +
" does not end on a variable.");
}

@Test
void invalidPathMultipleFactsInARow() {
assertThatCode(() -> RootVariableSource.from(
Expand Down
Loading