NamedViewCache { public void addNamedView(final NamedViewDetail namedViewDetail, final boolean overwrite) throws CacheOperationFailedException { add(namedViewDetail, overwrite, null, null); }  void addNamedView(final NamedViewDetail namedViewDetail, final boolean overwrite); void addNamedView(final NamedViewDetail namedViewDetail, final boolean overwrite, final User user, final String adminAuth); @Deprecated void deleteNamedView(final String name); void deleteNamedView(final String name, final User user); void deleteNamedView(final String name, final User user, final String adminAuth); @Deprecated NamedViewDetail getNamedView(final String name); NamedViewDetail getNamedView(final String name, final User user); NamedViewDetail getNamedView(final String name, final User user, final String adminAuth); @Deprecated CloseableIterable<NamedViewDetail> getAllNamedViews(); CloseableIterable<NamedViewDetail> getAllNamedViews(final User user); CloseableIterable<NamedViewDetail> getAllNamedViews(final User user, final String adminAuth); void clearCache(); void deleteFromCache(final String name); void addToCache(final NamedViewDetail namedView, final boolean overwrite); NamedViewDetail getFromCache(final String name);  }
@Test public void shouldThrowExceptionIfNamedViewAlreadyExists() throws CacheOperationFailedException { cache.addNamedView(standard, false); try { cache.addNamedView(standard, false); fail(EXCEPTION_EXPECTED); } catch (OverwritingException e) { assertTrue(e.getMessage().equals("Cache entry already exists for key: " + STANDARD_VIEW_NAME)); } }
@Test public void shouldThrowExceptionIfUnauthorisedUserTriesToOverwriteView() throws CacheOperationFailedException { cache.addNamedView(alternative, false, standardUser, EMPTY_ADMIN_AUTH); try { cache.addNamedView(standard, true, blankUser, EMPTY_ADMIN_AUTH); } catch (final CacheOperationFailedException e) { assertTrue(e.getMessage().contains("does not have permission to overwrite")); } }
@Test public void shouldAllowUserToAddWithAdminAuth() throws CacheOperationFailedException { cache.addNamedView(alternative, false, advancedUser, EMPTY_ADMIN_AUTH); NamedViewDetail alternativeWithADifferentView = new NamedViewDetail.Builder() .name(ALTERNATIVE_VIEW_NAME) .description("alternative View") .creatorId(standardUser.getUserId()) .view(new View()) .build(); cache.addNamedView(alternativeWithADifferentView, true, userWithAdminAuth, ADMIN_AUTH); }