2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
19 import java.util.Base64;
20 import java.util.HashSet;
22 import org.junit.Test;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.NokiaSvnfmApplication;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.Useless;
25 import org.springframework.boot.SpringApplication;
27 import static org.junit.Assert.*;
29 public class TestSystemFunctions {
35 public void testSleep() throws Exception {
36 long start = System.currentTimeMillis();
37 SystemFunctions.systemFunctions().sleep(123);
38 long end = System.currentTimeMillis();
39 assertTrue(end - start >= 123);
43 * test interrupted sleep
46 public void testInterruptedSleep() throws Exception {
47 long start = System.currentTimeMillis();
48 Set<RuntimeException> exceptions = new HashSet<>();
49 class Inter extends Thread {
53 SystemFunctions.systemFunctions().sleep(10000);
54 } catch (RuntimeException e) {
59 Inter inter = new Inter();
65 while (exceptions.size() != 1) {
74 public void testCurrentTime() {
75 long now = System.currentTimeMillis();
76 long now2 = SystemFunctions.systemFunctions().currentTimeMillis();
77 assertTrue(Math.abs(now2 - now) < 1000);
84 public void testFileLoad() {
85 byte[] bytes = SystemFunctions.systemFunctions().loadFile("unittests/empty.zip");
86 assertEquals("UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA==", Base64.getEncoder().encodeToString(bytes));
90 * missing file results in error
93 public void testMissingFileLoad() {
95 SystemFunctions.systemFunctions().loadFile("unittests/missing");
97 } catch (Exception e) {
98 assertEquals("Unable to load unittests/missing", e.getMessage());
103 * Test standard stream wrapping
106 public void testStandardStreams() {
107 assertEquals(System.err, SystemFunctions.systemFunctions().err());
108 assertEquals(System.out, SystemFunctions.systemFunctions().out());
109 assertEquals(System.in, SystemFunctions.systemFunctions().in());
113 * Test HTTP client wrapping
116 @Useless //more less already ensured by Java type safety
117 public void testHttp() {
118 assertNotNull(SystemFunctions.systemFunctions().getHttpClient());
122 * Test spring application wrapping
125 public void testSpring(){
126 SpringApplication springApplication = SystemFunctions.systemFunctions().newSpringApplication(NokiaSvnfmApplication.class);
128 assertEquals(1, springApplication.getAllSources().size());