@Before public void setUp() throws Exception { // Bootstrap WELD container StartMain startMain = new StartMain(new String[0]); beanManager = startMain.go().getBeanManager(); // Instantiate Paths used in tests for Path conversion final Bean pathsBean = (Bean) beanManager.getBeans(Paths.class).iterator().next(); final CreationalContext cc = beanManager.createCreationalContext(pathsBean); paths = (Paths) beanManager.getReference(pathsBean, Paths.class, cc); // Ensure URLs use the default:// scheme fs.forceAsDefault(); }
@Test public void testResolvePackageWithRootPath() throws Exception { final Bean projectServiceBean = (Bean) beanManager.getBeans(ProjectService.class).iterator().next(); final CreationalContext cc = beanManager.createCreationalContext(projectServiceBean); final ProjectService projectService = (ProjectService) beanManager.getReference(projectServiceBean, ProjectService.class, cc); final URL rootUrl = this.getClass().getResource("/ProjectBackendTestProjectStructureValid"); final org.kie.commons.java.nio.file.Path nioRootPath = fs.getPath(rootUrl.toURI()); final Path rootPath = paths.convert(nioRootPath); // Test a root resolves to null final Package result = projectService.resolvePackage(rootPath); assertNull(result); }
@Test public void testResolvePackageNameWithNonProjectPath() throws Exception { final Bean projectServiceBean = (Bean) beanManager.getBeans(ProjectService.class).iterator().next(); final CreationalContext cc = beanManager.createCreationalContext(projectServiceBean); final ProjectService projectService = (ProjectService) beanManager.getReference(projectServiceBean, ProjectService.class, cc); final URL testUrl = this.getClass().getResource("/"); final org.kie.commons.java.nio.file.Path testNioPath = fs.getPath(testUrl.toURI()); final Path testPath = paths.convert(testNioPath); // Test a non-Project Path resolves to null final Package result = projectService.resolvePackage(testPath); assertNull(result); }
@Test public void testResolvePackageDefaultResources() throws Exception { final Bean projectServiceBean = (Bean) beanManager.getBeans(ProjectService.class).iterator().next(); final CreationalContext cc = beanManager.createCreationalContext(projectServiceBean); final ProjectService projectService = (ProjectService) beanManager.getReference(projectServiceBean, ProjectService.class, cc); final URL testUrl = this.getClass().getResource("/ProjectBackendTestProjectStructureValid/src/main/resources"); final org.kie.commons.java.nio.file.Path nioTestPath = fs.getPath(testUrl.toURI()); final Path testPath = paths.convert(nioTestPath); // Test /src/main/resources resolves as the default package final Package result = projectService.resolvePackage(testPath); assertEquals("", result.getPackageName()); }