TemplateManagerImpl implements TemplateManager { @Override public Set<Template> getTemplates() { if ( isCacheUpToDate() ) { return templatesCache; } lock.lock(); try { if ( isCacheUpToDate() ) { return templatesCache; } CloseableHttpClient client = getHttpsClient(); try { HttpGet httpGet = new HttpGet( String.format( "https: CloseableHttpResponse response = client.execute( httpGet ); try { List<Template> freshTemplateList = Lists.newArrayList(); String json = readContent( response ); if ( !StringUtils.isBlank( json ) ) { Set<Template> templates = JsonUtil.fromJson( json, new TypeToken<Set<Template>>() { }.getType() ); freshTemplateList.addAll( templates ); } if ( !CollectionUtil.isCollectionEmpty( freshTemplateList ) ) { lastTemplatesFetchTime = System.currentTimeMillis(); freshTemplateList.sort( ( o1, o2 ) -> { ComparableVersion v1 = new ComparableVersion( o1.getVersion() ); ComparableVersion v2 = new ComparableVersion( o2.getVersion() ); return v2.compareTo( v1 ); } ); templatesCache.clear(); for ( Template template : freshTemplateList ) { if ( template != null && !StringUtils.isBlank( template.getId() ) ) { templatesCache.add( template ); } } } } finally { close( response ); } } catch ( Exception e ) { LOG.error( "Error getting templates from CDN", e ); lastTemplatesFetchErrorTime = System.currentTimeMillis(); } finally { IOUtils.closeQuietly( client ); } } finally { lock.unlock(); } return templatesCache; } TemplateManagerImpl( final IdentityManager identityManager ); @Override void resetTemplateCache(); @Override Set<Template> getTemplates(); @Override Template getTemplate( final String id ); @Override Template getTemplateByName( final String name ); @Override List<Template> getTemplatesByOwner( final String owner ); @Override Template getVerifiedTemplateByName( final String templateName ); @Override List<Template> getOwnTemplates(); String getFingerprint(); String getObtainedCdnToken(); String getTokenRequest(); String obtainCdnToken( final String signedRequest ); boolean isRegisteredWithCdn(); String getOwner( String token );  }
@Test public void testGetTemplates() throws Exception { Set<Template> templates = templateManager.getTemplates(); assertFalse( templates.isEmpty() ); }