Search in sources :

Example 1 with EnumCSVParameter

use of io.mantisrx.runtime.parameter.type.EnumCSVParameter in project mantis by Netflix.

the class ParameterDefinitionTest method testEnumCSVParameter.

@Test
public void testEnumCSVParameter() {
    Map<String, ParameterDefinition<?>> parameterDefinitions = new HashMap<>();
    parameterDefinitions.put("foo", new EnumCSVParameter<>(TestEnum.class).name("foo").required().validator(Validators.alwaysPass()).build());
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put("foo", new Parameter("foo", "   A   ,  C   "));
    Map<String, Object> parameterState = ParameterUtils.checkThenCreateState(parameterDefinitions, parameters);
    EnumSet<TestEnum> foo = (EnumSet<TestEnum>) parameterState.get("foo");
    Assert.assertTrue(foo.contains(TestEnum.A));
    Assert.assertTrue(foo.contains(TestEnum.C));
    Assert.assertFalse(foo.contains(TestEnum.B));
}
Also used : HashMap(java.util.HashMap) EnumSet(java.util.EnumSet) EnumCSVParameter(io.mantisrx.runtime.parameter.type.EnumCSVParameter) Parameter(io.mantisrx.runtime.parameter.Parameter) EnumParameter(io.mantisrx.runtime.parameter.type.EnumParameter) StringParameter(io.mantisrx.runtime.parameter.type.StringParameter) ParameterDefinition(io.mantisrx.runtime.parameter.ParameterDefinition) Test(org.junit.Test)

Example 2 with EnumCSVParameter

use of io.mantisrx.runtime.parameter.type.EnumCSVParameter in project mantis by Netflix.

the class ParameterDefinitionTest method emptyEnumCSVListValidation.

@Test(expected = IllegalArgumentException.class)
public void emptyEnumCSVListValidation() {
    Map<String, ParameterDefinition<?>> parameterDefinitions = new HashMap<>();
    parameterDefinitions.put("foo", new EnumCSVParameter<>(TestEnum.class).name("foo").required().validator(Validators.notNullOrEmptyEnumCSV()).build());
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put("foo", new Parameter("foo", "  "));
    ParameterUtils.checkThenCreateState(parameterDefinitions, parameters);
}
Also used : HashMap(java.util.HashMap) EnumCSVParameter(io.mantisrx.runtime.parameter.type.EnumCSVParameter) Parameter(io.mantisrx.runtime.parameter.Parameter) EnumParameter(io.mantisrx.runtime.parameter.type.EnumParameter) StringParameter(io.mantisrx.runtime.parameter.type.StringParameter) ParameterDefinition(io.mantisrx.runtime.parameter.ParameterDefinition) Test(org.junit.Test)

Aggregations

Parameter (io.mantisrx.runtime.parameter.Parameter)2 ParameterDefinition (io.mantisrx.runtime.parameter.ParameterDefinition)2 EnumCSVParameter (io.mantisrx.runtime.parameter.type.EnumCSVParameter)2 EnumParameter (io.mantisrx.runtime.parameter.type.EnumParameter)2 StringParameter (io.mantisrx.runtime.parameter.type.StringParameter)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 EnumSet (java.util.EnumSet)1