2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright (c) 2017-2019 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.babel;
24 import static org.hamcrest.CoreMatchers.containsString;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
29 import java.io.IOException;
30 import java.util.TimerTask;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.mockito.Mockito;
34 import org.onap.aai.auth.AAIAuthException;
35 import org.onap.aai.auth.AAIMicroServiceAuth;
36 import org.onap.aai.auth.AAIMicroServiceAuthCore;
37 import org.onap.aai.auth.AuthFileWatcher;
38 import org.onap.aai.babel.config.BabelAuthConfig;
41 * Tests {@link AuthFileWatcher}.
44 public class TestAuthFileWatcher {
46 private TimerTask task;
47 private File mockFile = Mockito.mock(File.class);
50 public void createTask() {
51 task = new AuthFileWatcher(mockFile);
55 public void testOnChangeDoesNotRun() {
56 assertDoesNotThrow(() -> {
62 public void testOnChangeDoesRun() throws IOException, AAIAuthException {
63 assertDoesNotThrow(() -> {
64 System.setProperty("CONFIG_HOME", "src/test/resources");
65 BabelAuthConfig babelServiceAuthConfig = new BabelAuthConfig();
66 babelServiceAuthConfig.setAuthPolicyFile("auth_policy.json");
67 new AAIMicroServiceAuth(babelServiceAuthConfig);
69 Mockito.when(mockFile.lastModified()).thenReturn(1000L);
75 public void testOnChangeRunAfterFailure() throws IOException {
76 File file = File.createTempFile("auth-policy", "json");
78 AAIMicroServiceAuthCore.init(file.getAbsolutePath());
79 } catch (AAIAuthException e) {
80 assertThat(e.getMessage(), containsString("Error processing Auth policy file"));
83 Mockito.when(mockFile.lastModified()).thenReturn(1000L);