ProjectTemplateDescriptionLoader { @PostConstruct public void start() { if (templateDescriptionsDir == null || !Files.exists(Paths.get(templateDescriptionsDir)) || !Files.isDirectory(Paths.get(templateDescriptionsDir))) { LOG.warn("ProjectTemplateDescriptionLoader", "The configuration of project templates descriptors wasn't found or some problem with configuration was found."); for (ProjectType projectType : projectTypes) { load(projectType.getId()); } } else { Path dirPath = Paths.get(templateDescriptionsDir); for (ProjectType projectType : projectTypes) { load(dirPath, projectType.getId()); } } } @Inject  ProjectTemplateDescriptionLoader(); protected  ProjectTemplateDescriptionLoader(String templateDescriptionsDir,
                                               String templateLocationDir,
                                               Set<ProjectType> projectTypes,
                                               ProjectTemplateRegistry templateRegistry); @PostConstruct void start();  }
@Test public void testWithOutConfig() { ProjectTemplateDescriptionLoader loader = new ProjectTemplateDescriptionLoader(null, null, pts, templateRegistry); loader.start(); verify(templateRegistry).register(eq(embedTypeId), anyListOf(ProjectTemplateDescriptor.class)); verify(templateRegistry, never()).register(eq(projectType1), anyListOf(ProjectTemplateDescriptor.class)); verify(templateRegistry, never()).register(eq(projectType2), anyListOf(ProjectTemplateDescriptor.class)); }
@Test public void testWithConfig() { URL resource = Resources.getResource(getClass(), "pt-tmpl"); Path path = Paths.get(URI.create(resource.toString())); Assert.assertNotNull(resource); ProjectTemplateDescriptionLoader loader = new ProjectTemplateDescriptionLoader(path.toString(), null, pts, templateRegistry); loader.start(); verify(templateRegistry, never()).register(eq(embedTypeId), anyListOf(ProjectTemplateDescriptor.class)); verify(templateRegistry).register(eq(projectType1), anyListOf(ProjectTemplateDescriptor.class)); verify(templateRegistry).register(eq(projectType2), anyListOf(ProjectTemplateDescriptor.class)); }
@Test public void testWithConfig2() { ProjectType type3 = mock(ProjectType.class); when(type3.getId()).thenReturn("type3"); pts.add(type3); URL resource = Resources.getResource(getClass(), "pt-tmpl"); Path path = Paths.get(URI.create(resource.toString())); Assert.assertNotNull(resource); ProjectTemplateDescriptionLoader loader = new ProjectTemplateDescriptionLoader(path.toString(), null, pts, templateRegistry); loader.start(); verify(templateRegistry).register(eq(projectType1), anyListOf(ProjectTemplateDescriptor.class)); verify(templateRegistry).register(eq(projectType2), anyListOf(ProjectTemplateDescriptor.class)); verify(templateRegistry, never()).register(eq("type3"), anyListOf(ProjectTemplateDescriptor.class)); }
@Test public void testWithConfigAndReplaceLocations() { ProjectTemplateRegistry templateRegistry = new ProjectTemplateRegistry(); Set<ProjectType> pts = new HashSet<>(); ProjectType type2 = mock(ProjectType.class); when(type2.getId()).thenReturn(projectType2); pts.add(type2); URL resource = Resources.getResource(getClass(), "pt-tmpl"); Path path = Paths.get(URI.create(resource.toString())); Assert.assertNotNull(resource); String location = NameGenerator.generate("location", 5); ProjectTemplateDescriptionLoader loader = new ProjectTemplateDescriptionLoader(path.toString(), location, pts, templateRegistry); loader.start(); List<ProjectTemplateDescriptor> type = templateRegistry.getTemplates(projectType2); Assert.assertNotNull(type); Assert.assertEquals(1, type.size()); ProjectTemplateDescriptor templateDescriptor = type.get(0); Assert.assertNotNull(templateDescriptor); ImportSourceDescriptor source = templateDescriptor.getSource(); Assert.assertNotNull(source); Assert.assertNotNull(source.getLocation()); Assert.assertTrue(source.getLocation().contains(location)); }