From 614c51d11b64fdd4dbb78d0971a0cc3a2c07c5ab Mon Sep 17 00:00:00 2001 From: teleivo Date: Mon, 22 Jul 2024 15:24:56 +0200 Subject: [PATCH] chore: Remove unused bean.xml files (#18136) --- .../main/resources/META-INF/dhis/beans.xml | 8 --- .../main/resources/META-INF/dhis/beans.xml | 10 ---- .../main/resources/META-INF/dhis/beans.xml | 10 ---- .../election/NoOpLeaderManagerTest.java} | 18 ++++--- .../java/org/hisp/dhis/system/SystemTest.java | 40 --------------- .../hisp/dhis/system/SystemTestConfig.java | 45 ---------------- dhis-2/dhis-test-web-api/pom.xml | 11 ++-- .../test/webapi/WebTestConfiguration.java | 14 +++-- .../event/EventExportTestConfiguration.java | 51 ------------------- .../event/EventsExportControllerTest.java | 16 +++++- 10 files changed, 38 insertions(+), 185 deletions(-) delete mode 100644 dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml delete mode 100644 dhis-2/dhis-support/dhis-support-artemis/src/main/resources/META-INF/dhis/beans.xml delete mode 100644 dhis-2/dhis-support/dhis-support-audit/src/main/resources/META-INF/dhis/beans.xml rename dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/{system/leader/LeaderManagerTest.java => leader/election/NoOpLeaderManagerTest.java} (80%) delete mode 100644 dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTest.java delete mode 100644 dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTestConfig.java delete mode 100644 dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventExportTestConfiguration.java diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml b/dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml deleted file mode 100644 index 861e4dbf6ac2..000000000000 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/dhis-2/dhis-support/dhis-support-artemis/src/main/resources/META-INF/dhis/beans.xml b/dhis-2/dhis-support/dhis-support-artemis/src/main/resources/META-INF/dhis/beans.xml deleted file mode 100644 index 32d77e202cf7..000000000000 --- a/dhis-2/dhis-support/dhis-support-artemis/src/main/resources/META-INF/dhis/beans.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/dhis-2/dhis-support/dhis-support-audit/src/main/resources/META-INF/dhis/beans.xml b/dhis-2/dhis-support/dhis-support-audit/src/main/resources/META-INF/dhis/beans.xml deleted file mode 100644 index 854d4a0ed13e..000000000000 --- a/dhis-2/dhis-support/dhis-support-audit/src/main/resources/META-INF/dhis/beans.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/leader/LeaderManagerTest.java b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/leader/election/NoOpLeaderManagerTest.java similarity index 80% rename from dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/leader/LeaderManagerTest.java rename to dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/leader/election/NoOpLeaderManagerTest.java index fa6a85a6f2dd..d9f9e3ab0173 100644 --- a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/leader/LeaderManagerTest.java +++ b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/leader/election/NoOpLeaderManagerTest.java @@ -25,26 +25,30 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.system.leader; +package org.hisp.dhis.leader.election; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import org.hisp.dhis.leader.election.LeaderManager; -import org.hisp.dhis.system.SystemTest; +import java.util.Properties; +import org.hisp.dhis.external.conf.ConfigurationKey; +import org.hisp.dhis.test.config.TestDhisConfigurationProvider; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; /** * @author Ameen Mohamed */ -class LeaderManagerTest extends SystemTest { - - @Autowired private LeaderManager leaderManager; +class NoOpLeaderManagerTest { @Test void testNodeInfo() { + Properties properties = new Properties(); + properties.put(ConfigurationKey.NODE_ID, "1"); + TestDhisConfigurationProvider dhisConfigurationProvider = + new TestDhisConfigurationProvider(properties); + NoOpLeaderManager leaderManager = new NoOpLeaderManager(dhisConfigurationProvider); + assertNotNull(leaderManager.getCurrentNodeUuid()); assertNotNull(leaderManager.getLeaderNodeUuid()); assertEquals(leaderManager.getCurrentNodeUuid(), leaderManager.getLeaderNodeUuid()); diff --git a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTest.java b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTest.java deleted file mode 100644 index ec0f03b3bbd8..000000000000 --- a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.system; - -import org.hisp.dhis.test.IntegrationH2Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = SystemTestConfig.class) -@ActiveProfiles(profiles = {"test-h2"}) -@IntegrationH2Test -public abstract class SystemTest {} diff --git a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTestConfig.java b/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTestConfig.java deleted file mode 100644 index 547bc1b367d1..000000000000 --- a/dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/SystemTestConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.system; - -import org.hisp.dhis.external.conf.DhisConfigurationProvider; -import org.hisp.dhis.leader.election.LeaderManager; -import org.hisp.dhis.leader.election.NoOpLeaderManager; -import org.hisp.dhis.test.config.H2DhisConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -@Configuration -@Import(H2DhisConfiguration.class) -public class SystemTestConfig { - @Bean - public LeaderManager leaderManager(DhisConfigurationProvider dhisConfigurationProvider) { - return new NoOpLeaderManager(dhisConfigurationProvider); - } -} diff --git a/dhis-2/dhis-test-web-api/pom.xml b/dhis-2/dhis-test-web-api/pom.xml index b6c5e2bba372..74916a36e0f5 100644 --- a/dhis-2/dhis-test-web-api/pom.xml +++ b/dhis-2/dhis-test-web-api/pom.xml @@ -54,6 +54,11 @@ dhis-service-tracker compile + + org.hisp.dhis + dhis-support-artemis + compile + org.hisp.dhis dhis-support-db-migration @@ -191,11 +196,6 @@ geojson-jackson test - - org.springframework.security - spring-security-crypto - test - org.junit.jupiter junit-jupiter-params @@ -371,6 +371,7 @@ org.skyscreamer:jsonassert + org.hisp.dhis:dhis-support-artemis org.hisp.dhis:dhis-support-hibernate org.hisp.dhis:dhis-service-setting org.hisp.dhis:dhis-service-dxf2 diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/test/webapi/WebTestConfiguration.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/test/webapi/WebTestConfiguration.java index 9ca3fef179af..e7fef91e3b7d 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/test/webapi/WebTestConfiguration.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/test/webapi/WebTestConfiguration.java @@ -32,6 +32,7 @@ import java.util.Map; import javax.sql.DataSource; import lombok.extern.slf4j.Slf4j; +import org.hisp.dhis.artemis.config.ArtemisConfig; import org.hisp.dhis.association.jdbc.JdbcOrgUnitAssociationStoreConfiguration; import org.hisp.dhis.commons.jackson.config.JacksonObjectMapperConfig; import org.hisp.dhis.commons.util.DebugUtils; @@ -54,6 +55,8 @@ import org.hisp.dhis.security.SystemAuthoritiesProvider; import org.hisp.dhis.test.config.NoOpFlywayConfiguration; import org.hisp.dhis.test.h2.H2SqlFunction; +import org.hisp.dhis.tracker.imports.config.TrackerPreheatConfig; +import org.hisp.dhis.webapi.security.config.PasswordEncoderConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; @@ -62,14 +65,12 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.FilterType; import org.springframework.context.annotation.Import; -import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.Primary; import org.springframework.core.annotation.Order; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.security.authentication.DefaultAuthenticationEventPublisher; import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; import org.springframework.security.core.session.SessionRegistry; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.oauth2.core.OAuth2AuthenticationException; import org.springframework.security.web.savedrequest.HttpSessionRequestCache; import org.springframework.security.web.savedrequest.RequestCache; @@ -82,7 +83,6 @@ * @author Gintare Vilkelyte (EventMapper.ORDERABLE_FIELDS.values())); - return eventService; - } -} diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java index 0f3fa3322b11..4f22f5872249 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/tracker/export/event/EventsExportControllerTest.java @@ -32,8 +32,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Stream; @@ -58,11 +60,23 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = EventExportTestConfiguration.class) +@ContextConfiguration(classes = EventsExportControllerTest.Configuration.class) class EventsExportControllerTest extends H2ControllerIntegrationTestBase { + static class Configuration { + @Bean + public EventService eventService() { + EventService eventService = mock(EventService.class); + // Orderable fields are checked within the controller constructor + when(eventService.getOrderableFields()) + .thenReturn(new HashSet<>(EventMapper.ORDERABLE_FIELDS.values())); + return eventService; + } + } + @Autowired private IdentifiableObjectManager manager; @Autowired private EventService eventService;