2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.distributed.locking;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
28 import java.util.Properties;
29 import java.util.TreeSet;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.common.utils.properties.exception.PropertyException;
34 public class DistributedLockPropertiesTest {
36 private Properties props;
39 * Populates {@link #props}.
43 props = new Properties();
45 props.setProperty(DistributedLockProperties.DB_DRIVER, "my driver");
46 props.setProperty(DistributedLockProperties.DB_URL, "my url");
47 props.setProperty(DistributedLockProperties.DB_USER, "my user");
48 props.setProperty(DistributedLockProperties.DB_PASS, "my pass");
49 props.setProperty(DistributedLockProperties.TRANSIENT_ERROR_CODES, "10,-20,,,30");
50 props.setProperty(DistributedLockProperties.EXPIRE_CHECK_SEC, "100");
51 props.setProperty(DistributedLockProperties.RETRY_SEC, "200");
52 props.setProperty(DistributedLockProperties.MAX_RETRIES, "300");
56 public void test() throws PropertyException {
57 DistributedLockProperties dlp = new DistributedLockProperties(props);
59 assertEquals("my driver", dlp.getDbDriver());
60 assertEquals("my url", dlp.getDbUrl());
61 assertEquals("my user", dlp.getDbUser());
62 assertEquals("my pass", dlp.getDbPwd());
63 assertEquals("10,-20,,,30", dlp.getErrorCodeStrings());
64 assertEquals("[-20, 10, 30]", new TreeSet<>(dlp.getTransientErrorCodes()).toString());
65 assertEquals(100, dlp.getExpireCheckSec());
66 assertEquals(200, dlp.getRetrySec());
67 assertEquals(300, dlp.getMaxRetries());
69 assertTrue(dlp.isTransient(10));
70 assertTrue(dlp.isTransient(-20));
71 assertTrue(dlp.isTransient(30));
73 assertFalse(dlp.isTransient(-10));
76 props.setProperty(DistributedLockProperties.TRANSIENT_ERROR_CODES, "10,abc,30");
78 assertThatThrownBy(() -> new DistributedLockProperties(props)).isInstanceOf(PropertyException.class)
79 .hasMessageContaining(DistributedLockProperties.TRANSIENT_ERROR_CODES);