Skip to content

Commit

Permalink
sabi-144 Migrate Testframework from junit4 to junit5
Browse files Browse the repository at this point in the history
- Migrated Server Module
  • Loading branch information
StefanSchubert committed Nov 24, 2023
1 parent 1511a13 commit 51f814b
Show file tree
Hide file tree
Showing 26 changed files with 163 additions and 337 deletions.
45 changes: 9 additions & 36 deletions sabi-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,22 @@
<springdoc.openapiv2.version>2.2.0</springdoc.openapiv2.version>
<eclipselink.version>4.0.2</eclipselink.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<micrometer.prometheus.version>1.11.5</micrometer.prometheus.version>
<spring.instrument.version>6.0.13</spring.instrument.version>
<surefire.version>3.2.2</surefire.version>
<micrometer.prometheus.version>1.12.0</micrometer.prometheus.version>
<spring.instrument.version>6.1.1</spring.instrument.version>
<lombok.version>1.18.30</lombok.version>
<owasp.plugin.version>8.4.2</owasp.plugin.version>
<owasp.plugin.version>9.0.0</owasp.plugin.version>
<passay.version>1.6.4</passay.version>
<mariadb.java.client.version>3.2.0</mariadb.java.client.version>
<mariadb.java.client.version>3.3.0</mariadb.java.client.version>
<h2.version>2.1.214</h2.version>
<dumbster.version>1.6</dumbster.version>
<junit.version>4.13.2</junit.version>
<archunit.version>1.2.0</archunit.version>
<auth0.jwt.version>4.4.0</auth0.jwt.version>
<jakarta.xml.bind.version>4.0.0</jakarta.xml.bind.version>
<jetbrains.annotation.version>24.0.1</jetbrains.annotation.version>
<versions.maven.plugin.version>2.16.1</versions.maven.plugin.version>
<jetbrains.annotation.version>24.1.0</jetbrains.annotation.version>
<versions.maven.plugin.version>2.16.2</versions.maven.plugin.version>
<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version>
</properties>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>

</dependencies>
</dependencyManagement>

<dependencies>

<!-- SABI Modules -->
Expand Down Expand Up @@ -254,7 +241,7 @@
<artifactId>spring-instrument</artifactId>
</dependency>

<!-- Test dependencies -->
<!-- Test dependencies, Since SB3 we have junit5 as default -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -291,13 +278,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- In case you want to switch from junit4.x make sure to adopt the surefire provider as well. -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<!-- Supports checking on architectural integrity -->
<dependency>
Expand Down Expand Up @@ -353,20 +333,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${spring.instrument.version}</version>
</dependency>
<dependency>
<!-- Surefire seemed to have difficulties to determine the test provider junit4
in our case, so we configured the provider manually here.-->
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<configuration>
<test>de.bluewhale.sabi.MasterTestSuite</test>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;
import com.tngtech.archunit.library.Architectures;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;


/**
* Checking on architectural constraints
*
* @author Stefan Schubert
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
public class ArchitectureTest {

private static final String PACKAGE_PREFIX = "de.bluewhale.sabi.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 by Stefan Schubert under the MIT License (MIT).
* Copyright (c) 2023 by Stefan Schubert under the MIT License (MIT).
* See project LICENSE file for the detailed terms and conditions.
*/

Expand All @@ -8,7 +8,7 @@
import de.bluewhale.sabi.model.SizeUnit;
import de.bluewhale.sabi.persistence.model.*;
import de.bluewhale.sabi.persistence.repositories.*;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

Expand Down Expand Up @@ -51,7 +51,7 @@ public class BasicDataFactory {
protected static final String P_USER1_EMAIL = "[email protected]";
protected static final String P_USER2_EMAIL = "[email protected]";

@Before
@BeforeEach
public void initOnlyOnce() {

if (populatedBasicData) return;
Expand Down
41 changes: 0 additions & 41 deletions sabi-server/src/test/java/de/bluewhale/sabi/MasterTestSuite.java

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions sabi-server/src/test/java/de/bluewhale/sabi/TankTestSuite.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@
import de.bluewhale.sabi.persistence.repositories.AquariumRepository;
import de.bluewhale.sabi.persistence.repositories.MeasurementRepository;
import de.bluewhale.sabi.persistence.repositories.UserRepository;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.util.AssertionErrors.assertNotNull;
import static org.springframework.test.util.AssertionErrors.assertTrue;


/**
Expand All @@ -42,7 +41,6 @@
* Date: 14.11.2015
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = AppConfig.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
// @DataJpaTest todo does not work yet missing visible constructor in JPAConfig class - maybe not compatible with eclipse way?
Expand All @@ -62,7 +60,7 @@ public class MeasurementRepositoryTest extends BasicDataFactory {
@Autowired
UserRepository userRepository;

@BeforeClass
@BeforeAll
public static void initTestDataFactory() {
testDataFactory = TestDataFactory.getInstance();
}
Expand All @@ -74,7 +72,7 @@ public static void initTestDataFactory() {
* The different behaviour can be observed by e.g. calling the master test suite and as comparising
* the measurement testsuite while this is method is deaktivated.
*/
@Before
@BeforeEach
public void ensureBasicDataAvailability() {

UserEntity byEmail = userRepository.getByEmail(P_USER1_EMAIL);
Expand All @@ -99,11 +97,11 @@ public void testCreateMeasurement() throws Exception {
MeasurementEntity createdMeasurementEntity = measurementRepository.saveAndFlush(measurementEntity);

// then
Assert.assertNotNull("Measurement was not persisted!", createdMeasurementEntity.getId());
assertNotNull("Measurement was not persisted!", createdMeasurementEntity.getId());
MeasurementEntity foundMeasurementEntity = measurementRepository.findById(createdMeasurementEntity.getId()).get();

Assert.assertEquals(createdMeasurementEntity.getAquarium(), foundMeasurementEntity.getAquarium());
Assert.assertEquals(createdMeasurementEntity.getAquarium().getId(), measurementTo.getAquariumId());
assertEquals(createdMeasurementEntity.getAquarium(), foundMeasurementEntity.getAquarium());
assertEquals(createdMeasurementEntity.getAquarium().getId(), measurementTo.getAquariumId());

}

Expand All @@ -115,7 +113,7 @@ public void testFetchStoredTestUsersMeasurements() throws Exception {
// when
List<MeasurementEntity> usersMeasurements = measurementRepository.findByUserOrderByMeasuredOnDesc(userEntity);
// then
Assert.assertTrue("Basic testdata missing!?", usersMeasurements.size() > 0);
assertTrue("Basic testdata missing!?", usersMeasurements.size() > 0);
}

@Test
Expand All @@ -127,7 +125,7 @@ public void testFetchStoredTestUsersMeasurementsWithResultLimit() throws Excepti
Pageable page = PageRequest.of(0, 2, Sort.by(Sort.Direction.DESC, "measuredOn"));
List<MeasurementEntity> usersMeasurements = measurementRepository.findByUserOrderByMeasuredOnDesc(userEntity,page);
// then expect 2 because of paging out of 3 rows available via BasicTestDataFactory
Assert.assertTrue("Basic testdata missing!?", usersMeasurements.size() == 2);
assertTrue("Basic testdata missing!?", usersMeasurements.size() == 2);
}


Expand All @@ -141,7 +139,7 @@ public void testGetConcreteMeasurement() throws Exception {
// When
MeasurementEntity measurement = measurementRepository.getByIdAndUser(testMeasurementId, userEntity);
// Then
Assert.assertEquals("Missing testdata for user 1L", measurement.getAquarium().getId(),testAquariumId);
assertTrue("Missing testdata for user 1L", measurement.getAquarium().getId()==testAquariumId);
}


Expand Down
Loading

0 comments on commit 51f814b

Please sign in to comment.