コード例 #1
0
 @Test
 public void testSingleReferenceToaPage() throws Exception {
   List<Reference> actual = instance.findReferences(resource);
   assertNotNull(actual);
   assertEquals(1, actual.size());
   assertEquals("geometrixx (Page)", actual.get(0).getName());
 }
コード例 #2
0
  @Test
  public void testManyReferenceToSinglePages() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    String path = "/content/geometrixx/en";
    String path1 = "/content/geometrixx/en";
    map.put("path", path);
    map.put("path1", path1);
    ValueMap vm = new ValueMapDecorator(map);
    when(resource.getValueMap()).thenReturn(vm);
    when(resource.getResourceResolver()).thenReturn(resolver);
    when(resolver.getResource(path)).thenReturn(res);
    when(resolver.getResource(path1)).thenReturn(res1);
    when(res.adaptTo(Page.class)).thenReturn(referredpage);
    when(res1.adaptTo(Page.class)).thenReturn(referredpage);
    when(referredpage.getName()).thenReturn("geometrixx");
    when(referredpage1.getName()).thenReturn("geometrixx");
    when(referredpage1.getPath()).thenReturn(path1);
    when(manager.getContainingPage(path1)).thenReturn(referredpage1);
    Calendar cal = GregorianCalendar.getInstance();
    when(referredpage.getLastModified()).thenReturn(cal);
    when(referredpage1.getLastModified()).thenReturn(cal);
    List<Reference> actual = instance.findReferences(resource);

    assertNotNull(actual);
    assertEquals(1, actual.size());
    assertEquals("geometrixx (Page)", actual.get(0).getName());
  }
コード例 #3
0
  @Test
  public void testMultipleReferencesReferenceToPages() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    String path = "\"/content/geometrixx/en\",\"/content/geometrixx/en/toolbar\"";
    String path1 = "/content/geometrixx/en/toolbar";
    map.put("path", path);
    // map.put("path1", path1);
    ValueMap vm = new ValueMapDecorator(map);
    when(resource.getValueMap()).thenReturn(vm);
    when(resource.getResourceResolver()).thenReturn(resolver);
    when(resolver.getResource(path)).thenReturn(res);
    when(resolver.getResource(path1)).thenReturn(res1);
    when(res.adaptTo(Page.class)).thenReturn(referredpage);
    when(res1.adaptTo(Page.class)).thenReturn(referredpage1);
    when(referredpage.getName()).thenReturn("geometrixx");
    when(referredpage1.getName()).thenReturn("geometrixx1");
    when(referredpage1.getPath()).thenReturn(path1);
    when(manager.getContainingPage(path1)).thenReturn(referredpage1);
    Calendar cal = GregorianCalendar.getInstance();
    when(referredpage.getLastModified()).thenReturn(cal);
    when(referredpage1.getLastModified()).thenReturn(cal);
    List<Reference> actual = instance.findReferences(resource);

    assertNotNull(actual);
    assertEquals(2, actual.size());

    boolean geometrixxFound = false;
    boolean geometrixxOneFound = false;
    for (Reference ref : actual) {
      if (ref.getName().equals("geometrixx (Page)")) {
        geometrixxFound = true;
      } else if (ref.getName().equals("geometrixx1 (Page)")) {
        geometrixxOneFound = true;
      }
    }

    assertTrue(geometrixxFound);
    assertTrue(geometrixxOneFound);
  }