/*
 * 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.support;

import java.io.File;
import java.util.Arrays;

import org.apache.camel.ContextTestSupport;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class RouteWatcherReloadStrategyTest extends ContextTestSupport {

    @Test
    public void testBasePath() throws Exception {
        RouteWatcherReloadStrategy strategy = new RouteWatcherReloadStrategy("./src/test/resources");
        strategy.setPattern("*");
        strategy.setCamelContext(context);
        strategy.doStart();

        assertNotNull(strategy.getFileFilter());
        File folder = new File("./src/test/resources");
        assertTrue(folder.isDirectory());

        File[] fs = folder.listFiles(strategy.getFileFilter());
        assertNotNull(fs);
        assertTrue(fs.length >= 9);
        assertTrue(Arrays.stream(fs).anyMatch(f -> f.getName().equals("log4j2.properties")));
    }

    @Test
    public void testNullPattern() throws Exception {
        RouteWatcherReloadStrategy strategy = new RouteWatcherReloadStrategy("./src/test/resources");
        strategy.setPattern(null);
        strategy.setCamelContext(context);
        strategy.doStart();

        assertNotNull(strategy.getFileFilter());
        File folder = new File("./src/test/resources");
        assertTrue(folder.isDirectory());

        File[] fs = folder.listFiles(strategy.getFileFilter());
        assertNotNull(fs);
        assertEquals(0, fs.length);
        // null goes back to default
        assertEquals("*.yaml,*.xml", strategy.getPattern());
    }

}

@@ -1253,16 +1253,1329 @@
 BasePath
+Exact() throws Exception %7B%0A        RouteWatcherReloadStrategy strategy = new RouteWatcherReloadStrategy(%22./src/test/resources%22);%0A        strategy.setPattern(%22log4j2.properties%22);%0A        strategy.setCamelContext(context);%0A        strategy.doStart();%0A%0A        assertNotNull(strategy.getFileFilter());%0A        File folder = new File(%22./src/test/resources%22);%0A        assertTrue(folder.isDirectory());%0A%0A        File%5B%5D fs = folder.listFiles(strategy.getFileFilter());%0A        assertNotNull(fs);%0A        assertEquals(1,fs.length);%0A        assertEquals(%22log4j2.properties%22,fs%5B0%5D.getName());%0A    %7D%0A%0A    @Test%0A    public void testBasePathWildcardExtension() throws Exception %7B%0A        RouteWatcherReloadStrategy strategy = new RouteWatcherReloadStrategy(%22./src/test/resources%22);%0A        strategy.setPattern(%22*.properties%22);%0A        strategy.setCamelContext(context);%0A        strategy.doStart();%0A%0A        assertNotNull(strategy.getFileFilter());%0A        File folder = new File(%22./src/test/resources%22);%0A        assertTrue(folder.isDirectory());%0A%0A        File%5B%5D fs = folder.listFiles(strategy.getFileFilter());%0A        assertNotNull(fs);%0A        assertTrue(fs.length %3E= 5);%0A        assertTrue(Arrays.stream(fs).anyMatch(f -%3E f.getName().equals(%22log4j2.properties%22)));%0A    %7D%0A%0A    @Test%0A    public void testBasePathFullWildcard
 () throw
@@ -2580,32 +2580,32 @@
 ows Exception %7B%0A
-
         RouteWat
@@ -3325,32 +3325,55 @@
 c/test/resources
+/org/apache/camel/model
 %22);%0A        stra
@@ -3560,32 +3560,55 @@
 c/test/resources
+/org/apache/camel/model
 %22);%0A        asse
@@ -3747,18 +3747,44 @@
 sert
-Equals(0, 
+True(fs.length %3E= 40,String.valueOf(
 fs.l
@@ -3781,32 +3781,33 @@
 lueOf(fs.length)
+)
 ;%0A        // nul

enhance test (#6963)