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

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

Merge branch 'improveTests' into 'development'

Improve tests

See merge request sharing/codeability-sharing-platform!75
parents d1bd2e8a cbd7206a
2 merge requests!91Bringing JHipster7.6.0 to production,!75Improve tests
......@@ -34,14 +34,17 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
......
package at.ac.uibk.gitsearch.service;
import at.ac.uibk.gitsearch.GitsearchApp;
import at.ac.uibk.gitsearch.es.model.ArtemisExerciseInfo;
import at.ac.uibk.gitsearch.es.model.ExerciseInfo;
import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestServerConfiguration;
import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.attributes.AttributesNodeProvider;
import org.eclipse.jgit.lib.*;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.elasticsearch.node.NodeValidationException;
import org.gitlab4j.api.models.Group;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import java.io.*;
import java.nio.file.Files;
import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN;
import static org.mockito.Mockito.*;
import at.ac.uibk.gitsearch.GitsearchApp;
import at.ac.uibk.gitsearch.es.model.ArtemisExerciseInfo;
@SpringBootTest(classes = GitsearchApp.class)
@RunWith(SpringJUnit4ClassRunner.class)
......@@ -78,7 +75,6 @@ public class ExerciseServiceIT {
Group group = new Group();
Repository jgitRepo = FileRepositoryBuilder.create(new File("tmp-import/" + token, ".git"));
// mocks
doNothing().when(gitlabService).setJGitDefaultAuth();
doReturn(group).when(gitlabService).getGroupById(gitlabGroup);
......@@ -86,7 +82,6 @@ public class ExerciseServiceIT {
doReturn(jgitRepo).when(gitlabService).checkoutRepo("repoUrl");
doNothing().when(gitlabService).commitAndPushToRepo(jgitRepo, new File("tmp-import", token));
exerciseService.importExercise(artemisExerciseInfo, token, gitlabGroup);
// asserts
......@@ -102,10 +97,9 @@ public class ExerciseServiceIT {
exerciseService.applyExerciseInfoChanges(artemisExerciseInfo, token);
Assert.assertEquals("metadataVersion: \"1\"\n" +
"title: \"TestTitle\"\n" +
"license: \"testLicense\"\n" +
"learningResourceType: \"Artemis\"", new String(Files.readAllBytes(metadata.toPath())).strip());
Assert.assertEquals("learningResourceType: \"Artemis\"\n" + "license: \"testLicense\"\n"
+ "metadataVersion: \"1\"\n" + "title: \"TestTitle\"",
new String(Files.readAllBytes(metadata.toPath())).strip());
}
@Test
......@@ -114,20 +108,11 @@ public class ExerciseServiceIT {
metadata.getParentFile().mkdirs();
metadata.createNewFile();
FileWriter writer = new FileWriter(metadata);
writer.write("{\n" +
" \"metadataVersion\": \"1\",\n" +
" \"type\": \"programming exercise\",\n" +
" \"title\": \"TestTitle\",\n" +
" \"license\": \"testLicense\",\n" +
" \"maxPoints\": 100,\n" +
" \"bonusPoints\": 100,\n" +
" \"mode\": \"INDIVIDUAL\",\n" +
" \"staticCodeAnalysis\": false,\n" +
" \"allowOfflineIDE\": false,\n" +
" \"allowOnlineEditor\": false,\n" +
" \"showTestNamesToStudents\": false,\n" +
" \"sequentialTestRuns\": false\n" +
"}");
writer.write("{\n" + " \"metadataVersion\": \"1\",\n" + " \"type\": \"programming exercise\",\n"
+ " \"title\": \"TestTitle\",\n" + " \"license\": \"testLicense\",\n" + " \"maxPoints\": 100,\n"
+ " \"bonusPoints\": 100,\n" + " \"mode\": \"INDIVIDUAL\",\n" + " \"staticCodeAnalysis\": false,\n"
+ " \"allowOfflineIDE\": false,\n" + " \"allowOnlineEditor\": false,\n"
+ " \"showTestNamesToStudents\": false,\n" + " \"sequentialTestRuns\": false\n" + "}");
writer.close();
artemisExerciseInfo.setMaxPoints(100f);
......@@ -138,6 +123,13 @@ public class ExerciseServiceIT {
artemisExerciseInfo.setAllowOnlineEditor(false);
artemisExerciseInfo.setShowTestNamesToStudents(false);
artemisExerciseInfo.setSequentialTestRuns(false);
artemisExerciseInfo.setLearningResourceType(null);
artemisExerciseInfo.setStructure("atomic");
List<String> str = new ArrayList<>();
str.add("artemis");
artemisExerciseInfo.setFormat(str);
Assert.assertEquals(artemisExerciseInfo, exerciseService.getArtemisExerciseInfo(token));
}
......@@ -148,14 +140,18 @@ public class ExerciseServiceIT {
metadata.getParentFile().mkdirs();
metadata.createNewFile();
FileWriter writer = new FileWriter(metadata);
writer.write("{\n" +
" \"metadataVersion\": \"1\",\n" +
" \"type\": \"programming exercise\",\n" +
" \"title\": \"TestTitle\",\n" +
" \"license\": \"testLicense\"\n" +
"}");
writer.write("{\n" + " \"metadataVersion\": \"1\",\n" + " \"type\": \"programming exercise\",\n"
+ " \"title\": \"TestTitle\",\n" + " \"license\": \"testLicense\"\n" + "}");
writer.close();
artemisExerciseInfo.setLearningResourceType(null);
artemisExerciseInfo.setStructure("atomic");
List<String> str = new ArrayList<>();
str.add("artemis");
artemisExerciseInfo.setFormat(str);
Assert.assertEquals(artemisExerciseInfo, exerciseService.getArtemisExerciseInfo(token));
}
......
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