Search in sources :

Example 6 with FieldDefinition

use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.

the class FieldDefinitionTest method testCreateFieldDefinitionComparatorGreater.

@Test
public void testCreateFieldDefinitionComparatorGreater() {
    final CronFieldName name1 = CronFieldName.DAY_OF_MONTH;
    final CronFieldName name2 = CronFieldName.SECOND;
    final FieldDefinition fieldDefinition1 = new FieldDefinition(name1, mockConstraints);
    final FieldDefinition fieldDefinition2 = new FieldDefinition(name2, mock(FieldConstraints.class));
    assertNotEquals(name1.getOrder(), name2.getOrder());
    assertTrue(FieldDefinition.createFieldDefinitionComparator().compare(fieldDefinition1, fieldDefinition2) > 0);
}
Also used : CronFieldName(com.cronutils.model.field.CronFieldName) FieldDefinition(com.cronutils.model.field.definition.FieldDefinition) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) Test(org.junit.Test)

Example 7 with FieldDefinition

use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.

the class FieldDefinitionTest method testCreateFieldDefinitionComparatorEqual.

@Test
public void testCreateFieldDefinitionComparatorEqual() {
    final CronFieldName name = CronFieldName.DAY_OF_MONTH;
    final FieldDefinition fieldDefinition1 = new FieldDefinition(name, mockConstraints);
    final FieldDefinition fieldDefinition2 = new FieldDefinition(name, mock(FieldConstraints.class));
    assertEquals(name.getOrder(), name.getOrder());
    assertEquals(0, FieldDefinition.createFieldDefinitionComparator().compare(fieldDefinition1, fieldDefinition2));
}
Also used : CronFieldName(com.cronutils.model.field.CronFieldName) FieldDefinition(com.cronutils.model.field.definition.FieldDefinition) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) Test(org.junit.Test)

Example 8 with FieldDefinition

use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.

the class FieldDefinitionBuilderTest method testAnd.

@Test
public void testAnd() {
    final FieldConstraints constraints = mock(FieldConstraints.class);
    when(mockConstraintsBuilder.createConstraintsInstance()).thenReturn(constraints);
    final ArgumentCaptor<FieldDefinition> argument = ArgumentCaptor.forClass(FieldDefinition.class);
    fieldDefinitionBuilder.and();
    verify(mockParserBuilder).register(argument.capture());
    assertEquals(testFieldName, argument.getValue().getFieldName());
    verify(mockConstraintsBuilder).createConstraintsInstance();
}
Also used : FieldDefinition(com.cronutils.model.field.definition.FieldDefinition) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with FieldDefinition

use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.

the class CronBuilder method addField.

@VisibleForTesting
CronBuilder addField(final CronFieldName name, final FieldExpression expression) {
    checkState(definition != null, "CronBuilder not initialized.");
    final FieldDefinition fieldDefinition = definition.getFieldDefinition(name);
    checkState(fieldDefinition != null, "Cron field definition does not exist: %s", name);
    final FieldConstraints constraints = fieldDefinition.getConstraints();
    expression.accept(new ValidationFieldExpressionVisitor(constraints));
    fields.put(name, new CronField(name, expression, constraints));
    return this;
}
Also used : FieldDefinition(com.cronutils.model.field.definition.FieldDefinition) ValidationFieldExpressionVisitor(com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) CronField(com.cronutils.model.field.CronField) VisibleForTesting(com.cronutils.utils.VisibleForTesting)

Example 10 with FieldDefinition

use of com.cronutils.model.field.definition.FieldDefinition in project cron-utils by jmrozanec.

the class CronDefinitionBuilderTest method testRegister.

@Test
public void testRegister() {
    final FieldDefinition testFieldDefinition = new FieldDefinition(CronFieldName.SECOND, new FieldConstraints(Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), 0, 1, true));
    builder.register(testFieldDefinition);
    final Set<FieldDefinition> definitions = builder.instance().getFieldDefinitions();
    assertNotNull(definitions);
    assertEquals(1, definitions.size());
    assertEquals(testFieldDefinition, definitions.iterator().next());
}
Also used : FieldDefinition(com.cronutils.model.field.definition.FieldDefinition) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) Test(org.junit.Test)

Aggregations

FieldDefinition (com.cronutils.model.field.definition.FieldDefinition)12 Test (org.junit.Test)7 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)6 CronFieldName (com.cronutils.model.field.CronFieldName)4 DayOfWeekFieldDefinition (com.cronutils.model.field.definition.DayOfWeekFieldDefinition)2 Function (com.cronutils.Function)1 CronField (com.cronutils.model.field.CronField)1 Every (com.cronutils.model.field.expression.Every)1 FieldExpression (com.cronutils.model.field.expression.FieldExpression)1 On (com.cronutils.model.field.expression.On)1 ValidationFieldExpressionVisitor (com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor)1 VisibleForTesting (com.cronutils.utils.VisibleForTesting)1 MessageFormat (java.text.MessageFormat)1 DayOfWeek (java.time.DayOfWeek)1 Month (java.time.Month)1 TextStyle (java.time.format.TextStyle)1 HashSet (java.util.HashSet)1 ResourceBundle (java.util.ResourceBundle)1 Before (org.junit.Before)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1