Package org.jboss.jopr.jsfunit.as5.jbcache

Source Code of org.jboss.jopr.jsfunit.as5.jbcache.JBossCacheCacheTest

package org.jboss.jopr.jsfunit.as5.jbcache;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTable;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTableRow;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.NavTreeNode;
import org.jboss.jopr.jsfunit.util.SingleProperties;
import org.jboss.jopr.jsfunit.util.ValuesValidator;

/**
*
* @author Ondrej Zizka
*
* JBoss Cache is only present in 'all' JBoss AS profile.
*/
public class JBossCacheCacheTest extends JBossCacheTestBase {



  /**
   * Test the navigation to JBoss Cache nodes.
   */
  public void testJBossCacheParentNode() throws HtmlElementNotFoundException, IOException, EmbJoprTestException {
    if( isJBossConfigWithoutCache() ) return;

    NavTreeNode cachesNode = ejtt.navTree.getNodeByLabel(NAV_JBCACHES);
    assertTrue( "JBoss Caches node has no children.", cachesNode.hasChildren() );
    cachesNode.click();
   
    final String HA_PARTITION = "ha-partition";
    assertTrue("JBoss Caches should list '"+HA_PARTITION+"'", client.getPageAsText().contains(HA_PARTITION) );

    ContentTable table = ejtt.getTabMenu().getTabContentBox().getFirstTable();
   
    // Rows 1+
    List<ContentTableRow> rows = table.getRows();
    assertTrue( "Caches list should contain at least one cache.", rows.size() > 0 );

    // The ha-partition cache is active by default.
    // Check that it's present.
    boolean haparPresent = false;
    // Check that all caches are UP.
    for( ContentTableRow row : rows ){
      String name = row.getCellByColumnName(COL_RESOURCE_NAME).getTextContent().trim();
      String status = row.getCellByColumnName(COL_RESOURCE_STATUS).getTextContent().trim();
      log.info("Cache '"+name+" - status '"+status+"'.");
      if( ! "UP".equals( status ) )
        fail("Cache '"+name+"' is not UP, but '"+status+"'.");
      if( JBCACHE_HA_PARTITION.equals(name) )
        haparPresent = true;
    }
    if( !haparPresent)
      throw new EmbJoprTestException("The '"+JBCACHE_HA_PARTITION+"' cache is not present.");

    // Click on the first row link.
    rows.get(0).getFirstLinkFromColumn(COL_RESOURCE_NAME).click();

    // Check that we got to the Summary page.
    assertTrue("JB Cache's Summary doesn't contain '"+LABEL_GENERAL_PROPERTIES+"' - is the Summary page ok?", client.getPageAsText().contains(LABEL_GENERAL_PROPERTIES));

  }


 
  /**
   * Test the navigation to JBoss Cache nodes.
   */
  public void testJBossCacheNavigation() throws HtmlElementNotFoundException, IOException, EmbJoprTestException {
    if( isJBossConfigWithoutCache() ) return;

    NavTreeNode haparNode = ejtt.getNavTree().getNodeByLabel(JBCACHE_HA_PARTITION);

    // All expected subnodes:
    String[] subnodesNames = new String[]{
      SUBNODE_CACHE,
      SUBNODE_INTERCEPTOR,
      SUBNODE_DATA_CONTAINER,
      SUBNODE_RPC_MANAGER,
      SUBNODE_REGION_MANAGER,
      SUBNODE_TRANSACTION_TABLE
    };


    // Check whether all expected child nodes are present.
    List<String> names = new ArrayList();
    CollectionUtils.addAll(names, subnodesNames);

    // Remove the names which we find.
    haparNode = ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION);
    List<NavTreeNode> children = haparNode.getChildren( /*new NodeFinder() {
      public HtmlTable getNodeElem(EmbJoprTestToolkit ejtt) throws HtmlElementNotFoundException {
        return (HtmlTable) ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).getElement();
      }
    }*/);

    haparNode = ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION);
    for( NavTreeNode node : children ){
      log.info("Found node: "+node.getName());
      names.remove( node.getName() );
    }
    // The remaining names are missing.
    if( names.size() > 0 ){
      throw new EmbJoprTestException("These cache nodes are not present: "+StringUtils.join(names, ", "), this);
    }


    // Click through all the subnodes (exception could occur).
    for( String name : subnodesNames ){
      ejtt.getNavTree().getNodeByLabel(name).click();
    }

  }




  /**
   * JBoss Cache Summary tab.
   */
  public void testJBossCacheSummary() throws EmbJoprTestException, IOException {
    if( isJBossConfigWithoutCache() ) return;

    ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
    ejtt.navTree.getNodeByLabel(SUBNODE_CACHE).click();


    /*
      General Properties
        Name:jboss.cache:config=ha-partition,service=Cache
        Version:--
        Description:JBoss Cache
     */

    /*ContentTable table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_GENERAL_PROPERTIES);
    ContentInfoTable traitsTable = ejtt.getTabMenu().getTabContentBox().getContentInfoTable( table.getElement() );
    Properties props = traitsTable.getProperties();

    assertEquals("Traits - Name", DEFAULT_JBCACHE, props.getProperty("Name"));/**/

    Properties props = new Properties();
    props.setProperty("Name", "Cache");
    ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_GENERAL_PROPERTIES).checkValuesEqual(props);



    /*
      Numeric Metrics
        Name  Value  Description
        Number of Nodes  1  Number of Nodes
     */
    props = new Properties();
    props.setProperty("Number of Nodes", "1");
    ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValuesEqual(props);
   

  }


 
  /**
   * JBoss Cache Metrics tab.
   */
  public void testJBossCacheMetrics() throws HtmlElementNotFoundException, IOException, EmbJoprTestException {
    if( isJBossConfigWithoutCache() ) return;

    ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
    ejtt.navTree.getNodeByLabel(SUBNODE_CACHE).click();

    ejtt.tabMenu.clickMetricsTab();
    assertTrue( "Metrics tab is not active", ejtt.tabMenu.isTabActive(TAB_NAME_METRICS) );

    Properties props = new Properties();
    props.setProperty("Node Locking Scheme", "PESSIMISTIC");
    props.setProperty("Expose Management Statistics?", "true");
    props.setProperty("Register JMX Resource?", "true");
    props.setProperty("Multiplexer Stack", "udp");
    props.setProperty("Cluster Name", "DefaultPartition-HAPartitionCache");
    props.setProperty("Inactive on Startup?", "false");
    props.setProperty("Cache Mode", "REPL_SYNC");
    props.setProperty("Isolation Level", "REPEATABLE_READ");
    //props.setProperty("Replication Version", "3.1.0");
    props.setProperty("Fetch In-Memory State?", "true");
    props.setProperty("Use Replication Queue?", "false");
    props.setProperty("Use Region-Based Marshalling?", "false");
    props.setProperty("Sync Commit Phase?", "false");
    props.setProperty("State", "3");
    props.setProperty("Transaction Manager Lookup Class", "org.jboss.cache.transaction.BatchModeTransactionManagerLookup");
    ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_TRAITS).checkValuesEqual(props);

    props = new SingleProperties("Replication Version", "\\d+.\\d+.\\d+");
    ejtt.getTabMenu().getTabContentBox().getTableUnformatted(LABEL_TRAITS).checkValues(props, ValuesValidator.MATCHES);




    // Numeric metrics
    props = new Properties();
    props.setProperty("Replication Queue Max Elements", "1,000");
    props.setProperty("Number of Attributes", "0");
    props.setProperty("Initial State Retrieval Timeout", "60,000");
    props.setProperty("Replication Queue Interval", "5,000");
    props.setProperty("Lock Acquisition Timeout", "15,000");
    props.setProperty("Number of Nodes", "1");
    props.setProperty("Sync Replication Timeout", "17,500");
    props.setProperty("State Retrieval Timeout", "60,000");
    ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(LABEL_NUMERIC_METRICS).checkValuesEqual(props);
   
  }

 

  /**
   * JBoss Cache Control tab - test operations.
   * Currently only testing whether the operations fails, because the print operations don't return usable information.
   * @see JOPR-319.
   */
  public void testJBossCacheControl() throws HtmlElementNotFoundException, IOException, ActionOutOfSyncException, EmbJoprTestException {
    if( isJBossConfigWithoutCache() ) return;
   

    ejtt.navTree.getNodeByLabel(JBCACHE_HA_PARTITION).expand();
    ejtt.navTree.getNodeByLabel(SUBNODE_CACHE).click();

    ejtt.tabMenu.clickControlTab();
    assertTrue( "Control tab is not active", ejtt.tabMenu.isTabActive(TAB_NAME_CONTROL) );


    // Click some buttons - should not harm.
    ejtt.tabMenu.getTabContentBox().getButtonInputByLabel("Print cache details as HTML.").click();
    ejtt.tabMenu.getTabContentBox().getButtonInputByLabel("Print lock information.").click();
    ejtt.tabMenu.getTabContentBox().getButtonInputByLabel("Print lock info as HTML.").click();
    ejtt.tabMenu.getTabContentBox().getButtonInputByLabel("Print configuration as plain text.").click();
    ejtt.tabMenu.getTabContentBox().getButtonInputByLabel("Print configuration as HTML.").click();

    ejtt.tabMenu.getTabContentBox().getButtonInputByLabel("Stop this cache.").click();
    ejtt.tabMenu.getTabContentBox().getButtonInputByLabel("Start this cache.").click();


    // Now test the operations, one by one.
    Map<String, String> operationsToTest = new HashMap();

    //operationsToTest.put("Print cache details.", "See JOPR-319.");

    operationsToTest.put("Print cache details.", null);
    operationsToTest.put("Print cache details as HTML.", null);
    operationsToTest.put("Print lock information.", null);
    operationsToTest.put("Print lock info as HTML.", null);
    operationsToTest.put("Print configuration as plain text.", null);
    operationsToTest.put("Print configuration as HTML.", null);


    for( String opName : operationsToTest.keySet() ){
      ejtt.operations.testOperation( opName, operationsToTest.get(opName) );
    }

  }



}// class
TOP

Related Classes of org.jboss.jopr.jsfunit.as5.jbcache.JBossCacheCacheTest

TOP
Copyright © 2018 www.massapi.com. 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.