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