@Test public void doAction_noChange() throws PersistenceException, ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException { when(resource.getName()).thenReturn(NEW_NAME); RenameResource action = new RenameResource(resolver, NEW_NAME); action.doAction(resource); verify(session, never()).move(Mockito.anyString(), Mockito.anyString()); }
@Override public String doAction(@Nonnull Resource resource) throws PersistenceException { String path = resource.getPath(); if (resource.getName().equals(newName)) { return "Resource " + path + " already has new name, no renaming done"; } Session session = resourceResolver.adaptTo(Session.class); String newPath = resource.getParent().getPath() + FileSystem.SEPARATOR + newName; try { session.move(path, newPath); } catch (ItemExistsException e) { throw new PersistenceException("Target path already exists", e); } catch (PathNotFoundException e) { throw new PersistenceException("Target path does not exist", e); } catch (VersionException e) { throw new PersistenceException("Version error", e); } catch (RepositoryException e) { throw new PersistenceException("Rename failed", e); } return "Renamed resource " + path + " to " + newName; }
RenameResource implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { String path = resource.getPath(); if (resource.getName().equals(newName)) { return "Resource " + path + " already has new name, no renaming done"; } Session session = resourceResolver.adaptTo(Session.class); String newPath = resource.getParent().getPath() + FileSystem.SEPARATOR + newName; try { session.move(path, newPath); } catch (ItemExistsException e) { throw new PersistenceException("Target path already exists", e); } catch (PathNotFoundException e) { throw new PersistenceException("Target path does not exist", e); } catch (VersionException e) { throw new PersistenceException("Version error", e); } catch (RepositoryException e) { throw new PersistenceException("Rename failed", e); } return "Renamed resource " + path + " to " + newName; } }
RenameResource implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { String path = resource.getPath(); if (resource.getName().equals(newName)) { return "Resource " + path + " already has new name, no renaming done"; } Session session = resourceResolver.adaptTo(Session.class); String newPath = resource.getParent().getPath() + FileSystem.SEPARATOR + newName; try { session.move(path, newPath); } catch (ItemExistsException e) { throw new PersistenceException("Target path already exists", e); } catch (PathNotFoundException e) { throw new PersistenceException("Target path does not exist", e); } catch (VersionException e) { throw new PersistenceException("Version error", e); } catch (RepositoryException e) { throw new PersistenceException("Rename failed", e); } return "Renamed resource " + path + " to " + newName; } RenameResource(@Nonnull ResourceResolver resourceResolver, @Nonnull String newName); }
RenameResource implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { String path = resource.getPath(); if (resource.getName().equals(newName)) { return "Resource " + path + " already has new name, no renaming done"; } Session session = resourceResolver.adaptTo(Session.class); String newPath = resource.getParent().getPath() + FileSystem.SEPARATOR + newName; try { session.move(path, newPath); } catch (ItemExistsException e) { throw new PersistenceException("Target path already exists", e); } catch (PathNotFoundException e) { throw new PersistenceException("Target path does not exist", e); } catch (VersionException e) { throw new PersistenceException("Version error", e); } catch (RepositoryException e) { throw new PersistenceException("Rename failed", e); } return "Renamed resource " + path + " to " + newName; } RenameResource(@Nonnull ResourceResolver resourceResolver, @Nonnull String newName); @Override String doAction(@Nonnull Resource resource); }
RenameResource implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { String path = resource.getPath(); if (resource.getName().equals(newName)) { return "Resource " + path + " already has new name, no renaming done"; } Session session = resourceResolver.adaptTo(Session.class); String newPath = resource.getParent().getPath() + FileSystem.SEPARATOR + newName; try { session.move(path, newPath); } catch (ItemExistsException e) { throw new PersistenceException("Target path already exists", e); } catch (PathNotFoundException e) { throw new PersistenceException("Target path does not exist", e); } catch (VersionException e) { throw new PersistenceException("Version error", e); } catch (RepositoryException e) { throw new PersistenceException("Rename failed", e); } return "Renamed resource " + path + " to " + newName; } RenameResource(@Nonnull ResourceResolver resourceResolver, @Nonnull String newName); @Override String doAction(@Nonnull Resource resource);  }