StringToMatchTypeConverter implements Converter<String, MatchType> { @Override public MatchType convert(@NotNull String type) { if (type.contains(DELIMITER)) { String[] matchType = type.split(DELIMITER); return new MatchType(RateLimitType.valueOf(matchType[0].toUpperCase()), matchType[1]); } return new MatchType(RateLimitType.valueOf(type.toUpperCase()), null); }  @Override MatchType convert(@NotNull String type);  }
@Test @SuppressWarnings("deprecation") public void testConvertStringTypeMethodOnly() { MatchType matchType = target.convert("httpmethod"); assertThat(matchType).isNotNull(); assertThat(matchType.getType()).isEqualByComparingTo(RateLimitType.HTTPMETHOD); assertThat(matchType.getMatcher()).isNull(); }
@Test @SuppressWarnings("deprecation") public void testConvertStringTypeMethodWithMatcher() { MatchType matchType = target.convert("httpmethod=get"); assertThat(matchType).isNotNull(); assertThat(matchType.getType()).isEqualByComparingTo(RateLimitType.HTTPMETHOD); assertThat(matchType.getMatcher()).isEqualTo("get"); }
@Test public void testConvertStringTypeHttpMethodOnly() { MatchType matchType = target.convert("http_method"); assertThat(matchType).isNotNull(); assertThat(matchType.getType()).isEqualByComparingTo(RateLimitType.HTTP_METHOD); assertThat(matchType.getMatcher()).isNull(); }
@Test public void testConvertStringTypeHttpMethodWithMatcher() { MatchType matchType = target.convert("http_method=get"); assertThat(matchType).isNotNull(); assertThat(matchType.getType()).isEqualByComparingTo(RateLimitType.HTTP_METHOD); assertThat(matchType.getMatcher()).isEqualTo("get"); }
@Test public void testConvertStringTypeHttpHeaderWithMatcher() { MatchType matchType = target.convert("http_header=customHeader"); assertThat(matchType).isNotNull(); assertThat(matchType.getType()).isEqualByComparingTo(RateLimitType.HTTP_HEADER); assertThat(matchType.getMatcher()).isEqualTo("customHeader"); }
@Test public void testConvertStringTypeOnly() { MatchType matchType = target.convert("url"); assertThat(matchType).isNotNull(); assertThat(matchType.getType()).isEqualByComparingTo(RateLimitType.URL); assertThat(matchType.getMatcher()).isNull(); }
@Test public void testConvertStringTypeUrlPatternWithMatcher() { MatchType matchType = target.convert("url_pattern=/apispecific"); }
@Test public void testConvertStringTypeWithMatcher() { MatchType matchType = target.convert("url=/api"); assertThat(matchType).isNotNull(); assertThat(matchType.getType()).isEqualByComparingTo(RateLimitType.URL); assertThat(matchType.getMatcher()).isEqualTo("/api"); }