fa7926acef50d5e7a5266d2936abc228be3bdf12
[sdc.git] /
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.openecomp.sdc.logging.slf4j;
18
19 import static org.testng.Assert.assertEquals;
20 import static org.testng.Assert.assertTrue;
21
22 import org.openecomp.sdc.logging.api.ContextData;
23 import org.testng.annotations.Test;
24
25 /**
26  * Unit-test retrieving values from client-provided request data.
27  *
28  * @author evitaliy
29  * @since 23 Mar 2018
30  */
31 public class RequestContextProviderTest {
32
33     @Test
34     public void valuesEmptyWhenInputEmpty() {
35         RequestContextProvider provider = new RequestContextProvider(ContextData.builder().build());
36         assertTrue(provider.values().isEmpty());
37     }
38
39     @Test
40     public void serviceNameReturnedWhenSupplied() {
41         final String service = "supplied-service-name";
42         RequestContextProvider provider =
43                 new RequestContextProvider(ContextData.builder().serviceName(service).build());
44         assertEquals(provider.values().get(ContextField.SERVICE_NAME), service);
45     }
46
47     @Test
48     public void partnerNameReturnedWhenSupplied() {
49         final String partner = "supplied-partner-name";
50         RequestContextProvider provider =
51                 new RequestContextProvider(ContextData.builder().partnerName(partner).build());
52         assertEquals(provider.values().get(ContextField.PARTNER_NAME), partner);
53     }
54
55     @Test
56     public void requestIdReturnedWhenSupplied() {
57         final String request = "supplied-request-id";
58         RequestContextProvider provider =
59                 new RequestContextProvider(ContextData.builder().requestId(request).build());
60         assertEquals(provider.values().get(ContextField.REQUEST_ID), request);
61     }
62 }