82f46c04abadb502b6cb63d5d23a9ec6b3957af1
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.testsuites.integration.common.testclasses;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.fail;
26
27 import org.junit.Test;
28 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
29
30 /**
31  * Test the ping test class.
32  */
33 public class TestPingClassTest {
34     @Test
35     public void testPingClass() {
36         PingTestClass ptc = new PingTestClass();
37
38         ptc.setName("Hello");
39         assertEquals("Hello", ptc.getName());
40
41         ptc.setDescription("Good Day");
42         assertEquals("Good Day", ptc.getDescription());
43
44         ptc.setPingTime(0);
45         assertEquals(0, ptc.getPingTime());
46
47         ptc.setPongTime(-1);
48         assertEquals(-1, ptc.getPongTime());
49
50         try {
51             ptc.verify();
52             fail("test should throw an exception");
53         } catch (ApexException ae) {
54             assertEquals("TestPing is not valid, name does not start with \"Rose\"", ae.getMessage());
55         }
56
57         ptc.setName(null);
58         try {
59             ptc.verify();
60             fail("test should throw an exception");
61         } catch (ApexException ae) {
62             assertEquals("TestPing is not valid, name length null or less than 4", ae.getMessage());
63         }
64
65         ptc.setName("Ros");
66         try {
67             ptc.verify();
68             fail("test should throw an exception");
69         } catch (ApexException ae) {
70             assertEquals("TestPing is not valid, name length null or less than 4", ae.getMessage());
71         }
72
73         ptc.setName("Rose");
74         try {
75             ptc.verify();
76             fail("test should throw an exception");
77         } catch (ApexException ae) {
78             assertEquals("TestPing is not valid, description length null or less than 44", ae.getMessage());
79         }
80
81         ptc.setDescription(null);
82         try {
83             ptc.verify();
84             fail("test should throw an exception");
85         } catch (ApexException ae) {
86             assertEquals("TestPing is not valid, description length null or less than 44", ae.getMessage());
87         }
88
89         ptc.setDescription("A rose by any other name would smell as swee");
90         try {
91             ptc.verify();
92             fail("test should throw an exception");
93         } catch (ApexException ae) {
94             assertEquals("TestPing is not valid, description length null or less than 44", ae.getMessage());
95         }
96
97         ptc.setDescription("A rose by any other name would smell as swell");
98         try {
99             ptc.verify();
100             fail("test should throw an exception");
101         } catch (ApexException ae) {
102             assertEquals("TestPing is not valid, description is incorrect", ae.getMessage());
103         }
104
105         ptc.setDescription("A rose by any other name would smell as sweet");
106         try {
107             ptc.verify();
108             fail("test should throw an exception");
109         } catch (ApexException ae) {
110             assertEquals("TestPing is not valid, pong time -1 is less than ping time 0", ae.getMessage());
111         }
112
113         ptc.setPongTime(-2);
114         try {
115             ptc.verify();
116             fail("test should throw an exception");
117         } catch (ApexException ae) {
118             assertEquals("TestPing is not valid, pong time -2 is less than ping time 0", ae.getMessage());
119         }
120
121         ptc.setPongTime(1);
122         try {
123             ptc.verify();
124         } catch (ApexException ae) {
125             fail("test should not throw an exception");
126         }
127
128         assertEquals(
129                 "PingTestClass(id=0, name=Rose, "
130                         + "description=A rose by any other name would smell as sweet, pingTime=0, pongTime=1)",
131                 ptc.toString());
132     }
133 }