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

Skip to content
Snippets Groups Projects
Commit b30ecc21 authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Merge branch 'improve_test_coverage' into 'development'

Improve test coverage

See merge request sharing/codeability-sharing-platform!63
parents 3acd511e 6590508a
Branches
Tags
2 merge requests!67Bereitstellung für August Release,!63Improve test coverage
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gitsearch</name>
<comment></comment>
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
......@@ -13,15 +18,6 @@
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/mvnw clean generate-sources.launch</value>
</dictionary>
<dictionary>
<key>incclean</key>
<value>true</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
......@@ -41,7 +37,7 @@
</natures>
<filteredResources>
<filter>
<id>1617023900149</id>
<id>1630247593152</id>
<name></name>
<type>30</type>
<matcher>
......
......@@ -13,5 +13,5 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
activeProfiles=dev
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
This diff is collapsed.
pom.xml 100644 → 100755
......@@ -34,8 +34,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<argLine>-Djava.security.egd=file:/dev/./urandom -Xmx256m</argLine>
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
<run.addResources>false</run.addResources>
......
......@@ -105,15 +105,4 @@ public class LikesCriteria implements Serializable, Criteria {
);
}
// prettier-ignore
@Override
public String toString() {
return "LikesCriteria{" +
(id != null ? "id=" + id + ", " : "") +
(date != null ? "date=" + date + ", " : "") +
(userID != null ? "userID=" + userID + ", " : "") +
(exerciseID != null ? "ExerciseID=" + exerciseID + ", " : "") +
"}";
}
}
package at.ac.uibk.gitsearch.service;
import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.node.NodeValidationException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithMockUser;
import at.ac.uibk.gitsearch.GitsearchApp;
import at.ac.uibk.gitsearch.repository.StatisticsRepository;
import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestServerConfiguration;
import at.ac.uibk.gitsearch.service.dto.StatisticsDTO;
@SpringBootTest(classes = GitsearchApp.class)
@WithMockUser(value = TEST_USER_LOGIN, authorities = "sharing")
public class AchievementServiceIT {
@SuppressWarnings("unused")
private static final Logger LOGGER = LogManager.getLogger(AchievementServiceIT.class);
@Autowired
RestHighLevelClient elasticsearchTestClient;
@BeforeAll
public static void setUpESServer() throws IOException, NodeValidationException {
ElasticSearchTestServerConfiguration.getTestInstance().startTestNode();
}
@BeforeEach
public void setUpIndex() {
}
@Autowired
AchievementService achievementService;
@Autowired
SearchService searchService;
@Autowired
private StatisticsRepository statisticsRepository;
@Autowired
private StatisticsService statisticsService;
@Test
public void testSearchUserStatisticsEmpty() throws IOException {
final StatisticsDTO result = achievementService.searchUserStatistics(" ");
assertEquals(Integer.valueOf(0), result.getDownloads());
assertEquals(Integer.valueOf(0), result.getViews());
}
@Test
public void testSearchUserStatisticsValid() throws IOException {
StatisticsDTO newStats = new StatisticsDTO();
newStats.setDownloads(1);
newStats.setViews(1);
newStats.setExerciseID("143");
statisticsService.save(newStats);
final StatisticsDTO result = achievementService.searchUserStatistics("stefan.podlipnig@tuwien.ac.at");
assertEquals(Integer.valueOf(1), result.getDownloads());
assertEquals(Integer.valueOf(1), result.getViews());
}
}
package at.ac.uibk.gitsearch.web.rest;
import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN;
import static org.assertj.core.api.Assertions.assertThat;
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.hamcrest.Matchers.hasItem;
......@@ -33,6 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.transaction.annotation.Transactional;
import at.ac.uibk.gitsearch.GitsearchApp;
......@@ -48,7 +50,7 @@ import at.ac.uibk.gitsearch.service.LikesService;
@SpringBootTest(classes = GitsearchApp.class)
@ExtendWith(MockitoExtension.class)
@AutoConfigureMockMvc
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
@WithMockUser(value = TEST_USER_LOGIN, authorities = {"sharing", AuthoritiesConstants.ADMIN})
public class LikesResourceIT {
private static final LocalDate DEFAULT_DATE = LocalDate.ofEpochDay(0L);
......@@ -280,6 +282,35 @@ public class LikesResourceIT {
}
@Test
@Transactional
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
public void testHasLikedProject() throws Exception {
// Initialize the database
likesRepository.saveAndFlush(likes);
// generate new like
Likes newLike = new Likes();
newLike.setExerciseID("1000/abc/bd");
//user likes a project
restLikesMockMvc.perform(put("/api/likes/likeExercise").with(csrf().asHeader()).contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(newLike))).andExpect(status().isOk());
MvcResult result = restLikesMockMvc.perform(get("/api/likes/hasLiked/{exerciseID}", "1000/abc/bd").with(csrf().asHeader()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
String content = result.getResponse().getContentAsString();
assertEquals("true", content);
result = restLikesMockMvc.perform(get("/api/likes/hasLiked/{exerciseID}", "imaginary").with(csrf().asHeader()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
content = result.getResponse().getContentAsString();
assertEquals("false", content);
}
@Test
@Transactional
public void testLikeWorkflowWithOutAuthorities() throws Exception {
......
......@@ -330,11 +330,24 @@ public class StatisticsResourceIT {
@Transactional
@WithMockUser(authorities = AuthoritiesConstants.ADMIN)
public void getStatisticsByExerciseId() throws Exception {
// Initialize the database
statisticsRepository.saveAndFlush(statistics);
// Get the statistics and see if it coincides with the mock stats
assertEquals(statisticsService.findOneByExerciseID(statistics.getExerciseID()).get().getExerciseID(), statistics.getExerciseID());
statisticsRepository.deleteAll();
//After the following call a new statistics entity for the exerciseID 143 should have been created because there exists a resource with this id in elastic search from stefan podlipnig
restStatisticsMockMvc.perform(get("/api/statistics/exercise/{id}", "143").with(csrf().asHeader())).andExpect(status().isOk());
assertEquals(statisticsService.findOneByExerciseID("143").get().getExerciseID(), "143");
//Do the same call again to see if the statisticsService understood that the entity already exists and it only needs to increase the views
restStatisticsMockMvc.perform(get("/api/statistics/exercise/{id}", "143").with(csrf().asHeader())).andExpect(status().isOk());
assertEquals(statisticsService.findOneByExerciseID("143").get().getViews(), 2);
//Test the search for an id which does not exist
assertEquals(Optional.empty(),statisticsService.findOneByExerciseID("notThere"));
}
......
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