7743e5558fbbdb465289e3463c6b24cf8d27dc70
[integration.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2019 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 org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.junit.runners.Parameterized;
27
28 import java.time.Instant;
29 import java.util.Arrays;
30 import java.util.Collection;
31
32 import static org.assertj.core.api.Assertions.assertThat;
33
34 @RunWith(Parameterized.class)
35 public class KeywordsExtractorValidTimestampPrimitiveTest {
36     private final String keyword;
37     private KeywordsExtractor keywordsExtractor;
38
39     private static final Collection VALID_TIMESTAMP_KEYWORDS = Arrays.asList(new Object[][]{
40             {"#TimestampPrimitive"}
41     });
42
43     public KeywordsExtractorValidTimestampPrimitiveTest(String keyword) {
44         this.keyword = keyword;
45     }
46
47     @Before
48     public void setUp() {
49         this.keywordsExtractor = new KeywordsExtractor();
50     }
51
52     @Parameterized.Parameters
53     public static Collection data() {
54         return VALID_TIMESTAMP_KEYWORDS;
55     }
56
57     @Test
58     public void checkValidRandomStringKeyword() {
59         long currentTimestamp = Instant.now().getEpochSecond();
60         Long timestamp = keywordsExtractor.substitutePrimitiveKeyword(this.keyword);
61         long afterExecution = Instant.now().getEpochSecond();
62
63         assertThat(timestamp).isBetween(currentTimestamp, afterExecution);
64     }
65
66 }