diff options
Diffstat (limited to 'datafile-app-server/src/test')
2 files changed, 56 insertions, 57 deletions
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java index 2cd854af..443ddae7 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java @@ -46,33 +46,32 @@ import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoE * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ @ExtendWith({MockitoExtension.class}) -class DatafileAppConfigTest { - +class AppConfigTest { + private static final String DATAFILE_ENDPOINTS = "datafile_endpoints.json"; private static final boolean CORRECT_JSON = true; private static final boolean INCORRECT_JSON = false; - private static DatafileAppConfig datafileAppConfig; - private static AppConfig appConfig; + private static AppConfig appConfigUnderTest; + private static String filePath = Objects - .requireNonNull(DatafileAppConfigTest.class.getClassLoader().getResource(DATAFILE_ENDPOINTS)).getFile(); + .requireNonNull(AppConfigTest.class.getClassLoader().getResource(DATAFILE_ENDPOINTS)).getFile(); @BeforeEach public void setUp() { - datafileAppConfig = spy(DatafileAppConfig.class); - appConfig = spy(new AppConfig()); + appConfigUnderTest = spy(AppConfig.class); } @Test public void whenApplicationWasStarted_FilePathIsSet() { // When - datafileAppConfig.setFilepath(filePath); + appConfigUnderTest.setFilepath(filePath); // Then - verify(datafileAppConfig, times(1)).setFilepath(anyString()); - verify(datafileAppConfig, times(0)).initFileStreamReader(); - Assertions.assertEquals(filePath, datafileAppConfig.getFilepath()); + verify(appConfigUnderTest, times(1)).setFilepath(anyString()); + verify(appConfigUnderTest, times(0)).initFileStreamReader(); + Assertions.assertEquals(filePath, appConfigUnderTest.getFilepath()); } @Test @@ -82,23 +81,23 @@ class DatafileAppConfigTest { new ByteArrayInputStream((getJsonConfig(CORRECT_JSON).getBytes(StandardCharsets.UTF_8))); // When - datafileAppConfig.setFilepath(filePath); - doReturn(inputStream).when(datafileAppConfig).getInputStream(any()); - datafileAppConfig.initFileStreamReader(); - appConfig.dmaapConsumerConfiguration = datafileAppConfig.getDmaapConsumerConfiguration(); - appConfig.dmaapPublisherConfiguration = datafileAppConfig.getDmaapPublisherConfiguration(); - appConfig.ftpesConfig = datafileAppConfig.getFtpesConfiguration(); + appConfigUnderTest.setFilepath(filePath); + doReturn(inputStream).when(appConfigUnderTest).getInputStream(any()); + appConfigUnderTest.initFileStreamReader(); + appConfigUnderTest.dmaapConsumerConfiguration = appConfigUnderTest.getDmaapConsumerConfiguration(); + appConfigUnderTest.dmaapPublisherConfiguration = appConfigUnderTest.getDmaapPublisherConfiguration(); + appConfigUnderTest.ftpesConfig = appConfigUnderTest.getFtpesConfiguration(); // Then - verify(datafileAppConfig, times(1)).setFilepath(anyString()); - verify(datafileAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNotNull(datafileAppConfig.getDmaapConsumerConfiguration()); - Assertions.assertNotNull(datafileAppConfig.getDmaapPublisherConfiguration()); - Assertions.assertEquals(appConfig.getDmaapPublisherConfiguration(), - datafileAppConfig.getDmaapPublisherConfiguration()); - Assertions.assertEquals(appConfig.getDmaapConsumerConfiguration(), - datafileAppConfig.getDmaapConsumerConfiguration()); - Assertions.assertEquals(appConfig.getFtpesConfiguration(), datafileAppConfig.getFtpesConfiguration()); + verify(appConfigUnderTest, times(1)).setFilepath(anyString()); + verify(appConfigUnderTest, times(1)).initFileStreamReader(); + Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration()); + Assertions.assertNotNull(appConfigUnderTest.getDmaapPublisherConfiguration()); + Assertions.assertEquals(appConfigUnderTest.getDmaapPublisherConfiguration(), + appConfigUnderTest.getDmaapPublisherConfiguration()); + Assertions.assertEquals(appConfigUnderTest.getDmaapConsumerConfiguration(), + appConfigUnderTest.getDmaapConsumerConfiguration()); + Assertions.assertEquals(appConfigUnderTest.getFtpesConfiguration(), appConfigUnderTest.getFtpesConfiguration()); } @@ -106,17 +105,17 @@ class DatafileAppConfigTest { public void whenFileIsNotExist_ThrowIoException() { // Given filePath = "/temp.json"; - datafileAppConfig.setFilepath(filePath); + appConfigUnderTest.setFilepath(filePath); // When - datafileAppConfig.initFileStreamReader(); + appConfigUnderTest.initFileStreamReader(); // Then - verify(datafileAppConfig, times(1)).setFilepath(anyString()); - verify(datafileAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNull(datafileAppConfig.getDmaapConsumerConfiguration()); - Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration()); - Assertions.assertNull(datafileAppConfig.getFtpesConfiguration()); + verify(appConfigUnderTest, times(1)).setFilepath(anyString()); + verify(appConfigUnderTest, times(1)).initFileStreamReader(); + Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration()); + Assertions.assertNull(appConfigUnderTest.getDmaapPublisherConfiguration()); + Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration()); } @@ -127,16 +126,16 @@ class DatafileAppConfigTest { new ByteArrayInputStream((getJsonConfig(INCORRECT_JSON).getBytes(StandardCharsets.UTF_8))); // When - datafileAppConfig.setFilepath(filePath); - doReturn(inputStream).when(datafileAppConfig).getInputStream(any()); - datafileAppConfig.initFileStreamReader(); + appConfigUnderTest.setFilepath(filePath); + doReturn(inputStream).when(appConfigUnderTest).getInputStream(any()); + appConfigUnderTest.initFileStreamReader(); // Then - verify(datafileAppConfig, times(1)).setFilepath(anyString()); - verify(datafileAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNotNull(datafileAppConfig.getDmaapConsumerConfiguration()); - Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration()); - Assertions.assertNotNull(datafileAppConfig.getFtpesConfiguration()); + verify(appConfigUnderTest, times(1)).setFilepath(anyString()); + verify(appConfigUnderTest, times(1)).initFileStreamReader(); + Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration()); + Assertions.assertNull(appConfigUnderTest.getDmaapPublisherConfiguration()); + Assertions.assertNotNull(appConfigUnderTest.getFtpesConfiguration()); } @@ -147,22 +146,22 @@ class DatafileAppConfigTest { InputStream inputStream = new ByteArrayInputStream((getJsonConfig(CORRECT_JSON).getBytes(StandardCharsets.UTF_8))); // When - datafileAppConfig.setFilepath(filePath); - doReturn(inputStream).when(datafileAppConfig).getInputStream(any()); + appConfigUnderTest.setFilepath(filePath); + doReturn(inputStream).when(appConfigUnderTest).getInputStream(any()); JsonElement jsonElement = mock(JsonElement.class); when(jsonElement.isJsonObject()).thenReturn(false); - doReturn(jsonElement).when(datafileAppConfig).getJsonElement(any(JsonParser.class), any(InputStream.class)); - datafileAppConfig.initFileStreamReader(); - appConfig.dmaapConsumerConfiguration = datafileAppConfig.getDmaapConsumerConfiguration(); - appConfig.dmaapPublisherConfiguration = datafileAppConfig.getDmaapPublisherConfiguration(); - appConfig.ftpesConfig = datafileAppConfig.getFtpesConfiguration(); + doReturn(jsonElement).when(appConfigUnderTest).getJsonElement(any(JsonParser.class), any(InputStream.class)); + appConfigUnderTest.initFileStreamReader(); + appConfigUnderTest.dmaapConsumerConfiguration = appConfigUnderTest.getDmaapConsumerConfiguration(); + appConfigUnderTest.dmaapPublisherConfiguration = appConfigUnderTest.getDmaapPublisherConfiguration(); + appConfigUnderTest.ftpesConfig = appConfigUnderTest.getFtpesConfiguration(); // Then - verify(datafileAppConfig, times(1)).setFilepath(anyString()); - verify(datafileAppConfig, times(1)).initFileStreamReader(); - Assertions.assertNull(datafileAppConfig.getDmaapConsumerConfiguration()); - Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration()); - Assertions.assertNull(datafileAppConfig.getFtpesConfiguration()); + verify(appConfigUnderTest, times(1)).setFilepath(anyString()); + verify(appConfigUnderTest, times(1)).initFileStreamReader(); + Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration()); + Assertions.assertNull(appConfigUnderTest.getDmaapPublisherConfiguration()); + Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration()); } private String getJsonConfig(boolean correct) { diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java index 05a4f515..0d5ea003 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * PROJECT * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved. + * Copyright (C) 2018-2019 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ package org.onap.dcaegen2.collectors.datafile.integration; import static org.mockito.Mockito.mock; -import org.onap.dcaegen2.collectors.datafile.configuration.DatafileAppConfig; +import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig; import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,8 +34,8 @@ import org.springframework.context.annotation.Configuration; class ServiceMockProvider { @Bean - public DatafileAppConfig getDatafileAppConfig() { - return mock(DatafileAppConfig.class); + public AppConfig getDatafileAppConfig() { + return mock(AppConfig.class); } @Bean |