PageRenderTime 148ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/javatests/com/google/gerrit/elasticsearch/ElasticQueryChangesTest.java

https://gitlab.com/chenfengxu/gerrit
Java | 87 lines | 63 code | 10 blank | 14 comment | 6 complexity | fad740ae70a606ac6d900a3b953890bf MD5 | raw file
  1. // Copyright (C) 2014 The Android Open Source Project
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package com.google.gerrit.elasticsearch;
  15. import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
  16. import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
  17. import com.google.gerrit.testing.ConfigSuite;
  18. import com.google.gerrit.testing.InMemoryModule;
  19. import com.google.gerrit.testing.InMemoryRepositoryManager.Repo;
  20. import com.google.gerrit.testing.IndexConfig;
  21. import com.google.inject.Guice;
  22. import com.google.inject.Injector;
  23. import java.util.concurrent.ExecutionException;
  24. import org.eclipse.jgit.junit.TestRepository;
  25. import org.eclipse.jgit.lib.Config;
  26. import org.junit.After;
  27. import org.junit.AfterClass;
  28. import org.junit.BeforeClass;
  29. import org.junit.Test;
  30. public class ElasticQueryChangesTest extends AbstractQueryChangesTest {
  31. @ConfigSuite.Default
  32. public static Config defaultConfig() {
  33. return IndexConfig.createForElasticsearch();
  34. }
  35. private static ElasticNodeInfo nodeInfo;
  36. @BeforeClass
  37. public static void startIndexService() throws InterruptedException, ExecutionException {
  38. if (nodeInfo != null) {
  39. // do not start Elasticsearch twice
  40. return;
  41. }
  42. nodeInfo = ElasticTestUtils.startElasticsearchNode();
  43. }
  44. @AfterClass
  45. public static void stopElasticsearchServer() {
  46. if (nodeInfo != null) {
  47. nodeInfo.node.close();
  48. nodeInfo.elasticDir.delete();
  49. nodeInfo = null;
  50. }
  51. }
  52. private String testName() {
  53. return testName.getMethodName().toLowerCase() + "_";
  54. }
  55. @After
  56. public void cleanupIndex() {
  57. if (nodeInfo != null) {
  58. ElasticTestUtils.deleteAllIndexes(nodeInfo, testName());
  59. }
  60. }
  61. @Override
  62. protected Injector createInjector() {
  63. Config elasticsearchConfig = new Config(config);
  64. InMemoryModule.setDefaults(elasticsearchConfig);
  65. String indicesPrefix = testName();
  66. ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix);
  67. ElasticTestUtils.createAllIndexes(nodeInfo, indicesPrefix);
  68. return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration));
  69. }
  70. @Test
  71. public void byOwnerInvalidQuery() throws Exception {
  72. TestRepository<Repo> repo = createProject("repo");
  73. insert(repo, newChange(repo), userId);
  74. String nameEmail = user.asIdentifiedUser().getNameEmail();
  75. assertQuery("owner: \"" + nameEmail + "\"\\");
  76. }
  77. }