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

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


    assertMenu( menu.getItem( Menu.byPath( "/aaa" ) ).getItem( Menu.byPath( "333" ) ), "111", "222", "333" );
  }

  @Test
  public void fixedOrderComparator() {
    Menu menu = new Menu( "any" );
    Menu subMenu = new Menu( "/aaa", "aaa" );
    subMenu.addItem( "111", "111" );
    subMenu.addItem( "222", "222" );
    subMenu.addItem( "333", "333" );
    menu.addItem( subMenu );

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

    Menu other = new Menu( "/ccc", "ccc" );
    other.addItem( "ddd", "fff" );
    other.addItem( "eee", "eee" );
    other.addItem( "fff", "ddd" );
    menu.addItem( other );

    menu.setComparator(
        new FixedMenuOrderComparator( MenuMatchers.pathEquals( "/bbb" ), MenuMatchers.pathMatches( "^/c" ),
                                      MenuMatchers.pathMatches( ".*a.*" ), MenuMatchers.pathEquals( "333" ),
View Full Code Here


public class TestMenu
{
  @Test
  public void parentAndRootValidation() {
    Menu menu = new Menu();
    assertFalse( menu.hasParent() );
    assertTrue( menu.isRoot() );

    Menu sub = menu.addItem( "sub" );
    assertFalse( menu.hasParent() );
    assertTrue( menu.isRoot() );
    assertTrue( sub.hasParent() );
    assertFalse( sub.isRoot() );
    assertSame( menu, sub.getParent() );
    assertSame( menu, sub.getRoot() );

    Menu subsub = sub.addItem( "subsub" );
    assertFalse( menu.hasParent() );
    assertTrue( menu.isRoot() );
    assertTrue( sub.hasParent() );
    assertFalse( sub.isRoot() );
    assertSame( menu, sub.getParent() );
    assertSame( menu, sub.getRoot() );
    assertTrue( subsub.hasParent() );
    assertFalse( subsub.isRoot() );
    assertSame( sub, subsub.getParent() );
    assertSame( menu, sub.getRoot() );
  }
View Full Code Here

    assertSame( menu, sub.getRoot() );
  }

  @Test
  public void menuLevelsAreDynamicallyCalculated() {
    Menu menu = new Menu( "", "" );
    assertEquals( Menu.ROOT_LEVEL, menu.getLevel() );

    Menu item1 = menu.addItem( "path1" );
    Menu item2 = menu.addItem( "path2" );
    Menu subItem1 = item2.addItem( "sub1" );
    Menu subItem2 = item2.addItem( "sub2" );
    Menu subSubItem1 = subItem1.addItem( "subsub1" );
    Menu subSubItem2 = subItem2.addItem( "subsub2" );

    assertEquals( 1, item1.getLevel() );
    assertEquals( 1, item2.getLevel() );
    assertEquals( 2, subItem1.getLevel() );
    assertEquals( 2, subItem2.getLevel() );
    assertEquals( 3, subSubItem1.getLevel() );
    assertEquals( 3, subSubItem2.getLevel() );

    Menu newRoot = new Menu();
    newRoot.addItem( menu );
    assertEquals( Menu.ROOT_LEVEL, newRoot.getLevel() );
    assertEquals( 1, menu.getLevel() );
    assertEquals( 2, item1.getLevel() );
    assertEquals( 2, item2.getLevel() );
    assertEquals( 3, subItem1.getLevel() );
    assertEquals( 3, subItem2.getLevel() );
View Full Code Here

    assertEquals( 4, subSubItem2.getLevel() );
  }

  @Test
  public void sameMenuCanOnlyBelongToSingleMenu() {
    Menu menu = new Menu();

    Menu item = new Menu( "path" );
    assertFalse( item.hasParent() );
    assertNull( item.getParent() );

    menu.addItem( item );
    assertTrue( item.hasParent() );
    assertSame( menu, item.getParent() );

    Menu otherMenu = new Menu();
    boolean failed = false;

    try {
      otherMenu.addItem( item );
    }
    catch ( RuntimeException rte ) {
      failed = true;
    }
View Full Code Here

    assertTrue( failed );
  }

  @Test
  public void removedMenuCanBeAddedToAnotherMenu() {
    Menu menu = new Menu();
    Menu item = new Menu( "sub" );
    Menu subSub = new Menu( "subsub" );

    menu.addItem( item );
    item.addItem( subSub );

    Menu otherMenu = new Menu();
    boolean failed = false;

    try {
      otherMenu.addItem( subSub );
    }
    catch ( RuntimeException rte ) {
      failed = true;
    }

    assertTrue( failed );

    menu.remove( subSub );
    otherMenu.addItem( subSub );

    assertTrue( subSub.hasParent() );
    assertSame( otherMenu, subSub.getParent() );
  }
View Full Code Here

    assertSame( otherMenu, subSub.getParent() );
  }

  @Test
  public void childItemMeansParentIsSelected() {
    Menu menu = new Menu();
    menu.addItem( "path1" );

    Menu item = menu.addItem( "path2" );
    item.addItem( "sub1" );
    Menu subItem = item.addItem( "sub2" );

    subItem.addItem( "subsub1" ).setSelected( true );
    subItem.addItem( "subsub2" );

    assertFalse( menu.getItem( Menu.byPath( "path1" ) ).isSelected() );
    assertTrue( menu.getItemWithPath( "path2" ).isSelected() );
    assertFalse( menu.getItemWithPath( "sub1" ).isSelected() );
    assertTrue( menu.getItemWithPath( "sub2" ).isSelected() );
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.