Removed support of dynamic configuration
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-api / src / test / java / org / onap / config / api / ConfigurationTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.config.api;
18
19 import java.util.concurrent.CompletableFuture;
20 import java.util.concurrent.ExecutionException;
21 import org.junit.After;
22 import org.junit.Assert;
23 import org.junit.Test;
24
25 /**
26  * @author evitaliy
27  * @since 28 Oct 2018
28  */
29 public class ConfigurationTest {
30
31     @After
32     public void cleanUp() {
33         Configuration.TENANT.remove();
34     }
35
36     @Test
37     public void tenantRetrievedWhenPreviouslySet() {
38         final String tenantId = "abc";
39         Configuration.setTenantId(tenantId);
40         Assert.assertEquals(tenantId, Configuration.TENANT.get());
41     }
42
43     @Test
44     public void tenantEmptyWhenNeverSet() {
45         Assert.assertNull(Configuration.TENANT.get());
46     }
47
48     @Test
49     public void tenantNullWhenNullSet() {
50         Configuration.setTenantId("xyz");
51         Configuration.setTenantId(null);
52         Assert.assertNull(Configuration.TENANT.get());
53     }
54
55     @Test
56     public void tenantNullWhenEmptySet() {
57         Configuration.setTenantId("xyz");
58         Configuration.setTenantId("");
59         Assert.assertNull(Configuration.TENANT.get());
60     }
61
62     @Test
63     public void tenantDoesNotPropagateToAnotherThread() throws ExecutionException, InterruptedException {
64         final String currentTenant = "xyz";
65         Configuration.setTenantId(currentTenant);
66         CompletableFuture<String> result = new CompletableFuture<>();
67         Thread otherThread = new Thread(() -> result.complete(Configuration.TENANT.get()));
68         otherThread.start();
69         Assert.assertNull("Tenant in the other thread expected to be null", result.get());
70         Assert.assertEquals(currentTenant, Configuration.TENANT.get());
71     }
72 }