@Test public void testAddViewInstance() throws Exception { ViewInstanceEntity viewInstanceEntity = ViewInstanceEntityTest.getViewInstanceEntity(); final WebAppContext handler = createNiceMock(WebAppContext.class); Server server = createNiceMock(Server.class); expect(handler.getServer()).andReturn(server); handler.setServer(null); Capture<FilterHolder> securityHeaderFilterCapture = EasyMock.newCapture(); Capture<FilterHolder> persistFilterCapture = EasyMock.newCapture(); Capture<FilterHolder> securityFilterCapture = EasyMock.newCapture(); handler.addFilter(capture(securityHeaderFilterCapture), eq("/*"), eq(AmbariServer.DISPATCHER_TYPES)); handler.addFilter(capture(persistFilterCapture), eq("/*"), eq(AmbariServer.DISPATCHER_TYPES)); handler.addFilter(capture(securityFilterCapture), eq("/*"), eq(AmbariServer.DISPATCHER_TYPES)); handler.setAllowNullPathInfo(true); replay(handler, server); AmbariHandlerList handlerList = getAmbariHandlerList(handler); handlerList.addViewInstance(viewInstanceEntity); ArrayList<Handler> handlers = new ArrayList<Handler>(Arrays.asList(handlerList.getHandlers())); Assert.assertTrue(handlers.contains(handler)); Assert.assertEquals(ambariViewsSecurityHeaderFilter, securityHeaderFilterCapture.getValue().getFilter()); Assert.assertEquals(persistFilter, persistFilterCapture.getValue().getFilter()); Assert.assertEquals(springSecurityFilter, securityFilterCapture.getValue().getFilter()); verify(handler, server); }
@Override public void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException { Handler handler = getHandler(viewInstanceDefinition); viewHandlerMap.put(viewInstanceDefinition, handler); super.addHandler(handler); if(!isStopped() && !isStopping()) { try { handler.start(); } catch (Exception e) { throw new SystemException("Caught exception adding a view instance.", e); } } }
AmbariHandlerList extends HandlerCollection implements ViewInstanceHandlerList { @Override public void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException { Handler handler = getHandler(viewInstanceDefinition); viewHandlerMap.put(viewInstanceDefinition, handler); super.addHandler(handler); if(!isStopped() && !isStopping()) { try { handler.start(); } catch (Exception e) { throw new SystemException("Caught exception adding a view instance.", e); } } } }
AmbariHandlerList extends HandlerCollection implements ViewInstanceHandlerList { @Override public void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException { Handler handler = getHandler(viewInstanceDefinition); viewHandlerMap.put(viewInstanceDefinition, handler); super.addHandler(handler); if(!isStopped() && !isStopping()) { try { handler.start(); } catch (Exception e) { throw new SystemException("Caught exception adding a view instance.", e); } } } AmbariHandlerList(); }
AmbariHandlerList extends HandlerCollection implements ViewInstanceHandlerList { @Override public void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException { Handler handler = getHandler(viewInstanceDefinition); viewHandlerMap.put(viewInstanceDefinition, handler); super.addHandler(handler); if(!isStopped() && !isStopping()) { try { handler.start(); } catch (Exception e) { throw new SystemException("Caught exception adding a view instance.", e); } } } AmbariHandlerList(); @Override void handle(String target, Request baseRequest,
                     HttpServletRequest request, HttpServletResponse response); @Override void addHandler(Handler handler); @Override void addViewInstance(ViewInstanceEntity viewInstanceDefinition); @Override void removeViewInstance(ViewInstanceEntity viewInstanceDefinition); }
AmbariHandlerList extends HandlerCollection implements ViewInstanceHandlerList { @Override public void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException { Handler handler = getHandler(viewInstanceDefinition); viewHandlerMap.put(viewInstanceDefinition, handler); super.addHandler(handler); if(!isStopped() && !isStopping()) { try { handler.start(); } catch (Exception e) { throw new SystemException("Caught exception adding a view instance.", e); } } } AmbariHandlerList(); @Override void handle(String target, Request baseRequest,
                     HttpServletRequest request, HttpServletResponse response); @Override void addHandler(Handler handler); @Override void addViewInstance(ViewInstanceEntity viewInstanceDefinition); @Override void removeViewInstance(ViewInstanceEntity viewInstanceDefinition);  }