diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-03-29 17:55:49 +0000 |
---|---|---|
committer | Tian Lee <TianL@amdocs.com> | 2019-04-03 10:35:00 +0000 |
commit | 77565ad85e22807027c743d119fe9bcd92247de5 (patch) | |
tree | 4cb37a21711c91a5239f55e61eaf1d381db72a04 /src/main/java | |
parent | 6b52f93a1965dfadd55410a4231446c9fb374633 (diff) |
Add tests for uncovered FileWatcher code
Move the onChange() method so that it can be tested.
Change-Id: I8a011ae581a16cf31e9573e6d4c9b2fa1c858b8a
Issue-ID: AAI-2280
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java | 17 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/auth/AuthFileWatcher.java | 46 |
2 files changed, 49 insertions, 14 deletions
diff --git a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java index 0eec7e1..bdb3bc7 100644 --- a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java +++ b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java @@ -91,19 +91,8 @@ public class AAIMicroServiceAuthCore { } AAIMicroServiceAuthCore.reloadUsers(); - TimerTask task = new FileWatcher(new File(policyAuthFileName)) { - @Override - protected void onChange(File file) { - // here we implement the onChange - applicationLogger.debug("File " + file.getName() + " has been changed!"); - try { - AAIMicroServiceAuthCore.reloadUsers(); - } catch (AAIAuthException e) { - applicationLogger.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, e); - } - applicationLogger.debug("File " + file.getName() + " has been reloaded!"); - } - }; + + TimerTask task = new AuthFileWatcher(new File(policyAuthFileName)); if (!timerSet) { timerSet = true; @@ -130,7 +119,7 @@ public class AAIMicroServiceAuthCore { * <li>If this fails, try resolving the path relative to the configuration home location (either * <code>$CONFIG_HOME</code> or <code>$APP_HOME/appconfig</code>).</li> * <li>If this fails try resolving relative to the <code>auth</code> folder under configuration home.</li> - * + * * @param authPolicyFile * filename or path * @return the Optional canonical path to the located policy file diff --git a/src/main/java/org/onap/aai/auth/AuthFileWatcher.java b/src/main/java/org/onap/aai/auth/AuthFileWatcher.java new file mode 100644 index 0000000..07b522d --- /dev/null +++ b/src/main/java/org/onap/aai/auth/AuthFileWatcher.java @@ -0,0 +1,46 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2019 European Software Marketing Ltd. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.auth; + +import java.io.File; +import org.onap.aai.babel.logging.ApplicationMsgs; +import org.onap.aai.babel.logging.LogHelper; + +public class AuthFileWatcher extends FileWatcher { + + private static LogHelper applicationLogger = LogHelper.INSTANCE; + + public AuthFileWatcher(File file) { + super(file); + } + + @Override + protected void onChange(File file) { + applicationLogger.debug("File " + file.getName() + " has been changed!"); + try { + AAIMicroServiceAuthCore.reloadUsers(); + } catch (AAIAuthException e) { + applicationLogger.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, e); + } + applicationLogger.debug("File " + file.getName() + " has been reloaded!"); + } +} |