846425059e8f525f6503c387298ecbed024720c8
[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.sdc.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.*;
29
30 /**
31  * @author evitaliy
32  * @since 14/09/2016.
33  */
34 public class LoggerFactoryTest {
35
36   @Test
37   public void testNoOpLoggerService() throws Exception {
38
39     assertFalse(ServiceLoader.load(LoggerCreationService.class).iterator().hasNext());
40
41     LoggerFactory.getLogger(LoggerFactoryTest.class);
42     Field factory = LoggerFactory.class.getDeclaredField("SERVICE");
43     factory.setAccessible(true);
44     Object impl = factory.get(null);
45     assertEquals("org.openecomp.sdc.logging.api.LoggerFactory$NoOpLoggerCreationService",
46         impl.getClass().getName());
47   }
48
49   @Test
50   public void testNoOpLoggerByClass() throws Exception {
51     Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class);
52     verifyLogger(logger);
53   }
54
55   @Test
56   public void testNoOpLoggerByName() throws Exception {
57     Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class.getName());
58     verifyLogger(logger);
59   }
60
61   private void verifyLogger(Logger logger) {
62     assertNotNull(logger);
63
64     // make sure no exceptions are thrown
65     logger.error("");
66     logger.warn("");
67     logger.info("");
68     logger.debug("");
69     logger.audit("");
70     logger.metrics("");
71   }
72 }