@Test public void resetCurrentUri() throws Exception { //GIVEN MockWebContext context = new MockWebContext(); MgnlContext.setInstance(context); ComponentsTestUtil.setImplementation(SystemContext.class, MockWebContext.class); AggregationState aggregationState = new AggregationState(); aggregationState.setCurrentURI("originalURI"); aggregationState.setQueryString("queryString"); context.setAggregationState(aggregationState); virtualURIManager = new VirtualURIManager(null, null, mock(EventBus.class)); ComponentsTestUtil.setInstance(VirtualURIManager.class, virtualURIManager); setVirtualURIMappingsToVirtualManager(); VirtualUriFilter filter = new VirtualUriFilter(); HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); FilterChain chain = mock(FilterChain.class); //WHEN filter.doFilter(request, response, chain); //THEN assertEquals("newURI", aggregationState.getCurrentURI()); }
@Test public void testReloadsTemplatesOnChange() throws RepositoryException, RegistrationException, InterruptedException { // GIVEN final VirtualURIManager manager = new VirtualURIManager(moduleRegistry, new Node2BeanProcessorImpl(new TypeMappingImpl(), new Node2BeanTransformerImpl()), eventBus); // WHEN eventBus.fireEvent(new ModulesStartedEvent()); // THEN, make sure that it found mapping 'first' assertHasDefaultMapping(manager, "/first", "/1"); // WHEN we remove the node for mapping 'first' and add a new one 'third' in zedModule session.getNode("/modules/fooModule/virtualURIMapping/first").remove(); Node node = session.getNode("/modules/zedModule/").addNode("virtualURIMapping").addNode("third"); node.setProperty("fromURI", "/third"); node.setProperty("toURI", "/3"); // It's enough to fire just this event because it reloads everything for each batch of events MockObservationManager observationManager = (MockObservationManager) session.getWorkspace().getObservationManager(); observationManager.fireEvent(MockEvent.nodeAdded("/modules/zedModule/virtualURIMapping/third")); // THEN 'first' must be gone and 'third' must have been found TestUtil.delayedAssert(new Assertion() { @Override public void evaluate() throws RegistrationException { assertEquals(2, manager.getURIMappings().size()); assertHasDefaultMapping(manager, "/second", "/2"); assertHasDefaultMapping(manager, "/third", "/3"); } }); }
@Test public void testRegistersTemplatesOnStart() throws RegistrationException { // GIVEN VirtualURIManager manager = new VirtualURIManager(moduleRegistry, new Node2BeanProcessorImpl(new TypeMappingImpl(), new Node2BeanTransformerImpl()), eventBus); // WHEN eventBus.fireEvent(new ModulesStartedEvent()); // THEN assertEquals(2, manager.getURIMappings().size()); assertHasDefaultMapping(manager, "/first", "/1"); assertHasDefaultMapping(manager, "/second", "/2"); }
@Test public void testMap() throws RegistrationException { // GIVEN VirtualURIManager manager = new VirtualURIManager(moduleRegistry, new Node2BeanProcessorImpl(new TypeMappingImpl(), new Node2BeanTransformerImpl()), eventBus); // WHEN eventBus.fireEvent(new ModulesStartedEvent()); // THEN assertEquals("/1", manager.getURIMapping("/first")); assertEquals("/2", manager.getURIMapping("/second")); assertEquals(StringUtils.EMPTY, manager.getURIMapping("/unmapped")); }