73e4c31df4bd42036831fd955101e8bd60341e46
[integration.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.pnfsimulator.simulator;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.onap.pnfsimulator.simulator.KeywordsValueProvider.DEFAULT_STRING_LENGTH;
26
27 import java.util.Random;
28 import org.junit.jupiter.api.RepeatedTest;
29 import org.junit.jupiter.api.Test;
30
31 class KeywordsValueProviderTest {
32
33     @RepeatedTest(10)
34     void randomLimitedStringTest() {
35         String supplierResult = KeywordsValueProvider.getRandomLimitedString().apply();
36         assertEquals(supplierResult.length(), DEFAULT_STRING_LENGTH);
37     }
38
39     @RepeatedTest(10)
40     void randomStringTest() {
41         int length = new Random().nextInt(15) + 1;
42         String supplierResult = KeywordsValueProvider.getRandomString().apply(length);
43         assertEquals(supplierResult.length(), length);
44     }
45
46     @RepeatedTest(10)
47     void  randomIntegerTest(){
48         int min = new Random().nextInt(10) + 1;
49         int max = new Random().nextInt(1000) + 20;
50         String supplierResult = KeywordsValueProvider.getRandomInteger().apply(min, max);
51         assertTrue(Integer.parseInt(supplierResult)>=min);
52         assertTrue(Integer.parseInt(supplierResult)<=max);
53     }
54
55     @Test
56     void  randomIntegerContainsMaximalAndMinimalValuesTest(){
57         int anyNumber = new Random().nextInt(10) + 1;
58         String supplierResult = KeywordsValueProvider.getRandomInteger().apply(anyNumber, anyNumber);
59         assertEquals(Integer.parseInt(supplierResult), anyNumber);
60     }
61
62     @Test
63     void  randomIntegerFromNegativeRangeTest(){
64         String supplierResult = KeywordsValueProvider.getRandomInteger().apply(-20, -20);
65         assertEquals(Integer.parseInt(supplierResult), -20);
66     }
67
68     @RepeatedTest(10)
69     void  randomIntegerFromParametersWithDifferentOrdersTest(){
70         String supplierResult = KeywordsValueProvider.getRandomInteger().apply(-20, -10);
71         assertTrue(Integer.parseInt(supplierResult)>=-20);
72         assertTrue(Integer.parseInt(supplierResult)<=-10);
73     }
74
75     @RepeatedTest(10)
76     void  epochSecondGeneratedInCorrectFormatTest(){
77         String supplierResult = KeywordsValueProvider.getEpochSecond().apply();
78         assertEquals(supplierResult.length(), 10);
79     }
80
81 }