f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna/*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* The contents of this file are subject to the terms of the Common Development and
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* Distribution License (the License). You may not use this file except in compliance with the
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* License.
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* specific language governing permission and limitations under the License.
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* When distributing Covered Software, include this CDDL Header Notice in each file and include
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* Header, with the fields enclosed by brackets [] replaced by your own identifying
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* information: "Portions copyright [year] [name of copyright owner]".
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna* Copyright 2016 ForgeRock AS.
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna*/
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunapackage com.sun.identity.common.configuration;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport static org.assertj.core.api.Assertions.*;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport java.util.Collections;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport java.util.HashSet;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport java.util.Set;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport org.testng.annotations.DataProvider;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunaimport org.testng.annotations.Test;
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Lunapublic class FilterModeValueValidatorTest {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna private final FilterModeValueValidator validator = new FilterModeValueValidator();
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @DataProvider(name = "data")
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public Object[][] data() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna return new Object[][] {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf]=ALL", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf]=SSO_ONLY", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf]=URL_POLICY", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf]=J2EE_POLICY", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf]=NONE", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"asdf=NONE", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"asdf=", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf]=", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf[]=NONE", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf]]=NONE", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[asdf[asdf]]=NONE", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"=ALL", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"=NONE", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"=SSO_ONLY", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"=URL_POLICY", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"=J2EE_POLICY", true},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[]=ALL", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[]=", false},
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna {"[key_and_or_value_contains_=_sign] ==", false}
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna };
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test(dataProvider = "data")
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkCorrectness(String name, boolean expected) {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(Collections.singleton(name));
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(expected);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkSetOnlyContainsOneConfigPerApp() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna Set<String> set = new HashSet<>();
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("[asdf]=ALL");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("[asdf]=NONE");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(set);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(false);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkSetOnlyContainsOneGlobalConfig() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna Set<String> set = new HashSet<>();
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("=ALL");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna set.add("=NONE");
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(set);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(false);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna @Test
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna public void checkEmptySetFails() {
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //given
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna Set<String> set = new HashSet<>();
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //when
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna boolean result = validator.validate(set);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna //then
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna assertThat(result).isEqualTo(false);
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna }
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna
f2b7e2373c5d1aacf05b91ab8e316d6aea0b948bDavid Luna}