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

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

Major Refactoring of Test Elastic Search Setup

parent a7de4285
Branches
Tags v1.2
1 merge request!55June Release
Showing
with 64 additions and 72 deletions
......@@ -385,7 +385,7 @@ public class MetaDataRepository {
SearchRepositoryConstants.METADATA_PUBLISHER)
.type(MultiMatchQueryBuilder.Type.PHRASE_PREFIX));
if (authorBuilder.hasClauses())
queryBuilder.must(QueryBuilders.matchQuery(null, fullTextBuilder));
queryBuilder.must(authorBuilder);
if (searchInputDTO.getMetadata().getTypes() != null && !searchInputDTO.getMetadata().getTypes().isEmpty()) {
BoolQueryBuilder typeBuilder = QueryBuilders.boolQuery();
......
......@@ -156,7 +156,7 @@ public class SearchResource {
* ResponseEntity with status
* @throws IOException if something during the zip process went wrong
*/
@PostMapping("/programming-exercises/{projectId}/export-programming-exercise")
@PostMapping("/programming-exercises/{exerciseId}/export-programming-exercise")
public ResponseEntity<Resource> exportProgrammingExercise(@PathVariable String exerciseId) throws IOException {
File zipFile = searchService.exportExercise(exerciseId);
......
......@@ -72,7 +72,7 @@ public class MetaDataRepositoryIT {
@Test
public void testProgrammingLanguageAutocompletion() throws IOException {
final List<AutoCompleteEntry> plAutoComplete = metaDataRepository.getProgrammingLanguageAutoComplete("Ja", 10);
assertThat(plAutoComplete, contains(hasProperty("target", is("Java"))));
assertThat(plAutoComplete, contains(hasProperty("target", is("JAVA"))));
}
@Test
......
package at.ac.uibk.gitsearch.repository.search.testESService;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
......@@ -199,6 +201,8 @@ public class ElasticSearchTestServerConfiguration {
return indices2;
}
int contentCount = 0;
private void setUpContent() throws IOException, URISyntaxException {
......@@ -206,20 +210,24 @@ public class ElasticSearchTestServerConfiguration {
URL test = this.getClass().getResource("../../../service/testData");
File rootData = new File(test.toURI());
File metaDataTestDir = new File(rootData, "metaData");
contentCount = 0;
visitSubdirectories(metaDataTestDir,
(File metaDataFile, List<SearchResultDTO> children, String relativePath) -> {
try {
final UserProvidedMetadataDTO userMetaData = parseMetaDataFile(metaDataFile);
SearchResultDTO toIndex = new SearchResultDTO();
toIndex.setMetadata(userMetaData);
final GitProject gitProject = new GitProject();
final ExerciseId exerciseId = calculateProjectId(relativePath);
toIndex.setExerciseId(exerciseId.toString());
final GitProject gitProject = new GitProject();
gitProject.setProjectId(Integer.parseInt(exerciseId.getProjectId()));
gitProject.setProject_name("SomeGitProject"+exerciseId.getProjectId());
toIndex.setProject(gitProject);
final MetadataFile file = new MetadataFile();
file.setFilename(metaDataFile.getName());
file.setIndexing_date(Instant.now());
......@@ -229,24 +237,24 @@ public class ElasticSearchTestServerConfiguration {
toIndex.setExerciseId(exerciseId.toString());
addContentToIndex(toIndex, exerciseId);
ElasticSearchTestServerConfiguration.this.contentCount++;
return Collections.singletonList(
toIndex
);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}, ""
);
int contentCount = 0;
while(true) {
contentCount++;
final String content = getContent(contentCount);
if(content==null) break;
}
//
//
//
// while(true) {
// contentCount++;
// final String content = getContent(contentCount);
// if(content==null) break;
// }
waitForCleanStartUp(contentCount-1);
}
......@@ -256,16 +264,28 @@ public class ElasticSearchTestServerConfiguration {
StringWriter sw = new StringWriter();
mapper.writeValue(sw, content);
String contentString = sw.toString();
addContentToIndex(contentString, id.toString());
// Hard Core: set everything to public
String addedContent = contentString.replace("\"project_id\":", "\"visibility\":\"public\", \"project_id\":");
addContentToIndex(addedContent, id.toString());
}
private static final Charset UTF8 = Charset.forName("UTF-8");
private void addContentToIndex(String content, String id) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> request =
new HttpEntity<String>(content, headers);
restTemplate.put("http://localhost:29200/metadata/_doc/"+id, request, String.class);
String encodedId = URLEncoder.encode(id, UTF8);
encodedId = id.replace("/", "%2F");
URI uri;
try {
uri = new URI("http://localhost:29200/metadata/_doc/"+encodedId);
restTemplate.put(uri, request);
} catch (URISyntaxException e) {
LOGGER.warn("Cannot add " + id, e);
}
}
......@@ -277,7 +297,7 @@ public class ElasticSearchTestServerConfiguration {
}
else {
int projectId = Integer.parseInt(relativePath.substring(0, relativePathPos));
return new ExerciseId(projectId+"", relativePath.substring(0, relativePathPos+1));
return new ExerciseId(projectId+"", relativePath.substring(relativePathPos+1));
}
}
......@@ -412,35 +432,6 @@ public class ElasticSearchTestServerConfiguration {
return text;
}
private String getContent(File f) throws IOException {
InputStream metaDataStream = new FileInputStream(f);
if(metaDataStream==null) return null;
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return metaDataStream;
}
};
String text = byteSource.asCharSource(Charsets.UTF_8).read();
return text;
}
private String getContent(int i) throws IOException {
InputStream metaDataStream = this.getClass().getResourceAsStream("../testData/content"+i+".json");
if(metaDataStream==null) return null;
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return metaDataStream;
}
};
String text = byteSource.asCharSource(Charsets.UTF_8).read();
return text;
}
@EventListener
public void onApplicationEvent(ApplicationStartingEvent event) {
try {
......
......@@ -48,7 +48,7 @@ public class GitLabServiceIT {
@Test
public void getREADMEmd() throws GitLabApiException, IOException {
final InputStream repositoryFile = gitlabService.getRepositoryFile(new ExerciseId("1", null), "README.md");
final InputStream repositoryFile = gitlabService.getRepositoryFile(new ExerciseId("3", null), "README.md");
Assert.assertNotNull(repositoryFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
......
......@@ -68,7 +68,7 @@ public class InfoMailServiceIT {
private static final String DEFAULT_LANGKEY = "en";
private static final String TEST_EXERCISE_ID = "3";
private static final String TEST_EXERCISE_ID = "1";
@Autowired
private JHipsterProperties jHipsterProperties;
......
......@@ -44,9 +44,9 @@ public class PluginManagerActionIT {
ActionWrapper actionWrapper = config.getActions().get("someId");
Assert.assertTrue("metaData1 should be applicable",
actionWrapper.isApplicable(readTestResults("metaData1.yaml")));
actionWrapper.isApplicable(readTestResults("metadata/1/metaData.yaml")));
Assert.assertFalse("metaData2 should not be applicable",
actionWrapper.isApplicable(readTestResults("metaData2.yaml")));
actionWrapper.isApplicable(readTestResults("metadata/2/metaData.yaml")));
}
......
package at.ac.uibk.gitsearch.service;
import static at.ac.uibk.gitsearch.web.rest.AccountResourceIT.TEST_USER_LOGIN;
import static org.hamcrest.CoreMatchers.containsStringIgnoringCase;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
......@@ -124,7 +125,7 @@ public class SearchServiceIT {
assertNotNull(searchResultPage.getSearchResult());
assertTrue("At least one test hit", searchResultPage.getHitCount() >= 1);
assertThat(searchResultPage.getSearchResult(), everyItem(
hasProperty("metadata", hasProperty("programmingLanguage", hasItemInArray(containsString("Java"))))));
hasProperty("metadata", hasProperty("programmingLanguage", hasItemInArray(containsStringIgnoringCase("Java"))))));
}
......
......@@ -49,7 +49,7 @@ public class UserWatchListServiceIT {
private static final String DEFAULT_LANGKEY = "dummy";
private static final String TEST_EXERCISE_ID = "3";
private static final String TEST_EXERCISE_ID = "1";
@Autowired
private UserService userService;
......
......@@ -43,7 +43,7 @@ public class ExerciseResourceIT {
@Test
public void getREADME() throws Exception {
String exerciseId = "1"; // warning: this depends on the sequence in the current search index :-(
String exerciseId = "3"; // warning: this depends on the sequence in the current search index :-(
restExerciseMockMvc.perform(get("/api/exercise/"+exerciseId).param("filePath", "README.md")
.with(csrf().asHeader())
.contentType(MediaType.APPLICATION_JSON))
......@@ -57,7 +57,7 @@ public class ExerciseResourceIT {
@Test
public void getExercisemd() throws Exception {
String exerciseId = "1"; // warning: this depends on the sequence in the current search index :-(
String exerciseId = "3"; // warning: this depends on the sequence in the current search index :-(
restExerciseMockMvc.perform(get("/api/exercise/"+exerciseId).param("filePath", "exercise.md")
.with(csrf().asHeader())
.contentType(MediaType.APPLICATION_JSON))
......@@ -70,7 +70,7 @@ public class ExerciseResourceIT {
@Test
public void getNestedPath() throws Exception {
String exerciseId = "1"; // warning: this depends on the sequence in the current search index :-(
String exerciseId = "3"; // warning: this depends on the sequence in the current search index :-(
restExerciseMockMvc.perform(get("/api/exercise/"+exerciseId).param("filePath", "solution/src/at/ac/uibk/ac/artemis/Receiver.java")
.with(csrf().asHeader())
.contentType(MediaType.APPLICATION_JSON))
......@@ -82,7 +82,7 @@ public class ExerciseResourceIT {
@Test
public void getSplitPath() throws Exception {
String exerciseId = "1:solution/src/at"; // warning: this depends on the sequence in the current search index :-(
String exerciseId = "3:solution/src/at"; // warning: this depends on the sequence in the current search index :-(
restExerciseMockMvc.perform(get("/api/exercise/"+exerciseId).param("filePath", "ac/uibk/ac/artemis/Receiver.java")
.with(csrf().asHeader())
.contentType(MediaType.APPLICATION_JSON))
......
......@@ -130,7 +130,7 @@ public class PluginInterfaceResourceIT {
.andExpect(TestUtil.testResult(org.codeability.sharing.plugins.api.search.SearchResultsDTO.class,
result -> {
// not really a good test :-(
assertTrue("Currently only one public result", result.getSearchResult().size() == 1);
assertTrue("Currently only one public result", result.getSearchResult().size() == 3);
// result.getSearchResult().forEach(r -> r.getProject()..getNamespace());
}));
}
......
......@@ -78,14 +78,14 @@ public class SearchResourceIT {
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(TestUtil.testResult(AutoCompleteEntry[].class, r -> {
assertThat(r, Matchers.hasItemInArray(hasProperty("target", is("Java"))));
assertThat(r, Matchers.hasItemInArray(hasProperty("target", is("JAVA"))));
}));
}
@Test
public void getREADME() throws Exception {
String projectId = "3"; // warning: this depends on the sequence in the current search index :-(
restSearchMockMvc.perform(post("/api/programming-exercises/"+projectId+"/export-programming-exercise")
String exerciseId = "3"; // warning: this depends on the sequence in the current search index :-(
restSearchMockMvc.perform(post("/api/programming-exercises/"+exerciseId+"/export-programming-exercise")
.with(csrf().asHeader())
.contentType(MediaType.APPLICATION_JSON))
// .andDo(print())
......
# metadataVersion: 0.2
type: collection
metadataVersion: 0.2
type: programming exercise
# format (not used here)
identifier: simpleIO
collectionContent:
"solution/src/at/metaData.yaml"
structure: hierarchical # one from atomic, networked, hierarchical, linear
identifier: collection1
structure: atomic # one from atomic, networked, hierarchical, linear
version: "1.0" # just a version tag
status: final # one fo draft, final, revised, unavailable
title: Simple IO Test
......
metadataVersion: 0.2
# metadataVersion: 0.2
type: collection
# format (not used here)
identifier: collection1
structure: atomic # one from atomic, networked, hierarchical, linear
identifier: simpleIO
collectionContent:
"solution/src/at/metaData.yaml"
structure: hierarchical # one from atomic, networked, hierarchical, linear
version: "1.0" # just a version tag
status: final # one fo draft, final, revised, unavailable
title: Simple IO Test
......
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