summaryrefslogtreecommitdiff
path: root/dotnet/Qpid.Integration.Tests/framework/FrameworkBaseCase.cs
blob: 77c1cae0add5d5e21d20f4cbce64830312b6da5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
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
{
    /// <summary>
    /// FrameworkBaseCase provides a starting point for writing test cases against the test framework. Its main purpose is
    /// to provide some convenience methods for testing.
    ///
    /// <p/><table id="crc"><caption>CRC Card</caption>
    /// <tr><th> Responsibilities <th> Collaborations
    /// <tr><td> Create and clean up in-vm brokers on every test case.
    /// <tr><td> Produce lists of assertions from assertion creation calls.
    /// <tr><td> Produce JUnit failures from assertion failures.
    /// <tr><td> Convert failed assertions to error messages.
    /// </table>
    /// </summary>
    public class FrameworkBaseCase //extends AsymptoticTestCase : FrameworkTestContext, SetupTaskAware, BrokerLifecycleAware
    {
        /// <summary> Used for debugging purposes. </summary>
        private static ILog log = LogManager.GetLogger(typeof(FrameworkBaseCase));

        /// <summary> Holds the test sequencer to create and run test circuits with. </summary>
        protected CircuitFactory circuitFactory;// = new LocalCircuitFactory();

        /// <summary> Used to read the tests configurable properties through. </summary>
        protected TestModel testProps;

        /// <summary> A default setup task processor to delegate setup tasks to. </summary>
        //protected SetupTaskHandler taskHandler = new SetupTaskHandler();

        /// <summary> Flag used to track whether the test is in-vm or not. </summary>
        //protected bool isUsingInVM;

        /// <summary> Holds the failure mechanism. </summary>
        //protected CauseFailure failureMechanism = new CauseFailureUserPrompt();

        /*
        /// <summary>
        /// Creates a new test case with the specified name.
        /// </summary>
        /// <param name="name"> The test case name. </param>
        public FrameworkBaseCase(string name) : base(name)
        {            
        }
        */

        /// <summary>
        /// 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.
        /// </summary>
        /// <return> The test case sequencer. </return>
        protected CircuitFactory GetCircuitFactory()
        {
            return circuitFactory;
        }

        /// <summary>
        /// Overrides the default test circuit factory. Test decorators can use this to supply distributed test sequencers or
        /// other test circuit factory specializations.
        /// </summary>
        /// <param name="circuitFactory"> The new test circuit factory. </param>
        public void SetCircuitFactory(CircuitFactory circuitFactory)
        {
            this.circuitFactory = circuitFactory;
        }

        /*
        /// <summary>
        /// Reports the current test case name.
        /// </summary>
        /// <return> The current test case name. </return>
        public TestCaseVector GetTestCaseVector()
        {
            return new TestCaseVector(this.getName(), 0);
        }
        */

        /// <summary>
        /// Reports the current test case parameters.
        /// </summary>
        /// <return> The current test case parameters. </return>
        public TestModel getTestParameters()
        {
            return testProps;
        }

        /// <summary>
        /// Creates a list of assertions.
        /// </summary>
        /// <param name="asserts"> The assertions to compile in a list. </param>
        ///
        /// <return> A list of assertions. </return>
        protected IList<Assertion> AssertionList(params Assertion[] asserts)
        {
            IList<Assertion> result = new List<Assertion>();

            foreach (Assertion assertion in asserts)
            {
                result.Add(assertion);
            }

            return result;
        }

        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="asserts"> The list of failed assertions. </param>
        protected static void AssertNoFailures(List<Assertion> asserts)
        {
            log.Debug("protected void assertNoFailures(List<Assertion> 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);
        }

        /// <summary>
        /// Converts a list of failed assertions into an error message.
        /// </summary>
        /// <param name="asserts"> The failed assertions. </param>
        ///
        /// <return> The error message. </return>
        protected static string AssertionsToString(List<Assertion> asserts)
        {
            string errorMessage = "";

            foreach (Assertion assertion in asserts)
            {
                errorMessage += assertion.ToString() + "\n";
            }

            return errorMessage;
        }

        /// <summary>
        /// Ensures that the in-vm broker is created and initialized.
        /// </summary>
        ///
        /// <exception cref="Exception"> Any exceptions allowed to fall through and fail the test. </exception>
        [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();
        }

        /// <summary> Ensures that the in-vm broker is cleaned up after each test run. </summary>
        [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();
        }

        /*
        /// <summary>
        /// Adds the specified task to the tests setup.
        /// </summary>
        /// <param name="task"> The task to add to the tests setup. </param>
        public void chainSetupTask(Runnable task)
        {
            taskHandler.chainSetupTask(task);
        }
        */

        /*
        /// <summary>
        /// Adds the specified task to the tests tear down.
        /// </summary>
        /// <param name="task"> The task to add to the tests tear down. </param>
        public void chainTearDownTask(Runnable task)
        {
            taskHandler.chainTearDownTask(task);
        }
        */

        /*
        /// <summary>
        /// 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".
        /// </summary>
        /// <param name="methodName"> The name of the JUnit test method. </param>
        ///
        /// <return> The name of the corresponding interop test case. </return>
        public string getTestCaseNameForTestMethod(string methodName)
        {
            return methodName;
        }

        public void setInVmBrokers()
        {
            isUsingInVM = true;
        }

        /// <summary>
        /// Indicates whether or not a test case is using in-vm brokers.
        /// </summary>
        /// <return> <tt>true</tt> if the test is using in-vm brokers, <tt>false</tt> otherwise. </return>
        public bool usingInVmBroker()
        {
            return isUsingInVM;
        }

        /// <summary>
        /// Sets the currently live in-vm broker.
        /// </summary>
        /// <param name="i"> The currently live in-vm broker. </param>
        public void setLiveBroker(int i)
        { }

        /// <summary>
        /// Reports the currently live in-vm broker.
        /// </summary>
        /// <return> The currently live in-vm broker. </return>
        public int getLiveBroker()
        {
            return 0;
        }

        /// <summary>
        /// Accepts a failure mechanism.
        /// </summary>
        /// <param name="failureMechanism"> The failure mechanism. </param>
        public void setFailureMechanism(CauseFailure failureMechanism)
        {
            this.failureMechanism = failureMechanism;
        }
        */
    }
}