use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.
the class TestRunner method main.
public static void main(String[] args) {
if (args.length != 0 && args[0].equals("-help")) {
usage();
return;
}
String runnerDefPath = null;
final List servicePaths = new ArrayList();
boolean validate = false;
boolean verbose = false;
String userId = null;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-verbose")) {
verbose = true;
} else if (args[i].equals("-validate")) {
validate = true;
} else if (args[i].equals("-userId")) {
userId = args[++i];
} else if (runnerDefPath == null) {
runnerDefPath = args[i];
} else {
servicePaths.add(args[i]);
}
}
if (runnerDefPath == null || servicePaths.size() == 0) {
usage();
return;
}
if (userId == null) {
userId = System.getProperty("user.name");
}
try {
for (int i = 0, max = servicePaths.size(); i < max; i++) {
if (!ServiceManagerFactory.loadManager((String) servicePaths.get(i), false, validate)) {
System.exit(-1);
}
}
if (!ServiceManagerFactory.checkLoadManagerCompleted()) {
System.exit(-1);
}
TestController testController = null;
List testReporterList = null;
String phase = null;
Map scenarioGroupMap = new HashMap();
boolean isTest = true;
try {
final InputSource inputSource = new InputSource(new FileInputStream(runnerDefPath));
final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(validate);
final DocumentBuilder builder = domFactory.newDocumentBuilder();
final NimbusEntityResolver resolver = new NimbusEntityResolver();
builder.setEntityResolver(resolver);
final MyErrorHandler handler = new MyErrorHandler();
builder.setErrorHandler(handler);
final Document doc = builder.parse(inputSource);
if (handler.isError()) {
ServiceManagerFactory.getLogger().write("TR___00004", runnerDefPath);
System.exit(-1);
}
final Element root = doc.getDocumentElement();
isTest = MetaData.getOptionalBooleanAttribute(root, "test", true);
final Element controllerElement = MetaData.getOptionalChild(root, "controller");
final String controllerServiceNameStr = controllerElement == null ? "Nimbus#TestController" : MetaData.getElementContent(controllerElement, "Nimbus#TestController");
final ServiceNameEditor editor = new ServiceNameEditor();
editor.setAsText(controllerServiceNameStr);
final ServiceName controllerServiceName = (ServiceName) editor.getValue();
testController = (TestController) ServiceManagerFactory.getServiceObject(controllerServiceName);
final Iterator reporterElements = MetaData.getChildrenByTagName(root, "reporter");
testReporterList = new ArrayList();
if (reporterElements.hasNext()) {
while (reporterElements.hasNext()) {
final Element reporterElement = (Element) reporterElements.next();
final String reporterServiceNameStr = MetaData.getElementContent(reporterElement);
editor.setAsText(reporterServiceNameStr);
final ServiceName reporterServiceName = (ServiceName) editor.getValue();
TestReporter testReporter = (TestReporter) ServiceManagerFactory.getServiceObject(reporterServiceName);
testReporterList.add(testReporter);
}
} else {
editor.setAsText("Nimbus#TestReporter");
final ServiceName reporterServiceName = (ServiceName) editor.getValue();
TestReporter testReporter = (TestReporter) ServiceManagerFactory.getServiceObject(reporterServiceName);
testReporterList.add(testReporter);
}
final Element phaseElement = MetaData.getOptionalChild(root, "phase");
if (phaseElement != null) {
phase = MetaData.getElementContent(phaseElement, null);
}
testController.setTestPhase(phase);
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00005", phase);
}
final Iterator includeElements = MetaData.getChildrenByTagName(root, "include");
if (includeElements.hasNext()) {
while (includeElements.hasNext()) {
final Element includeElement = (Element) includeElements.next();
final Iterator scenarioGroupElements = MetaData.getChildrenByTagName(includeElement, "scenarioGroup");
while (scenarioGroupElements.hasNext()) {
final Element scenarioGroupElement = (Element) scenarioGroupElements.next();
final String scenarioGroupId = MetaData.getUniqueAttribute(scenarioGroupElement, "id");
Map scenarioMap = (Map) scenarioGroupMap.get(scenarioGroupId);
if (scenarioMap == null) {
scenarioMap = new HashMap();
scenarioGroupMap.put(scenarioGroupId, scenarioMap);
}
final Iterator scenarioElements = MetaData.getChildrenByTagName(scenarioGroupElement, "scenario");
if (scenarioElements.hasNext()) {
while (scenarioElements.hasNext()) {
final Element scenarioElement = (Element) scenarioElements.next();
final String scenarioId = MetaData.getUniqueAttribute(scenarioElement, "id");
Set testCaseSet = (Set) scenarioMap.get(scenarioId);
if (testCaseSet == null) {
testCaseSet = new HashSet();
scenarioMap.put(scenarioId, testCaseSet);
}
TestCase[] testCases = testController.getTestCases(scenarioGroupId, scenarioId);
for (int k = 0; k < testCases.length; k++) {
testCaseSet.add(testCases[k].getTestCaseId());
}
}
} else {
TestScenario[] scenarios = testController.getScenarios(scenarioGroupId);
for (int j = 0; j < scenarios.length; j++) {
Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
if (testCaseSet == null) {
testCaseSet = new HashSet();
scenarioMap.put(scenarios[j].getScenarioId(), testCaseSet);
}
TestCase[] testCases = testController.getTestCases(scenarioGroupId, scenarios[j].getScenarioId());
for (int k = 0; k < testCases.length; k++) {
testCaseSet.add(testCases[k].getTestCaseId());
}
}
}
}
}
} else {
TestScenarioGroup[] groups = testController.getScenarioGroups();
for (int i = 0; i < groups.length; i++) {
Map scenarioMap = (Map) scenarioGroupMap.get(groups[i].getScenarioGroupId());
if (scenarioMap == null) {
scenarioMap = new HashMap();
scenarioGroupMap.put(groups[i].getScenarioGroupId(), scenarioMap);
}
TestScenario[] scenarios = testController.getScenarios(groups[i].getScenarioGroupId());
for (int j = 0; j < scenarios.length; j++) {
Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
if (testCaseSet == null) {
testCaseSet = new HashSet();
scenarioMap.put(scenarios[j].getScenarioId(), testCaseSet);
}
TestCase[] testCases = testController.getTestCases(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
for (int k = 0; k < testCases.length; k++) {
testCaseSet.add(testCases[k].getTestCaseId());
}
}
}
}
final Iterator excludeElements = MetaData.getChildrenByTagName(root, "exclude");
while (excludeElements.hasNext()) {
final Element excludeElement = (Element) excludeElements.next();
final Iterator scenarioGroupElements = MetaData.getChildrenByTagName(excludeElement, "scenarioGroup");
while (scenarioGroupElements.hasNext()) {
final Element scenarioGroupElement = (Element) scenarioGroupElements.next();
final String scenarioGroupId = MetaData.getUniqueAttribute(scenarioGroupElement, "id");
Map scenarioMap = (Map) scenarioGroupMap.get(scenarioGroupId);
if (scenarioMap == null) {
continue;
}
final Iterator scenarioElements = MetaData.getChildrenByTagName(scenarioGroupElement, "scenario");
if (scenarioElements.hasNext()) {
while (scenarioElements.hasNext()) {
final Element scenarioElement = (Element) scenarioElements.next();
final String scenarioId = MetaData.getUniqueAttribute(scenarioElement, "id");
scenarioMap.remove(scenarioId);
}
} else {
scenarioGroupMap.remove(scenarioGroupId);
}
}
}
} catch (Exception e) {
ServiceManagerFactory.getLogger().write("TR___00004", runnerDefPath, e);
System.exit(-1);
}
TestScenarioGroup[] groups = null;
try {
groups = testController.getScenarioGroups();
} catch (Exception e) {
// TODO
ServiceManagerFactory.getLogger().write("TR___00006", e);
System.exit(-1);
}
for (int i = 0; i < groups.length; i++) {
Map scenarioMap = (Map) scenarioGroupMap.get(groups[i].getScenarioGroupId());
if (scenarioMap == null) {
continue;
}
try {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00007", groups[i].getScenarioGroupId());
}
if (isTest) {
testController.startScenarioGroup(userId, groups[i].getScenarioGroupId());
if (!groups[i].getStatus().getResult()) {
continue;
}
} else {
testController.downloadTestScenarioGroupResource(groups[i].getScenarioGroupId());
}
TestScenario[] scenarios = testController.getScenarios(groups[i].getScenarioGroupId());
for (int j = 0; j < scenarios.length; j++) {
Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
if (testCaseSet == null) {
continue;
}
try {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00008", scenarios[j].getScenarioId());
}
if (isTest) {
testController.startScenario(userId, scenarios[j].getScenarioId());
if (!scenarios[j].getStatus().getResult()) {
testController.cancelScenario(scenarios[j].getScenarioId());
continue;
}
int defaultTestCaseErrorContinue = scenarios[j].getTestScenarioResource().getErrorContinue();
TestCase[] testCases = testController.getTestCases(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
for (int k = 0; k < testCases.length; k++) {
if (!testCaseSet.contains(testCases[k].getTestCaseId())) {
continue;
}
try {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00009", testCases[k].getTestCaseId());
}
testController.startTestCase(userId, scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
if (testCases[k].getStatus().getResult()) {
testController.endTestCase(scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
} else {
testController.cancelTestCase(scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
}
if (testCases[k].getStatus().getResult()) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00010", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() });
}
} else {
int ErrorContinue = testCases[k].getTestCaseResource().getErrorContinue();
if (!(ErrorContinue == TestResourceBase.CONTINUE_TYPE_TRUE || (ErrorContinue == TestResourceBase.CONTINUE_TYPE_DEFAULT && defaultTestCaseErrorContinue == TestResourceBase.CONTINUE_TYPE_TRUE))) {
break;
}
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00011", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() });
}
}
} catch (Exception e) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00012", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() }, e);
}
continue;
}
}
testController.endScenario(scenarios[j].getScenarioId());
if (verbose) {
if (scenarios[j].getStatus().getResult()) {
ServiceManagerFactory.getLogger().write("TR___00013", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() });
} else {
ServiceManagerFactory.getLogger().write("TR___00014", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() });
}
}
} else {
testController.downloadTestScenarioResource(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
}
} catch (Exception e) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00015", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() }, e);
}
continue;
}
}
if (isTest) {
testController.endScenarioGroup();
}
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00016", groups[i].getScenarioGroupId());
}
} catch (Exception e) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00017", groups[i].getScenarioGroupId(), e);
}
continue;
}
}
// レポート
if (testReporterList != null) {
for (int i = 0; i < testReporterList.size(); i++) {
((TestReporter) testReporterList.get(i)).report(testController);
}
}
} finally {
for (int i = servicePaths.size(); --i >= 0; ) {
ServiceManagerFactory.unloadManager((String) servicePaths.get(i));
}
}
}
use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.
the class SelectableServletFilterInterceptorService method startService.
/**
* サービスの開始処理を行う。<p>
*
* @exception Exception サービスの開始処理に失敗した場合
*/
public void startService() throws Exception {
super.preStartService();
final ServiceNameEditor editor = new ServiceNameEditor();
editor.setServiceManagerName(getServiceManagerName());
if (urlAndInterceptorServiceNameMapping != null && urlAndInterceptorServiceNameMapping.length != 0) {
for (int i = 0; i < urlAndInterceptorServiceNameMapping.length; i++) {
final int index = urlAndInterceptorServiceNameMapping[i].lastIndexOf('=');
if (index == urlAndInterceptorServiceNameMapping[i].length() - 1 || index == -1) {
throw new IllegalArgumentException("Invalid format : " + urlAndInterceptorServiceNameMapping[i]);
}
editor.setAsText(urlAndInterceptorServiceNameMapping[i].substring(index + 1));
urlAndInterceptorServiceNameMap.put(Pattern.compile(urlAndInterceptorServiceNameMapping[i].substring(0, index)), editor.getValue());
}
}
if (uriAndInterceptorServiceNameMapping != null && uriAndInterceptorServiceNameMapping.length != 0) {
for (int i = 0; i < uriAndInterceptorServiceNameMapping.length; i++) {
final int index = uriAndInterceptorServiceNameMapping[i].lastIndexOf('=');
if (index == uriAndInterceptorServiceNameMapping[i].length() - 1 || index == -1) {
throw new IllegalArgumentException("Invalid format : " + uriAndInterceptorServiceNameMapping[i]);
}
editor.setAsText(uriAndInterceptorServiceNameMapping[i].substring(index + 1));
uriAndInterceptorServiceNameMap.put(Pattern.compile(uriAndInterceptorServiceNameMapping[i].substring(0, index)), editor.getValue());
}
}
if (pathAndInterceptorServiceNameMapping != null && pathAndInterceptorServiceNameMapping.length != 0) {
for (int i = 0; i < pathAndInterceptorServiceNameMapping.length; i++) {
final int index = pathAndInterceptorServiceNameMapping[i].lastIndexOf('=');
if (index == pathAndInterceptorServiceNameMapping[i].length() - 1 || index == -1) {
throw new IllegalArgumentException("Invalid format : " + pathAndInterceptorServiceNameMapping[i]);
}
editor.setAsText(pathAndInterceptorServiceNameMapping[i].substring(index + 1));
pathAndInterceptorServiceNameMap.put(Pattern.compile(pathAndInterceptorServiceNameMapping[i].substring(0, index)), editor.getValue());
}
}
}
use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.
the class TestSwingRunner method main.
public static void main(String[] args) throws Exception {
if (args.length != 0 && args[0].equals("-help")) {
usage();
return;
}
final List servicePaths = new ArrayList();
boolean validate = false;
for (int i = 0; i < args.length; i++) {
servicePaths.add(args[i]);
}
if (servicePaths.size() == 0) {
usage();
return;
}
for (int i = 0, max = servicePaths.size(); i < max; i++) {
if (!ServiceManagerFactory.loadManager((String) servicePaths.get(i), false, validate)) {
System.exit(-1);
}
}
if (!ServiceManagerFactory.checkLoadManagerCompleted()) {
System.exit(-1);
}
TestController testController = null;
try {
String controllerServiceNameStr = null;
// コントローラーのサービス名は、とりあえずテストで固定値
if (controllerServiceNameStr == null)
controllerServiceNameStr = "Nimbus#TestController";
final ServiceNameEditor editor = new ServiceNameEditor();
editor.setAsText(controllerServiceNameStr);
final ServiceName controllerServiceName = (ServiceName) editor.getValue();
testController = (TestController) ServiceManagerFactory.getServiceObject(controllerServiceName);
} catch (Exception e) {
ServiceManagerFactory.getLogger().write("TR___00004", e);
System.exit(-1);
}
// GUI を起動
final UserIdInputView view = new UserIdInputView(servicePaths);
view.setTestController(testController);
view.setVisible(true);
view.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
view.setWindowClosed(true);
}
});
while (!view.isWindowClosed()) {
synchronized (view) {
view.wait(1000);
}
}
}
use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.
the class ExceptionHandlerMappingService method startService.
@Override
public void startService() throws Exception {
final ClassLoader loader = NimbusClassLoader.getInstance();
if (exceptionAndHandlerMapping != null) {
exceptionMapForHandler = new ClassMappingTree();
final ServiceNameEditor editor = new ServiceNameEditor();
editor.setServiceManagerName(getServiceManagerName());
final Iterator exNames = exceptionAndHandlerMapping.keySet().iterator();
while (exNames.hasNext()) {
final String exName = (String) exNames.next();
final Class clazz = Class.forName(exName, true, loader);
final String name = (String) exceptionAndHandlerMapping.get(exName);
editor.setAsText(name);
final ServiceName serviceName = (ServiceName) editor.getValue();
exceptionMapForHandler.add(clazz, ServiceManagerFactory.getServiceObject(serviceName));
}
}
if (defaultExceptionHandlerServiceName != null) {
defaultExceptionHandler = (ExceptionHandler) ServiceManagerFactory.getServiceObject(defaultExceptionHandlerServiceName);
}
}
use of jp.ossc.nimbus.beans.ServiceNameEditor in project nimbus by nimbus-org.
the class TestControllerService method loadTestActionResources.
private TestActionContext[] loadTestActionResources(Element element, File targetDir) throws Exception {
List resourceList = new ArrayList();
ServiceNameEditor editor = new ServiceNameEditor();
Iterator actionElements = MetaData.getChildrenByTagName(element, "action");
while (actionElements.hasNext()) {
Element testResourceElement = (Element) actionElements.next();
TestActionContextImpl testActionResource = new TestActionContextImpl();
String id = MetaData.getUniqueAttribute(testResourceElement, "id");
testActionResource.setId(id);
String type = MetaData.getOptionalAttribute(testResourceElement, "type");
if (TestActionContext.TYPE_BEFORE_STR.equals(type)) {
testActionResource.setType(TestActionContext.TYPE_BEFORE);
} else if (TestActionContext.TYPE_ACTION_STR.equals(type)) {
testActionResource.setType(TestActionContext.TYPE_ACTION);
} else if (TestActionContext.TYPE_AFTER_STR.equals(type)) {
testActionResource.setType(TestActionContext.TYPE_AFTER);
} else if (TestActionContext.TYPE_FINALLY_STR.equals(type)) {
testActionResource.setType(TestActionContext.TYPE_FINALLY);
} else {
throw new TestException("This type is not support at Action. type=" + type);
}
String serviceName = MetaData.getUniqueAttribute(testResourceElement, "serviceName");
editor.setAsText(serviceName);
Object testAction = ServiceManagerFactory.getServiceObject((ServiceName) editor.getValue());
testActionResource.setAction(testAction);
if (testAction instanceof TestActionEstimation) {
double cost = ((TestActionEstimation) testAction).getExpectedCost();
if (!Double.isNaN(cost)) {
testActionResource.setExpectedCost(cost);
}
}
String expectedCost = MetaData.getOptionalAttribute(testResourceElement, "expectedCost");
if (expectedCost != null && !"".equals(expectedCost)) {
testActionResource.setExpectedCost(Double.parseDouble(expectedCost));
}
String cost = MetaData.getOptionalAttribute(testResourceElement, "cost");
if (cost != null && !"".equals(cost)) {
testActionResource.setCost(Double.parseDouble(cost));
}
Iterator descriptionElements = MetaData.getChildrenByTagName(testResourceElement, "description");
if (descriptionElements.hasNext()) {
Element descriptionElement = (Element) descriptionElements.next();
String description = MetaData.getElementContent(descriptionElement);
if (description != null && !"".equals(description)) {
testActionResource.setDescription(description.trim());
}
}
Iterator titleElements = MetaData.getChildrenByTagName(testResourceElement, "title");
if (titleElements.hasNext()) {
Element titleElement = (Element) titleElements.next();
String title = MetaData.getElementContent(titleElement);
if (title != null && !"".equals(title)) {
testActionResource.setTitle(title.trim());
}
}
Element resourcesElement = MetaData.getUniqueChild(testResourceElement, "resources");
Iterator resourceElements = MetaData.getChildrenByTagName(resourcesElement, "resource");
List resources = new ArrayList();
while (resourceElements.hasNext()) {
Element resourceElement = (Element) resourceElements.next();
String name = MetaData.getOptionalAttribute(resourceElement, "name");
Reader resource = null;
if (name == null) {
final String resourceStr = MetaData.getElementContent(resourceElement, "");
resource = new RetryReader(new StringReader(resourceStr));
} else {
final File resourceFile = new File(targetDir, name);
final String encoding = MetaData.getOptionalAttribute(resourceElement, "encoding");
resource = getReader(resourceFile, encoding);
}
resources.add(resource);
}
testActionResource.setResources((Reader[]) resources.toArray(new Reader[resources.size()]));
String retryInterval = MetaData.getOptionalAttribute(testResourceElement, "retryInterval");
if (retryInterval != null && !"".equals(retryInterval)) {
testActionResource.setRetryInterval(Long.parseLong(retryInterval));
}
String retryCount = MetaData.getOptionalAttribute(testResourceElement, "retryCount");
if (retryCount != null && !"".equals(retryCount)) {
testActionResource.setRetryCount(Integer.parseInt(retryCount));
}
resourceList.add(testActionResource);
}
return (TestActionContextImpl[]) resourceList.toArray(new TestActionContextImpl[] {});
}
Aggregations