// Path: endpoints-control/src/main/java/com/google/api/control/model/MethodRegistry.java
// public static class Info {
//   private static final String API_KEY_NAME = "api_key";
// 
//   private final Optional<AuthInfo> authInfo;
//   private final QuotaInfo quotaInfo;
// 
//   private boolean allowUnregisteredCalls;
//   private String selector;
//   private String backendAddress;
//   private String bodyFieldPath;
//   private Map<String, List<String>> urlQueryParams;
//   private Map<String, List<String>> headerParams;
//   private PathTemplate template;
// 
//   public Info(String selector, @CheckForNull AuthInfo authInfo,
//       @CheckForNull QuotaInfo quotaInfo) {
//     this.selector = selector;
//     this.authInfo = Optional.<AuthInfo>fromNullable(authInfo);
//     this.quotaInfo = quotaInfo != null ? quotaInfo : QuotaInfo.DEFAULT;
// 
//     this.urlQueryParams = Maps.newHashMap();
//     this.headerParams = Maps.newHashMap();
//   }
// 
//   public PathTemplate getTemplate() {
//     return template;
//   }
// 
//   public void setTemplate(PathTemplate template) {
//     this.template = template;
//   }
// 
//   public void addUrlQueryParam(String name, String param) {
//     List<String> l = urlQueryParams.get(name);
//     if (l == null) {
//       l = Lists.newArrayList();
//       urlQueryParams.put(name, l);
//     }
//     l.add(param);
//   }
// 
//   public List<String> urlQueryParam(String name) {
//     List<String> l = urlQueryParams.get(name);
//     if (l == null) {
//       return Collections.emptyList();
//     }
//     return ImmutableList.copyOf(l);
//   }
// 
//   public List<String> apiKeyUrlQueryParam() {
//     return urlQueryParam(API_KEY_NAME);
//   }
// 
//   public void addHeaderParam(String name, String param) {
//     List<String> l = headerParams.get(name);
//     if (l == null) {
//       l = Lists.newArrayList();
//       headerParams.put(name, l);
//     }
//     l.add(param);
//   }
// 
//   public List<String> headerParam(String name) {
//     List<String> l = headerParams.get(name);
//     if (l == null) {
//       return Collections.emptyList();
//     }
//     return ImmutableList.copyOf(l);
//   }
// 
//   public List<String> apiKeyHeaderParam() {
//     return headerParam(API_KEY_NAME);
//   }
// 
//   public Optional<AuthInfo> getAuthInfo() {
//     return this.authInfo;
//   }
// 
//   public QuotaInfo getQuotaInfo() {
//     return quotaInfo;
//   }
// 
//   public boolean shouldAllowUnregisteredCalls() {
//     return allowUnregisteredCalls;
//   }
// 
//   public void setAllowUnregisteredCalls(boolean allowRegisteredCalls) {
//     this.allowUnregisteredCalls = allowRegisteredCalls;
//   }
// 
//   public String getSelector() {
//     return selector;
//   }
// 
//   public void setSelector(String selector) {
//     this.selector = selector;
//   }
// 
//   public String getBackendAddress() {
//     return backendAddress;
//   }
// 
//   public void setBackendAddress(String backendAddress) {
//     this.backendAddress = backendAddress;
//   }
// 
//   public String getBodyFieldPath() {
//     return bodyFieldPath;
//   }
// 
//   public void setBodyFieldPath(String bodyFieldPath) {
//     this.bodyFieldPath = bodyFieldPath;
//   }
// }


import static com.google.common.truth.Truth.assertThat;
import com.google.api.Http;
import com.google.api.HttpRule;
import com.google.api.Service;
import com.google.api.control.model.MethodRegistry.Info;
import org.junit.Test;
package com.google.api.control.model;




/**
 * Tests for {@link MethodRegistry}.
 */
public class MethodRegistryTest {
  private static final String SELECTOR = "a.selector";
  private static final String SLASH_SELECTOR = "slash.selector";
  private static final Service SERVICE = Service.newBuilder()
      .setName("the-service")
      .setHttp(Http.newBuilder()
          .addRules(HttpRule.newBuilder()
              .setSelector(SELECTOR)
              .setGet("/v1/foo/{bar}/baz"))
          .addRules(HttpRule.newBuilder()
              .setSelector(SLASH_SELECTOR)
              .setGet("/v1/baz/{bar}/foo/")))
      .build();

  @Test
  public void lookup_matchesWithOrWithoutTrailingSlashes() {
    MethodRegistry r = new MethodRegistry(SERVICE);
    assertSuccess(r.lookup("GET", "/v1/foo/2/baz"), SELECTOR);
    assertSuccess(r.lookup("GET", "/v1/foo/2/baz/"), SELECTOR);
    assertFailure(r.lookup("POST", "/v1/foo/2/baz"));
    assertFailure(r.lookup("POST", "/v1/foo/2/baz/"));

    assertSuccess(r.lookup("GET", "/v1/baz/2/foo"), SLASH_SELECTOR);
    assertSuccess(r.lookup("GET", "/v1/baz/2/foo/"), SLASH_SELECTOR);
    assertFailure(r.lookup("POST", "/v1/baz/2/foo"));
    assertFailure(r.lookup("POST", "/v1/baz/2/foo/"));
  }

// Path: endpoints-control/src/main/java/com/google/api/control/model/MethodRegistry.java
// public static class Info {
//   private static final String API_KEY_NAME = "api_key";
// 
//   private final Optional<AuthInfo> authInfo;
//   private final QuotaInfo quotaInfo;
// 
//   private boolean allowUnregisteredCalls;
//   private String selector;
//   private String backendAddress;
//   private String bodyFieldPath;
//   private Map<String, List<String>> urlQueryParams;
//   private Map<String, List<String>> headerParams;
//   private PathTemplate template;
// 
//   public Info(String selector, @CheckForNull AuthInfo authInfo,
//       @CheckForNull QuotaInfo quotaInfo) {
//     this.selector = selector;
//     this.authInfo = Optional.<AuthInfo>fromNullable(authInfo);
//     this.quotaInfo = quotaInfo != null ? quotaInfo : QuotaInfo.DEFAULT;
// 
//     this.urlQueryParams = Maps.newHashMap();
//     this.headerParams = Maps.newHashMap();
//   }
// 
//   public PathTemplate getTemplate() {
//     return template;
//   }
// 
//   public void setTemplate(PathTemplate template) {
//     this.template = template;
//   }
// 
//   public void addUrlQueryParam(String name, String param) {
//     List<String> l = urlQueryParams.get(name);
//     if (l == null) {
//       l = Lists.newArrayList();
//       urlQueryParams.put(name, l);
//     }
//     l.add(param);
//   }
// 
//   public List<String> urlQueryParam(String name) {
//     List<String> l = urlQueryParams.get(name);
//     if (l == null) {
//       return Collections.emptyList();
//     }
//     return ImmutableList.copyOf(l);
//   }
// 
//   public List<String> apiKeyUrlQueryParam() {
//     return urlQueryParam(API_KEY_NAME);
//   }
// 
//   public void addHeaderParam(String name, String param) {
//     List<String> l = headerParams.get(name);
//     if (l == null) {
//       l = Lists.newArrayList();
//       headerParams.put(name, l);
//     }
//     l.add(param);
//   }
// 
//   public List<String> headerParam(String name) {
//     List<String> l = headerParams.get(name);
//     if (l == null) {
//       return Collections.emptyList();
//     }
//     return ImmutableList.copyOf(l);
//   }
// 
//   public List<String> apiKeyHeaderParam() {
//     return headerParam(API_KEY_NAME);
//   }
// 
//   public Optional<AuthInfo> getAuthInfo() {
//     return this.authInfo;
//   }
// 
//   public QuotaInfo getQuotaInfo() {
//     return quotaInfo;
//   }
// 
//   public boolean shouldAllowUnregisteredCalls() {
//     return allowUnregisteredCalls;
//   }
// 
//   public void setAllowUnregisteredCalls(boolean allowRegisteredCalls) {
//     this.allowUnregisteredCalls = allowRegisteredCalls;
//   }
// 
//   public String getSelector() {
//     return selector;
//   }
// 
//   public void setSelector(String selector) {
//     this.selector = selector;
//   }
// 
//   public String getBackendAddress() {
//     return backendAddress;
//   }
// 
//   public void setBackendAddress(String backendAddress) {
//     this.backendAddress = backendAddress;
//   }
// 
//   public String getBodyFieldPath() {
//     return bodyFieldPath;
//   }
// 
//   public void setBodyFieldPath(String bodyFieldPath) {
//     this.bodyFieldPath = bodyFieldPath;
//   }
// }


// Path: endpoints-control/src/test/java/com/google/api/control/model/MethodRegistryTest.java
import static com.google.common.truth.Truth.assertThat;
import com.google.api.Http;
import com.google.api.HttpRule;
import com.google.api.Service;
import com.google.api.control.model.MethodRegistry.Info;
import org.junit.Test;

package com.google.api.control.model;




/**
 * Tests for {@link MethodRegistry}.
 */
public class MethodRegistryTest {
  private static final String SELECTOR = "a.selector";
  private static final String SLASH_SELECTOR = "slash.selector";
  private static final Service SERVICE = Service.newBuilder()
      .setName("the-service")
      .setHttp(Http.newBuilder()
          .addRules(HttpRule.newBuilder()
              .setSelector(SELECTOR)
              .setGet("/v1/foo/{bar}/baz"))
          .addRules(HttpRule.newBuilder()
              .setSelector(SLASH_SELECTOR)
              .setGet("/v1/baz/{bar}/foo/")))
      .build();

  @Test
  public void lookup_matchesWithOrWithoutTrailingSlashes() {
    MethodRegistry r = new MethodRegistry(SERVICE);
    assertSuccess(r.lookup("GET", "/v1/foo/2/baz"), SELECTOR);
    assertSuccess(r.lookup("GET", "/v1/foo/2/baz/"), SELECTOR);
    assertFailure(r.lookup("POST", "/v1/foo/2/baz"));
    assertFailure(r.lookup("POST", "/v1/foo/2/baz/"));

    assertSuccess(r.lookup("GET", "/v1/baz/2/foo"), SLASH_SELECTOR);
    assertSuccess(r.lookup("GET", "/v1/baz/2/foo/"), SLASH_SELECTOR);
    assertFailure(r.lookup("POST", "/v1/baz/2/foo"));
    assertFailure(r.lookup("POST", "/v1/baz/2/foo/"));
  }

  private static void assertFailure(Info info) {