-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix/programming exercise/fix broken endpoints (#838)
- Loading branch information
1 parent
b417c41
commit a714635
Showing
8 changed files
with
190 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
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
122 changes: 122 additions & 0 deletions
122
src/test/java/de/tum/in/www1/artemis/ProgrammingExerciseTest.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,122 @@ | ||
package de.tum.in.www1.artemis; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import de.tum.in.www1.artemis.domain.ProgrammingExercise; | ||
import de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository; | ||
import de.tum.in.www1.artemis.security.SecurityUtils; | ||
import de.tum.in.www1.artemis.service.connectors.BambooService; | ||
import de.tum.in.www1.artemis.service.connectors.BitbucketService; | ||
import de.tum.in.www1.artemis.util.DatabaseUtilService; | ||
import de.tum.in.www1.artemis.util.RequestUtilService; | ||
import de.tum.in.www1.artemis.web.rest.ProblemStatementUpdate; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@AutoConfigureTestDatabase | ||
@ActiveProfiles("artemis, bamboo") | ||
class ProgrammingExerciseTest { | ||
|
||
@Autowired | ||
DatabaseUtilService database; | ||
|
||
@Autowired | ||
RequestUtilService request; | ||
|
||
@Autowired | ||
ProgrammingExerciseRepository programmingExerciseRepository; | ||
|
||
@MockBean | ||
BambooService continuousIntegrationService; | ||
|
||
@MockBean | ||
BitbucketService versionControlService; | ||
|
||
Long programmingExerciseId; | ||
|
||
@BeforeEach | ||
void init() { | ||
database.addUsers(2, 2, 2); | ||
database.addCourseWithOneProgrammingExercise(); | ||
|
||
programmingExerciseId = programmingExerciseRepository.findAll().get(0).getId(); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
database.resetDatabase(); | ||
} | ||
|
||
void updateProgrammingExercise(ProgrammingExercise programmingExercise, String newProblem, String newTitle) throws Exception { | ||
programmingExercise.setProblemStatement(newProblem); | ||
programmingExercise.setTitle(newTitle); | ||
when(continuousIntegrationService.buildPlanIdIsValid(programmingExercise.getTemplateBuildPlanId())).thenReturn(true); | ||
when(versionControlService.repositoryUrlIsValid(programmingExercise.getTemplateRepositoryUrlAsUrl())).thenReturn(true); | ||
when(continuousIntegrationService.buildPlanIdIsValid(programmingExercise.getSolutionBuildPlanId())).thenReturn(true); | ||
when(versionControlService.repositoryUrlIsValid(programmingExercise.getSolutionRepositoryUrlAsUrl())).thenReturn(true); | ||
|
||
ProgrammingExercise updatedProgrammingExercise = request.putWithResponseBody("/api/programming-exercises", programmingExercise, ProgrammingExercise.class, HttpStatus.OK); | ||
|
||
// The result from the put response should be updated with the new data. | ||
assertThat(updatedProgrammingExercise.getProblemStatement()).isEqualTo(newProblem); | ||
assertThat(updatedProgrammingExercise.getTitle()).isEqualTo(newTitle); | ||
|
||
SecurityUtils.setAuthorizationObject(); | ||
// There should still be only 1 programming exercise. | ||
assertThat(programmingExerciseRepository.count()).isEqualTo(1); | ||
// The programming exercise in the db should also be updated. | ||
ProgrammingExercise fromDb = programmingExerciseRepository.findById(programmingExercise.getId()).get(); | ||
assertThat(fromDb.getProblemStatement()).isEqualTo(newProblem); | ||
assertThat(fromDb.getTitle()).isEqualTo(newTitle); | ||
} | ||
|
||
@Test | ||
@WithMockUser(value = "instructor1", roles = "INSTRUCTOR") | ||
void updateProgrammingExerciseOnce() throws Exception { | ||
ProgrammingExercise programmingExercise = programmingExerciseRepository.findById(programmingExerciseId).get(); | ||
updateProgrammingExercise(programmingExercise, "new problem 1", "new title 1"); | ||
} | ||
|
||
@Test | ||
@WithMockUser(value = "instructor1", roles = "INSTRUCTOR") | ||
void updateProgrammingExerciseTwice() throws Exception { | ||
ProgrammingExercise programmingExercise = programmingExerciseRepository.findById(programmingExerciseId).get(); | ||
updateProgrammingExercise(programmingExercise, "new problem 1", "new title 1"); | ||
updateProgrammingExercise(programmingExercise, "new problem 2", "new title 2"); | ||
} | ||
|
||
@Test | ||
@WithMockUser(value = "instructor1", roles = "INSTRUCTOR") | ||
void updateProblemStatement() throws Exception { | ||
String newProblem = "a new problem statement"; | ||
ProgrammingExercise programmingExercise = programmingExerciseRepository.findById(programmingExerciseId).get(); | ||
ProblemStatementUpdate problemStatementUpdate = new ProblemStatementUpdate(); | ||
problemStatementUpdate.setExerciseId(programmingExerciseId); | ||
problemStatementUpdate.setProblemStatement(newProblem); | ||
ProgrammingExercise updatedProgrammingExercise = request.patchWithResponseBody("/api/programming-exercises-problem", problemStatementUpdate, ProgrammingExercise.class, | ||
HttpStatus.OK); | ||
|
||
assertThat(updatedProgrammingExercise.getProblemStatement()).isEqualTo(newProblem); | ||
|
||
SecurityUtils.setAuthorizationObject(); | ||
ProgrammingExercise fromDb = programmingExerciseRepository.findById(programmingExerciseId).get(); | ||
assertThat(fromDb.getProblemStatement()).isEqualTo(newProblem); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.