@Test public void checkRulePassengerIntersection() { List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>(); workDayRulesOfGagarina.add( PassengerGenerationRule.of( 8, LocalTime.of(6, 0), LocalTime.of(9, 50), LocalTime.of(0, 15))); workDayRulesOfGagarina.add( PassengerGenerationRule.of( 8, LocalTime.of(5, 0), LocalTime.of(8, 50), LocalTime.of(0, 20))); workDayRulesOfGagarina.add( PassengerGenerationRule.of( 8, LocalTime.of(22, 0), LocalTime.of(4, 50), LocalTime.of(0, 20))); PassengerGenerationRuleList item = PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina); Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations = validator.validate(item, ImitationSourceSequence.class); constraintViolations.forEach(System.out::println); assertEquals(1, constraintViolations.size()); assertEquals( "{rule passenger generation is intersection}", constraintViolations.iterator().next().getMessage()); }
@Test public void checkRulePassengerTime() { List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>(); workDayRulesOfGagarina.add( PassengerGenerationRule.of(8, LocalTime.of(6, 0), LocalTime.of(6, 0), LocalTime.of(0, 15))); // workDayRulesOfGagarina.add(PassengerGenerationRule.of( // 4, LocalTime.of(9, 0), LocalTime.of(13, 0), LocalTime.of(0, 17)) // ); // workDayRulesOfGagarina.add(PassengerGenerationRule.of( // 2, LocalTime.of(13, 0), LocalTime.of(16, 0), LocalTime.of(0, 17)) // ); // workDayRulesOfGagarina.add(PassengerGenerationRule.of( // 8, LocalTime.of(16, 0), LocalTime.of(19, 0), LocalTime.of(0, 15)) // ); // workDayRulesOfGagarina.add(PassengerGenerationRule.of( // 4, LocalTime.of(19, 0), LocalTime.of(23, 0), LocalTime.of(0, 15)) // ); PassengerGenerationRuleList item = PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina); Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations = validator.validate(item, ImitationSourceSequence.class); constraintViolations.forEach(System.out::println); assertEquals(1, constraintViolations.size()); assertEquals( "{incorrect rule passenger generation time}", constraintViolations.iterator().next().getMessage()); }
@Test public void checkPassengerGenerationRuleIsNull() { PassengerGenerationRule item = PassengerGenerationRule.of(2, null, null, null); Set<ConstraintViolation<PassengerGenerationRule>> constraintViolations = validator.validate(item, ImitationSourceSequence.class); constraintViolations.forEach(System.out::println); assertEquals(3, constraintViolations.size()); constraintViolations.forEach( constraint -> assertEquals("may not be null", constraint.getMessage())); }
@Test public void checkPassengerGenerationRuleMax() { PassengerGenerationRule item = PassengerGenerationRule.of(1001, LocalTime.now(), LocalTime.now(), LocalTime.now()); Set<ConstraintViolation<PassengerGenerationRule>> constraintViolations = validator.validate(item, ImitationSourceSequence.class); constraintViolations.forEach(System.out::println); assertEquals(1, constraintViolations.size()); constraintViolations.forEach( constraint -> assertEquals("must be less than or equal toXML 1000", constraint.getMessage())); }
@Test public void checkRulePassengerMaxSize() { List<PassengerGenerationRule> workDayRulesOfGagarina = new ArrayList<>(); for (int i = 0; i < 51; i++) { workDayRulesOfGagarina.add( PassengerGenerationRule.of( 8, LocalTime.of(6, 0), LocalTime.of(9, 50), LocalTime.of(0, 15))); } PassengerGenerationRuleList item = PassengerGenerationRuleList.of(HOLIDAY, workDayRulesOfGagarina); Set<ConstraintViolation<PassengerGenerationRuleList>> constraintViolations = validator.validate(item, ImitationSourceSequence.class); constraintViolations.forEach(System.out::println); assertEquals(1, constraintViolations.size()); assertEquals( "size must be between 2 and 50", constraintViolations.iterator().next().getMessage()); }