### Question:
TemplateLibraryFactory { public TemplateLibrary loadTemplateLibrary(GadgetContext context, Uri uri) throws GadgetException { HttpRequest request = new HttpRequest(uri).setSecurityToken( new AnonymousSecurityToken( "", 0L, context.getUrl().toString())); request.setCacheTtl(300); request.setIgnoreCache(context.getIgnoreCache()); HttpResponse response = pipeline.execute(request); if (response.getHttpStatusCode() != HttpResponse.SC_OK) { int retcode = response.getHttpStatusCode(); if (retcode == HttpResponse.SC_INTERNAL_SERVER_ERROR) { retcode = HttpResponse.SC_BAD_GATEWAY; } throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "Unable to retrieve template library xml. HTTP error " + response.getHttpStatusCode(), retcode); } String content = response.getResponseAsString(); try { String key = null; Element element = null; if (!context.getIgnoreCache()) { key = HashUtil.checksum(CharsetUtil.getUtf8Bytes(content)); element = parsedXmlCache.getElement(key); } if (element == null) { element = XmlUtil.parse(content); if (key != null) { parsedXmlCache.addElement(key, element); } } synchronized(element){ return new XmlTemplateLibrary(uri, element, content); } } catch (XmlException e) { throw new GadgetException(GadgetException.Code.MALFORMED_XML_DOCUMENT, e, HttpResponse.SC_BAD_REQUEST); } } @Inject  TemplateLibraryFactory(RequestPipeline pipeline, CacheProvider cacheProvider); TemplateLibrary loadTemplateLibrary(GadgetContext context, Uri uri);  }### Answer:
@Test public void testTemplateRequestAnonymousSecurityToken() throws GadgetException { CapturingPipeline pipeline = new CapturingPipeline(); TemplateLibraryFactory factory = new TemplateLibraryFactory( pipeline, null ); GadgetContext context = new GadgetContext() { @Override public Uri getUrl() { return SPEC_URL; } @Override public String getContainer() { return "default"; } @Override public boolean getDebug() { return false; } @Override public boolean getIgnoreCache() { return true; } }; factory.loadTemplateLibrary(context, TEMPLATE_URL); assertNotNull( pipeline.request ); SecurityToken st = pipeline.request.getSecurityToken(); assertNotNull( st ); assertTrue( st.isAnonymous() ); assertEquals( SPEC_URL.toString(), st.getAppUrl() ); assertTrue(pipeline.request.getIgnoreCache()); }