Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / ErrorConfigurationTest.java
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;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.openecomp.sdc.be.config.ErrorConfiguration;
26 import org.openecomp.sdc.be.config.ErrorInfo;
27 import org.openecomp.sdc.common.api.BasicConfiguration;
28 import org.openecomp.sdc.common.api.ConfigurationListener;
29 import org.openecomp.sdc.common.api.ConfigurationSource;
30 import org.openecomp.sdc.common.api.FileChangeCallback;
31 import org.openecomp.sdc.common.impl.ExternalConfiguration;
32 import org.openecomp.sdc.common.impl.FSConfigurationSource;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 import java.io.File;
37
38 import static org.junit.Assert.assertNotNull;
39
40 public class ErrorConfigurationTest {
41     ConfigurationSource configurationSource = null;
42     private static final Logger log = LoggerFactory.getLogger(ErrorConfigurationTest.class);
43
44     @Before
45     public void setup() {
46
47         ExternalConfiguration.setAppName("catalog-be");
48         ExternalConfiguration.setConfigDir("src/test/resources/config");
49         ExternalConfiguration.listenForChanges();
50
51         configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), ExternalConfiguration.getConfigDir() + File.separator + ExternalConfiguration.getAppName());
52
53     }
54
55     @Test
56     public void testReadConfigurationFile() {
57
58         ConfigurationListener configurationListener = new ConfigurationListener(ErrorConfiguration.class, new FileChangeCallback() {
59
60             public void reconfigure(BasicConfiguration obj) {
61                 // TODO Auto-generated method stub
62                 log.debug("In reconfigure of {}", obj);
63             }
64
65         });
66
67         ErrorConfiguration testConfiguration = configurationSource.getAndWatchConfiguration(ErrorConfiguration.class, configurationListener);
68
69         assertNotNull(testConfiguration);
70         ErrorInfo errorInfo = testConfiguration.getErrorInfo("USER_NOT_FOUND");
71         assertNotNull(errorInfo);
72         log.debug("{}", testConfiguration);
73         log.debug("{}", errorInfo);
74
75     }
76
77 }