Commit 1345bcb9 authored by Mathijs den Burger's avatar Mathijs den Burger

Reintegrate bugfix/CMS-9922

parents 30a1114b 42f6fc14
/*
* Copyright 2014-2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2014-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,6 +16,7 @@
package org.onehippo.cms7.services.webfiles.watch;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......@@ -29,11 +30,11 @@ public class WebFilesWatcherJavaConfig implements WebFilesWatcherConfig {
private long maxFileLengthBytes;
public WebFilesWatcherJavaConfig() {
watchedModules = new ArrayList<>();
includedFiles = new ArrayList<>();
excludedDirs = new ArrayList<>();
useWatchServiceOnOsNames = new ArrayList<>();
watchDelayMillis = 0;
watchedModules = new ArrayList<>(Arrays.asList(DEFAULT_WATCHED_MODULES));
includedFiles = new ArrayList<>(Arrays.asList(DEFAULT_INCLUDED_FILES));
excludedDirs = new ArrayList<>(Arrays.asList(DEFAULT_EXCLUDED_DIRECTORIES));
useWatchServiceOnOsNames = new ArrayList<>(Arrays.asList(DEFAULT_USE_WATCH_SERVICE_ON_OS_NAMES));
watchDelayMillis = DEFAULT_WATCH_DELAY_MILLIS;
maxFileLengthBytes = 1024 * DEFAULT_MAX_FILE_LENGTH_KB;
}
......
/*
* Copyright 2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed 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.onehippo.cms7.services.webfiles.watch;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
/**
* Test defaults to 'official' default values and that the lists returned by different instances are properly
* independent.
*/
public class WebFilesWatcherJavaConfigTest {
public static final List<String> WATCHED = Arrays.asList(WebFilesWatcherConfig.DEFAULT_WATCHED_MODULES);
public static final List<String> INCLUDED = Arrays.asList(WebFilesWatcherConfig.DEFAULT_INCLUDED_FILES);
public static final List<String> EXCLUDED = Arrays.asList(WebFilesWatcherConfig.DEFAULT_EXCLUDED_DIRECTORIES);
public static final List<String> WATCH_SERVICE = Arrays.asList(WebFilesWatcherConfig.DEFAULT_USE_WATCH_SERVICE_ON_OS_NAMES);
public static final Long WATCH_DELAY = WebFilesWatcherConfig.DEFAULT_WATCH_DELAY_MILLIS;
private WebFilesWatcherJavaConfig config1, config2;
@Before
public void init() {
config1 = new WebFilesWatcherJavaConfig();
config2 = new WebFilesWatcherJavaConfig();
}
@Test
public void testGetWatchedModulesDefault() throws Exception {
assertThat(config1.getWatchedModules(), is(WATCHED));
}
@Test
public void testAddWatchedModule() throws Exception {
config1.addWatchedModule("hippo");
assertThat(config1.getWatchedModules(), contains("hippo"));
assertThat(config2.getWatchedModules(), is(WATCHED));
}
@Test
public void testGetIncludedFilesDefault() throws Exception {
assertThat(config1.getIncludedFiles(), is(INCLUDED));
}
@Test
public void testIncludeFiles() throws Exception {
config1.includeFiles("hippo");
assertThat(config1.getIncludedFiles(), contains("hippo"));
assertThat(config2.getIncludedFiles(), is(INCLUDED));
}
@Test
public void testGetExcludedDirectoriesDefault() throws Exception {
assertThat(config1.getExcludedDirectories(), is(EXCLUDED));
}
@Test
public void testExcludeDirs() throws Exception {
config1.excludeDirs("hippo");
assertThat(config1.getExcludedDirectories(), contains("hippo"));
assertThat(config2.getExcludedDirectories(), is(EXCLUDED));
}
@Test
public void testGetUseWatchServiceOnOsNamesDefault() throws Exception {
assertThat(config1.getUseWatchServiceOnOsNames(), is(WATCH_SERVICE));
}
@Test
public void testUseWatchServiceOnOsNames() throws Exception {
config1.useWatchServiceOnOsNames("hippo");
assertThat(config1.getUseWatchServiceOnOsNames(), contains("hippo"));
assertThat(config2.getUseWatchServiceOnOsNames(), is(WATCH_SERVICE));
}
@Test
public void testGetWatchDelayMillisDefault() throws Exception {
assertThat(config1.getWatchDelayMillis(), is(WATCH_DELAY));
}
@Test
public void testSetWatchDelayMillis() throws Exception {
config1.setWatchDelayMillis(WATCH_DELAY + 42);
assertThat(config1.getWatchDelayMillis(), is(WATCH_DELAY + 42));
assertThat(config2.getWatchDelayMillis(), is(WATCH_DELAY));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment