Search in sources :

Example 6 with OptionMetadata

use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.

the class AtlasDbCliCommandTest method requiredIsSetOnArgument.

@Test
public void requiredIsSetOnArgument() {
    boolean expectedRequired = true;
    OptionMetadata metadata = new OptionMetadata(OptionType.COMMAND, ImmutableSet.of("arg"), "name", "description", 0, expectedRequired, false, ImmutableSet.of(), getOptionFields());
    Argument argument = getArgumentMockFromAddOptionToParser(metadata, "arg");
    verify(argument).required(expectedRequired);
}
Also used : OptionMetadata(io.airlift.airline.model.OptionMetadata) Argument(net.sourceforge.argparse4j.inf.Argument) Test(org.junit.Test)

Example 7 with OptionMetadata

use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.

the class AtlasDbCliCommandTest method zeroArityConstantIsSetOnArgumentWhenThereArentAnyExpectedArguments.

@Test
public void zeroArityConstantIsSetOnArgumentWhenThereArentAnyExpectedArguments() {
    OptionMetadata metadata = new OptionMetadata(OptionType.COMMAND, ImmutableSet.of("arg"), "name", "description", 0, false, false, ImmutableSet.of(), getOptionFields());
    Argument argument = getArgumentMockFromAddOptionToParser(metadata, "arg");
    verify(argument).action(Arguments.storeConst());
    verify(argument).setConst(AtlasDbCommandUtils.ZERO_ARITY_ARG_CONSTANT);
}
Also used : OptionMetadata(io.airlift.airline.model.OptionMetadata) Argument(net.sourceforge.argparse4j.inf.Argument) Test(org.junit.Test)

Example 8 with OptionMetadata

use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.

the class AtlasDbCliCommandTest method helpIsSetOnArgument.

@Test
public void helpIsSetOnArgument() {
    String expectedDescription = "description";
    OptionMetadata metadata = new OptionMetadata(OptionType.COMMAND, ImmutableSet.of("arg"), "name", expectedDescription, 0, false, false, ImmutableSet.of(), getOptionFields());
    Argument argument = getArgumentMockFromAddOptionToParser(metadata, "arg");
    verify(argument).help(expectedDescription);
}
Also used : OptionMetadata(io.airlift.airline.model.OptionMetadata) Argument(net.sourceforge.argparse4j.inf.Argument) Test(org.junit.Test)

Example 9 with OptionMetadata

use of io.airlift.airline.model.OptionMetadata in project atlasdb by palantir.

the class AtlasDbCliCommandTest method getArgumentMockFromAddOptionToParser.

private static Argument getArgumentMockFromAddOptionToParser(OptionMetadata metadata, String... argNames) {
    Subparser parser = mock(Subparser.class);
    Argument argument = mock(Argument.class, (Answer<Object>) (invocation) -> {
        Object mock = invocation.getMock();
        if (invocation.getMethod().getReturnType().isInstance(mock)) {
            return mock;
        } else {
            return Mockito.RETURNS_DEFAULTS.answer(invocation);
        }
    });
    when(parser.addArgument(argNames)).thenReturn(argument);
    AtlasDbCliCommand.addOptionToParser(parser, metadata);
    return argument;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Throwables(com.google.common.base.Throwables) Subparser(net.sourceforge.argparse4j.inf.Subparser) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) OptionMetadata(io.airlift.airline.model.OptionMetadata) Arguments(net.sourceforge.argparse4j.impl.Arguments) Map(java.util.Map) OptionType(io.airlift.airline.OptionType) ArgumentsMetadata(io.airlift.airline.model.ArgumentsMetadata) CommandMetadata(io.airlift.airline.model.CommandMetadata) Argument(net.sourceforge.argparse4j.inf.Argument) Mockito.mock(org.mockito.Mockito.mock) Argument(net.sourceforge.argparse4j.inf.Argument) Subparser(net.sourceforge.argparse4j.inf.Subparser)

Aggregations

OptionMetadata (io.airlift.airline.model.OptionMetadata)9 Argument (net.sourceforge.argparse4j.inf.Argument)8 Test (org.junit.Test)6 Subparser (net.sourceforge.argparse4j.inf.Subparser)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 OptionType (io.airlift.airline.OptionType)3 CommandMetadata (io.airlift.airline.model.CommandMetadata)3 Map (java.util.Map)3 Arguments (net.sourceforge.argparse4j.impl.Arguments)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 Iterables (com.google.common.collect.Iterables)2 Maps (com.google.common.collect.Maps)2 AtlasCli (com.palantir.atlasdb.cli.AtlasCli)2 AtlasDbConfig (com.palantir.atlasdb.config.AtlasDbConfig)2 AtlasDbConfigurationProvider (com.palantir.atlasdb.dropwizard.AtlasDbConfigurationProvider)2 Cli (io.airlift.airline.Cli)2 CommandGroupMetadata (io.airlift.airline.model.CommandGroupMetadata)2 Configuration (io.dropwizard.Configuration)2 Bootstrap (io.dropwizard.setup.Bootstrap)2