/*-
 * -\-\-
 * Spydra
 * --
 * Copyright (C) 2016 - 2018 Spotify AB
 * --
 * 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 com.spotify.spydra.historytools;

import static org.junit.Assert.assertEquals;

import com.spotify.spydra.CliTestHelpers;
import com.spotify.spydra.historytools.commands.RunJhsCommand;
import com.spotify.spydra.submitter.runner.CliConsts;
import com.spotify.spydra.submitter.runner.CliParser;
import java.util.Arrays;
import org.junit.Test;

public class RunJhsCliParserTest {

  private static final RunJhsCliParser PARSER = new RunJhsCliParser();
  private static final String DUMMY_CLIENT_ID = "pretty-client-2342";
  private static final String DUMMY_BUCKET = "bucket";

  @Test
  public void testParseWithUser() {
    RunJhsCommand jhsCmd = PARSER.parse(new String[]{
        CliTestHelpers.toStrOpt(CliConsts.CLIENT_ID_OPTION_NAME, DUMMY_CLIENT_ID),
        CliTestHelpers.toStrOpt(CliConsts.LOG_BUCKET_OPTION_NAME, DUMMY_BUCKET)
    });

    assertEquals(jhsCmd.clientId(), DUMMY_CLIENT_ID);
  }

  @Test
  public void testParseWithoutUser() {
    RunJhsCommand jhsCmd = PARSER.parse(new String[]{
        CliTestHelpers.toStrOpt(CliConsts.CLIENT_ID_OPTION_NAME, DUMMY_CLIENT_ID),
        CliTestHelpers.toStrOpt(CliConsts.LOG_BUCKET_OPTION_NAME, DUMMY_BUCKET)
    });

    assertEquals(jhsCmd.clientId(), DUMMY_CLIENT_ID);
  }

  @Test
  public void testMissingArgs() {
    CliTestHelpers.ensureAllThrow(
        PARSER,
        Arrays.asList(new String[]{}, new String[]{"--noSuchThing=FOO"}),
        CliParser.ParsingException.class);
  }
}
