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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.pnfsimulator.simulator;
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;
27 import java.util.Random;
28 import org.junit.jupiter.api.RepeatedTest;
29 import org.junit.jupiter.api.Test;
31 class KeywordsValueProviderTest {
34 void randomLimitedStringTest() {
35 String supplierResult = KeywordsValueProvider.getRandomLimitedString().apply();
36 assertEquals(supplierResult.length(), DEFAULT_STRING_LENGTH);
40 void randomStringTest() {
41 int length = new Random().nextInt(15) + 1;
42 String supplierResult = KeywordsValueProvider.getRandomString().apply(length);
43 assertEquals(supplierResult.length(), length);
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);
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);
63 void randomIntegerFromNegativeRangeTest(){
64 String supplierResult = KeywordsValueProvider.getRandomInteger().apply(-20, -20);
65 assertEquals(Integer.parseInt(supplierResult), -20);
69 void randomIntegerFromParametersWithDifferentOrdersTest(){
70 String supplierResult = KeywordsValueProvider.getRandomInteger().apply(-20, -10);
71 assertTrue(Integer.parseInt(supplierResult)>=-20);
72 assertTrue(Integer.parseInt(supplierResult)<=-10);
76 void epochSecondGeneratedInCorrectFormatTest(){
77 String supplierResult = KeywordsValueProvider.getEpochSecond().apply();
78 assertEquals(supplierResult.length(), 10);