Skip to content

Commit

Permalink
Adds Server test to ensure lazy loading of LearnerProfile in User.
Browse files Browse the repository at this point in the history
  • Loading branch information
N0W0RK committed Jan 14, 2025
1 parent faadc49 commit 86250b1
Showing 1 changed file with 52 additions and 0 deletions.
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()));
}
}

0 comments on commit 86250b1

Please sign in to comment.