summaryrefslogtreecommitdiff
path: root/M4-RCs/qpid/dotnet/Qpid.Integration.Tests/framework/NotApplicableAssertion.csx
blob: 3e3505725ffbbb5133a6cc0092cb1072ca4e26bf (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
/*
 *
 * 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 uk.co.thebadgerset.junit.extensions.util.ParsedProperties;

namespace Apache.Qpid.Integration.Tests.framework
{
    /// <summary>
    /// NotApplicableAssertion is a messaging assertion that can be used when an assertion requested by a test-case is not
    /// applicable to the testing scenario. For example an assertion may relate to AMQP functionality, but a test case may be
    /// being run over a non-AMQP JMS implementation, in which case the request to create the assertion may return this
    /// instead of the proper assertion. The test framework is configurable to quietly drop these assertions, log them
    /// as warnings to the console, or raise them as test failures.
    ///
    /// <p/><table id="crc"><caption>CRC Card</caption>
    /// <tr><th> Responsibilities <th> Collaborations
    /// <tr><td> Quitely pass.
    /// <tr><td> Log a warning.
    /// <tr><td> Raise a test failure.
    /// </table>
    /// </summary>
    public class NotApplicableAssertion : Assertion
    {
        /// <summary> Used for logging to the console. </summary>
        private static ILog console = LogManager.GetLogger("CONSOLE." + NotApplicableAssertion.class.getName());

        /// <summary> The possible behavioural modes of this assertion. </summary>
        private enum Mode
        {
            /// <summary> Quietly ignore the assertion by passing. </summary>
            Quiet,

            /// <summary> Ignore the assertion by passing but log a warning about it. </summary>
            Warn,

            /// <summary> Fail the assertion. </summary>
            Fail;
        }

        /// <summary> The behavioural mode of the assertion. </summary>
        private Mode mode;

        /// <summary>
        /// Creates an assertion that is driven by the value of the 'notApplicableAssertion' property of the test
        /// configuration. Its value should match one of 'quiet', 'warn' or 'fail' and if it does not it is automatically
        /// read as 'fail'.
        /// </summary>
        /// <param name="testProperties"> The test configuration properties. </param>
        public NotApplicableAssertion(ParsedProperties testProperties)
        {
            // Cast the test properties into a typed interface for convenience.
            MessagingTestConfigProperties props = new MessagingTestConfigProperties(testProperties);

            string modeName = props.getNotApplicableAssertionMode();

            if ("quiet".equals(modeName))
            {
                mode = Mode.Quiet;
            }
            else if ("warn".equals(modeName))
            {
                mode = Mode.Warn;
            }
            else
            {
                mode = Mode.Fail;
            }
        }

        /// <summary>
        /// Applies the assertion.
        /// </summary>
        /// <return> <tt>true</tt> if the assertion passes, <tt>false</tt> if it fails. </return>
        public bool apply()
        {
            switch (mode)
            {
            case Quiet:
                return true;

            case Warn:
                console.warn("Warning: Not applicable assertion being ignored.");

                return true;

            case Fail:
            default:
                return false;
            }
        }
    }
}