use of io.apiman.gateway.engine.policies.config.IgnoredResource in project apiman by apiman.
the class IgnoredResourcesPolicyTest method testParseConfiguration.
@Test
public void testParseConfiguration() throws Exception {
IgnoredResourcesPolicy policy = new IgnoredResourcesPolicy();
String config = "{}";
Object parsed = policy.parseConfiguration(config);
assertNotNull(parsed);
assertEquals(IgnoredResourcesConfig.class, parsed.getClass());
IgnoredResourcesConfig parsedConfig = (IgnoredResourcesConfig) parsed;
assertNotNull(parsedConfig.getRules());
assertTrue(parsedConfig.getRules().isEmpty());
IgnoredResourcesConfig configObj = new IgnoredResourcesConfig();
ArrayList<IgnoredResource> elements = new ArrayList<>(2);
elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, firstPath));
configObj.setRules(elements);
// Single Path
assertConfigurationParseResults(policy, configObj);
elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, secondPath));
configObj.setRules(elements);
assertConfigurationParseResults(policy, configObj);
}
use of io.apiman.gateway.engine.policies.config.IgnoredResource in project apiman by apiman.
the class IgnoredResourcesPolicyTest method createResource.
private IgnoredResource createResource(String verb, String path) {
IgnoredResource resource = new IgnoredResource();
resource.setPathPattern(path);
resource.setVerb(verb);
return resource;
}
use of io.apiman.gateway.engine.policies.config.IgnoredResource in project apiman by apiman.
the class IgnoredResourcesPolicyTest method assertConfigurationParseResults.
private void assertConfigurationParseResults(IgnoredResourcesPolicy policy, IgnoredResourcesConfig configObj) throws Exception {
IgnoredResourcesConfig parsedConfig;
List<IgnoredResource> expectedConfiguration;
String config = mapper.writeValueAsString(configObj);
parsedConfig = policy.parseConfiguration(config);
assertNotNull(parsedConfig.getRules());
expectedConfiguration = configObj.getRules();
assertEquals(expectedConfiguration, parsedConfig.getRules());
}
use of io.apiman.gateway.engine.policies.config.IgnoredResource in project apiman by apiman.
the class IgnoredResourcesPolicyTest method requestWithVerb.
private ApiRequest requestWithVerb(IPolicyChain<ApiRequest> chain, String verb) throws IOException, JsonGenerationException, JsonMappingException {
IgnoredResourcesPolicy policy = new IgnoredResourcesPolicy();
IgnoredResourcesConfig configObj = new IgnoredResourcesConfig();
ArrayList<IgnoredResource> elements = new ArrayList<>(2);
elements.add(createResource(verb, firstPath));
elements.add(createResource(verb, 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);
createFailurePolicyObject(context);
// Success
policy.apply(request, context, config, chain);
// Fail
request.setDestination("/invoices/23/items/43");
policy.apply(request, context, config, chain);
// Fail
request.setDestination("/items/43");
policy.apply(request, context, config, chain);
return request;
}
use of io.apiman.gateway.engine.policies.config.IgnoredResource in project apiman by apiman.
the class IgnoredResourcesPolicyTest method testApply.
@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);
// Success
policy.apply(request, context, config, chain);
// Success
request.setDestination("/invoices");
policy.apply(request, context, config, chain);
// Success
request.setDestination("/invoices/items");
policy.apply(request, context, config, chain);
// Success
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);
// Failure
request.setDestination("/items/43");
policy.apply(request, context, config, chain);
Mockito.verify(chain, Mockito.times(2)).doFailure(failure);
}
Aggregations