NamedOperationCache { public void addNamedOperation(final NamedOperationDetail namedOperation, final boolean overwrite, final User user) throws CacheOperationFailedException { add(namedOperation, overwrite, user, null); }  void addNamedOperation(final NamedOperationDetail namedOperation, final boolean overwrite, final User user); void addNamedOperation(final NamedOperationDetail namedOperation, final boolean overwrite, final User user, final String adminAuth); void deleteNamedOperation(final String name, final User user); void deleteNamedOperation(final String name, final User user, final String adminAuth); NamedOperationDetail getNamedOperation(final String name, final User user); NamedOperationDetail getNamedOperation(final String name, final User user, final String adminAuth); CloseableIterable<NamedOperationDetail> getAllNamedOperations(final User user); CloseableIterable<NamedOperationDetail> getAllNamedOperations(final User user, final String adminAuth); void clear(); void deleteFromCache(final String name); void addToCache(final String name, final NamedOperationDetail operation, final boolean overwrite); NamedOperationDetail getFromCache(final String name);  }
@Test public void shouldThrowExceptionIfNamedOperationAlreadyExists() throws CacheOperationFailedException { cache.addNamedOperation(standard, false, standardUser); assertThrows(OverwritingException.class, () -> cache.addNamedOperation(alternative, false, advancedUser)); }
@Test public void shouldThrowExceptionIfNamedOperationIsNull() throws CacheOperationFailedException { assertThrows(CacheOperationFailedException.class, () -> cache.addNamedOperation(null, false, standardUser)); }
@Test public void shouldThrowExceptionIfUnauthorisedUserTriesToOverwriteOperation() throws CacheOperationFailedException { cache.addNamedOperation(alternative, false, advancedUser); assertThrows(CacheOperationFailedException.class, () -> cache.addNamedOperation(standard, true, standardUser)); }
@Test public void shouldAllowAddingWhenUserHasAdminAuth() throws CacheOperationFailedException { cache.addNamedOperation(alternative, false, advancedUser, EMPTY_ADMIN_AUTH); NamedOperationDetail alt = new NamedOperationDetail.Builder() .operationName(alternative.getOperationName()) .description("alt") .creatorId(standardUser.getUserId()) .operationChain(alternativeOpChain) .build(); cache.addNamedOperation(alt, true, userWithAdminAuth, ADMIN_AUTH); }