@Before public void setUp() throws GadgetException { control = EasyMock.createControl(); request = control.createMock(JsRequest.class); response = new JsResponseBuilder(); processor = new AddJslLoadedVariableProcessor(fregProvider); EasyMock.reset(fregProvider, freg); EasyMock.expect(fregProvider.get(EasyMock.anyObject(String.class))).andReturn(freg).anyTimes(); Set<String> required = Sets.newHashSet(REQ_LIBS); EasyMock.expect(freg.getAllFeatureNames()).andReturn(required).anyTimes(); EasyMock.replay(fregProvider, freg); }
public boolean process(JsRequest jsRequest, JsResponseBuilder builder) throws JsException { JsUri jsUri = jsRequest.getJsUri(); FeatureRegistry registry = null; String repository = jsUri.getRepository(); try { registry = featureRegistryProvider.get(jsUri.getRepository()); } catch (GadgetException e) { if (LOG.isLoggable(Level.WARNING)) { LOG.log(Level.WARNING, "No registry found for repository: " + repository, e); } } if (registry != null && !jsUri.isNohint()) { Set<String> allfeatures = registry.getAllFeatureNames(); Set<String> libs = Sets.newTreeSet(); libs.addAll(jsUri.getLibs()); libs.removeAll(jsUri.getLoadedLibs()); libs.retainAll(allfeatures); String array = toArrayString(libs); builder.appendJs(String.format(TEMPLATE, array), CODE_ID, true); } return true; }
@Test public void testSucceeds() throws Exception { setUpJsUri(URI + "/" + REQ_1_LIB + ".js"); control.replay(); processor.process(request, response); assertEquals(String.format(AddJslLoadedVariableProcessor.TEMPLATE, "['foo','gig']"), response.build().toJsString()); control.verify(); }
@Test public void testSucceeds() throws Exception { setUpJsUri(URI + "/" + REQ_1_LIB + ".js"); control.replay(); processor.process(request, response); assertEquals(String.format(AddJslLoadedVariableProcessor.TEMPLATE, "['foo','gig']"), response.build().toJsString()); control.verify(); }
@Test public void testSkips() throws Exception { setUpJsUri(URI + "?nohint=1"); control.replay(); processor.process(request, response); assertEquals("", response.build().toJsString()); control.verify(); }
@Before public void setUp() throws GadgetException { control = EasyMock.createControl(); request = control.createMock(JsRequest.class); response = new JsResponseBuilder(); processor = new AddJslLoadedVariableProcessor(fregProvider); EasyMock.reset(fregProvider, freg); EasyMock.expect(fregProvider.get(EasyMock.anyObject(String.class))).andReturn(freg).anyTimes(); Set<String> required = Sets.newHashSet(REQ_LIBS); EasyMock.expect(freg.getAllFeatureNames()).andReturn(required).anyTimes(); EasyMock.replay(fregProvider, freg); }
@Test public void testSkips() throws Exception { setUpJsUri(URI + "?nohint=1"); control.replay(); processor.process(request, response); assertEquals("", response.build().toJsString()); control.verify(); }