From a8982ce4c25e35ec754009f067f9c9e5ef6217ea Mon Sep 17 00:00:00 2001 From: felmer <franz-josef.elmer@id.ethz.ch> Date: Thu, 7 Feb 2019 13:33:12 +0100 Subject: [PATCH] SSDM-7857: add tests for DataSourceUtils --- .../sync/datasource/DataSourceUtilsTest.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/server/dss/plugins/sync/datasource/DataSourceUtilsTest.java diff --git a/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/server/dss/plugins/sync/datasource/DataSourceUtilsTest.java b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/server/dss/plugins/sync/datasource/DataSourceUtilsTest.java new file mode 100644 index 00000000000..041b15bb806 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/ethz/sis/openbis/generic/server/dss/plugins/sync/datasource/DataSourceUtilsTest.java @@ -0,0 +1,103 @@ +/* + * Copyright 2019 ETH Zuerich, SIS + * + * 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 ch.ethz.sis.openbis.generic.server.dss.plugins.sync.datasource; + +import static org.testng.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.testng.annotations.Test; + +/** + * @author Franz-Josef Elmer + */ +public class DataSourceUtilsTest +{ + + @Test + public void testGetRquestedAndAllowedSubSetWithUnspecifiedWhiteAndBlackList() + { + // Given + List<String> fullSet = Arrays.asList("abc", "age", "Affe"); + List<String> whiteLists = null; + List<String> blackLists = null; + + // When + Set<String> subSet = DataSourceUtils.getRequestedAndAllowedSubSet(fullSet, whiteLists, blackLists); + + // Then + List<String> sortedSubSet = new ArrayList<String>(subSet); + Collections.sort(sortedSubSet); + assertEquals(sortedSubSet.toString(), "[Affe, abc, age]"); + } + + @Test + public void testGetRquestedAndAllowedSubSetWithBlackListAndUnspecifiedWhiteList() + { + // Given + List<String> fullSet = Arrays.asList("abc", "age", "abcdef"); + List<String> whiteLists = null; + List<String> blackLists = Arrays.asList("a, age", ".*f"); + + // When + Set<String> subSet = DataSourceUtils.getRequestedAndAllowedSubSet(fullSet, whiteLists, blackLists); + + // Then + List<String> sortedSubSet = new ArrayList<String>(subSet); + Collections.sort(sortedSubSet); + assertEquals(sortedSubSet.toString(), "[abc]"); + } + + @Test + public void testGetRquestedAndAllowedSubSetWithWhiteListAndUnspecifiedBlackList() + { + // Given + List<String> fullSet = Arrays.asList("abc", "age", "abcdef"); + List<String> whiteLists = Arrays.asList("age", ".*f, a"); + List<String> blackLists = null; + + // When + Set<String> subSet = DataSourceUtils.getRequestedAndAllowedSubSet(fullSet, whiteLists, blackLists); + + // Then + List<String> sortedSubSet = new ArrayList<String>(subSet); + Collections.sort(sortedSubSet); + assertEquals(sortedSubSet.toString(), "[abcdef, age]"); + } + + @Test + public void testGetRquestedAndAllowedSubSetWithWhiteListAndBlackList() + { + // Given + List<String> fullSet = Arrays.asList("abc", "a", "age", "abcdef", "defg"); + List<String> whiteLists = Arrays.asList("hijk", "a.*"); + List<String> blackLists = Arrays.asList("age, .*f, a"); + + // When + Set<String> subSet = DataSourceUtils.getRequestedAndAllowedSubSet(fullSet, whiteLists, blackLists); + + // Then + List<String> sortedSubSet = new ArrayList<String>(subSet); + Collections.sort(sortedSubSet); + assertEquals(sortedSubSet.toString(), "[abc]"); + } + +} -- GitLab