From 77565ad85e22807027c743d119fe9bcd92247de5 Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Fri, 29 Mar 2019 17:55:49 +0000 Subject: 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 --- .../org/onap/aai/auth/AAIMicroServiceAuthCore.java | 17 ++------ .../java/org/onap/aai/auth/AuthFileWatcher.java | 46 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/onap/aai/auth/AuthFileWatcher.java (limited to 'src/main/java') 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 { *
  • If this fails, try resolving the path relative to the configuration home location (either * $CONFIG_HOME or $APP_HOME/appconfig).
  • *
  • If this fails try resolving relative to the auth folder under configuration home.
  • - * + * * @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!"); + } +} -- cgit 1.2.3-korg