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

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

Minor cleanup and extending tests

parents de245d49 33abf6d9
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
...@@ -9,9 +9,10 @@ import java.net.URISyntaxException; ...@@ -9,9 +9,10 @@ import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -21,8 +22,6 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder; ...@@ -21,8 +22,6 @@ import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.gitlab4j.api.GitLabApi;
import org.gitlab4j.api.GitLabApiException;
import at.ac.uibk.gitsearch.repository.gitlab.GitLabRepository; import at.ac.uibk.gitsearch.repository.gitlab.GitLabRepository;
import at.ac.uibk.gitsearch.repository.search.MetaDataRepository; import at.ac.uibk.gitsearch.repository.search.MetaDataRepository;
...@@ -184,57 +183,6 @@ public class SearchService { ...@@ -184,57 +183,6 @@ public class SearchService {
} }
} }
/**
* temporary static test data.
*
* @param searchString just a string to add to testdata description.
* @return
*/
@SuppressWarnings("unused")
private SearchResultsDTO readTestResults(String searchString, long first, int length) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.findAndRegisterModules();
List<SearchResultDTO> loadedMetaData = new ArrayList<>();
for (String testFile : new String[] { "metaData1.yaml", "metaData2.yaml" }) {
log.debug("reading test data from {} ", testFile);
final File metaDataFile = new File("src/main/java/at/ac/uibk/gitsearch/service/testData/" + testFile);
try {
byte[] fileContent = FileCopyUtils.copyToByteArray(metaDataFile);
SearchResultDTO searchResultDTO = mapper.readValue(fileContent, SearchResultDTO.class);
loadedMetaData.add(searchResultDTO);
} catch (IOException e) {
log.error("Cannot read test search input from " + testFile, e);
}
}
List<SearchResultDTO> result = new ArrayList<>();
if (length > 0) {
int metadataPos = 0;
long recordNr = first;
// This loop is only used for testing to get more results.
for (int i = 0; i < 12; ++i) {
metadataPos = 0; // also for testing, remove later
while (metadataPos < length && metadataPos < loadedMetaData.size()) {
final SearchResultDTO loadedMetaDataRecord = new SearchResultDTO(loadedMetaData.get(metadataPos++));
if (loadedMetaDataRecord.toString().contains(searchString)) {
loadedMetaDataRecord.getMetadata()
.setTitle("#" + (recordNr + 1) + " " + loadedMetaDataRecord.getMetadata().getTitle());
result.add(loadedMetaDataRecord);
recordNr++;
log.debug("Added MetaData Record {}", loadedMetaData);
}
log.debug("{} does not contain {}", loadedMetaData, searchString);
}
}
}
return new SearchResultsDTO(result, NUM_TESTRESULTS, first);
}
public File exportExercise(long exerciseId) throws IOException { public File exportExercise(long exerciseId) throws IOException {
try{ try{
final GitLabApi gitLabApi = gitLabRepository.getGitLabApi(tokenProvider.getGitLabAccessInfo()); final GitLabApi gitLabApi = gitLabRepository.getGitLabApi(tokenProvider.getGitLabAccessInfo());
......
...@@ -75,7 +75,7 @@ export class ExerciseDetailsComponent implements OnInit, OnDestroy { ...@@ -75,7 +75,7 @@ export class ExerciseDetailsComponent implements OnInit, OnDestroy {
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
} }
}, },
() => alert('Unable to export exercise. Please log in to export.') () => alert('Unable to export exercise. Please log in to export, or check your git lab permissions.')
); );
} }
......
...@@ -2,31 +2,42 @@ package at.ac.uibk.gitsearch.service; ...@@ -2,31 +2,42 @@ package at.ac.uibk.gitsearch.service;
import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN; import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN;
import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.everyItem; import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasItemInArray; import static org.hamcrest.Matchers.hasItemInArray;
import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.codeability.sharing.plugins.api.SharingPluginConfig;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.node.NodeValidationException; import org.elasticsearch.node.NodeValidationException;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; 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.security.test.context.support.WithMockUser;
import at.ac.uibk.gitsearch.GitsearchApp; import at.ac.uibk.gitsearch.GitsearchApp;
import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestServerConfiguration; import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestServerConfiguration;
import at.ac.uibk.gitsearch.service.PluginManagementService.PluginConfigWrapper;
import at.ac.uibk.gitsearch.service.dto.AutoCompleteEntry;
import at.ac.uibk.gitsearch.service.dto.SearchInputDTO; import at.ac.uibk.gitsearch.service.dto.SearchInputDTO;
import at.ac.uibk.gitsearch.service.dto.SearchInputMetadataDTO; import at.ac.uibk.gitsearch.service.dto.SearchInputMetadataDTO;
import at.ac.uibk.gitsearch.service.dto.SearchResultsDTO; import at.ac.uibk.gitsearch.service.dto.SearchResultsDTO;
import static org.mockito.Mockito.when;
@SpringBootTest(classes = GitsearchApp.class) @SpringBootTest(classes = GitsearchApp.class)
@WithMockUser(value = TEST_USER_LOGIN, authorities = "sharing") @WithMockUser(value = TEST_USER_LOGIN, authorities = "sharing")
...@@ -34,6 +45,9 @@ public class SearchServiceIT { ...@@ -34,6 +45,9 @@ public class SearchServiceIT {
@Autowired @Autowired
RestHighLevelClient searchClient; RestHighLevelClient searchClient;
@MockBean
PluginManagementService pluginManagementService;
private static final Logger LOGGER = LoggerFactory.getLogger(SearchServiceIT.class); private static final Logger LOGGER = LoggerFactory.getLogger(SearchServiceIT.class);
...@@ -44,6 +58,16 @@ public class SearchServiceIT { ...@@ -44,6 +58,16 @@ public class SearchServiceIT {
public static void setUpESServer() throws IOException, NodeValidationException { public static void setUpESServer() throws IOException, NodeValidationException {
ElasticSearchTestServerConfiguration.getTestInstance().startTestNode(); ElasticSearchTestServerConfiguration.getTestInstance().startTestNode();
} }
@BeforeEach
public void initMock() {
Collection<PluginConfigWrapper> mockConfigs = Collections.singletonList(
new PluginConfigWrapper(new SharingPluginConfig("mockedPlugin", new SharingPluginConfig.Action[] {
new SharingPluginConfig.Action("mockedAction", "http://unused/unused-transferURL", "mocked Action", "true")
}), "http://unused/hopefully-unused")
);
when(pluginManagementService.getRegisteredPluginConfigs()).thenReturn(mockConfigs);
}
@Test @Test
public void testAllSearch() throws Exception { public void testAllSearch() throws Exception {
...@@ -141,4 +165,30 @@ public class SearchServiceIT { ...@@ -141,4 +165,30 @@ public class SearchServiceIT {
everyItem(hasProperty("metadata", hasProperty("license", containsString("MIT"))))); everyItem(hasProperty("metadata", hasProperty("license", containsString("MIT")))));
} }
@Test
public void testKeywordAutocompletion() throws IOException {
final List<AutoCompleteEntry> keywordsAutoComplete = searchService.getKeywordsAutoComplete("Jav");
assertThat(keywordsAutoComplete, contains(hasProperty("target", is("Java"))));
}
@Test
public void testCreatorAutocompletion() throws IOException {
final List<AutoCompleteEntry> creatorAutoComplete = searchService.getCreatorAutoComplete("Pod");
assertThat(creatorAutoComplete, contains(hasProperty("target", is("Stefan Podlipnig"))));
final List<AutoCompleteEntry> creatorAutoComplete2 = searchService.getCreatorAutoComplete("Po");
assertThat(creatorAutoComplete2, contains(hasProperty("target", is("Stefan Podlipnig"))));
}
@Test
public void testContributorAutocompletion() throws IOException {
final List<AutoCompleteEntry> contributorAutoComplete = searchService.getContributorAutoComplete("Bast");
assertThat(contributorAutoComplete, contains(hasProperty("target", is("Daniel Bastta"))));
}
@Test
public void testContributorCreatorAutocompletion() throws IOException {
final List<AutoCompleteEntry> contributorAutoComplete = searchService.getContributorCreatorAutoComplete("Bast");
assertThat(contributorAutoComplete, contains(hasProperty("target", is("Daniel Bastta"))));
}
} }
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