Skip to content

Commit

Permalink
Development: Refactor lti tests (#9375)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAnzinger authored Oct 3, 2024
1 parent e5d9c6c commit 93138e3
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.tum.cit.aet.artemis.atlas.architecture;

import de.tum.cit.aet.artemis.atlas.AbstractAtlasIntegrationTest;
import de.tum.cit.aet.artemis.shared.architecture.AbstractModuleTestArchitectureTest;

class AtlasTestArchitectureTest extends AbstractModuleTestArchitectureTest<AbstractAtlasIntegrationTest> {

@Override
protected String getModulePackageName() {
return "atlas";
}

@Override
protected Class<AbstractAtlasIntegrationTest> getAbstractModuleIntegrationTestClass() {
return AbstractAtlasIntegrationTest.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.tum.cit.aet.artemis.lti;

import org.springframework.beans.factory.annotation.Autowired;

import com.fasterxml.jackson.databind.ObjectMapper;

import de.tum.cit.aet.artemis.core.util.RequestUtilService;
import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService;
import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository;
import de.tum.cit.aet.artemis.lti.test_repository.OnlineCourseConfigurationTestRepository;
import de.tum.cit.aet.artemis.programming.util.ProgrammingExerciseUtilService;
import de.tum.cit.aet.artemis.quiz.service.QuizExerciseService;
import de.tum.cit.aet.artemis.quiz.service.QuizSubmissionService;
import de.tum.cit.aet.artemis.quiz.test_repository.QuizExerciseTestRepository;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

public abstract class AbstractLtiIntegrationTest extends AbstractSpringIntegrationIndependentTest {

// Repositories
@Autowired
protected OnlineCourseConfigurationTestRepository onlineCourseConfigurationRepository;

// External Repositories
@Autowired
protected QuizExerciseTestRepository quizExerciseTestRepository;

@Autowired
protected SubmissionTestRepository submissionRepository;

// External Services
@Autowired
protected QuizExerciseService quizExerciseService;

@Autowired
protected QuizSubmissionService quizSubmissionService;

// External Util Services
@Autowired
protected ProgrammingExerciseUtilService programmingExerciseUtilService;

@Autowired
protected ParticipationUtilService participationUtilService;

@Autowired
protected RequestUtilService request;

// Misc
@Autowired
protected ObjectMapper objectMapper;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.springframework.security.test.context.support.WithAnonymousUser;
import org.springframework.security.test.context.support.WithMockUser;

import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;
import io.jsonwebtoken.Jwts;

/**
Expand All @@ -35,7 +34,7 @@
* see <a href="https://www.imsglobal.org/spec/lti/v1p3/#lti-message-general-details">LTI message general details</a>
* see <a href="https://www.imsglobal.org/spec/security/v1p0/#openid_connect_launch_flow">OpenId Connect launch flow</a>
*/
class Lti13LaunchIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class Lti13LaunchIntegrationTest extends AbstractLtiIntegrationTest {

private static final SecretKey SIGNING_KEY = Jwts.SIG.HS256.key().build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.util.LinkedMultiValueMap;
Expand All @@ -31,17 +30,12 @@
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.lti.config.CustomLti13Configurer;
import de.tum.cit.aet.artemis.lti.dto.Claims;
import de.tum.cit.aet.artemis.programming.util.ProgrammingExerciseUtilService;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;
import io.jsonwebtoken.Jwts;

class LtiDeepLinkingIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class LtiDeepLinkingIntegrationTest extends AbstractLtiIntegrationTest {

private static final String TEST_PREFIX = "ltideeplinkingintegrationtest";

@Autowired
private ProgrammingExerciseUtilService programmingExerciseUtilService;

private Course course;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.hibernate.Hibernate;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
Expand All @@ -28,19 +27,14 @@
import org.springframework.util.LinkedMultiValueMap;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import de.tum.cit.aet.artemis.core.exception.EntityNotFoundException;
import de.tum.cit.aet.artemis.lti.domain.LtiPlatformConfiguration;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

class LtiIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class LtiIntegrationTest extends AbstractLtiIntegrationTest {

private static final String TEST_PREFIX = "ltiintegrationtest";

@Autowired
ObjectMapper objectMapper;

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void dynamicRegistrationFailsAsStudent() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.junit.jupiter.api.parallel.Isolated;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -26,50 +25,20 @@
import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import com.fasterxml.jackson.databind.ObjectMapper;

import de.tum.cit.aet.artemis.assessment.domain.AssessmentType;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.util.RequestUtilService;
import de.tum.cit.aet.artemis.exercise.domain.participation.StudentParticipation;
import de.tum.cit.aet.artemis.exercise.participation.util.ParticipationUtilService;
import de.tum.cit.aet.artemis.exercise.test_repository.SubmissionTestRepository;
import de.tum.cit.aet.artemis.quiz.domain.DragAndDropQuestion;
import de.tum.cit.aet.artemis.quiz.domain.QuizExercise;
import de.tum.cit.aet.artemis.quiz.domain.QuizMode;
import de.tum.cit.aet.artemis.quiz.domain.QuizSubmission;
import de.tum.cit.aet.artemis.quiz.service.QuizExerciseService;
import de.tum.cit.aet.artemis.quiz.service.QuizSubmissionService;
import de.tum.cit.aet.artemis.quiz.test_repository.QuizExerciseTestRepository;
import de.tum.cit.aet.artemis.quiz.util.QuizExerciseFactory;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

@Isolated
class LtiQuizIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class LtiQuizIntegrationTest extends AbstractLtiIntegrationTest {

private static final String TEST_PREFIX = "ltiquizsubmissiontest";

@Autowired
private QuizExerciseService quizExerciseService;

@Autowired
private QuizExerciseTestRepository quizExerciseTestRepository;

@Autowired
private SubmissionTestRepository submissionRepository;

@Autowired
private ParticipationUtilService participationUtilService;

@Autowired
private ObjectMapper objectMapper;

@Autowired
protected RequestUtilService request;

@Autowired
private QuizSubmissionService quizSubmissionService;

@BeforeEach
void init() {
doNothing().when(lti13Service).onNewResult(any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithAnonymousUser;

Expand All @@ -14,16 +13,11 @@
import de.tum.cit.aet.artemis.core.util.CourseFactory;
import de.tum.cit.aet.artemis.lti.domain.LtiPlatformConfiguration;
import de.tum.cit.aet.artemis.lti.domain.OnlineCourseConfiguration;
import de.tum.cit.aet.artemis.lti.test_repository.OnlineCourseConfigurationTestRepository;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;

class OAuth2JWKSIntegrationTest extends AbstractSpringIntegrationIndependentTest {
class OAuth2JWKSIntegrationTest extends AbstractLtiIntegrationTest {

private static final String TEST_PREFIX = "oauth2jwksintegrationtest";

@Autowired
private OnlineCourseConfigurationTestRepository onlineCourseConfigurationRepository;

@Test
@WithAnonymousUser
void getKeysetIsPublicAndReturnsJson() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.tum.cit.aet.artemis.lti.architecture;

import de.tum.cit.aet.artemis.lti.AbstractLtiIntegrationTest;
import de.tum.cit.aet.artemis.shared.architecture.AbstractModuleTestArchitectureTest;

class LtiTestArchitectureTest extends AbstractModuleTestArchitectureTest<AbstractLtiIntegrationTest> {

@Override
protected String getModulePackageName() {
return "lti";
}

@Override
protected Class<AbstractLtiIntegrationTest> getAbstractModuleIntegrationTestClass() {
return AbstractLtiIntegrationTest.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.tum.cit.aet.artemis.shared.architecture;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMembers;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class AbstractModuleTestArchitectureTest<T> extends AbstractArchitectureTest {

abstract protected String getModulePackageName();

abstract protected Class<T> getAbstractModuleIntegrationTestClass();

@Test
void integrationTestsShouldExtendAbstractModuleIntegrationTest() {
classes().that().resideInAPackage(ARTEMIS_PACKAGE + "." + getModulePackageName()).and().haveSimpleNameEndingWith("IntegrationTest").should()
.beAssignableTo(getAbstractModuleIntegrationTestClass()).because("All integration tests should extend %s".formatted(getAbstractModuleIntegrationTestClass()))
.check(testClasses);
}

@Test
void integrationTestsShouldNotAutowireMembers() {
noMembers().that().areAnnotatedWith(Autowired.class).should().beDeclaredInClassesThat().areAssignableTo(getAbstractModuleIntegrationTestClass()).andShould()
.notBeDeclaredIn(getAbstractModuleIntegrationTestClass())
.because("Integration tests should not autowire members in any class that inherits from %s".formatted(getAbstractModuleIntegrationTestClass())).check(testClasses);
}
}

0 comments on commit 93138e3

Please sign in to comment.