Skip to content

Commit

Permalink
Merge pull request #123 from utPLSQL/feature/issue-65-hierarchical-view
Browse files Browse the repository at this point in the history
#65 - Alternative hierarchical view
  • Loading branch information
PhilippSalvisberg committed Jan 3, 2021
2 parents 8dfb38f + 4d28aa9 commit 32ef3e1
Show file tree
Hide file tree
Showing 37 changed files with 1,960 additions and 322 deletions.
Binary file modified images/runner_model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 48 additions & 2 deletions sqldev/src/main/java/org/utplsql/sqldev/model/StringTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
*/
package org.utplsql.sqldev.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.utplsql.sqldev.exception.GenericRuntimeException;

public class StringTools {
// do not instantiate this class
private StringTools() {
Expand All @@ -38,11 +43,11 @@ public static String getCSV(List<String> list, String indent) {
sb.append("\n");
return sb.toString();
}

public static String getCSV(List<String> list, int indentSpaces) {
return getCSV(list, repeat(" ", indentSpaces));
}

public static String getSimpleCSV(List<String> list) {
final StringBuilder sb = new StringBuilder();
for (final String item : list) {
Expand Down Expand Up @@ -74,4 +79,45 @@ public static String formatDateTime(final String dateTime) {
}
}
}

public static String millisToDateTimeString(long millis) {
final Date dateTime = new Date(millis);
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'000'");
return df.format(dateTime);
}

public static String getSysdate() {
return millisToDateTimeString(System.currentTimeMillis());
}

public static long dateTimeStringToMillis(final String dateTime) {
// handle milliseconds separately since they get lost (rounded) when converted to date
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date;
try {
date = df.parse(dateTime.substring(0, 20));
} catch (ParseException e) {
throw new GenericRuntimeException("cannot parse datetime string " + dateTime + ".", e);
}
long millis = Long.parseLong(dateTime.substring(20, 23));
return date.getTime() + millis;
}

public static double elapsedTime(String startDateTime, String endDateTime) {
double start = (double) dateTimeStringToMillis(startDateTime);
double end = (double) dateTimeStringToMillis(endDateTime);
return (end - start) / 1000;
}

public static boolean isNotBlank(String value) {
return value != null && !value.trim().isEmpty();
}

public static String trim(String value) {
if (value == null) {
return null;
}
return value.trim();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static PreferenceModel getInstance(final PropertyStorage prefs) {
private static final String KEY_SHOW_DISABLED_TESTS = "showDisabledTests";
private static final String KEY_SHOW_TEST_DESCRIPTION = "showTestDescription";
private static final String KEY_SYNC_DETAIL_TAB = "syncDetailTab";
private static final String KEY_SHOW_SUITES = "showSuites";
private static final String KEY_TEST_PACKAGE_PREFIX = "testPackagePrefix";
private static final String KEY_TEST_PACKAGE_SUFFIX = "testPackageSuffix";
private static final String KEY_TEST_UNIT_PREFIX = "testUnitPrefix";
Expand Down Expand Up @@ -88,6 +89,7 @@ public String toString() {
.append(KEY_SHOW_DISABLED_TESTS, isShowDisabledTests())
.append(KEY_SHOW_TEST_DESCRIPTION, isShowTestDescription())
.append(KEY_SYNC_DETAIL_TAB, isSyncDetailTab())
.append(KEY_SHOW_SUITES, isShowSuites())
.append(KEY_TEST_PACKAGE_PREFIX, getTestPackagePrefix())
.append(KEY_TEST_PACKAGE_SUFFIX, getTestPackageSuffix())
.append(KEY_TEST_UNIT_PREFIX, getTestUnitPrefix())
Expand Down Expand Up @@ -241,6 +243,14 @@ public void setSyncDetailTab(final boolean syncDetailTab) {
getHashStructure().putBoolean(KEY_SYNC_DETAIL_TAB, syncDetailTab);
}

public boolean isShowSuites() {
return getHashStructure().getBoolean(KEY_SHOW_SUITES, true);
}

public void setShowSuites(final boolean showSuites) {
getHashStructure().putBoolean(KEY_SHOW_SUITES, showSuites);
}

public String getTestPackagePrefix() {
return getHashStructure().getString(KEY_TEST_PACKAGE_PREFIX, "test_");
}
Expand Down
81 changes: 81 additions & 0 deletions sqldev/src/main/java/org/utplsql/sqldev/model/runner/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
*/
package org.utplsql.sqldev.model.runner;

import javax.swing.Icon;

import org.springframework.core.style.ToStringCreator;
import org.utplsql.sqldev.model.JsonToStringStyler;
import org.utplsql.sqldev.resources.UtplsqlResources;

public abstract class Item {
private String id;
private String name;
private String description;
private String startTime;
private String endTime;
private Double executionTime;
Expand All @@ -36,15 +41,75 @@ public Item() {
public String toString() {
return new ToStringCreator(this, JsonToStringStyler.getInstance())
.append("id", id)
.append("name", name)
.append("description", description)
.append("startTime", startTime)
.append("endTime", endTime)
.append("executionTime", executionTime)
.append("counter", counter)
.append("errorStack", errorStack)
.append("serverOutput", serverOutput)
.append("warnings", warnings)
.append("parentId", getParentId())
.append("statusIcon", getStatusIcon())
.append("warningIcon", getWarningIcon())
.append("infoIcon", getInfoIcon())
.toString();
}

public String getParentId() {
// Works only if id (suitepath) is build based on names delimited with a period
// that's expected for real utPLSQL runs, but may fail for artificial runs.
// Returning null is valid, it means this item has no parent and as a
// consequence it will be shown on the top level in the runner.
// A key is required to identify an item since suites can be delivered
// multiple times, e.g. when running a chosen list of tests. This way
// the tests will shown at the right position in the tree, regardless of the call
// parameters.
if (name != null && id != null && name.length() < id.length() && id.endsWith(name)) {
return id.substring(0, id.length() - name.length() - 1);
}
return null;
}

public Icon getStatusIcon() {
Icon icon = null;
if (getStartTime() != null && getEndTime() == null) {
icon = UtplsqlResources.getIcon("PROGRESS_ICON");
} else {
if (getCounter() != null) {
// Escalation logic as for the color of the progress bar.
// A suite with errors or failed tests cannot be considered successful,
// even if some tests completed successfully.
if (getCounter().getError() > 0) {
icon = UtplsqlResources.getIcon("ERROR_ICON");
} else if (getCounter().getFailure() > 0) {
icon = UtplsqlResources.getIcon("FAILURE_ICON");
} else if (getCounter().getSuccess() > 0) {
icon = UtplsqlResources.getIcon("SUCCESS_ICON");
} else if (getCounter().getDisabled() > 0) {
icon = UtplsqlResources.getIcon("DISABLED_ICON");
}
}
}
return icon;
}

public Icon getWarningIcon() {
Icon icon = null;
if (getCounter() != null && getCounter().getWarning() > 0) {
icon = UtplsqlResources.getIcon("WARNING_ICON");
}
return icon;
}

public Icon getInfoIcon() {
Icon icon = null;
if (getServerOutput() != null && getServerOutput().length() > 0) {
icon = UtplsqlResources.getIcon("INFO_ICON");
}
return icon;
}

public String getId() {
return id;
Expand All @@ -54,6 +119,22 @@ public void setId(final String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(final String description) {
this.description = description;
}

public String getStartTime() {
return startTime;
}
Expand Down
Loading

0 comments on commit 32ef3e1

Please sign in to comment.