
package com.google.api.codegen;

import com.google.api.codegen.config.ApiConfig;
import com.google.api.codegen.config.InterfaceConfig;
import com.google.api.codegen.php.PhpGapicCodePathMapper;
import com.google.api.gax.grpc.ApiCallable;
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.Truth;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Tests for {@link ApiCallable}. */
@RunWith(JUnit4.class)
public class PhpGapicCodePathMapperTest {

  @Rule public ExpectedException thrown = ExpectedException.none();

  @Test
  public void getOutputPathTest() {
    PhpGapicCodePathMapper pathMapper =
        PhpGapicCodePathMapper.newBuilder().setPrefix("prefix").setSuffix("suffix").build();

    ApiConfig configWithGoogleCloud =
        ApiConfig.createDummyApiConfig(
            ImmutableMap.<String, InterfaceConfig>of(),
            "Google\\Cloud\\Sample\\Package\\V1",
            "",
            null);
    Truth.assertThat(pathMapper.getOutputPath(null, configWithGoogleCloud))
        .isEqualTo("prefix/Sample/Package/V1/suffix");

    ApiConfig configWithGoogleNonCloud =
        ApiConfig.createDummyApiConfig(
            ImmutableMap.<String, InterfaceConfig>of(),
            "Google\\NonCloud\\Sample\\Package\\V1",
            "",
            null);
    Truth.assertThat(pathMapper.getOutputPath(null, configWithGoogleNonCloud))
        .isEqualTo("prefix/NonCloud/Sample/Package/V1/suffix");

    ApiConfig configWithAlphabet =
        ApiConfig.createDummyApiConfig(
            ImmutableMap.<String, InterfaceConfig>of(),
            "Alphabet\\Google\\Cloud\\Sample\\Package\\V1",
            "",
            null);
    Truth.assertThat(pathMapper.getOutputPath(null, configWithAlphabet))
        .isEqualTo("prefix/Alphabet/Google/Cloud/Sample/Package/V1/suffix");
  }
}
