Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Define DTO architecture test per module with module-specific thresholds #9959

Merged
merged 17 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.cit.aet.artemis.assessment.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class AssessmentCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".assessment";
}

@Override
protected int dtoAsAnnotatedRecordThreshold() {
return 3;
}

@Override
protected int dtoNameEndingThreshold() {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tum.cit.aet.artemis.athena.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class AthenaCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".athena";
}

@Override
protected int dtoNameEndingThreshold() {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tum.cit.aet.artemis.atlas.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class AtlasCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".atlas";
}

@Override
protected int dtoNameEndingThreshold() {
return 4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.cit.aet.artemis.communication.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class CommunicationCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".communication";
}

@Override
protected int dtoAsAnnotatedRecordThreshold() {
return 7;
}

@Override
protected int dtoNameEndingThreshold() {
return 6;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.cit.aet.artemis.core.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class CoreCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".core";
}

@Override
protected int dtoAsAnnotatedRecordThreshold() {
return 10;
}

@Override
protected int dtoNameEndingThreshold() {
return 10;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tum.cit.aet.artemis.exam.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class ExamCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".exam";
}

@Override
protected int dtoNameEndingThreshold() {
return 4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.cit.aet.artemis.exercise.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class ExerciseCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".exercise";
}

@Override
protected int dtoAsAnnotatedRecordThreshold() {
return 2;
}

@Override
protected int dtoNameEndingThreshold() {
return 7;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.cit.aet.artemis.fileupload.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class FileUploadCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".fileupload";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.cit.aet.artemis.iris.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class IrisCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".iris";
}

@Override
protected int dtoAsAnnotatedRecordThreshold() {
return 2;
}

@Override
protected int dtoNameEndingThreshold() {
return 4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.cit.aet.artemis.lecture.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class LectureCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".lecture";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tum.cit.aet.artemis.lti.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class LtiCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".lti";
}

@Override
protected int dtoNameEndingThreshold() {
return 11;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.cit.aet.artemis.modeling.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class ModelingCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".modeling";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tum.cit.aet.artemis.plagiarism.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class PlagiarismCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".plagiarism";
}

@Override
protected int dtoNameEndingThreshold() {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.cit.aet.artemis.programming.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class ProgrammingCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".programming";
}

@Override
protected int dtoAsAnnotatedRecordThreshold() {
return 1;
}

@Override
protected int dtoNameEndingThreshold() {
return 17;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.cit.aet.artemis.quiz.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class QuizCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".quiz";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -200,25 +199,6 @@ void testJSONImplementations() {
.check(allClasses);
}

@Disabled // TODO: Enable this test once the restructuring is done
@Test
void testDTOImplementations() {
var dtoRecordRule = classes().that().haveSimpleNameEndingWith("DTO").and().areNotInterfaces().should().beRecords().andShould().beAnnotatedWith(JsonInclude.class)
.because("All DTOs should be records and annotated with @JsonInclude(JsonInclude.Include.NON_EMPTY)");
var result = dtoRecordRule.evaluate(allClasses);
log.info("Current number of DTO classes: {}", result.getFailureReport().getDetails().size());
log.info("Current DTO classes: {}", result.getFailureReport().getDetails());
// TODO: reduce the following number to 0, if the current number is less and the test fails, decrease it
assertThat(result.getFailureReport().getDetails()).hasSize(26);

var dtoPackageRule = classes().that().resideInAPackage("..dto").should().haveSimpleNameEndingWith("DTO");
result = dtoPackageRule.evaluate(allClasses);
log.info("Current number of DTOs that do not end with \"DTO\": {}", result.getFailureReport().getDetails().size());
log.info("Current DTOs that do not end with \"DTO\": {}", result.getFailureReport().getDetails());
// TODO: reduce the following number to 0, if the current number is less and the test fails, decrease it
assertThat(result.getFailureReport().getDetails()).hasSize(32);
}

@Test
void testGsonExclusion() {
// TODO: Replace all uses of gson with Jackson and check that gson is not used any more
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.tum.cit.aet.artemis.shared.architecture.module;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonInclude;

import de.tum.cit.aet.artemis.shared.architecture.AbstractArchitectureTest;

public abstract class AbstractModuleCodeStyleTest extends AbstractArchitectureTest implements ModuleArchitectureTest {

private static final Logger log = LoggerFactory.getLogger(AbstractModuleCodeStyleTest.class);

/**
* Threshold for number of classes with name ending DTO, that are no records or not annotated with JsonInclude.
* We should aim to reduce this threshold to 0.
*/
protected int dtoAsAnnotatedRecordThreshold() {
return 0;
}

/**
* Threshold or number of classes in a 'dto'-package which file name does not end with DTO.
* We should aim to reduce this threshold to 0.
*/
protected int dtoNameEndingThreshold() {
return 0;
}

@Test
void testDTOImplementations() {
var dtoRecordRule = classes().that().resideInAPackage(getModuleDtoSubpackage()).and().haveSimpleNameEndingWith("DTO").and().areNotInterfaces().should().beRecords()
.andShould().beAnnotatedWith(JsonInclude.class).because("All DTOs should be records and annotated with @JsonInclude(JsonInclude.Include.NON_EMPTY)");
var result = dtoRecordRule.allowEmptyShould(true).evaluate(allClasses);
log.info("Current number of DTO classes: {}", result.getFailureReport().getDetails().size());
log.info("Current DTO classes: {}", result.getFailureReport().getDetails());
assertThat(result.getFailureReport().getDetails()).hasSize(dtoAsAnnotatedRecordThreshold());

var dtoPackageRule = classes().that().resideInAPackage(getModuleDtoSubpackage()).should().haveSimpleNameEndingWith("DTO");
result = dtoPackageRule.allowEmptyShould(true).evaluate(allClasses);
log.info("Current number of DTOs that do not end with \"DTO\": {}", result.getFailureReport().getDetails().size());
log.info("Current DTOs that do not end with \"DTO\": {}", result.getFailureReport().getDetails());
assertThat(result.getFailureReport().getDetails()).hasSize(dtoNameEndingThreshold());
}

private String getModuleDtoSubpackage() {
return getModulePackage() + "..dto..";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tum.cit.aet.artemis.text.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class TextCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".text";
}

@Override
protected int dtoAsAnnotatedRecordThreshold() {
return 1;
}

@Override
protected int dtoNameEndingThreshold() {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.cit.aet.artemis.tutorialgroup.architecture;

import de.tum.cit.aet.artemis.shared.architecture.module.AbstractModuleCodeStyleTest;

class TutorialGroupCodeStyleArchitectureTest extends AbstractModuleCodeStyleTest {

@Override
public String getModulePackage() {
return ARTEMIS_PACKAGE + ".tutorialgroup";
}
}
Loading