/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.component.quartz.cron;

import org.apache.camel.DelegateEndpoint;
import org.apache.camel.Endpoint;
import org.apache.camel.Route;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.quartz.BaseQuartzTest;
import org.apache.camel.component.quartz.QuartzEndpoint;
import org.junit.jupiter.api.Test;

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

public class QuartzCronMappingTest extends BaseQuartzTest {

    @Test
    public void test5PartsCronPattern() throws Exception {
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("cron://myName?schedule=* * * * ?")
                        .id("cron")
                        .to("mock:result");
            }
        });
        context.start();
        assertEquals("0 * * * * ?", getQuartzEndpoint(context.getRoute("cron")).getCron());
    }

    @Test
    public void test6PartsCronPattern() throws Exception {
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("cron://myName?schedule=0/2 * * * * ?")
                        .id("cron")
                        .to("mock:result");
            }
        });
        context.start();
        assertEquals("0/2 * * * * ?", getQuartzEndpoint(context.getRoute("cron")).getCron());
    }

    @Test
    public void testAdditionalProperties() throws Exception {
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("cron://myName?schedule=0/2+*+*+*+*+?&deleteJob=false")
                        .id("cron")
                        .to("mock:result");
            }
        });
        context.start();
        assertEquals("0/2 * * * * ?", getQuartzEndpoint(context.getRoute("cron")).getCron());
        assertFalse(getQuartzEndpoint(context.getRoute("cron")).isDeleteJob());
    }

    private QuartzEndpoint getQuartzEndpoint(Route route) {
        Endpoint endpoint = route.getEndpoint();
        while (endpoint instanceof DelegateEndpoint) {
            endpoint = ((DelegateEndpoint) endpoint).getEndpoint();
        }
        return (QuartzEndpoint) endpoint;
    }

    @Override
    public boolean isUseRouteBuilder() {
        return false;
    }

}

@@ -1212,68 +1212,8 @@
 als;
-%0Aimport static org.junit.jupiter.api.Assertions.assertFalse;
 %0A%0Apu
@@ -2241,593 +2241,8 @@
  %7D%0A%0A
-    @Test%0A    public void testAdditionalProperties() throws Exception %7B%0A        context.addRoutes(new RouteBuilder() %7B%0A            @Override%0A            public void configure() throws Exception %7B%0A                from(%22cron://myName?schedule=0/2+*+*+*+*+?&deleteJob=false%22)%0A                        .id(%22cron%22)%0A                        .to(%22mock:result%22);%0A            %7D%0A        %7D);%0A        context.start();%0A        assertEquals(%220/2 * * * * ?%22, getQuartzEndpoint(context.getRoute(%22cron%22)).getCron());%0A        assertFalse(getQuartzEndpoint(context.getRoute(%22cron%22)).isDeleteJob());%0A    %7D%0A%0A
     

Remove synchronous on default endpoint as its rarely in use.