Merge "Rewrite LoggerControllerTests"
[vid.git] / vid-app-common / src / test / java / org / onap / vid / controller / LogfilePathCreatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. 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
22 package org.onap.vid.controller;
23
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
27
28 import javax.ws.rs.InternalServerErrorException;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 public class LogfilePathCreatorTest {
33
34     private static final String AUDIT = "audit";
35     private static final String ERROR = "error";
36     private static final String METRICS = "metrics";
37
38     private LogfilePathCreator creator;
39
40     @Before
41     public void setUp() {
42         creator = new LogfilePathCreator();
43     }
44
45     @Test
46     public void shouldThrowInternalServerErrorException_whenLogfileDoesntExist() {
47         String loggerName = "notExisting";
48         assertThatExceptionOfType(InternalServerErrorException.class)
49             .isThrownBy(() -> creator.getLogfilePath(loggerName))
50             .withMessage(String.format("logfile for %s not found", loggerName));
51     }
52
53     @Test
54     public void shouldReturnAuditPath_whenAuditNameIsGiven() {
55         assertThat(creator.getLogfilePath(AUDIT)).isEqualTo("logs/EELF/audit.log");
56     }
57
58     @Test
59     public void shouldReturnErrorPath_whenErrorNameIsGiven() {
60         assertThat(creator.getLogfilePath(ERROR)).isEqualTo("logs/EELF/error.log");
61     }
62
63     @Test
64     public void shouldReturnMetricsPath_whenMetricsNameIsGiven() {
65         assertThat(creator.getLogfilePath(METRICS)).isEqualTo("logs/EELF/metrics.log");
66     }
67 }