2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.oauthprovider.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import java.io.IOException;
27 import org.junit.Test;
28 import org.onap.ccsdk.features.sdnr.wt.oauthprovider.data.Config;
29 import org.onap.ccsdk.features.sdnr.wt.oauthprovider.data.InvalidConfigurationException;
31 public class TestConfig {
33 public static String TEST_CONFIG_FILENAME = "src/test/resources/test.config.json";
34 public static String TEST_OOMCONFIG_FILENAME = "src/test/resources/oom.test.config.json";
35 public static String TEST_RS256_FILENAME = "src/test/resources/test.configRS256.json";
36 public static String TEST_RS256INVALID_FILENAME = "src/test/resources/test.configRS256-invalid.json";
37 public static String TEST_RS512_FILENAME = "src/test/resources/test.configRS512.json";
41 public void test() throws IOException, InvalidConfigurationException {
43 Config config = Config.load(TEST_CONFIG_FILENAME);
44 System.out.println("config="+config);
45 assertEquals(60*60,config.getTokenLifetime());
46 assertNotNull(config.getAlgorithm());
47 assertNotNull(config.getTokenSecret());
48 //assertNotNull(config.getPublicKey());
49 assertEquals(Config.TOKENALG_HS256, config.getAlgorithm());
52 public void testOom() throws IOException, InvalidConfigurationException {
54 Config config = Config.load(TEST_OOMCONFIG_FILENAME);
55 System.out.println("config="+config);
56 assertEquals(30*60,config.getTokenLifetime());
60 public void testRS256() throws IOException, InvalidConfigurationException {
62 Config config = Config.load(TEST_RS256_FILENAME);
63 System.out.println("config="+config);
64 assertEquals(60*60,config.getTokenLifetime());
68 public void testRS512() throws IOException, InvalidConfigurationException {
70 Config config = Config.load(TEST_RS512_FILENAME);
71 System.out.println("config="+config);
72 assertEquals(60*60,config.getTokenLifetime());
75 @Test(expected = InvalidConfigurationException.class)
76 public void testRS256Invalid() throws IOException, InvalidConfigurationException {
78 Config.load(TEST_RS256INVALID_FILENAME);