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

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

More Tests

parent 4b48624e
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
......@@ -20,6 +20,7 @@ import java.util.List;
import org.codeability.sharing.plugins.api.SharingPluginConfig;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.node.NodeValidationException;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......@@ -75,6 +76,7 @@ public class SearchServiceIT {
SearchInputDTO searchQuery = new SearchInputDTO(null, searchMetadata, null, null, null, 0);
SearchResultsDTO searchResultPage = searchService.searchResultPage(searchQuery, 0, SearchInputDTO.PAGE_SIZE);
Assert.assertTrue("At least one hit?", searchResultPage.getSearchResult().size() >= 1);
LOGGER.info("found {} hits for all", searchResultPage.getHitCount());
}
......
package at.ac.uibk.gitsearch.service;
import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.codeability.sharing.plugins.api.ShoppingBasket;
import org.elasticsearch.node.NodeValidationException;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll;
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.search.testESService.ElasticSearchTestServerConfiguration;
import at.ac.uibk.gitsearch.service.ShoppingBasketService.ShoppingBasketInfoDTO;
import at.ac.uibk.gitsearch.service.ShoppingBasketService.ShoppingBasketRedirectInfoDTO;
import at.ac.uibk.gitsearch.service.dto.SearchInputDTO;
import at.ac.uibk.gitsearch.service.dto.SearchInputMetadataDTO;
import at.ac.uibk.gitsearch.service.dto.SearchResultDTO;
import at.ac.uibk.gitsearch.service.dto.SearchResultsDTO;
@SpringBootTest(classes = GitsearchApp.class)
@WithMockUser(value = TEST_USER_LOGIN, authorities = "sharing")
public class ShoppingBasketServiceIT {
private static final String TEST_ZIP_LOCATION = "./testData/junit-quality-tests-exercise-master.zip";
@Autowired
protected ShoppingBasketService shoppingBasketService;
@Autowired
private SearchService searchService;
private static final Logger log = LoggerFactory.getLogger(ShoppingBasketServiceIT.class);
@BeforeAll
public static void setUpESServer() throws IOException, NodeValidationException {
ElasticSearchTestServerConfiguration.getTestInstance().startTestNode();
}
@Test
public void testRepackage() throws IOException {
......@@ -45,6 +69,33 @@ public class ShoppingBasketServiceIT {
testRepackagedZip.close();
}
@Test
public void testGetBasket() throws IOException {
// just load everything from index :-)
final SearchInputMetadataDTO searchMetadata = new SearchInputMetadataDTO(null, null, null, null, null);
SearchInputDTO searchQuery = new SearchInputDTO(null, searchMetadata, null, null, null, 0);
SearchResultsDTO searchResultPage = searchService.searchResultPage(searchQuery, 0, SearchInputDTO.PAGE_SIZE);
Assert.assertTrue("At least one hit?", searchResultPage.getSearchResult().size() >= 1);
ShoppingBasketInfoDTO sbi = new ShoppingBasketInfoDTO(searchResultPage.getSearchResult().toArray(new SearchResultDTO[] {}));
ShoppingBasketRedirectInfoDTO redInfo = shoppingBasketService.getRedirectInfo(sbi, "http://unused/unused");
Pattern tokenParser = Pattern.compile("/([^/?]*)\\?");
final Matcher matcher = tokenParser.matcher(redInfo.getRedirectURL());
Assert.assertTrue(matcher.find());
String token=matcher.group(1);
final ShoppingBasket basket = shoppingBasketService.getBasket(token);
int count=0;
for(SearchResultDTO hitResult: searchResultPage.getSearchResult()) {
// we assume same sequence
Assert.assertEquals(basket.exerciseInfo[count].title, hitResult.getMetadata().getTitle());
count++;
}
}
}
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