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 java.io.IOException;
25 import org.hamcrest.Description;
26 import org.hamcrest.TypeSafeMatcher;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.springframework.boot.test.context.SpringBootTest;
33 @SpringBootTest(classes = BabelApplication.class)
34 public class TestApplication {
37 public ExpectedException expectedEx = ExpectedException.none();
41 System.setProperty("APP_HOME", ".");
42 System.setProperty("CONFIG_HOME", "src/test/resources");
43 System.setProperty("server.ssl.key-store", "src/test/resources/auth/keystore.jks");
47 public void testApplicationStarts() {
48 System.setProperty("KEY_STORE_PASSWORD", "password");
49 BabelApplication.main(new String[] {});
53 public void testApplicationWithNullArgs() {
54 System.setProperty("KEY_STORE_PASSWORD", "test");
55 expectedEx.expect(IllegalArgumentException.class);
56 expectedEx.expectMessage("Args must not be null");
57 BabelApplication.main(null);
61 public void testApplicationWithEmptyKeyStorePassword() {
62 System.setProperty("KEY_STORE_PASSWORD", "");
63 expectedEx.expect(IllegalArgumentException.class);
64 expectedEx.expectMessage("roperty KEY_STORE_PASSWORD not set");
65 BabelApplication.main(new String[] {});
69 public void testApplicationWithNullKeyStorePassword() {
70 System.clearProperty("KEY_STORE_PASSWORD");
71 expectedEx.expect(IllegalArgumentException.class);
72 expectedEx.expectMessage("roperty KEY_STORE_PASSWORD not set");
73 BabelApplication.main(new String[] {});
77 public void testApplicationWithIncorrectKeyStorePassword() {
78 System.setProperty("KEY_STORE_PASSWORD", "test");
79 final CauseMatcher expectedCause = new CauseMatcher(IOException.class, "password was incorrect");
80 expectedEx.expectCause(expectedCause);
81 BabelApplication.main(new String[] {});
84 private static class CauseMatcher extends TypeSafeMatcher<Throwable> {
86 private final Class<? extends Throwable> type;
87 private final String expectedMessage;
89 public CauseMatcher(Class<? extends Throwable> type, String expectedMessage) {
91 this.expectedMessage = expectedMessage;
95 protected boolean matchesSafely(Throwable item) {
96 return item.getClass().isAssignableFrom(type) && item.getMessage().contains(expectedMessage);
100 public void describeTo(Description description) {
101 description.appendValue(type).appendText(" and message ").appendValue(expectedMessage);