// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/Rate.java
// @Entity
// public class Rate {
// 
//     @Id
//     @Column(name = "rate_key")
//     private String key;
//     private Long remaining;
//     private Long remainingQuota;
//     private Long reset;
//     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
//     private Date expiration;
// 
//     public Rate() {
//     }
// 
//     public Rate(String key, Long remaining, Long remainingQuota, Long reset, Date expiration) {
//         this.key = key;
//         this.remaining = remaining;
//         this.remainingQuota = remainingQuota;
//         this.reset = reset;
//         this.expiration = expiration;
//     }
// 
//     public String getKey() {
//         return key;
//     }
// 
//     public void setKey(String key) {
//         this.key = key;
//     }
// 
//     public Long getRemaining() {
//         return remaining;
//     }
// 
//     public void setRemaining(Long remaining) {
//         this.remaining = remaining;
//     }
// 
//     public Long getRemainingQuota() {
//         return remainingQuota;
//     }
// 
//     public void setRemainingQuota(Long remainingQuota) {
//         this.remainingQuota = remainingQuota;
//     }
// 
//     public Long getReset() {
//         return reset;
//     }
// 
//     public void setReset(Long reset) {
//         this.reset = reset;
//     }
// 
//     public Date getExpiration() {
//         return expiration;
//     }
// 
//     public void setExpiration(Date expiration) {
//         this.expiration = expiration;
//     }
// }
// 
// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/repository/RateLimiterErrorHandler.java
// public interface RateLimiterErrorHandler {
// 
//     void handleSaveError(String key, Exception e);
// 
//     void handleFetchError(String key, Exception e);
// 
//     void handleError(String msg, Exception e);
// 
// }
// 
// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/repository/springdata/JpaRateLimiter.java
// public class JpaRateLimiter extends AbstractRateLimiter {
// 
//     private final RateLimiterRepository repository;
// 
//     public JpaRateLimiter(final RateLimiterErrorHandler rateLimiterErrorHandler,
//                           final RateLimiterRepository repository) {
//         super(rateLimiterErrorHandler);
//         this.repository = repository;
//     }
// 
//     @Override
//     protected Rate getRate(String key) {
//         return this.repository.findById(key).orElse(null);
//     }
// 
//     @Override
//     protected void saveRate(Rate rate) {
//         this.repository.save(rate);
//     }
// 
// }
// 
// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/repository/springdata/RateLimiterRepository.java
// public interface RateLimiterRepository extends CrudRepository<Rate, String> {
// 
// }


import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.Rate;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.RateLimiterErrorHandler;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.springdata.JpaRateLimiter;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.springdata.RateLimiterRepository;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.jupiter.api.BeforeEach;
package com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.filters.pre;



/**
 * @author Marcos Barbero
 * @since 2017-06-30
 */
public class JpaLimitPreFilterTest extends BaseRateLimitPreFilterTest {

    @BeforeEach
    @Override
    public void setUp() {
        Map<String, Rate> repository = new ConcurrentHashMap<>();
// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/Rate.java
// @Entity
// public class Rate {
// 
//     @Id
//     @Column(name = "rate_key")
//     private String key;
//     private Long remaining;
//     private Long remainingQuota;
//     private Long reset;
//     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss")
//     private Date expiration;
// 
//     public Rate() {
//     }
// 
//     public Rate(String key, Long remaining, Long remainingQuota, Long reset, Date expiration) {
//         this.key = key;
//         this.remaining = remaining;
//         this.remainingQuota = remainingQuota;
//         this.reset = reset;
//         this.expiration = expiration;
//     }
// 
//     public String getKey() {
//         return key;
//     }
// 
//     public void setKey(String key) {
//         this.key = key;
//     }
// 
//     public Long getRemaining() {
//         return remaining;
//     }
// 
//     public void setRemaining(Long remaining) {
//         this.remaining = remaining;
//     }
// 
//     public Long getRemainingQuota() {
//         return remainingQuota;
//     }
// 
//     public void setRemainingQuota(Long remainingQuota) {
//         this.remainingQuota = remainingQuota;
//     }
// 
//     public Long getReset() {
//         return reset;
//     }
// 
//     public void setReset(Long reset) {
//         this.reset = reset;
//     }
// 
//     public Date getExpiration() {
//         return expiration;
//     }
// 
//     public void setExpiration(Date expiration) {
//         this.expiration = expiration;
//     }
// }
// 
// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/repository/RateLimiterErrorHandler.java
// public interface RateLimiterErrorHandler {
// 
//     void handleSaveError(String key, Exception e);
// 
//     void handleFetchError(String key, Exception e);
// 
//     void handleError(String msg, Exception e);
// 
// }
// 
// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/repository/springdata/JpaRateLimiter.java
// public class JpaRateLimiter extends AbstractRateLimiter {
// 
//     private final RateLimiterRepository repository;
// 
//     public JpaRateLimiter(final RateLimiterErrorHandler rateLimiterErrorHandler,
//                           final RateLimiterRepository repository) {
//         super(rateLimiterErrorHandler);
//         this.repository = repository;
//     }
// 
//     @Override
//     protected Rate getRate(String key) {
//         return this.repository.findById(key).orElse(null);
//     }
// 
//     @Override
//     protected void saveRate(Rate rate) {
//         this.repository.save(rate);
//     }
// 
// }
// 
// Path: spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/repository/springdata/RateLimiterRepository.java
// public interface RateLimiterRepository extends CrudRepository<Rate, String> {
// 
// }


// Path: spring-cloud-zuul-ratelimit-core/src/test/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/filters/pre/JpaLimitPreFilterTest.java
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.Rate;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.RateLimiterErrorHandler;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.springdata.JpaRateLimiter;
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.springdata.RateLimiterRepository;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.jupiter.api.BeforeEach;

package com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.filters.pre;



/**
 * @author Marcos Barbero
 * @since 2017-06-30
 */
public class JpaLimitPreFilterTest extends BaseRateLimitPreFilterTest {

    @BeforeEach
    @Override
    public void setUp() {
        Map<String, Rate> repository = new ConcurrentHashMap<>();
        RateLimiterRepository rateLimiterRepository = mock(RateLimiterRepository.class);