use of org.apache.knox.test.log.NoOpLogger in project knox by apache.
the class ServiceRegistryFunctionsTest method setUp.
public void setUp(String username, Map<String, String> initParams) throws Exception {
ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-nn-scheme://test-nn-host:411").anyTimes();
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "JOBTRACKER")).andReturn("test-jt-scheme://test-jt-host:511").anyTimes();
GatewayServices mockGatewayServices = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(mockGatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(mockServiceRegistry).anyTimes();
EasyMock.replay(mockServiceRegistry, mockGatewayServices);
String descriptorUrl = getTestResource("rewrite.xml").toExternalForm();
Log.setLog(new NoOpLogger());
server = new ServletTester();
server.setContextPath("/");
server.getContext().addEventListener(new UrlRewriteServletContextListener());
server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);
server.getContext().setAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster");
server.getContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices);
FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
setupFilter.setFilter(new SetupFilter(username));
FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
if (initParams != null) {
for (Map.Entry<String, String> entry : initParams.entrySet()) {
rewriteFilter.setInitParameter(entry.getKey(), entry.getValue());
}
}
rewriteFilter.setFilter(new UrlRewriteServletFilter());
interactions = new ArrayQueue<MockInteraction>();
ServletHolder servlet = server.addServlet(MockServlet.class, "/");
servlet.setServlet(new MockServlet("mock-servlet", interactions));
server.start();
interaction = new MockInteraction();
request = HttpTester.newRequest();
response = null;
}
use of org.apache.knox.test.log.NoOpLogger in project knox by apache.
the class UsernameFunctionProcessorTest method setUp.
public void setUp(String username, Map<String, String> initParams) throws Exception {
String descriptorUrl = getTestResource("rewrite.xml").toExternalForm();
Log.setLog(new NoOpLogger());
server = new ServletTester();
server.setContextPath("/");
server.getContext().addEventListener(new UrlRewriteServletContextListener());
server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);
FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
setupFilter.setFilter(new SetupFilter(username));
FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
if (initParams != null) {
for (Map.Entry<String, String> entry : initParams.entrySet()) {
rewriteFilter.setInitParameter(entry.getKey(), entry.getValue());
}
}
rewriteFilter.setFilter(new UrlRewriteServletFilter());
interactions = new ArrayQueue<MockInteraction>();
ServletHolder servlet = server.addServlet(MockServlet.class, "/");
servlet.setServlet(new MockServlet("mock-servlet", interactions));
server.start();
interaction = new MockInteraction();
request = HttpTester.newRequest();
response = null;
}
use of org.apache.knox.test.log.NoOpLogger in project knox by apache.
the class FrontendFunctionProcessorTest method setUp.
public void setUp(String username, Map<String, String> initParams, Attributes attributes) throws Exception {
ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "NAMENODE")).andReturn("test-nn-scheme://test-nn-host:411").anyTimes();
EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "JOBTRACKER")).andReturn("test-jt-scheme://test-jt-host:511").anyTimes();
GatewayServices mockGatewayServices = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(mockGatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)).andReturn(mockServiceRegistry).anyTimes();
EasyMock.replay(mockServiceRegistry, mockGatewayServices);
String descriptorUrl = TestUtils.getResourceUrl(FrontendFunctionProcessorTest.class, "rewrite.xml").toExternalForm();
Log.setLog(new NoOpLogger());
server = new ServletTester();
server.setContextPath("/");
server.getContext().addEventListener(new UrlRewriteServletContextListener());
server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);
if (attributes != null) {
server.getContext().setAttributes(attributes);
}
server.getContext().setAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster");
server.getContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices);
FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
setupFilter.setFilter(new SetupFilter(username));
FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
if (initParams != null) {
for (Map.Entry<String, String> entry : initParams.entrySet()) {
rewriteFilter.setInitParameter(entry.getKey(), entry.getValue());
}
}
rewriteFilter.setFilter(new UrlRewriteServletFilter());
interactions = new ArrayQueue<MockInteraction>();
ServletHolder servlet = server.addServlet(MockServlet.class, "/");
servlet.setServlet(new MockServlet("mock-servlet", interactions));
server.start();
interaction = new MockInteraction();
request = HttpTester.newRequest();
response = null;
}
Aggregations