Search in sources :

Example 31 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class AccountResourceIntTest method testSaveAccount.

@Test
@Transactional
@WithMockUser("save-account")
public void testSaveAccount() throws Exception {
    User user = new User();
    user.setLogin("save-account");
    user.setEmail("save-account@example.com");
    user.setPassword(RandomStringUtils.random(60));
    user.setActivated(true);
    userRepository.saveAndFlush(user);
    UserDTO userDTO = new UserDTO(// id
    null, // login
    "not-used", // firstName
    "firstname", // lastName
    "lastname", // email
    "save-account@example.com", // activated
    false, // imageUrl
    "http://placehold.it/50x50", // langKey
    Constants.DEFAULT_LANGUAGE, // createdBy
    null, // createdDate
    null, // lastModifiedBy
    null, // lastModifiedDate
    null, new HashSet<>(Collections.singletonList(AuthoritiesConstants.ADMIN)), new ArrayList<String>());
    restMvc.perform(post("/api/account").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(userDTO))).andExpect(status().isOk());
    User updatedUser = userRepository.findOneByLogin(user.getLogin()).orElse(null);
    assertThat(updatedUser.getFirstName()).isEqualTo(userDTO.getFirstName());
    assertThat(updatedUser.getLastName()).isEqualTo(userDTO.getLastName());
    assertThat(updatedUser.getEmail()).isEqualTo(userDTO.getEmail());
    assertThat(updatedUser.getLangKey()).isEqualTo(userDTO.getLangKey());
    assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());
    assertThat(updatedUser.getImageUrl()).isEqualTo(userDTO.getImageUrl());
    assertThat(updatedUser.getActivated()).isEqualTo(true);
    assertThat(updatedUser.getAuthorities()).isEmpty();
}
Also used : User(de.tum.in.www1.artemis.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UserDTO(de.tum.in.www1.artemis.service.dto.UserDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class CourseResourceIntTest method createCourse.

@Test
@Transactional
public void createCourse() throws Exception {
    int databaseSizeBeforeCreate = courseRepository.findAll().size();
    // Create the Course
    restCourseMockMvc.perform(post("/api/courses").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(course))).andExpect(status().isCreated());
    // Validate the Course in the database
    List<Course> courseList = courseRepository.findAll();
    assertThat(courseList).hasSize(databaseSizeBeforeCreate + 1);
    Course testCourse = courseList.get(courseList.size() - 1);
    assertThat(testCourse.getTitle()).isEqualTo(DEFAULT_TITLE);
    assertThat(testCourse.getStudentGroupName()).isEqualTo(DEFAULT_STUDENT_GROUP_NAME);
    assertThat(testCourse.getTeachingAssistantGroupName()).isEqualTo(DEFAULT_TEACHING_ASSISTANT_GROUP_NAME);
    assertThat(testCourse.getInstructorGroupName()).isEqualTo(DEFAULT_INSTRUCTOR_GROUP_NAME);
    assertThat(testCourse.getStartDate()).isEqualTo(DEFAULT_START_DATE);
    assertThat(testCourse.getEndDate()).isEqualTo(DEFAULT_END_DATE);
    assertThat(testCourse.isOnlineCourse()).isEqualTo(DEFAULT_ONLINE_COURSE);
}
Also used : Course(de.tum.in.www1.artemis.domain.Course) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class FeedbackResourceIntTest method createFeedback.

@Test
@Transactional
public void createFeedback() throws Exception {
    int databaseSizeBeforeCreate = feedbackRepository.findAll().size();
    // Create the Feedback
    restFeedbackMockMvc.perform(post("/api/feedbacks").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(feedback))).andExpect(status().isCreated());
    // Validate the Feedback in the database
    List<Feedback> feedbackList = feedbackRepository.findAll();
    assertThat(feedbackList).hasSize(databaseSizeBeforeCreate + 1);
    Feedback testFeedback = feedbackList.get(feedbackList.size() - 1);
    assertThat(testFeedback.getText()).isEqualTo(DEFAULT_TEXT);
    assertThat(testFeedback.getDetailText()).isEqualTo(DEFAULT_DETAIL_TEXT);
    assertThat(testFeedback.isPositive()).isEqualTo(DEFAULT_POSITIVE);
    assertThat(testFeedback.getType()).isEqualTo(DEFAULT_TYPE);
}
Also used : Feedback(de.tum.in.www1.artemis.domain.Feedback) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class LtiUserIdResourceIntTest method createLtiUserId.

@Test
@Transactional
public void createLtiUserId() throws Exception {
    int databaseSizeBeforeCreate = ltiUserIdRepository.findAll().size();
    // Create the LtiUserId
    restLtiUserIdMockMvc.perform(post("/api/lti-user-ids").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(ltiUserId))).andExpect(status().isCreated());
    // Validate the LtiUserId in the database
    List<LtiUserId> ltiUserIdList = ltiUserIdRepository.findAll();
    assertThat(ltiUserIdList).hasSize(databaseSizeBeforeCreate + 1);
    LtiUserId testLtiUserId = ltiUserIdList.get(ltiUserIdList.size() - 1);
    assertThat(testLtiUserId.getLtiUserId()).isEqualTo(DEFAULT_LTI_USER_ID);
}
Also used : LtiUserId(de.tum.in.www1.artemis.domain.LtiUserId) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with Post

use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.

the class ModelingExerciseResourceIntTest method createModelingExercise.

@Test
@Transactional
public void createModelingExercise() throws Exception {
    int databaseSizeBeforeCreate = modelingExerciseRepository.findAll().size();
    // Create the ModelingExercise
    restModelingExerciseMockMvc.perform(post("/api/modeling-exercises").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(modelingExercise))).andExpect(status().isCreated());
    // Validate the ModelingExercise in the database
    List<ModelingExercise> modelingExerciseList = modelingExerciseRepository.findAll();
    assertThat(modelingExerciseList).hasSize(databaseSizeBeforeCreate + 1);
    ModelingExercise testModelingExercise = modelingExerciseList.get(modelingExerciseList.size() - 1);
    assertThat(testModelingExercise.getBaseFilePath()).isEqualTo(DEFAULT_BASE_FILE_PATH);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.ModelingExercise) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Post (de.tum.in.www1.artemis.domain.metis.Post)155 WithMockUser (org.springframework.security.test.context.support.WithMockUser)150 Test (org.junit.jupiter.api.Test)136 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)118 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)97 User (de.tum.in.www1.artemis.domain.User)88 AnswerPost (de.tum.in.www1.artemis.domain.metis.AnswerPost)87 URI (java.net.URI)63 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)56 Course (de.tum.in.www1.artemis.domain.Course)52 Transactional (org.springframework.transaction.annotation.Transactional)37 Reaction (de.tum.in.www1.artemis.domain.metis.Reaction)36 Test (org.junit.Test)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)36 Exercise (de.tum.in.www1.artemis.domain.Exercise)35 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 Exam (de.tum.in.www1.artemis.domain.exam.Exam)20 Lecture (de.tum.in.www1.artemis.domain.Lecture)16 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)16 SortingOrder (de.tum.in.www1.artemis.domain.enumeration.SortingOrder)16