2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.config.api;
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;
29 public class ConfigurationTest {
32 public void cleanUp() {
33 Configuration.TENANT.remove();
37 public void tenantRetrievedWhenPreviouslySet() {
38 final String tenantId = "abc";
39 Configuration.setTenantId(tenantId);
40 Assert.assertEquals(tenantId, Configuration.TENANT.get());
44 public void tenantEmptyWhenNeverSet() {
45 Assert.assertNull(Configuration.TENANT.get());
49 public void tenantNullWhenNullSet() {
50 Configuration.setTenantId("xyz");
51 Configuration.setTenantId(null);
52 Assert.assertNull(Configuration.TENANT.get());
56 public void tenantNullWhenEmptySet() {
57 Configuration.setTenantId("xyz");
58 Configuration.setTenantId("");
59 Assert.assertNull(Configuration.TENANT.get());
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()));
69 Assert.assertNull("Tenant in the other thread expected to be null", result.get());
70 Assert.assertEquals(currentTenant, Configuration.TENANT.get());