This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit ae882025 authored by Daniel Crazzolara's avatar Daniel Crazzolara
Browse files

Fixed previous tests

parent b8079128
2 merge requests!110HotFix Artemis,!109Bugfix: Fix Sharing import/export with Artemis
...@@ -12,6 +12,7 @@ import java.io.FileWriter; ...@@ -12,6 +12,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
...@@ -58,8 +59,8 @@ public class ExerciseServiceIT { ...@@ -58,8 +59,8 @@ public class ExerciseServiceIT {
@After @After
public void cleanUp() throws IOException { public void cleanUp() throws IOException {
if (new File("tmp-import/", token).exists()) { if (new File(System.getProperty("java.io.tmpdir"), token).exists()) {
FileUtils.deleteDirectory(new File("tmp-import/" + token)); FileUtils.deleteDirectory(new File(System.getProperty("java.io.tmpdir") + token));
} }
} }
...@@ -67,29 +68,29 @@ public class ExerciseServiceIT { ...@@ -67,29 +68,29 @@ public class ExerciseServiceIT {
public void testImportExercise() throws Exception { public void testImportExercise() throws Exception {
int gitlabGroup = 1; int gitlabGroup = 1;
File metadata = new File("tmp-import/" + token, "Exercise-Details-something.json"); File metadata = Paths.get(System.getProperty("java.io.tmpdir"), token, "Exercise-Details-something.json").toFile();
metadata.getParentFile().mkdirs(); metadata.getParentFile().mkdirs();
metadata.createNewFile(); metadata.createNewFile();
Group group = new Group(); Group group = new Group();
Repository jgitRepo = FileRepositoryBuilder.create(new File("tmp-import/" + token, ".git")); Repository jgitRepo = FileRepositoryBuilder.create(Paths.get(System.getProperty("java.io.tmpdir"), token, ".git").toFile());
// mocks // mocks
doNothing().when(gitlabService).setJGitDefaultAuth(); doNothing().when(gitlabService).setJGitDefaultAuth();
doReturn(group).when(gitlabService).getGroupById(gitlabGroup); doReturn(group).when(gitlabService).getGroupById(gitlabGroup);
doReturn("repoUrl").when(gitlabService).createRepository(group, artemisExerciseInfo.getTitle()); doReturn("repoUrl").when(gitlabService).createRepository(group, artemisExerciseInfo.getTitle());
doReturn(jgitRepo).when(gitlabService).checkoutRepo("repoUrl"); doReturn(jgitRepo).when(gitlabService).checkoutRepo("repoUrl");
doNothing().when(gitlabService).commitAndPushToRepo(jgitRepo, new File("tmp-import", token)); doNothing().when(gitlabService).commitAndPushToRepo(jgitRepo, new File(System.getProperty("java.io.tmpdir"), token));
exerciseService.importExercise(artemisExerciseInfo, token, gitlabGroup); exerciseService.importExercise(artemisExerciseInfo, token, gitlabGroup);
// asserts // asserts
verify(gitlabService, times(1)).createRepository(group, artemisExerciseInfo.getTitle()); verify(gitlabService, times(1)).createRepository(group, artemisExerciseInfo.getTitle());
verify(gitlabService, times(1)).commitAndPushToRepo(jgitRepo, new File("tmp-import", token)); verify(gitlabService, times(1)).commitAndPushToRepo(jgitRepo, new File(System.getProperty("java.io.tmpdir"), token));
} }
@Test @Test
public void testApplyExerciseInfoChanges() throws Exception { public void testApplyExerciseInfoChanges() throws Exception {
File metadata = new File("tmp-import/" + token, "metadata.yaml"); File metadata = Paths.get(System.getProperty("java.io.tmpdir"), token, "metadata.yaml").toFile();
metadata.getParentFile().mkdirs(); metadata.getParentFile().mkdirs();
metadata.createNewFile(); metadata.createNewFile();
...@@ -103,7 +104,7 @@ public class ExerciseServiceIT { ...@@ -103,7 +104,7 @@ public class ExerciseServiceIT {
@Test @Test
public void testGetArtemisExerciseInfo() throws Exception { public void testGetArtemisExerciseInfo() throws Exception {
File metadata = new File("tmp-import/" + token, "Exercise-Details-something.json"); File metadata = Paths.get(System.getProperty("java.io.tmpdir"), token, "Exercise-Details-something.json").toFile();
metadata.getParentFile().mkdirs(); metadata.getParentFile().mkdirs();
metadata.createNewFile(); metadata.createNewFile();
FileWriter writer = new FileWriter(metadata, StandardCharsets.UTF_8); FileWriter writer = new FileWriter(metadata, StandardCharsets.UTF_8);
...@@ -145,7 +146,7 @@ public class ExerciseServiceIT { ...@@ -145,7 +146,7 @@ public class ExerciseServiceIT {
@Test @Test
public void testGetArtemisExerciseInfo_onlyMetadata() throws Exception { public void testGetArtemisExerciseInfo_onlyMetadata() throws Exception {
File metadata = new File("tmp-import/" + token, "Exercise-Details-something.json"); File metadata = Paths.get(System.getProperty("java.io.tmpdir"), token, "Exercise-Details-something.json").toFile();
metadata.getParentFile().mkdirs(); metadata.getParentFile().mkdirs();
metadata.createNewFile(); metadata.createNewFile();
FileWriter writer = new FileWriter(metadata, StandardCharsets.UTF_8); FileWriter writer = new FileWriter(metadata, StandardCharsets.UTF_8);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment