@Test public void testListKeys() throws Exception { CacheManager cm = lookup(CacheManager.class); PathCache c = cm.getPathCache("test"); c.put("/com/", Boolean.TRUE); c.put("/com/sonatype", Boolean.TRUE); c.put("/com/sonatype/nexus", Boolean.TRUE); Collection<String> keys = c.listKeysInCache(); // NOTE keys are stored with the front and end '/' removed assertTrue("expected key not found, keys are: " + keys, keys.contains("com")); assertTrue("expected key not found, keys are: " + keys, keys.contains("com/sonatype")); assertTrue("expected key not found, keys are: " + keys, keys.contains("com/sonatype/nexus")); }
@Test public void testPathAsKey() throws Exception { CacheManager cm = lookup(CacheManager.class); PathCache c = cm.getPathCache("test"); c.put("/com/", Boolean.TRUE); assertTrue(c.contains("/com/")); assertTrue(c.contains("/com")); assertTrue(c.contains("com")); c.put("/com/sonatype", Boolean.TRUE); assertTrue(c.contains("/com/sonatype/")); assertTrue(c.contains("/com/sonatype")); assertTrue(c.contains("com/sonatype")); assertTrue(c.contains("com/sonatype/")); c.removeWithParents("/com/sonatype/"); assertFalse(c.contains("/com/sonatype/")); assertFalse(c.contains("/com/sonatype")); assertFalse(c.contains("/com/")); assertFalse(c.contains("/com")); }
@Test public void testRemoveWithChildren() throws Exception { CacheManager cm = lookup(CacheManager.class); PathCache c = cm.getPathCache("test"); c.put("/com", Boolean.TRUE); c.put("/com/sonatype", Boolean.TRUE); c.put("/com/sonatype/nexus", Boolean.TRUE); c.put("/org", Boolean.TRUE); c.put("/org/sonatype", Boolean.TRUE); c.put("/org/sonatype/nexus", Boolean.TRUE); boolean removed = c.removeWithChildren("/com"); assertTrue(removed); // this should have removed stuff assertFalse(c.contains("/com/sonatype/nexus")); assertFalse(c.contains("/com/sonatype")); assertFalse(c.contains("/com")); assertTrue(c.contains("/org/sonatype/nexus")); assertTrue(c.contains("/org/sonatype")); assertTrue(c.contains("/org")); removed = c.removeWithChildren("/com"); assertFalse(removed); // this should have removed nothing removed = c.removeWithChildren("/"); assertTrue(removed); // this should have removed everything assertFalse(c.contains("/org/sonatype/nexus")); assertFalse(c.contains("/org/sonatype")); assertFalse(c.contains("/org")); }
@Test public void testRemoveWithParents() throws Exception { CacheManager cm = lookup(CacheManager.class); PathCache c = cm.getPathCache("test"); c.put("/com", Boolean.TRUE); c.put("/com/sonatype", Boolean.TRUE); c.put("/com/sonatype/nexus", Boolean.TRUE); boolean removed = c.removeWithParents("/com/sonatype"); assertEquals(true, removed); assertTrue(c.contains("/com/sonatype/nexus")); assertFalse(c.contains("/com/sonatype")); assertFalse(c.contains("/com")); removed = c.removeWithParents("/com/sonatype/nexus"); assertEquals(true, removed); assertFalse(c.contains("/com/sonatype/nexus")); assertFalse(c.contains("/com/sonatype")); assertFalse(c.contains("/com")); removed = c.removeWithParents("/com/sonatype/nexus"); assertEquals(false, removed); }