@Test public void test() throws Exception { JobCatalogWithTemplates underlying = Mockito.mock(JobCatalogWithTemplates.class); JobCatalogWithTemplates catalog = new PackagedTemplatesJobCatalogDecorator(underlying); JobTemplate classTemplate = catalog.getTemplate(new URI(PackagedTemplatesJobCatalogDecorator.CLASS + ": Assert.assertEquals(classTemplate.getClass(), TestTemplate.class); try { catalog.getTemplate(new URI(PackagedTemplatesJobCatalogDecorator.CLASS + ": Assert.fail(); } catch (SpecNotFoundException exc) { } JobTemplate resourceTemplate = catalog.getTemplate(new URI(PackagedTemplatesJobCatalogDecorator.RESOURCE + ": Assert.assertEquals(resourceTemplate.getClass(), ResourceBasedJobTemplate.class); Assert.assertEquals(resourceTemplate.getRequiredConfigList().size(), 3); URI uri = new URI("scheme: try { catalog.getTemplate(uri); Assert.fail(); } catch (SpecNotFoundException exc) { } Mockito.verify(underlying).getTemplate(uri); }
@Override public JobTemplate getTemplate(URI uri) throws SpecNotFoundException, JobTemplate.TemplateException { if (RESOURCE.equals(uri.getScheme())) { try { URI actualResourceUri = new URI(uri.getPath().substring(1)); return ResourceBasedJobTemplate.forURI(actualResourceUri, this); } catch (URISyntaxException use) { throw new RuntimeException("Error when computing resource path.", use); } catch (IOException ioe) { throw new SpecNotFoundException(uri, ioe); } } else if(CLASS.equals(uri.getScheme())) { try { return ((Class<? extends JobTemplate>) Class.forName(uri.getAuthority())).newInstance(); } catch (ReflectiveOperationException roe) { throw new SpecNotFoundException(uri, roe); } } if (this.underlying != null && this.underlying instanceof JobCatalogWithTemplates) { JobTemplate template = ((JobCatalogWithTemplates) this.underlying).getTemplate(uri); if (template == null) { throw new SpecNotFoundException(uri); } return template; } throw new SpecNotFoundException(uri); }
PackagedTemplatesJobCatalogDecorator implements Decorator, JobCatalogWithTemplates { @Override public JobTemplate getTemplate(URI uri) throws SpecNotFoundException, JobTemplate.TemplateException { if (RESOURCE.equals(uri.getScheme())) { try { URI actualResourceUri = new URI(uri.getPath().substring(1)); return ResourceBasedJobTemplate.forURI(actualResourceUri, this); } catch (URISyntaxException use) { throw new RuntimeException("Error when computing resource path.", use); } catch (IOException ioe) { throw new SpecNotFoundException(uri, ioe); } } else if(CLASS.equals(uri.getScheme())) { try { return ((Class<? extends JobTemplate>) Class.forName(uri.getAuthority())).newInstance(); } catch (ReflectiveOperationException roe) { throw new SpecNotFoundException(uri, roe); } } if (this.underlying != null && this.underlying instanceof JobCatalogWithTemplates) { JobTemplate template = ((JobCatalogWithTemplates) this.underlying).getTemplate(uri); if (template == null) { throw new SpecNotFoundException(uri); } return template; } throw new SpecNotFoundException(uri); } }
PackagedTemplatesJobCatalogDecorator implements Decorator, JobCatalogWithTemplates { @Override public JobTemplate getTemplate(URI uri) throws SpecNotFoundException, JobTemplate.TemplateException { if (RESOURCE.equals(uri.getScheme())) { try { URI actualResourceUri = new URI(uri.getPath().substring(1)); return ResourceBasedJobTemplate.forURI(actualResourceUri, this); } catch (URISyntaxException use) { throw new RuntimeException("Error when computing resource path.", use); } catch (IOException ioe) { throw new SpecNotFoundException(uri, ioe); } } else if(CLASS.equals(uri.getScheme())) { try { return ((Class<? extends JobTemplate>) Class.forName(uri.getAuthority())).newInstance(); } catch (ReflectiveOperationException roe) { throw new SpecNotFoundException(uri, roe); } } if (this.underlying != null && this.underlying instanceof JobCatalogWithTemplates) { JobTemplate template = ((JobCatalogWithTemplates) this.underlying).getTemplate(uri); if (template == null) { throw new SpecNotFoundException(uri); } return template; } throw new SpecNotFoundException(uri); } PackagedTemplatesJobCatalogDecorator();  PackagedTemplatesJobCatalogDecorator(JobCatalog underlying); }
PackagedTemplatesJobCatalogDecorator implements Decorator, JobCatalogWithTemplates { @Override public JobTemplate getTemplate(URI uri) throws SpecNotFoundException, JobTemplate.TemplateException { if (RESOURCE.equals(uri.getScheme())) { try { URI actualResourceUri = new URI(uri.getPath().substring(1)); return ResourceBasedJobTemplate.forURI(actualResourceUri, this); } catch (URISyntaxException use) { throw new RuntimeException("Error when computing resource path.", use); } catch (IOException ioe) { throw new SpecNotFoundException(uri, ioe); } } else if(CLASS.equals(uri.getScheme())) { try { return ((Class<? extends JobTemplate>) Class.forName(uri.getAuthority())).newInstance(); } catch (ReflectiveOperationException roe) { throw new SpecNotFoundException(uri, roe); } } if (this.underlying != null && this.underlying instanceof JobCatalogWithTemplates) { JobTemplate template = ((JobCatalogWithTemplates) this.underlying).getTemplate(uri); if (template == null) { throw new SpecNotFoundException(uri); } return template; } throw new SpecNotFoundException(uri); } PackagedTemplatesJobCatalogDecorator();  PackagedTemplatesJobCatalogDecorator(JobCatalog underlying); @Override Object getDecoratedObject(); @Override JobTemplate getTemplate(URI uri); @Override Collection<JobTemplate> getAllTemplates(); }
PackagedTemplatesJobCatalogDecorator implements Decorator, JobCatalogWithTemplates { @Override public JobTemplate getTemplate(URI uri) throws SpecNotFoundException, JobTemplate.TemplateException { if (RESOURCE.equals(uri.getScheme())) { try { URI actualResourceUri = new URI(uri.getPath().substring(1)); return ResourceBasedJobTemplate.forURI(actualResourceUri, this); } catch (URISyntaxException use) { throw new RuntimeException("Error when computing resource path.", use); } catch (IOException ioe) { throw new SpecNotFoundException(uri, ioe); } } else if(CLASS.equals(uri.getScheme())) { try { return ((Class<? extends JobTemplate>) Class.forName(uri.getAuthority())).newInstance(); } catch (ReflectiveOperationException roe) { throw new SpecNotFoundException(uri, roe); } } if (this.underlying != null && this.underlying instanceof JobCatalogWithTemplates) { JobTemplate template = ((JobCatalogWithTemplates) this.underlying).getTemplate(uri); if (template == null) { throw new SpecNotFoundException(uri); } return template; } throw new SpecNotFoundException(uri); } PackagedTemplatesJobCatalogDecorator();  PackagedTemplatesJobCatalogDecorator(JobCatalog underlying); @Override Object getDecoratedObject(); @Override JobTemplate getTemplate(URI uri); @Override Collection<JobTemplate> getAllTemplates(); static final String RESOURCE; static final String CLASS; }