2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.model.util;
\r
24 import org.junit.Test;
\r
25 import org.mockito.Mockito;
\r
26 import org.openecomp.dcae.apod.analytics.model.BaseAnalyticsModelUnitTest;
\r
28 import java.io.IOException;
\r
29 import java.io.InputStream;
\r
30 import java.util.Properties;
\r
32 import static org.hamcrest.CoreMatchers.is;
\r
33 import static org.junit.Assert.assertEquals;
\r
34 import static org.junit.Assert.assertThat;
\r
35 import static org.mockito.ArgumentMatchers.any;
\r
36 import static org.mockito.Mockito.doThrow;
\r
39 * @author Rajiv Singla . Creation Date: 10/17/2016.
\r
41 public class AnalyticsModelIOUtilsTest extends BaseAnalyticsModelUnitTest {
\r
43 private static final String TEST_CONFIG_FILE_LOCATION = "data/json/config/testAppConfig.json";
\r
44 private static final String INVALID_TEST_CONFIG_FILE_LOCATION = "data/json/config/invalidJsonConfig.json";
\r
45 private static final String TEST_PROPERTIES_FILE_LOCATION = "data/properties/testApp.properties";
\r
48 public void testConvertToJsonObjectWhenFileLocationIsValid() throws Exception {
\r
49 ConfigHolder configHolder =
\r
50 AnalyticsModelIOUtils.convertToJsonObject(TEST_CONFIG_FILE_LOCATION, ConfigHolder.class);
\r
51 String appName = configHolder.getConfig().getAppName();
\r
52 assertEquals("App Name must match with json settings file value", "TestAppName", appName);
\r
53 String appDescription = configHolder.getConfig().getAppDescription();
\r
54 assertEquals("App Description much with json settings file value", "Test App Description", appDescription);
\r
57 @Test(expected = IOException.class)
\r
58 public void testConvertToJsonObjectWhenFileLocationIsInvValid() throws Exception {
\r
59 AnalyticsModelIOUtils.convertToJsonObject("InvalidFileLocation", ConfigHolder.class);
\r
62 @Test(expected = IOException.class)
\r
63 public void testConvertToJsonObjectWhenJsonFileHasInvalidJson() throws Exception {
\r
64 AnalyticsModelIOUtils.convertToJsonObject(INVALID_TEST_CONFIG_FILE_LOCATION, ConfigHolder.class);
\r
68 public void testValidPropertiesFileLoading() throws Exception {
\r
69 final Properties properties =
\r
70 AnalyticsModelIOUtils.loadPropertiesFile(TEST_PROPERTIES_FILE_LOCATION, new Properties());
\r
71 assertThat("Properties File must contain 2 properties", properties.size(), is(2));
\r
74 @Test(expected = RuntimeException.class)
\r
75 public void testNonExistingPropertiesFileLoading() throws Exception {
\r
76 AnalyticsModelIOUtils.loadPropertiesFile("InvalidPropertiesFileLocation", new Properties());
\r
79 @Test(expected = RuntimeException.class)
\r
80 public void testLoadPropertiesFileWhenIOException() throws Exception {
\r
81 final Properties mockProperties = Mockito.mock(Properties.class);
\r
82 doThrow(new IOException()).when(mockProperties).load(any(InputStream.class));
\r
83 AnalyticsModelIOUtils.loadPropertiesFile(TEST_PROPERTIES_FILE_LOCATION, mockProperties);
\r