7158db7ab4cc1d224e5058eca491e56ad5a3bc64
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.core.logging.api;
22
23 import org.testng.annotations.Test;
24
25 import java.lang.reflect.Field;
26 import java.util.ServiceLoader;
27
28 import static org.testng.Assert.assertEquals;
29 import static org.testng.Assert.assertFalse;
30 import static org.testng.Assert.assertNotNull;
31
32 /**
33  * @author evitaliy
34  * @since 14/09/2016.
35  */
36 public class LoggerFactoryTest {
37
38   @Test
39   public void testNoOpLoggerService() throws Exception {
40
41     assertFalse(ServiceLoader.load(LoggerCreationService.class).iterator().hasNext());
42
43     LoggerFactory.getLogger(LoggerFactoryTest.class);
44     Field factory = LoggerFactory.class.getDeclaredField("SERVICE");
45     factory.setAccessible(true);
46     Object impl = factory.get(null);
47     assertEquals("org.openecomp.core.logging.api.LoggerFactory$NoOpLoggerCreationService",
48         impl.getClass().getName());
49   }
50
51   @Test
52   public void testNoOpLoggerByClass() throws Exception {
53     Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class);
54     verifyLogger(logger);
55   }
56
57   @Test
58   public void testNoOpLoggerByName() throws Exception {
59     Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class.getName());
60     verifyLogger(logger);
61   }
62
63   private void verifyLogger(Logger logger) {
64     assertNotNull(logger);
65
66     // make sure no exceptions are thrown
67     logger.error("");
68     logger.warn("");
69     logger.info("");
70     logger.debug("");
71     logger.audit("");
72     logger.metrics("");
73   }
74 }