### Question:
IgnoredResourcesPolicy extends AbstractMappedPolicy<IgnoredResourcesConfig> { @Override protected void doApply(ApiRequest request, IPolicyContext context, IgnoredResourcesConfig config, IPolicyChain<ApiRequest> chain) { if (!satisfiesAnyPath(config, request.getDestination(), request.getType())) { super.doApply(request, context, config, chain); } else { IPolicyFailureFactoryComponent ffactory = context .getComponent(IPolicyFailureFactoryComponent.class); String msg = Messages.i18n.format("IgnoredResourcesPolicy.PathIgnored", request.getDestination()); PolicyFailure failure = ffactory.createFailure(PolicyFailureType.NotFound, PolicyFailureCodes.PATHS_TO_IGNORE, msg); chain.doFailure(failure); } } IgnoredResourcesPolicy();   }### Answer:
@Test public void testApply() throws Exception { IgnoredResourcesPolicy policy = new IgnoredResourcesPolicy(); IgnoredResourcesConfig configObj = new IgnoredResourcesConfig(); ArrayList<IgnoredResource> elements = new ArrayList<>(2); elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, firstPath)); elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, secondPath)); configObj.setRules(elements); String json = mapper.writeValueAsString(configObj); Object config = policy.parseConfiguration(json); ApiRequest request = new ApiRequest(); request.setType("GET"); request.setApiKey("12345"); request.setRemoteAddr("1.2.3.4"); request.setDestination("/invoices/1"); IPolicyContext context = Mockito.mock(IPolicyContext.class); IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class); policy.apply(request, context, config, chain); request.setDestination("/invoices"); policy.apply(request, context, config, chain); request.setDestination("/invoices/items"); policy.apply(request, context, config, chain); request.setDestination("/invoices/items/13"); policy.apply(request, context, config, chain); Mockito.verify(chain, Mockito.times(4)).doApply(request); Mockito.verify(chain, Mockito.never()).doFailure(Mockito.<PolicyFailure> any()); final PolicyFailure failure = createFailurePolicyObject(context); chain = Mockito.mock(IPolicyChain.class); request.setDestination("/invoices/23/items/43"); policy.apply(request, context, config, chain); request.setDestination("/items/43"); policy.apply(request, context, config, chain); Mockito.verify(chain, Mockito.times(2)).doFailure(failure); }
@Test public void testApplyWithType() throws Exception { IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class); String verb = "GET"; ApiRequest request = requestWithVerb(chain, verb); Mockito.verify(chain, Mockito.times(1)).doApply(request); Mockito.verify(chain, Mockito.times(2)).doFailure(Mockito.<PolicyFailure> any()); }
@Test public void testApplyWithDifferentType() throws Exception { IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class); String verb = "TRACE"; ApiRequest request = requestWithVerb(chain, verb); Mockito.verify(chain, Mockito.times(3)).doApply(request); Mockito.verify(chain, Mockito.never()).doFailure(Mockito.<PolicyFailure> any()); }