Beispiel #1
0
  @Test
  public void testOtherParentParsysResource() {
    parsysResource =
        context.create().resource(page.getContentResource().getPath() + "/parsysOther");
    par1Resource = context.create().resource(parsysResource.getPath() + "/par1");

    context.request().setAttribute(RA_PARSYS_PARENT_RESOURCE, parsysResource);

    WCMMode.EDIT.toRequest(context.request());
    Parsys parsys = context.request().adaptTo(Parsys.class);

    List<Item> items = parsys.getItems();
    assertEquals(2, items.size());

    Item item1 = items.get(0);
    assertEquals(par1Resource.getPath(), item1.getResourcePath());
    assertNull(item1.getResourceType());
    assertEquals(SECTION_DEFAULT_CLASS_NAME, item1.getCssClassName());
    assertFalse(item1.isNewArea());

    Item item2 = items.get(1);
    assertEquals(NEWAREA_RESOURCE_PATH, item2.getResourcePath());
    assertEquals(FALLBACK_NEWAREA_RESOURCE_TYPE, item2.getResourceType());
    assertEquals(
        NEWAREA_CSS_CLASS_NAME + " " + SECTION_DEFAULT_CLASS_NAME, item2.getCssClassName());
    assertTrue(item2.isNewArea());
  }
 private JSONArray getJsonResult() throws Exception {
   PageListProvider underTest = context.registerInjectActivateService(new PageListProvider());
   underTest.service(context.request(), context.response());
   if (context.response().getStatus() == HttpServletResponse.SC_OK) {
     return new JSONArray(context.response().getOutputAsString());
   } else {
     return null;
   }
 }
  @Test
  public void testEquals() throws Exception {
    Page page1 = context.pageManager().getPage("/content/sample/en");
    Page page2 = context.pageManager().getPage("/content/sample/en");
    Page page3 = context.pageManager().getPage("/content/sample/en/toolbar/profiles");

    assertTrue(page1.equals(page2));
    assertFalse(page1.equals(page3));
  }
  @Test
  public void testWithCurrentResource() throws Exception {
    context.currentResource(
        context.resourceResolver().getResource("/content/sample/en/jcr:content"));

    JSONArray result = getJsonResult();

    assertEquals(2, result.length());
    assertItem(result.getJSONObject(0), "/content/sample/en/page1", "title1");
    assertItem(result.getJSONObject(1), "/content/sample/en/page2", "title2");
  }
  @Before
  public void setup() throws Exception {
    resource = context.create().resource("app/content/any/resource");
    context.addModelsForPackage("com.thoughtworks.www.samples.models");

    String slingId = UUID.randomUUID().toString();
    when(settings.getSlingId()).thenReturn(slingId);

    buttonModel = context.currentResource(resource).adaptTo(ButtonModel.class);
    PrivateAccessor.setField(buttonModel, "settings", settings);
  }
Beispiel #6
0
  @Test
  public void testNewAreaResourceTypeFromCurrentComponent() {
    context.create().resource(RESOURCE_TYPE_SAMPLE);
    context.create().resource(RESOURCE_TYPE_SAMPLE + "/" + NEWAREA_CHILD_NAME);

    WCMMode.EDIT.toRequest(context.request());
    Parsys parsys = context.request().adaptTo(Parsys.class);
    List<Item> items = parsys.getItems();

    Item item3 = items.get(2);
    assertEquals(RESOURCE_TYPE_SAMPLE + "/" + NEWAREA_CHILD_NAME, item3.getResourceType());
  }
    @Override
    public void execute(AemContext context) throws PersistenceException, IOException {

      // call test-specific callback first
      if (testCallback != null) {
        testCallback.execute(context);
      }

      // wcm.io Sling extensions
      MockSlingExtensions.setUp(context);

      // URL handler-specific parameter definitions
      context.registerService(ParameterProvider.class, new UrlHandlerParameterProviderImpl());

      // application provider
      context.registerService(
          ApplicationProvider.class, MockConfig.applicationProvider(APPLICATION_ID, "/content"));

      // configuration finder strategy
      context.registerService(
          ConfigurationFinderStrategy.class,
          MockConfig.configurationFinderStrategyAbsoluteParent(
              APPLICATION_ID, DummyUrlHandlerConfig.SITE_ROOT_LEVEL));

      // wcm.io configuration
      MockConfig.setUp(context);

      // media formats
      context.registerInjectActivateService(new MediaFormatProviderManagerImpl());

      // sling models registration
      context.addModelsForPackage("io.wcm.handler.url");
      context.addModelsForPackage("io.wcm.handler.media");
      context.addModelsForPackage("io.wcm.handler.link");
      context.addModelsForPackage("io.wcm.handler.richtext");

      // create current page in site context
      context.currentPage(
          context.create().page(ROOTPATH_CONTENT, DummyAppTemplate.CONTENT.getTemplatePath()));

      // default site config
      MockConfig.writeConfiguration(
          context,
          ROOTPATH_CONTENT,
          ImmutableValueMap.builder()
              .put(UrlParams.SITE_URL.getName(), "http://www.dummysite.org")
              .put(UrlParams.SITE_URL_SECURE.getName(), "https://www.dummysite.org")
              .put(UrlParams.SITE_URL_AUTHOR.getName(), "https://author.dummysite.org")
              .build());
    }
  @Test
  public void testGetAbsoluteParent() {
    // contract:
    // http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/Page.html#getAbsoluteParent%28int%29

    context.create().page("/content2");
    context.create().page("/content2/sample");
    context.create().page("/content2/sample/en");
    Page testPage = context.create().page("/content2/sample/en/products");

    assertEquals("/content2", testPage.getAbsoluteParent(0).getPath());
    assertEquals("/content2/sample", testPage.getAbsoluteParent(1).getPath());
    assertEquals("/content2/sample/en", testPage.getAbsoluteParent(2).getPath());
    assertEquals("/content2/sample/en/products", testPage.getAbsoluteParent(3).getPath());
    assertNull(testPage.getAbsoluteParent(4));
  }
  @Before
  public void setUp() throws Exception {
    context.load().json("/json-import-samples/content.json", "/content/sample/en");

    Resource resource = this.context.resourceResolver().getResource("/content/sample/en");
    this.page = resource.adaptTo(Page.class);
  }
Beispiel #10
0
  @Test
  public void testEditMode_Customized() {
    when(component.getProperties())
        .thenReturn(
            ImmutableValueMap.builder()
                .put(PN_PARSYS_GENERATE_DEAFULT_CSS, false)
                .put(PN_PARSYS_PARAGRAPH_CSS, "paracss")
                .put(PN_PARSYS_NEWAREA_CSS, "newareacss")
                .put(PN_PARSYS_PARAGRAPH_ELEMENT, "li")
                .put(PN_PARSYS_WRAPPER_ELEMENT, "ul")
                .put(PN_PARSYS_WRAPPER_CSS, "wrappercss")
                .build());

    WCMMode.EDIT.toRequest(context.request());
    Parsys parsys = context.request().adaptTo(Parsys.class);

    assertTrue(parsys.isWrapperElement());
    assertEquals("wrappercss", parsys.getWrapperCss());
    assertEquals("ul", parsys.getWrapperElementName());

    List<Item> items = parsys.getItems();
    assertEquals(3, items.size());

    Item item1 = items.get(0);
    assertEquals(par1Resource.getPath(), item1.getResourcePath());
    assertNull(item1.getResourceType());
    assertNull(item1.getStyle());
    assertEquals("paracss", item1.getCssClassName());
    assertEquals("li", item1.getElementName());
    assertFalse(item1.isNewArea());

    Item item2 = items.get(1);
    assertEquals(par2Resource.getPath(), item2.getResourcePath());
    assertNull(item2.getResourceType());
    assertNull(item2.getStyle());
    assertEquals("paracss", item2.getCssClassName());
    assertEquals("li", item2.getElementName());
    assertFalse(item2.isNewArea());

    Item item3 = items.get(2);
    assertEquals(NEWAREA_RESOURCE_PATH, item3.getResourcePath());
    assertEquals(FALLBACK_NEWAREA_RESOURCE_TYPE, item3.getResourceType());
    assertNull(item3.getStyle());
    assertEquals(NEWAREA_CSS_CLASS_NAME + " newareacss", item3.getCssClassName());
    assertEquals("li", item3.getElementName());
    assertTrue(item3.isNewArea());
  }
  @Test
  public void testWithPredicate() throws Exception {
    context.registerService(PredicateProvider.class, new DummyPredicateProvider());

    context
        .request()
        .setParameterMap(
            ImmutableValueMap.of(
                AbstractPageProvider.RP_PATH,
                "/content/sample/en",
                AbstractPageProvider.RP_PREDICATE,
                DummyPredicateProvider.PREDICATE_PAGENAME_PAGE1));

    JSONArray result = getJsonResult();
    assertEquals(1, result.length());
    assertItem(result.getJSONObject(0), "/content/sample/en/page1", "title1");
  }
 @Test
 public void testInvalidPath() throws Exception {
   context
       .request()
       .setParameterMap(
           ImmutableValueMap.of(AbstractPageProvider.RP_PATH, "/content/sample/en/invalid/path"));
   assertNull(getJsonResult());
 }
Beispiel #13
0
  @Before
  public void setUp() {
    MockSlingExtensions.setUp(context);

    context.addModelsForPackage("io.wcm.wcm.parsys.controller");

    context.request().setAttribute(ComponentContext.CONTEXT_ATTR_NAME, componentContext);
    when(componentContext.getComponent()).thenReturn(component);
    when(component.getPath()).thenReturn(RESOURCE_TYPE_SAMPLE);
    when(component.getProperties()).thenReturn(ImmutableValueMap.of());

    page = context.create().page("/content/page1", "/apps/sample/templates/test1");
    parsysResource = context.create().resource(page.getContentResource().getPath() + "/parsys");
    par1Resource =
        context
            .create()
            .resource(
                parsysResource.getPath() + "/par1",
                ImmutableValueMap.of("sling:resourceType", COMPONENT_PATH_1));
    par2Resource =
        context
            .create()
            .resource(
                parsysResource.getPath() + "/par2",
                ImmutableValueMap.of("sling:resourceType", COMPONENT_PATH_2));

    context.currentResource(parsysResource);
  }
Beispiel #14
0
  @Test
  public void testWcmDisabledMode() {
    WCMMode.DISABLED.toRequest(context.request());
    Parsys parsys = context.request().adaptTo(Parsys.class);

    List<Item> items = parsys.getItems();
    assertEquals(2, items.size());

    Item item1 = items.get(0);
    assertEquals(par1Resource.getPath(), item1.getResourcePath());
    assertNull(item1.getResourceType());
    assertEquals(SECTION_DEFAULT_CLASS_NAME, item1.getCssClassName());
    assertFalse(item1.isNewArea());

    Item item2 = items.get(1);
    assertEquals(par2Resource.getPath(), item2.getResourcePath());
    assertNull(item2.getResourceType());
    assertEquals(SECTION_DEFAULT_CLASS_NAME, item2.getCssClassName());
    assertFalse(item2.isNewArea());
  }
Beispiel #15
0
  @Test
  public void testNewAreaResourceTypeFromSuperComponent() {
    context
        .create()
        .resource(
            RESOURCE_TYPE_SAMPLE,
            ImmutableValueMap.of(
                SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE,
                SUPER_RESOURCE_TYPE_SAMPLE));

    context.create().resource(SUPER_RESOURCE_TYPE_SAMPLE);
    context.create().resource(SUPER_RESOURCE_TYPE_SAMPLE + "/" + NEWAREA_CHILD_NAME);

    WCMMode.EDIT.toRequest(context.request());
    Parsys parsys = context.request().adaptTo(Parsys.class);
    List<Item> items = parsys.getItems();

    Item item3 = items.get(2);
    assertEquals(SUPER_RESOURCE_TYPE_SAMPLE + "/" + NEWAREA_CHILD_NAME, item3.getResourceType());
  }
  @Test
  public void testWithPath() throws Exception {
    context
        .request()
        .setParameterMap(ImmutableValueMap.of(AbstractPageProvider.RP_PATH, "/content/sample/en"));

    JSONArray result = getJsonResult();

    assertEquals(2, result.length());
    assertItem(result.getJSONObject(0), "/content/sample/en/page1", "title1");
    assertItem(result.getJSONObject(1), "/content/sample/en/page2", "title2");
  }
Beispiel #17
0
  @Test
  public void testComponentWithTagDecoration() {

    // prepare tag decoration for one component
    context
        .create()
        .resource(
            "/apps/sample/components/comp1/" + NameConstants.NN_HTML_TAG,
            ImmutableValueMap.of(NameConstants.PN_TAG_NAME, "article", "class", "css1"));

    WCMMode.EDIT.toRequest(context.request());
    Parsys parsys = context.request().adaptTo(Parsys.class);

    List<Item> items = parsys.getItems();
    assertEquals(3, items.size());

    Item item1 = items.get(0);
    assertEquals(par1Resource.getPath(), item1.getResourcePath());
    assertNull(item1.getResourceType());
    assertEquals("css1 section", item1.getCssClassName());
    assertEquals("article", item1.getElementName());
    assertFalse(item1.isNewArea());

    Item item2 = items.get(1);
    assertEquals(par2Resource.getPath(), item2.getResourcePath());
    assertNull(item2.getResourceType());
    assertEquals(SECTION_DEFAULT_CLASS_NAME, item2.getCssClassName());
    assertEquals(DEFAULT_ELEMENT_NAME, item2.getElementName());
    assertFalse(item2.isNewArea());

    Item item3 = items.get(2);
    assertEquals(NEWAREA_RESOURCE_PATH, item3.getResourcePath());
    assertEquals(FALLBACK_NEWAREA_RESOURCE_TYPE, item3.getResourceType());
    assertEquals(
        NEWAREA_CSS_CLASS_NAME + " " + SECTION_DEFAULT_CLASS_NAME, item3.getCssClassName());
    assertEquals(DEFAULT_ELEMENT_NAME, item3.getElementName());
    assertTrue(item3.isNewArea());
  }
Beispiel #18
0
  @Test
  public void testEditMode() {
    WCMMode.EDIT.toRequest(context.request());
    Parsys parsys = context.request().adaptTo(Parsys.class);

    assertFalse(parsys.isWrapperElement());
    assertNull(parsys.getWrapperCss());
    assertEquals(DEFAULT_ELEMENT_NAME, parsys.getWrapperElementName());

    List<Item> items = parsys.getItems();
    assertEquals(3, items.size());

    Item item1 = items.get(0);
    assertEquals(par1Resource.getPath(), item1.getResourcePath());
    assertNull(item1.getResourceType());
    assertNull(item1.getStyle());
    assertEquals(SECTION_DEFAULT_CLASS_NAME, item1.getCssClassName());
    assertEquals(DEFAULT_ELEMENT_NAME, item1.getElementName());
    assertFalse(item1.isNewArea());

    Item item2 = items.get(1);
    assertEquals(par2Resource.getPath(), item2.getResourcePath());
    assertNull(item2.getResourceType());
    assertNull(item2.getStyle());
    assertEquals(SECTION_DEFAULT_CLASS_NAME, item2.getCssClassName());
    assertEquals(DEFAULT_ELEMENT_NAME, item2.getElementName());
    assertFalse(item2.isNewArea());

    Item item3 = items.get(2);
    assertEquals(NEWAREA_RESOURCE_PATH, item3.getResourcePath());
    assertEquals(FALLBACK_NEWAREA_RESOURCE_TYPE, item3.getResourceType());
    assertEquals(NEWAREA_STYLE, item3.getStyle());
    assertEquals(
        NEWAREA_CSS_CLASS_NAME + " " + SECTION_DEFAULT_CLASS_NAME, item3.getCssClassName());
    assertEquals(DEFAULT_ELEMENT_NAME, item3.getElementName());
    assertTrue(item3.isNewArea());
  }
  @Test
  public void testGetLanguage() {
    Page profilesPage = context.pageManager().getPage("/content/sample/en/toolbar/profiles");

    // set language in site root
    ModifiableValueMap props = this.page.getContentResource().adaptTo(ModifiableValueMap.class);
    props.put(JcrConstants.JCR_LANGUAGE, "fr_FR");

    // test get language from content
    Locale locale = profilesPage.getLanguage(false);
    assertEquals(Locale.forLanguageTag("fr-FR"), locale);

    // test get language from path
    locale = profilesPage.getLanguage(true);
    assertEquals(Locale.forLanguageTag("en"), locale);
  }
 @Before
 public void setUp() throws Exception {
   context.create().page("/content/sample/en");
   context.create().page("/content/sample/en/page1", "", "title1");
   context.create().page("/content/sample/en/page2", "", "title2");
 }