92f86f434c2e47a30da6685c60917455ce2678d9
[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.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
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() throws ApexException {
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         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
50             .hasMessageContaining("TestPing is not valid, name does not start with \"Rose\"");
51
52         ptc.setName(null);
53         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
54             .hasMessageContaining("TestPing is not valid, name length null or less than 4");
55
56         ptc.setName("Ros");
57         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
58             .hasMessageContaining("TestPing is not valid, name length null or less than 4");
59
60         ptc.setName("Rose");
61         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
62             .hasMessageContaining("TestPing is not valid, description length null or less than 44");
63
64         ptc.setDescription(null);
65         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
66             .hasMessageContaining("TestPing is not valid, description length null or less than 44");
67
68         ptc.setDescription("A rose by any other name would smell as swee");
69         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
70             .hasMessageContaining("TestPing is not valid, description length null or less than 44");
71
72         ptc.setDescription("A rose by any other name would smell as swell");
73         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
74            .hasMessageContaining("TestPing is not valid, description is incorrect");
75
76         ptc.setDescription("A rose by any other name would smell as sweet");
77         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
78             .hasMessageContaining("TestPing is not valid, pong time -1 is less than ping time 0");
79
80         ptc.setPongTime(-2);
81         assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
82            .hasMessageContaining("TestPing is not valid, pong time -2 is less than ping time 0");
83
84         ptc.setPongTime(1);
85         ptc.verify();
86
87         assertEquals(
88                 "PingTestClass(id=0, name=Rose, "
89                         + "description=A rose by any other name would smell as sweet, pingTime=0, pongTime=1)",
90                 ptc.toString());
91     }
92 }