-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Server test to ensure lazy loading of LearnerProfile in User.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/test/java/de/tum/cit/aet/artemis/atlas/profile/LearnerProfileArchitectureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.tum.cit.aet.artemis.atlas.profile; | ||
|
||
import de.tum.cit.aet.artemis.atlas.AbstractAtlasIntegrationTest; | ||
import de.tum.cit.aet.artemis.core.domain.User; | ||
import de.tum.cit.aet.artemis.shared.TestRepositoryConfiguration; | ||
import io.zonky.test.db.AutoConfigureEmbeddedDatabase; | ||
import org.hibernate.Hibernate; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
import org.junit.jupiter.api.parallel.ExecutionMode; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@ExtendWith(SpringExtension.class) | ||
@Execution(ExecutionMode.CONCURRENT) | ||
@Import(TestRepositoryConfiguration.class) | ||
@AutoConfigureEmbeddedDatabase | ||
public class LearnerProfileArchitectureTest extends AbstractAtlasIntegrationTest { | ||
|
||
private static final String TEST_PREFIX = "learningpathintegration"; | ||
|
||
private static final int NUMBER_OF_STUDENTS = 1; | ||
|
||
private static final String STUDENT1_OF_COURSE = TEST_PREFIX + "student1"; | ||
|
||
@BeforeEach | ||
void setupTestScenario() { | ||
userUtilService.addUsers(TEST_PREFIX, NUMBER_OF_STUDENTS, 1, 1, 1); | ||
|
||
// Add users that are not in the course | ||
userUtilService.createAndSaveUser(TEST_PREFIX + "student1337"); | ||
userUtilService.createAndSaveUser(TEST_PREFIX + "instructor1337"); | ||
|
||
learnerProfileUtilService.createLearnerProfilesForUsers(TEST_PREFIX); | ||
} | ||
|
||
|
||
@Test | ||
@WithMockUser(username = STUDENT1_OF_COURSE, roles = "USER") | ||
void testAll_asStudent() { | ||
User user = userTestRepository.getUserWithGroupsAndAuthorities(STUDENT1_OF_COURSE); | ||
assertFalse(Hibernate.isInitialized(user.getLearnerProfile())); | ||
} | ||
} |