Skip to content

Commit

Permalink
test: allow non-transactional controller integration tests
Browse files Browse the repository at this point in the history
by moving the @transactional annotation from our ControllerIntegrationTestBase to the test itself.
We did the same for our service/repo integration tests already.
  • Loading branch information
teleivo committed Oct 3, 2024
1 parent 3f202cc commit 18558d4
Show file tree
Hide file tree
Showing 142 changed files with 282 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;

/**
* Base class for convenient testing of the web API on basis of {@link
Expand All @@ -58,6 +59,7 @@
WebMvcConfig.class,
AuthConfigProviderConfig.class,
})
@Transactional
public abstract class AuthenticationApiTestBase extends H2ControllerIntegrationTestBase {

static class AuthConfigProviderConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -88,7 +87,6 @@
*/
@WebAppConfiguration
@ContextConfiguration(classes = {MvcTestConfig.class, WebTestConfig.class})
@Transactional
public abstract class ControllerIntegrationTestBase extends IntegrationTestBase
implements WebClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;

/**
* Base class for convenient testing of the web API on basis of {@link
Expand All @@ -51,6 +52,7 @@
@ContextConfiguration(
inheritLocations = false,
classes = {H2TestConfig.class, WebMvcConfig.class})
@Transactional
public abstract class ControllerWithApiTokenAuthTestBase extends H2ControllerIntegrationTestBase {
@Autowired private FilterChainProxy springSecurityFilterChain;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.security.web.FilterChainProxy;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;

/**
* Base class for convenient testing of the web API on basis of {@link
Expand All @@ -50,6 +51,7 @@
@ContextConfiguration(
inheritLocations = false,
classes = {DhisConfig.class, WebMvcConfig.class})
@Transactional
public abstract class ControllerWithJwtTokenAuthTestBase extends H2ControllerIntegrationTestBase {

static class DhisConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.filter.CharacterEncodingFilter;

/**
* @author Morten Olav Hansen <[email protected]>
*/
@ExtendWith({RestDocumentationExtension.class})
@Transactional
public abstract class WebSpringTestBase extends H2ControllerIntegrationTestBase {

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the generic operations offered by the {@link AbstractCrudController} using specific
* endpoints.
*
* @author Jan Bernitt
*/
@Transactional
class AbstractCrudControllerTest extends H2ControllerIntegrationTestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.hisp.dhis.user.User;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.transaction.annotation.Transactional;

@Transactional
abstract class AbstractDataValueControllerTest extends H2ControllerIntegrationTestBase {
protected String dataElementId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import org.hisp.dhis.test.utils.JavaToJson;
import org.hisp.dhis.test.web.HttpStatus;
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.springframework.transaction.annotation.Transactional;

/**
* Base class for testing the {@link DatastoreController} providing helpers to set up entries in the
* store.
*
* @author Jan Bernitt
*/
@Transactional
abstract class AbstractDatastoreControllerTest extends H2ControllerIntegrationTestBase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the generic operations offered by the {@link AbstractFullReadOnlyController} using specific
* endpoints.
*
* @author David Mackessy
*/
@Transactional
class AbstractFullReadOnlyControllerTest extends H2ControllerIntegrationTestBase {

@Autowired private DataElementService dataElementService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
import org.hisp.dhis.user.User;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
* Base class for controller tests of the Gist API.
*
* @author Jan Bernitt
*/
@Transactional
abstract class AbstractGistControllerTest extends H2ControllerIntegrationTestBase {
@Autowired protected OrganisationUnitService organisationUnitService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import org.hisp.dhis.test.utils.JavaToJson;
import org.hisp.dhis.test.web.HttpStatus;
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.springframework.transaction.annotation.Transactional;

/**
* Base class for testing the {@link UserDatastoreController} providing helpers to set up entries in
* the store.
*
* @author Jan Bernitt
*/
@Transactional
public abstract class AbstractUserDatastoreControllerTest extends H2ControllerIntegrationTestBase {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link AccountController} using (mocked) REST requests.
*
* @author Jan Bernitt
*/
@Transactional
class AccountControllerTest extends PostgresControllerIntegrationTestBase {
@Autowired private SystemSettingManager systemSettingManager;
@Autowired private FakeMessageSender messageSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link
Expand All @@ -42,6 +43,7 @@
*
* @author david mackessy
*/
@Transactional
class AnalyticsOutlierDetectionControllerTest extends H2ControllerIntegrationTestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link AppController}
Expand All @@ -61,6 +62,7 @@
classes = {
DhisConfig.class,
})
@Transactional
class AppControllerTest extends H2ControllerIntegrationTestBase {

static class DhisConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link AppHubController} using (mocked) REST requests.
*
* @author Jan Bernitt
*/
@Transactional
class AppHubControllerTest extends H2ControllerIntegrationTestBase {
@Autowired private DhisConfigurationProvider configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
import org.hisp.dhis.test.web.HttpStatus;
import org.hisp.dhis.test.webapi.PostgresControllerIntegrationTestBase;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link AttributeController}.
*
* @author Jan Bernitt
*/
@Transactional
class AttributeControllerTest extends PostgresControllerIntegrationTestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import org.hisp.dhis.jsontree.JsonObject;
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link org.hisp.dhis.webapi.controller.security.AuthoritiesController}.
*
* @author Jan Bernitt
*/
@Transactional
class AuthoritiesControllerTest extends H2ControllerIntegrationTestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
import org.hisp.dhis.user.sharing.Sharing;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
* @author [email protected]
*/
@Transactional
class BulkPatchSharingControllerTest extends H2ControllerIntegrationTestBase {

@Autowired private ObjectMapper jsonMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import org.hisp.dhis.test.webapi.json.domain.JsonCategoryOptionCombo;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.annotation.Transactional;

@Transactional
class CategoryComboModificationControllerTest extends H2ControllerIntegrationTestBase {

String testCatCombo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
class ChangeLogControllerTest extends H2ControllerIntegrationTestBase {

@Autowired private IdentifiableObjectManager manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@
import org.hisp.dhis.test.webapi.json.domain.JsonImportSummary;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link CompleteDataSetRegistrationController} using (mocked) REST requests.
*
* @author Jan Bernitt
*/
@Transactional
class CompleteDataSetRegistrationControllerTest extends H2ControllerIntegrationTestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Transactional
class CrudControllerIntegrationTest extends PostgresControllerIntegrationTestBase {

@Autowired private UserSettingService userSettingService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
class CrudControllerPagingTest extends H2ControllerIntegrationTestBase {
@Autowired private OrganisationUnitService ouService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
import org.hisp.dhis.user.CurrentUserUtil;
import org.hisp.dhis.user.UserDetails;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.annotation.Transactional;

/**
* @author david mackessy
*/
@Transactional
class CurrentUserUtilTest extends H2ControllerIntegrationTestBase {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
import org.hisp.dhis.visualization.Visualization;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
class DashboardControllerTest extends PostgresControllerIntegrationTestBase {
@Autowired private AclService aclService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link DataApprovalController} using (mocked) REST requests.
*
* @author Jan Bernitt
*/
@Transactional
class DataApprovalControllerTest extends H2ControllerIntegrationTestBase {

private String ouId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
import org.hisp.dhis.test.webapi.H2ControllerIntegrationTestBase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.transaction.annotation.Transactional;

/**
* Tests the {@link DataSetController} using (mocked) REST requests.
*
* @author Jan Bernitt
*/
@Transactional
class DataSetControllerTest extends H2ControllerIntegrationTestBase {

private String dsId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.transaction.annotation.Transactional;

/**
* @author david mackessy
*/
@Transactional
class DataSetMetadataControllerTest extends PostgresControllerIntegrationTestBase {

@ParameterizedTest
Expand Down
Loading

0 comments on commit 18558d4

Please sign in to comment.