1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2019, Red Hat Inc. All rights reserved.
   4  *
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * The contents of this file are subject to the terms of either the Universal Permissive License
   8  * v 1.0 as shown at http://oss.oracle.com/licenses/upl
   9  *
  10  * or the following license:
  11  *
  12  * Redistribution and use in source and binary forms, with or without modification, are permitted
  13  * provided that the following conditions are met:
  14  *
  15  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions
  16  * and the following disclaimer.
  17  *
  18  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
  19  * conditions and the following disclaimer in the documentation and/or other materials provided with
  20  * the distribution.
  21  *
  22  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to
  23  * endorse or promote products derived from this software without specific prior written permission.
  24  *
  25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  28  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  32  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33  */
  34 
  35 package org.openjdk.jmc.flightrecorder.uitest.pages;
  36 
  37 import static org.junit.Assert.assertEquals;
  38 
  39 import java.util.List;
  40 
  41 import org.openjdk.jmc.common.IDisplayable;
  42 import org.openjdk.jmc.common.unit.ITypedQuantity;
  43 import org.openjdk.jmc.common.unit.LinearUnit;
  44 import org.openjdk.jmc.common.unit.UnitLookup;
  45 import org.openjdk.jmc.flightrecorder.ui.common.DurationPercentileTable;
  46 import org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages;
  47 import org.openjdk.jmc.test.jemmy.MCJemmyTestBase;
  48 import org.openjdk.jmc.test.jemmy.misc.wrappers.MCTable;
  49 import org.openjdk.jmc.test.jemmy.misc.wrappers.MCTable.TableRow;
  50 
  51 public abstract class IOPageTestBase extends MCJemmyTestBase {
  52 
  53         private static final String PERCENTILE_COL = Messages.DurationPercentileTable_PERCENTILE_COL_NAME;
  54         private static final double[] PERCENTILES = { 0.0, 90.0, 99.0, 99.9, 99.99, 99.999, 100.0 };
  55 
  56         protected void checkPercentileTable(String readCol, String readCountCol, String writeCol, String writeCountCol, long[][] tableValues) {
  57                 MCTable table = MCTable.getByName(DurationPercentileTable.TABLE_NAME);
  58                 List<TableRow> rows = table.getRows();
  59                 assertEquals(PERCENTILES.length, rows.size());
  60 
  61                 int index = 0;
  62                 for (TableRow row : rows) {
  63                         ITypedQuantity<LinearUnit> expectedPercentile = UnitLookup.NUMBER_UNITY.quantity(PERCENTILES[index]);
  64                         assertEquals(expectedPercentile.displayUsing(IDisplayable.EXACT), row.getText(PERCENTILE_COL));
  65 
  66                         long[] rawRowValues = tableValues[index];
  67                         assertEquals(getExpectedDuration(rawRowValues[0]), row.getText(readCol));
  68                         assertEquals(getExpectedCount(rawRowValues[1]), row.getText(readCountCol));
  69                         assertEquals(getExpectedDuration(rawRowValues[2]), row.getText(writeCol));
  70                         assertEquals(getExpectedCount(rawRowValues[3]), row.getText(writeCountCol));
  71                         index++;
  72                 }
  73         }
  74 
  75         private String getExpectedDuration(long rawValue) {
  76                 ITypedQuantity<LinearUnit> expectedDuration = UnitLookup.NANOSECOND.quantity(rawValue);
  77                 return expectedDuration.displayUsing(IDisplayable.AUTO);
  78         }
  79 
  80         private String getExpectedCount(long rawValue) {
  81                 ITypedQuantity<LinearUnit> expectedDuration = UnitLookup.NUMBER_UNITY.quantity(rawValue);
  82                 return expectedDuration.displayUsing(IDisplayable.AUTO);
  83         }
  84 
  85 }