From 5518fd899d97459bcd8c45b850da447697a60fe8 Mon Sep 17 00:00:00 2001 From: Aidan Skinner Date: Wed, 23 Apr 2008 23:56:38 +0000 Subject: QPID-832 sync from M2.x git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@651113 13f79535-47bb-0310-9956-ffa450edef68 --- .../framework/FrameworkBaseCase.cs | 282 +++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 qpid/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs (limited to 'qpid/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs') diff --git a/qpid/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs b/qpid/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs new file mode 100644 index 0000000000..a7a663e531 --- /dev/null +++ b/qpid/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs @@ -0,0 +1,282 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +using log4net; +using NUnit.Framework; +//using org.apache.log4j.NDC; + +using Apache.Qpid.Integration.Tests.framework.sequencers;//.CircuitFactory; + +//using uk.co.thebadgerset.junit.extensions.AsymptoticTestCase; +//using uk.co.thebadgerset.junit.extensions.SetupTaskAware; +//using uk.co.thebadgerset.junit.extensions.SetupTaskHandler; +//using uk.co.thebadgerset.junit.extensions.util.ParsedProperties; +//using uk.co.thebadgerset.junit.extensions.util.TestContextProperties; + +//using java.util.ArrayList; +using System.Collections.Generic;//.IList; + +namespace Apache.Qpid.Integration.Tests.framework +{ + /// + /// FrameworkBaseCase provides a starting point for writing test cases against the test framework. Its main purpose is + /// to provide some convenience methods for testing. + /// + ///

+ ///
CRC Card
Responsibilities Collaborations + ///
Create and clean up in-vm brokers on every test case. + ///
Produce lists of assertions from assertion creation calls. + ///
Produce JUnit failures from assertion failures. + ///
Convert failed assertions to error messages. + ///
+ ///

+ public class FrameworkBaseCase //extends AsymptoticTestCase : FrameworkTestContext, SetupTaskAware, BrokerLifecycleAware + { + /// Used for debugging purposes. + private static ILog log = LogManager.GetLogger(typeof(FrameworkBaseCase)); + + /// Holds the test sequencer to create and run test circuits with. + protected CircuitFactory circuitFactory;// = new LocalCircuitFactory(); + + /// Used to read the tests configurable properties through. + protected TestModel testProps; + + /// A default setup task processor to delegate setup tasks to. + //protected SetupTaskHandler taskHandler = new SetupTaskHandler(); + + /// Flag used to track whether the test is in-vm or not. + //protected bool isUsingInVM; + + /// Holds the failure mechanism. + //protected CauseFailure failureMechanism = new CauseFailureUserPrompt(); + + /* + /// + /// Creates a new test case with the specified name. + /// + /// The test case name. + public FrameworkBaseCase(string name) : base(name) + { + } + */ + + /// + /// Returns the test case sequencer that provides test circuit, and test sequence implementations. The sequencer + /// that this base case returns by default is suitable for running a test circuit with both circuit ends colocated + /// on the same JVM. + /// + /// The test case sequencer. + protected CircuitFactory GetCircuitFactory() + { + return circuitFactory; + } + + /// + /// Overrides the default test circuit factory. Test decorators can use this to supply distributed test sequencers or + /// other test circuit factory specializations. + /// + /// The new test circuit factory. + public void SetCircuitFactory(CircuitFactory circuitFactory) + { + this.circuitFactory = circuitFactory; + } + + /* + /// + /// Reports the current test case name. + /// + /// The current test case name. + public TestCaseVector GetTestCaseVector() + { + return new TestCaseVector(this.getName(), 0); + } + */ + + /// + /// Reports the current test case parameters. + /// + /// The current test case parameters. + public TestModel getTestParameters() + { + return testProps; + } + + /// + /// Creates a list of assertions. + /// + /// The assertions to compile in a list. + /// + /// A list of assertions. + protected IList AssertionList(params Assertion[] asserts) + { + IList result = new List(); + + foreach (Assertion assertion in asserts) + { + result.Add(assertion); + } + + return result; + } + + /// + /// Generates a JUnit assertion exception (failure) if any assertions are passed into this method, also concatenating + /// all of the error messages in the assertions together to form an error message to diagnose the test failure with. + /// + /// The list of failed assertions. + protected static void AssertNoFailures(List asserts) + { + log.Debug("protected void assertNoFailures(List asserts = " + asserts + "): called"); + + // Check if there are no assertion failures, and return without doing anything if so. + if ((asserts == null) || (asserts.Count == 0)) + { + return; + } + + // Compile all of the assertion failure messages together. + string errorMessage = AssertionsToString(asserts); + + // Fail with the error message from all of the assertions. + Assert.Fail(errorMessage); + } + + /// + /// Converts a list of failed assertions into an error message. + /// + /// The failed assertions. + /// + /// The error message. + protected static string AssertionsToString(List asserts) + { + string errorMessage = ""; + + foreach (Assertion assertion in asserts) + { + errorMessage += assertion.ToString() + "\n"; + } + + return errorMessage; + } + + /// + /// Ensures that the in-vm broker is created and initialized. + /// + /// + /// Any exceptions allowed to fall through and fail the test. + [SetUp] + protected void SetUp() + { + //NDC.Push(Name); + + //testProps = TestContextProperties.getInstance(TestModel.defaults); + + // Process all optional setup tasks. This may include in-vm broker creation, if a decorator has added it. + //taskHandler.runSetupTasks(); + } + + /// Ensures that the in-vm broker is cleaned up after each test run. + [TearDown] + protected void TearDown() + { + //NDC.Pop(); + + // Process all optional tear down tasks. This may include in-vm broker clean up, if a decorator has added it. + //taskHandler.runTearDownTasks(); + } + + /* + /// + /// Adds the specified task to the tests setup. + /// + /// The task to add to the tests setup. + public void chainSetupTask(Runnable task) + { + taskHandler.chainSetupTask(task); + } + */ + + /* + /// + /// Adds the specified task to the tests tear down. + /// + /// The task to add to the tests tear down. + public void chainTearDownTask(Runnable task) + { + taskHandler.chainTearDownTask(task); + } + */ + + /* + /// + /// Should provide a translation from the junit method name of a test to its test case name as known to the test + /// clients that will run the test. The purpose of this is to convert the JUnit method name into the correct test + /// case name to place into the test invite. For example the method "testP2P" might map onto the interop test case + /// name "TC2_BasicP2P". + /// + /// The name of the JUnit test method. + /// + /// The name of the corresponding interop test case. + public string getTestCaseNameForTestMethod(string methodName) + { + return methodName; + } + + public void setInVmBrokers() + { + isUsingInVM = true; + } + + /// + /// Indicates whether or not a test case is using in-vm brokers. + /// + /// true if the test is using in-vm brokers, false otherwise. + public bool usingInVmBroker() + { + return isUsingInVM; + } + + /// + /// Sets the currently live in-vm broker. + /// + /// The currently live in-vm broker. + public void setLiveBroker(int i) + { } + + /// + /// Reports the currently live in-vm broker. + /// + /// The currently live in-vm broker. + public int getLiveBroker() + { + return 0; + } + + /// + /// Accepts a failure mechanism. + /// + /// The failure mechanism. + public void setFailureMechanism(CauseFailure failureMechanism) + { + this.failureMechanism = failureMechanism; + } + */ + } +} \ No newline at end of file -- cgit v1.2.1