Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first spike of a junit plugin for hawtio for #817 ; we can now visual…
…ise any unit tests found on the classpath
- Loading branch information
Showing
6 changed files
with
186 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
hawtio-web/src/main/webapp/app/junit/html/layoutJUnitTree.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="row-fluid" ng-controller="JUnit.TreeController"> | ||
<div id="tree-container" class="span3"> | ||
<ul id="tree-ctrl" class="nav"> | ||
<li> | ||
<a data-toggle="collapse" data-target="#junittree"> | ||
<span>Unit Tests</span> | ||
</a> | ||
</li> | ||
</ul> | ||
<div id="junittree" class="in collapse"></div> | ||
</div> | ||
|
||
<div class="span9"> | ||
<div id="properties" ng-view></div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>Tests</h1> | ||
|
||
<ul> | ||
<li ng-repeat="test in selectedTests">{{test}}</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @module JUnit | ||
*/ | ||
module JUnit { | ||
|
||
export var log:Logging.Logger = Logger.get("JUnit"); | ||
|
||
export function isJUnitPluginEnabled(workspace:Workspace) { | ||
return getIntrospectorMBean(workspace); | ||
} | ||
|
||
export function getIntrospectorMBean(workspace: Workspace) { | ||
return Core.getMBeanTypeObjectName(workspace, "io.hawt.introspect", "Introspector"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @module JUnit | ||
* @main JUnit | ||
*/ | ||
module JUnit { | ||
var pluginName = 'junit'; | ||
angular.module(pluginName, ['bootstrap', 'ngResource', 'ngGrid', 'datatable', 'hawtioCore']). | ||
config(($routeProvider) => { | ||
$routeProvider. | ||
when('/junit/tests', {templateUrl: 'app/junit/html/tests.html', reloadOnSearch: false}) | ||
}). | ||
run(($location:ng.ILocationService, workspace:Workspace, viewRegistry, layoutFull, helpRegistry) => { | ||
|
||
viewRegistry['junit'] = 'app/junit/html/layoutJUnitTree.html'; | ||
/* | ||
helpRegistry.addUserDoc('junit', 'app/junit/doc/help.md', () => { | ||
return isJUnitPluginEnabled(workspace); | ||
}); | ||
*/ | ||
|
||
workspace.topLevelTabs.push({ | ||
content: "JUnit", | ||
title: "View and run test cases in this process", | ||
isValid: (workspace:Workspace) => isJUnitPluginEnabled(workspace), | ||
href: () => "#/junit/tests" | ||
}); | ||
|
||
/* | ||
workspace.subLevelTabs.push({ | ||
content: '<i class="icon-list-alt"></i> JUnit', | ||
title: "View the logs in this process", | ||
isValid: (workspace:Workspace) => workspace.hasDomainAndProperties('org.fusesource.insight', {type: 'JUnitQuery'}), | ||
href: () => "#/logs" | ||
}); | ||
*/ | ||
}); | ||
|
||
hawtioPluginLoader.addModule(pluginName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
module JUnit { | ||
|
||
export function TreeController($scope, $location:ng.ILocationService, workspace:Workspace, jolokia) { | ||
|
||
var log:Logging.Logger = Logger.get("JUnit"); | ||
|
||
$scope.testClasses = []; | ||
$scope.testClassMap = {}; | ||
|
||
$scope.$on("$routeChangeSuccess", function (event, current, previous) { | ||
// lets do this asynchronously to avoid Error: $digest already in progress | ||
setTimeout(updateSelectionFromURL, 50); | ||
}); | ||
|
||
$scope.$on('jmxTreeUpdated', function () { | ||
reloadTree(); | ||
}); | ||
|
||
function updateSelectionFromURL() { | ||
Jmx.updateTreeSelectionFromURL($location, $("#junittree"), true); | ||
} | ||
|
||
reloadTree(); | ||
|
||
function selectionChanged(data) { | ||
var selectionKey = data ? data.key : null; | ||
log.debug("Selection is now: " + selectionKey); | ||
var selectedTests = $scope.testClasses; | ||
$scope.selectionKey = selectionKey; | ||
if (selectionKey) { | ||
selectedTests = $scope.testClassMap[selectionKey] || [selectionKey]; | ||
} | ||
$scope.selectedTests = selectedTests; | ||
Core.$apply($scope); | ||
} | ||
|
||
function reloadTree() { | ||
var mbean = JUnit.getIntrospectorMBean(workspace); | ||
var domain = "org.unit"; | ||
var rootFolder = new Folder("Test Cases"); | ||
rootFolder.addClass = "testCases"; | ||
rootFolder.typeName = "testCases"; | ||
rootFolder.domain = domain; | ||
rootFolder.key = "all"; | ||
var children = [rootFolder]; | ||
|
||
if (mbean) { | ||
function render(results) { | ||
$scope.testClasses = results; | ||
$scope.testClassMap = {}; | ||
|
||
angular.forEach(results, (className) => { | ||
var paths = className.split("."); | ||
var last = paths.length - 1; | ||
var folder = rootFolder; | ||
var prefix = ""; | ||
for (var i = 0; i < last; i++) { | ||
var path = paths[i]; | ||
if (prefix) { | ||
prefix += "."; | ||
} | ||
prefix += path; | ||
var list = $scope.testClassMap[prefix]; | ||
if (!list) { | ||
list = []; | ||
$scope.testClassMap[prefix] = list; | ||
} | ||
list.push(className); | ||
folder = workspace.folderGetOrElse(folder, path); | ||
folder.key = prefix; | ||
} | ||
var lastPath = paths[last]; | ||
|
||
// lets add the test case... | ||
var testClass = new Folder(lastPath); | ||
testClass.addClass = "testClass"; | ||
testClass.domain = domain; | ||
testClass.key = className; | ||
folder.children.push(testClass); | ||
}); | ||
|
||
Core.$apply($scope); | ||
|
||
var treeElement = $("#junittree"); | ||
Jmx.enableTree($scope, $location, workspace, treeElement, children, true, (selectedNode) => { | ||
var data = selectedNode.data; | ||
//$scope.select(data); | ||
//workspace.updateSelectionNode(data); | ||
selectionChanged(data); | ||
Core.$apply($scope); | ||
}); | ||
// lets do this asynchronously to avoid Error: $digest already in progress | ||
setTimeout(updateSelectionFromURL, 50); | ||
} | ||
|
||
jolokia.execute(mbean, "findJUnitTestClassNames", onSuccess(render)); | ||
} | ||
} | ||
} | ||
} |