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

[incubator-kie-issues#1612] Adding validation for calendar properties. #3769

Closed
wants to merge 1 commit into from

Conversation

Abhitocode
Copy link
Contributor

@Abhitocode Abhitocode commented Nov 13, 2024

Modified BusinessCalendarImpl class to include validation for calendar properties preventing misconfigurations.

  • Modified init as there should be no validation error and consider default value incase of scenario where user does not provide value for end hours per day/hours per day/start hour.

  • Added validations for properties to throw exceptions when calendar.properties file is misconfigured.

  • Added test testValidation() in BusinessCalendarImplTest to verify the modified intialization logic.

Closes: apache/incubator-kie-issues#1612

@Abhitocode Abhitocode changed the title incubator-kie-issues-1612-validation [incubator-kie-issues#1612] Adding validation for calendar properties. Nov 13, 2024
@kie-ci3
Copy link
Contributor

kie-ci3 commented Nov 13, 2024

PR job #1 was: UNSTABLE
Possible explanation: This should be test failures

Reproducer

build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-kogito-runtimes -u #3769 --skipParallelCheckout

NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution

Please look here: https://ci-builds.apache.org/job/KIE/job/kogito/job/main/job/pullrequest_jobs/job/kogito-runtimes-pr/job/PR-3769/1/display/redirect

Test results:

  • PASSED: 3468
  • FAILED: 3

Those are the test failures:

org.jbpm.process.core.timer.BusinessCalendarImplTest.testCalculateMinutesPassingHoliday Invalid configuration: business.hours.per.day must be equal to the difference between business.end.hour and business.start.hour.
org.jbpm.process.core.timer.BusinessCalendarImplTest.testCalculateHoursCustomWorkingHours
expected: "2012-05-04 15:45"
but was: "2012-05-07 09:45"
org.jbpm.bpmn2.calendar.BusinessCalendarTest.(?) Invalid configuration: business.end.hour must be between 0 and 23.

Copy link
Contributor

@pibizza pibizza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes to make the tests clearer.

Field weekendDaysField = BusinessCalendarImpl.class.getDeclaredField("weekendDays");
weekendDaysField.setAccessible(true);

assertEquals(expectedValuesMap.get(DAYS_PER_WEEK), daysPerWeekField.get(businessCalendar));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use assertEquals. Use assertj assertions instead.

List<BusinessCalendarImpl> businessCalendarList = new ArrayList<>();
assertDoesNotThrow(() -> {
businessCalendarList.add(new BusinessCalendarImpl(businessCalendarProperties));
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are testing that you can create the object in the proper way. Remove the adding to the list, this is not part of the test at all.

assertDoesNotThrow(() -> {
businessCalendarList.add(new BusinessCalendarImpl(businessCalendarProperties));
});
assertCalendarProperties(businessCalendarList.get(0), expectedValuesMap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method hides what are your intentions. Given that it is used only here, it is easier to inline the whole method.


private void assertCalendarProperties(BusinessCalendarImpl businessCalendar, Map<String, Object> expectedValuesMap) throws NoSuchFieldException, IllegalAccessException {
Field daysPerWeekField = BusinessCalendarImpl.class.getDeclaredField("daysPerWeek");
daysPerWeekField.setAccessible(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two lines are a good candidate for a small helper method that takes as input a string fieldName and returns a field

At that point you can do a test like assertThat(field("startHour").get(businessCalendar).isEqualTo(startHour).

@Abhitocode Abhitocode closed this Nov 13, 2024
@Abhitocode Abhitocode deleted the incubator-kie-issues#1612 branch November 20, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Providing an inconsistent set of properties on calendar.properties may lead to unexpected behavior
3 participants