80ae8cf952295efd0f4e9881c716f20d48f0e248
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.oauthprovider.test;
23
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;
30
31 public class TestConfig {
32
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";
38
39
40     @Test
41     public void test() throws IOException, InvalidConfigurationException {
42
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());
50     }
51     @Test
52     public void testOom() throws IOException, InvalidConfigurationException {
53
54         Config config = Config.load(TEST_OOMCONFIG_FILENAME);
55         System.out.println("config="+config);
56         assertEquals(30*60,config.getTokenLifetime());
57
58     }
59     @Test
60     public void testRS256() throws IOException, InvalidConfigurationException {
61
62         Config config = Config.load(TEST_RS256_FILENAME);
63         System.out.println("config="+config);
64         assertEquals(60*60,config.getTokenLifetime());
65
66     }
67     @Test
68     public void testRS512() throws IOException, InvalidConfigurationException {
69
70         Config config = Config.load(TEST_RS512_FILENAME);
71         System.out.println("config="+config);
72         assertEquals(60*60,config.getTokenLifetime());
73
74     }
75     @Test(expected = InvalidConfigurationException.class)
76     public void testRS256Invalid() throws IOException, InvalidConfigurationException {
77
78         Config.load(TEST_RS256INVALID_FILENAME);
79     }
80 }