Search in sources :

Example 46 with UrlRewriteRulesDescriptor

use of org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor in project knox by apache.

the class OozieServiceDefinitionTest method testOozieRewriteRulesForLiteralTemplateValuesBugKnox394.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testOozieRewriteRulesForLiteralTemplateValuesBugKnox394() throws Exception {
    LOG_ENTER();
    // This is a unique part of this test.
    String testResource = "oozie-request-with-var.xml";
    // Mock out the service url registry which is required for several url rewrite functions to work.
    ServiceRegistry registry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(registry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-scheme://test-host:42").anyTimes();
    // Mock out the gateway services registry which is required for several url rewrite functions to work.
    GatewayServices services = EasyMock.createNiceMock(GatewayServices.class);
    EasyMock.expect(services.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(registry).anyTimes();
    UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
    ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class);
    EasyMock.expect(servletContext.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)).andReturn(rewriteProcessor).anyTimes();
    EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(services).anyTimes();
    EasyMock.expect(servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE)).andReturn("test-cluster").anyTimes();
    HttpServletRequest servletRequest = EasyMock.createNiceMock(HttpServletRequest.class);
    EasyMock.expect(servletRequest.getInputStream()).andReturn(new MockServletInputStream(TestUtils.getResourceStream(OozieServiceDefinitionTest.class, testResource))).anyTimes();
    EasyMock.expect(servletRequest.getContentType()).andReturn("text/xml").anyTimes();
    FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class);
    EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
    EasyMock.expect(filterConfig.getInitParameter(UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM)).andReturn("OOZIE/oozie/configuration").anyTimes();
    EasyMock.replay(registry, services, servletContext, servletRequest, filterConfig);
    UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment(servletContext);
    Reader rulesReader = TestUtils.getResourceReader("services/oozie/4.0.0/rewrite.xml", "UTF-8");
    UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load("xml", rulesReader);
    rulesReader.close();
    rewriteProcessor.initialize(rewriteEnvironment, rewriteRules);
    UrlRewriteRequest rewriteRequest = new UrlRewriteRequest(filterConfig, servletRequest);
    InputStream stream = rewriteRequest.getInputStream();
    Document document = XmlUtils.readXml(stream);
    assertThat(document, hasXPath("/configuration/property[name='oozie.wf.application.path']/value", equalTo("${appPath}/workflow.xml")));
    LOG_EXIT();
}
Also used : MockServletInputStream(org.apache.knox.test.mock.MockServletInputStream) UrlRewriteEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment) GatewayServices(org.apache.knox.gateway.services.GatewayServices) UrlRewriteRequest(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteRequest) UrlRewriteProcessor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteProcessor) MockServletInputStream(org.apache.knox.test.mock.MockServletInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) UrlRewriteRulesDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor) UrlRewriteServletEnvironment(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteServletEnvironment) Document(org.w3c.dom.Document) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) ServiceRegistry(org.apache.knox.gateway.services.registry.ServiceRegistry) Test(org.junit.Test)

Aggregations

UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)46 Test (org.junit.Test)38 StringReader (java.io.StringReader)20 UrlRewriteFilterContentDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)20 UrlRewriteFilterDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterDescriptor)20 Matchers.containsString (org.hamcrest.Matchers.containsString)19 InputStream (java.io.InputStream)16 UrlRewriteRuleDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRuleDescriptor)13 UrlRewriteFilterApplyDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterApplyDescriptor)12 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)11 UrlRewriteFilterBufferDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterBufferDescriptor)11 UrlRewriteProcessor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteProcessor)11 UrlRewriteActionRewriteDescriptorExt (org.apache.knox.gateway.filter.rewrite.ext.UrlRewriteActionRewriteDescriptorExt)9 StringWriter (java.io.StringWriter)8 Resolver (org.apache.knox.gateway.util.urltemplate.Resolver)8 Template (org.apache.knox.gateway.util.urltemplate.Template)8 URL (java.net.URL)7 Source (javax.xml.transform.Source)6 IOException (java.io.IOException)5 GatewayServices (org.apache.knox.gateway.services.GatewayServices)5