Package com.foreach.across.modules.web.menu

Examples of com.foreach.across.modules.web.menu.Menu


  @Test
  public void itemBuilder() {
    builder.item( "child", "Child", "url" );

    Menu menu = builder.build();

    assertEquals( 1, menu.size() );
    verify( menu.getFirstItem(), "child", "Child", "url" );

    menu = builder.item( "child" ).title( "test" ).and().build();
    assertEquals( 1, menu.size() );
    verify( menu.getFirstItem(), "child", "test", "url" );
  }
View Full Code Here


  @Test
  public void requestMatcherAttributes() {
    builder.item( "item" ).matchRequests( "/test/", "/other" );

    Menu menu = builder.build();

    Collection<String> matchers = menu.getFirstItem().getAttribute( RequestMenuSelector.ATTRIBUTE_MATCHERS );
    assertEquals( 2, matchers.size() );
    assertTrue( matchers.contains( "/test/" ) );
    assertTrue( matchers.contains( "/other" ) );
  }
View Full Code Here

    builder.item( "2" ).title( "Title two" ).url( "URL two" ).disable();
    builder.item( "3" ).title( "Title three" ).url( "URL three" ).order( 33 ).options( "option-one", "option-two" );
    builder.item( "4" ).title( "Title four" ).group( true ).attribute( "attribute-one", "value" ).attribute(
        "attribute-two", "value2" ).options( "test-option" );

    Menu menu = builder.build();
    assertEquals( 4, menu.size() );

    Menu one = menu.getItems().get( 0 );
    assertEquals( "1", one.getPath() );
    assertEquals( "Title one", one.getTitle() );
    assertEquals( "URL one", one.getUrl() );
    assertFalse( one.isDisabled() );
    assertFalse( one.isGroup() );
    assertTrue( one.getAttributes().isEmpty() );

    Menu two = menu.getItems().get( 1 );
    assertEquals( "2", two.getPath() );
    assertEquals( "Title two", two.getTitle() );
    assertEquals( "URL two", two.getUrl() );
    assertTrue( two.isDisabled() );
    assertFalse( two.isGroup() );
    assertTrue( two.getAttributes().isEmpty() );

    Menu three = menu.getItems().get( 2 );
    assertEquals( "3", three.getPath() );
    assertEquals( "Title three", three.getTitle() );
    assertEquals( "URL three", three.getUrl() );
    assertFalse( three.isDisabled() );
    assertFalse( three.isGroup() );
    assertEquals( 33, three.getOrder() );
    assertEquals( 2, three.getAttributes().size() );
    assertTrue( three.hasAttribute( "option-one" ) );
    assertTrue( three.hasAttribute( "option-two" ) );

    Menu four = menu.getItems().get( 3 );
    assertEquals( "4", four.getPath() );
    assertEquals( "Title four", four.getTitle() );
    assertFalse( four.hasUrl() );
    assertFalse( four.isDisabled() );
    assertTrue( four.isGroup() );
    assertEquals( 3, four.getAttributes().size() );
    assertTrue( four.hasAttribute( "test-option" ) );
    assertEquals( "value", four.getAttribute( "attribute-one" ) );
    assertEquals( "value2", four.getAttribute( "attribute-two" ) );
  }
View Full Code Here

           .and()
           .item( "/news/international", "International news", "intnl" )
           .and()
           .item( "/news/national", "National news", "national" );

    Menu cursor = builder.build();
    assertNotNull( cursor );

    cursor = verify( cursor, "home", "Home", "/home" );
    cursor = verify( cursor.getFirstItem(), "/news", "News", "http://news-section" );

    Menu news = cursor;
    assertTrue( news.isGroup() );
    cursor = verify( news.getItems().get( 0 ), "/news/international", "International news", "intnl" );
    verify( cursor.getFirstItem(), "/news/international/australia", "Australia", "aussies" );

    verify( news.getItems().get( 1 ), "/news/national", "National news", "national" );
  }
View Full Code Here

           .item( "/users/users", "Users" ).and()
           .item( "/loggers", "Loggers" ).and()
           .group( "/administration", "Administration" ).and()
           .item( "/administration/system-info", "System info" );

    Menu menu = builder.build();
    assertEquals( 3, menu.size() );

    Menu administration = menu.getItems().get( 0 );
    verify( administration, "/administration", "Administration", "/administration" );
    verify( administration.getFirstItem(), "/administration/system-info", "System info",
            "/administration/system-info" );

    verify( menu.getItems().get( 1 ), "/loggers", "Loggers", "/loggers" );

    Menu userManagement = menu.getItems().get( 2 );
    verify( userManagement, "/users", "User management", "/users" );
    verify( userManagement.getItems().get( 0 ), "/users/roles", "User roles", "/users/roles" );
    verify( userManagement.getItems().get( 1 ), "/users/users", "Users", "/users/users" );

    builder.move( "/users", "/administration/users" )
           .move( "/loggers", "/administration/loggers" );

    // Items should have been moved, but still the same data
    menu = builder.build();
    assertEquals( 1, menu.size() );

    administration = menu.getItems().get( 0 );
    verify( administration, "/administration", "Administration", "/administration" );
    assertEquals( 3, administration.size() );

    verify( administration.getItems().get( 0 ), "/loggers", "Loggers", "/loggers" );

    verify( administration.getItems().get( 1 ), "/administration/system-info", "System info",
            "/administration/system-info" );

    userManagement = administration.getItems().get( 2 );
    verify( userManagement, "/users", "User management", "/users" );
    verify( userManagement.getItems().get( 0 ), "/users/roles", "User roles", "/users/roles" );
    verify( userManagement.getItems().get( 1 ), "/users/users", "Users", "/users/users" );

    // Moving back should be possible, builder itself should not have been modified by previous build
    builder.undoMove( "/loggers" );

    menu = builder.build();
    assertEquals( 2, menu.size() );

    administration = menu.getItems().get( 0 );
    verify( administration, "/administration", "Administration", "/administration" );
    assertEquals( 2, administration.size() );

    verify( administration.getItems().get( 0 ), "/administration/system-info", "System info",
            "/administration/system-info" );

    userManagement = administration.getItems().get( 1 );
    verify( userManagement, "/users", "User management", "/users" );
    verify( userManagement.getItems().get( 0 ), "/users/roles", "User roles", "/users/roles" );
    verify( userManagement.getItems().get( 1 ), "/users/users", "Users", "/users/users" );

    verify( menu.getItems().get( 1 ), "/loggers", "Loggers", "/loggers" );
  }
View Full Code Here

    assertMenu( menu, "ccc", "aaa", "bbb" );
  }

  @Test
  public void orderedMustBeSetOnAllMenusExplicitly() {
    Menu menu = new Menu( "any" );
    menu.setOrdered( true );

    Menu subMenu = new Menu( "/aaa", "ccc" );
    subMenu.setOrdered( true );
    subMenu.addItem( "111", "333" );
    subMenu.addItem( "222", "222" );
    subMenu.addItem( "333", "111" );
    menu.addItem( subMenu );

    menu.addItem( "/bbb", "aaa" );

    Menu otherSubMenu = new Menu( "/ccc", "bbb" );
    otherSubMenu.addItem( "111", "111" );
    otherSubMenu.addItem( "222", "333" );
    otherSubMenu.addItem( "333", "222" );
    menu.addItem( otherSubMenu );

    menu.sort();

    assertMenu( menu, "ccc", "aaa", "bbb" );
View Full Code Here

    assertMenu( menu.getItems().get( 2 ), "111", "222", "333" );
  }

  @Test
  public void comparatorCanBeInherited() {
    Menu menu = new Menu( "any" );
    menu.setComparator( REVERSE_SORT, true );

    Menu subMenu = new Menu( "/aaa", "ccc" );
    subMenu.addItem( "111", "333" );
    subMenu.addItem( "222", "222" );
    subMenu.addItem( "333", "111" );
    menu.addItem( subMenu );

    menu.addItem( "/bbb", "aaa" );

    Menu otherSubMenu = new Menu( "/ccc", "bbb" );
    otherSubMenu.addItem( "111", "111" );
    otherSubMenu.addItem( "222", "333" );
    otherSubMenu.addItem( "333", "222" );
    menu.addItem( otherSubMenu );

    menu.sort();

    assertMenu( menu, "ccc", "bbb", "aaa" );
View Full Code Here

    assertMenu( menu.getItemWithPath( "/ccc" ), "333", "222", "111" );
  }

  @Test
  public void comparatorCanBeNonInheritable() {
    Menu menu = new Menu( "any" );
    menu.setComparator( REVERSE_SORT, true );

    Menu subMenu = new Menu( "/aaa", "ccc" );
    subMenu.setComparator( Menu.SORT_BY_ORDER_AND_TITLE, false );
    subMenu.addItem( "111", "333" );
    subMenu.addItem( "222", "222" );
    menu.addItem( subMenu );

    Menu subSubMenu = new Menu( "333", "111" );
    subSubMenu.addItem( "111", "111" );
    subSubMenu.addItem( "222", "333" );
    subSubMenu.addItem( "333", "222" );
    subMenu.addItem( subSubMenu );

    menu.addItem( "/bbb", "aaa" );
    menu.addItem( "/ccc", "bbb" );
View Full Code Here

    assertMenu( menu.getItemWithPath( "/aaa" ).getItemWithPath( "333" ), "333", "222", "111" );
  }

  @Test
  public void comparatorIsInheritedUnlessOverruled() {
    Menu menu = new Menu( "any" );
    menu.setComparator( REVERSE_SORT, true );

    Menu subMenu = new Menu( "/aaa", "ccc" );
    subMenu.setComparator( Menu.SORT_BY_ORDER_AND_TITLE, true );
    subMenu.addItem( "111", "333" );
    subMenu.addItem( "222", "222" );
    menu.addItem( subMenu );

    Menu subSubMenu = new Menu( "333", "111" );
    subSubMenu.addItem( "111", "111" );
    subSubMenu.addItem( "222", "333" );
    subSubMenu.addItem( "333", "222" );
    subMenu.addItem( subSubMenu );

    menu.addItem( "/bbb", "aaa" );
    menu.addItem( "/ccc", "bbb" );
View Full Code Here

    assertMenu( menu.getItemWithPath( "/aaa" ).getItemWithPath( "333" ), "111", "222", "333" );
  }

  @Test
  public void orderedHasPriorityOverAComparator() {
    Menu menu = new Menu( "any" );
    menu.setComparator( REVERSE_SORT, true );

    Menu subMenu = new Menu( "/aaa", "ccc" );
    subMenu.setComparator( Menu.SORT_BY_ORDER_AND_TITLE, true );
    subMenu.setOrdered( true );
    subMenu.addItem( "111", "333" );
    subMenu.addItem( "222", "222" );
    menu.addItem( subMenu );

    Menu subSubMenu = new Menu( "333", "111" );
    subSubMenu.addItem( "111", "111" );
    subSubMenu.addItem( "222", "333" );
    subSubMenu.addItem( "333", "222" );
    subMenu.addItem( subSubMenu );

    menu.addItem( "/bbb", "aaa" );
    menu.addItem( "/ccc", "bbb" );
View Full Code Here

TOP

Related Classes of com.foreach.across.modules.web.menu.Menu

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.