private void checkIfExists() { final org.uberfire.java.nio.file.Path pathToModulePom = Paths.convert(moduleRoot).resolve("pom.xml"); if (ioService.exists(pathToModulePom)) { throw new FileAlreadyExistsException(pathToModulePom.toString()); } }
protected KieModule getModule(final Path path) { //We need to create the project.repositories file first otherwise Module resolution fails final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (!ioService.exists(nioPath)) { ioService.createFile(nioPath); } return resourceResolver.resolveModule(path); } }
public void createModuleWhiteList(final Path packageNamesWhiteListPath) { if (ioService.exists(Paths.convert(packageNamesWhiteListPath))) { throw new FileAlreadyExistsException(packageNamesWhiteListPath.toString()); } else { ioService.write(Paths.convert(packageNamesWhiteListPath), ""); } }
@Test public void acquireLockUpdatesSession() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); lockService.acquireLock(path); verify(httpSession).setAttribute(eq(VFSLockServiceImpl.LOCK_SESSION_ATTRIBUTE_NAME), any(Set.class)); }
@Test(expected = FileAlreadyExistsException.class) public void testPackageNameWhiteListFileExists() throws URISyntaxException { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); projectImportsService.saveProjectImports(pathToImports); }
@Override public ModuleRepositories load(final Path path) { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (ioService.exists(nioPath)) { final String content = ioService.readAllString(nioPath); return contentHandler.toModel(content); } else { return create(path); } }
@Override public ProjectRepositories load(final Path path) { final org.uberfire.java.nio.file.Path nioPath = Paths.convert(path); if (ioService.exists(nioPath)) { final String content = ioService.readAllString(nioPath); return contentHandler.toModel(content); } else { return create(path); } }
@Test public void testPackageNameWhiteList() throws URISyntaxException { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); projectImportsService.saveProjectImports(pathToImports); verify(ioService).write(any(org.uberfire.java.nio.file.Path.class), importsArgumentCaptor.capture()); assertExternalDataObjects(importsArgumentCaptor.getValue()); }
public void saveProjectImports(final Path path) { if (ioService.exists(Paths.convert(path))) { throw new FileAlreadyExistsException(path.toString()); } else { ioService.write(Paths.convert(path), projectConfigurationContentHandler.toString(createProjectImports())); } }
@Test public void releaseLockFailsIfLockNotOwned() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); when(ioService.readAllString(any(org.uberfire.java.nio.file.Path.class))).thenReturn("some-other-user"); try { lockService.releaseLock(path); fail("Expected exception on attempt to release lock not owned by user"); } catch (Exception ioe) { // expected } }
@Test public void testEnsurePackageStructureWhenProvidedPackageAlreadyExists() { prepareEnsurePackageTest(); Package existingPackage = mock(Package.class); when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); when(moduleService.resolvePackage(any(Path.class))).thenReturn(existingPackage); Package result = serviceHelper.ensurePackageStructure(module, NEW_PACKAGE_NAME); assertEquals(existingPackage, result); verify(moduleService, never()).newPackage(any(Package.class), anyString()); }
private void mockIoService() { final String artifact = "existentModule"; final String uri = repository.getUri() + fileSystem.getSeparator() + artifact; final Path path = PathFactory.newPath(artifact, uri); doReturn(fileSystem).when(ioService).getFileSystem(any(URI.class)); doReturn(Paths.convert(path)).when(ioService).get(eq(uri)); doReturn(true).when(ioService).exists(eq(Paths.convert(path))); } }
@Test public void testProjectImportsLoad_NotExists() throws URISyntaxException { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); final ProjectImports projectImports = projectImportsService.load(pathToImports); verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), importsArgumentCaptor.capture()); assertExternalDataObjects(importsArgumentCaptor.getValue()); // projects imports need always to contain java.lang.Number // because of the guided rule editor assertTrue(projectImports.getImports().contains(new Import(Number.class))); }
@Test public void retrieveLockInfoForLockedFile() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); when(ioService.readAllString(any(org.uberfire.java.nio.file.Path.class))).thenReturn("some-user"); final LockInfo info = lockService.retrieveLockInfo(path); assertTrue(info.isLocked()); assertEquals("some-user", info.lockedBy()); }
@Test public void retrieveLockInfoForUnlockedFile() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); when(ioService.readAllString(any(org.uberfire.java.nio.file.Path.class))).thenReturn(null); final LockInfo info = lockService.retrieveLockInfo(path); assertFalse(info.isLocked()); assertNull(info.lockedBy()); }
@Test public void retrieveLockInfoNoSuchFileException() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); when(ioService.readAllString(any(org.uberfire.java.nio.file.Path.class))).thenThrow(new NoSuchFileException()); final LockInfo info = lockService.retrieveLockInfo(path); assertFalse(info.isLocked()); assertNull(info.lockedBy()); }
@Test public void releaseLockSucceedsIfLockOwned() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); when(ioService.readAllString(any(org.uberfire.java.nio.file.Path.class))).thenReturn("testUser"); final LockResult result = lockService.releaseLock(path); assertTrue(result.isSuccess()); assertEquals(path, result.getLockInfo().getFile()); assertEquals(null, result.getLockInfo().lockedBy()); assertFalse(result.getLockInfo().isLocked()); }
@Test public void acquireLockFailsIfFileLocked() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); when(ioService.readAllString(any(org.uberfire.java.nio.file.Path.class))).thenReturn("some-other-user"); final LockResult result = lockService.acquireLock(path); assertFalse(result.isSuccess()); assertEquals(path, result.getLockInfo().getFile()); assertEquals("some-other-user", result.getLockInfo().lockedBy()); assertTrue(result.getLockInfo().isLocked()); }
@Test public void acquireLockSucceedsIfFileUnlocked() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); final LockResult result = lockService.acquireLock(path); assertTrue(result.isSuccess()); assertEquals(path, result.getLockInfo().getFile()); assertEquals("testUser", result.getLockInfo().lockedBy()); assertTrue(result.getLockInfo().isLocked()); }
@Test public void releaseLockFailsIfFileUnlocked() { when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); final LockResult result = lockService.releaseLock(path); assertFalse(result.isSuccess()); assertEquals(path, result.getLockInfo().getFile()); assertEquals(null, result.getLockInfo().lockedBy()); assertFalse(result.getLockInfo().isLocked()); }