summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/nosqldb/util/CassandraConfigurationManagerTest.java
blob: 021f1c715bb77af042185263e247b62a005f5248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright © 2016-2018 European Support Limited
 * ================================================================================
 * Modifications Copyright (C) 2021 AT&T.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openecomp.core.nosqldb.util;

import java.io.FileNotFoundException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
 * @author EVITALIY
 * @since 22 Oct 17
 */
public class CassandraConfigurationManagerTest {

    private static final String NON_EXISTENT = "unexistentfile";

    @AfterEach
    public void resetSystemVar() {
        System.clearProperty(CassandraConfigurationManager.JVM_PARAM_CONFIGURATION_FILE);
    }

    @Test
    public void testGetInstanceSystemProperty() throws Throwable {
        System.setProperty(CassandraConfigurationManager.JVM_PARAM_CONFIGURATION_FILE, NON_EXISTENT);
        RuntimeException e = Assertions.assertThrows(RuntimeException.class,()-> {
            CassandraConfigurationManager.getInstance();
        });
        Assertions.assertTrue(e.getCause() instanceof FileNotFoundException);
        Assertions.assertEquals("Failed to read configuration unexistentfile",e.getMessage());
    }

    @Test()
    public void testGetInstanceDefault() {
        // Do not set the JVM param for config file, by default code will get it from Resource
        CassandraConfigurationManager manager = CassandraConfigurationManager.getInstance();
        Assertions.assertArrayEquals(new String[] {"127.0.0.1"}, manager.getAddresses());
        Assertions.assertEquals(9042, manager.getCassandraPort());
        Assertions.assertEquals("dox", manager.getKeySpace());
        Assertions.assertEquals("LOCAL_QUORUM", manager.getConsistencyLevel());
        Assertions.assertEquals(null, manager.getLocalDataCenter());
        Assertions.assertEquals("Aa1234%^!", manager.getPassword());
        Assertions.assertEquals(30000L, manager.getReconnectTimeout().longValue());
        Assertions.assertEquals("/path/path", manager.getTruststorePath());
        Assertions.assertEquals("Aa123456", manager.getTruststorePassword());
        Assertions.assertFalse(manager.isSsl());
        Assertions.assertFalse(manager.isAuthenticate());
    }
}