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.junit.Assert.assertThat;
28 import java.io.IOException;
29 import java.util.TimerTask;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.onap.aai.auth.AAIAuthException;
34 import org.onap.aai.auth.AAIMicroServiceAuth;
35 import org.onap.aai.auth.AAIMicroServiceAuthCore;
36 import org.onap.aai.auth.AuthFileWatcher;
37 import org.onap.aai.babel.config.BabelAuthConfig;
40 * Tests {@link AuthFileWatcher}.
43 public class TestAuthFileWatcher {
45 private TimerTask task;
46 private File mockFile = Mockito.mock(File.class);
49 public void createTask() {
50 task = new AuthFileWatcher(mockFile);
53 @Test(expected = Test.None.class /* no exception expected */)
54 public void testOnChangeDoesNotRun() {
58 @Test(expected = Test.None.class /* no exception expected */)
59 public void testOnChangeDoesRun() throws IOException, AAIAuthException {
60 System.setProperty("CONFIG_HOME", "src/test/resources");
61 BabelAuthConfig babelServiceAuthConfig = new BabelAuthConfig();
62 babelServiceAuthConfig.setAuthPolicyFile("auth_policy.json");
63 new AAIMicroServiceAuth(babelServiceAuthConfig);
65 Mockito.when(mockFile.lastModified()).thenReturn(1000L);
70 public void testOnChangeRunAfterFailure() throws IOException {
71 File file = File.createTempFile("auth-policy", "json");
73 AAIMicroServiceAuthCore.init(file.getAbsolutePath());
74 } catch (AAIAuthException e) {
75 assertThat(e.getMessage(), containsString("Error processing Auth policy file"));
78 Mockito.when(mockFile.lastModified()).thenReturn(1000L);