Format all Java files with google-java-format
Having a standard tool for formatting saves reviewers' valuable time. google-java-format is Google's standard formatter and is somewhat inspired by gofmt[1]. This commit formats everything using google-java-format version 1.2. The downside of this one-off formatting is breaking blame. This can be somewhat hacked around with a tool like git-hyper-blame[2], but it's definitely not optimal until/unless this kind of feature makes its way to git core. Not in this change: * Tool support, e.g. Eclipse. The command must be run manually [3]. * Documentation of best practice, e.g. new 100-column default. [1] https://talks.golang.org/2015/gofmt-en.slide#3 [2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html [3] git ls-files | grep java$ | xargs google-java-format -i Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3 Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
committed by
David Pursehouse
parent
6723b6d0fa
commit
292fa154c1
@@ -16,9 +16,8 @@ package com.google.gerrit.server;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ChangeUtilTest {
|
||||
@Test
|
||||
|
||||
@@ -37,25 +37,21 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(ConfigSuite.class)
|
||||
public class IdentifiedUserTest {
|
||||
@ConfigSuite.Parameter
|
||||
public Config config;
|
||||
@ConfigSuite.Parameter public Config config;
|
||||
|
||||
private IdentifiedUser identifiedUser;
|
||||
|
||||
@Inject
|
||||
private IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||
@Inject private IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||
|
||||
private static final String[] TEST_CASES = {
|
||||
"",
|
||||
@@ -66,37 +62,42 @@ public class IdentifiedUserTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
final FakeAccountCache accountCache = new FakeAccountCache();
|
||||
final Realm mockRealm = new FakeRealm() {
|
||||
HashSet<String> emails = new HashSet<>(Arrays.asList(TEST_CASES));
|
||||
final Realm mockRealm =
|
||||
new FakeRealm() {
|
||||
HashSet<String> emails = new HashSet<>(Arrays.asList(TEST_CASES));
|
||||
|
||||
@Override
|
||||
public boolean hasEmailAddress(IdentifiedUser who, String email) {
|
||||
return emails.contains(email);
|
||||
}
|
||||
@Override
|
||||
public boolean hasEmailAddress(IdentifiedUser who, String email) {
|
||||
return emails.contains(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getEmailAddresses(IdentifiedUser who) {
|
||||
return emails;
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public Set<String> getEmailAddresses(IdentifiedUser who) {
|
||||
return emails;
|
||||
}
|
||||
};
|
||||
|
||||
AbstractModule mod = new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
|
||||
.toInstance(Boolean.FALSE);
|
||||
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(config);
|
||||
bind(String.class).annotatedWith(AnonymousCowardName.class)
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
bind(String.class).annotatedWith(CanonicalWebUrl.class)
|
||||
.toInstance("http://localhost:8080/");
|
||||
bind(AccountCache.class).toInstance(accountCache);
|
||||
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
|
||||
bind(CapabilityControl.Factory.class)
|
||||
.toProvider(Providers.<CapabilityControl.Factory>of(null));
|
||||
bind(Realm.class).toInstance(mockRealm);
|
||||
}
|
||||
};
|
||||
AbstractModule mod =
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Boolean.class)
|
||||
.annotatedWith(DisableReverseDnsLookup.class)
|
||||
.toInstance(Boolean.FALSE);
|
||||
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(config);
|
||||
bind(String.class)
|
||||
.annotatedWith(AnonymousCowardName.class)
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
bind(String.class)
|
||||
.annotatedWith(CanonicalWebUrl.class)
|
||||
.toInstance("http://localhost:8080/");
|
||||
bind(AccountCache.class).toInstance(accountCache);
|
||||
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
|
||||
bind(CapabilityControl.Factory.class)
|
||||
.toProvider(Providers.<CapabilityControl.Factory>of(null));
|
||||
bind(Realm.class).toInstance(mockRealm);
|
||||
}
|
||||
};
|
||||
|
||||
Injector injector = Guice.createInjector(mod);
|
||||
injector.injectMembers(this);
|
||||
@@ -122,7 +123,6 @@ public class IdentifiedUserTest {
|
||||
assertThat(identifiedUser.hasEmailAddress(TEST_CASES[2])).isTrue();
|
||||
assertThat(identifiedUser.hasEmailAddress(TEST_CASES[2].toLowerCase())).isTrue();
|
||||
|
||||
|
||||
assertThat(identifiedUser.hasEmailAddress("non-exist@email.com")).isFalse();
|
||||
/* assert again to test cached email address by IdentifiedUser.invalidEmails */
|
||||
assertThat(identifiedUser.hasEmailAddress("non-exist@email.com")).isFalse();
|
||||
|
||||
@@ -19,39 +19,31 @@ import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringUtilTest {
|
||||
/**
|
||||
* Test the boundary condition that the first character of a string
|
||||
* should be escaped.
|
||||
*/
|
||||
/** Test the boundary condition that the first character of a string should be escaped. */
|
||||
@Test
|
||||
public void escapeFirstChar() {
|
||||
assertEquals(StringUtil.escapeString("\tLeading tab"), "\\tLeading tab");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the boundary condition that the last character of a string
|
||||
* should be escaped.
|
||||
*/
|
||||
/** Test the boundary condition that the last character of a string should be escaped. */
|
||||
@Test
|
||||
public void escapeLastChar() {
|
||||
assertEquals(StringUtil.escapeString("Trailing tab\t"), "Trailing tab\\t");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that various forms of input strings are escaped (or left as-is)
|
||||
* in the expected way.
|
||||
*/
|
||||
/** Test that various forms of input strings are escaped (or left as-is) in the expected way. */
|
||||
@Test
|
||||
public void escapeString() {
|
||||
final String[] testPairs =
|
||||
{ "", "",
|
||||
"plain string", "plain string",
|
||||
"string with \"quotes\"", "string with \"quotes\"",
|
||||
"string with 'quotes'", "string with 'quotes'",
|
||||
"string with 'quotes'", "string with 'quotes'",
|
||||
"C:\\Program Files\\MyProgram", "C:\\\\Program Files\\\\MyProgram",
|
||||
"string\nwith\nnewlines", "string\\nwith\\nnewlines",
|
||||
"string\twith\ttabs", "string\\twith\\ttabs", };
|
||||
final String[] testPairs = {
|
||||
"", "",
|
||||
"plain string", "plain string",
|
||||
"string with \"quotes\"", "string with \"quotes\"",
|
||||
"string with 'quotes'", "string with 'quotes'",
|
||||
"string with 'quotes'", "string with 'quotes'",
|
||||
"C:\\Program Files\\MyProgram", "C:\\\\Program Files\\\\MyProgram",
|
||||
"string\nwith\nnewlines", "string\\nwith\\nnewlines",
|
||||
"string\twith\ttabs", "string\\twith\\ttabs",
|
||||
};
|
||||
for (int i = 0; i < testPairs.length; i += 2) {
|
||||
assertEquals(StringUtil.escapeString(testPairs[i]), testPairs[i + 1]);
|
||||
}
|
||||
|
||||
@@ -18,39 +18,37 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountSshKey;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AuthorizedKeysTest {
|
||||
private static final String KEY1 =
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCgug5VyMXQGnem2H1KVC4/HcRcD4zzBqS"
|
||||
+ "uJBRWVonSSoz3RoAZ7bWXCVVGwchtXwUURD689wFYdiPecOrWOUgeeyRq754YWRhU+W28"
|
||||
+ "vf8IZixgjCmiBhaL2gt3wff6pP+NXJpTSA4aeWE5DfNK5tZlxlSxqkKOS8JRSUeNQov5T"
|
||||
+ "w== john.doe@example.com";
|
||||
+ "uJBRWVonSSoz3RoAZ7bWXCVVGwchtXwUURD689wFYdiPecOrWOUgeeyRq754YWRhU+W28"
|
||||
+ "vf8IZixgjCmiBhaL2gt3wff6pP+NXJpTSA4aeWE5DfNK5tZlxlSxqkKOS8JRSUeNQov5T"
|
||||
+ "w== john.doe@example.com";
|
||||
private static final String KEY2 =
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDm5yP7FmEoqzQRDyskX+9+N0q9GrvZeh5"
|
||||
+ "RG52EUpE4ms/Ujm3ewV1LoGzc/lYKJAIbdcZQNJ9+06EfWZaIRA3oOwAPe1eCnX+aLr8E"
|
||||
+ "6Tw2gDMQOGc5e9HfyXpC2pDvzauoZNYqLALOG3y/1xjo7IH8GYRS2B7zO/Mf9DdCcCKSf"
|
||||
+ "w== john.doe@example.com";
|
||||
+ "RG52EUpE4ms/Ujm3ewV1LoGzc/lYKJAIbdcZQNJ9+06EfWZaIRA3oOwAPe1eCnX+aLr8E"
|
||||
+ "6Tw2gDMQOGc5e9HfyXpC2pDvzauoZNYqLALOG3y/1xjo7IH8GYRS2B7zO/Mf9DdCcCKSf"
|
||||
+ "w== john.doe@example.com";
|
||||
private static final String KEY3 =
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCaS7RHEcZ/zjl9hkWkqnm29RNr2OQ/TZ5"
|
||||
+ "jk2qBVMH3BgzPsTsEs+7ag9tfD8OCj+vOcwm626mQBZoR2e3niHa/9gnHBHFtOrGfzKbp"
|
||||
+ "RjTWtiOZbB9HF+rqMVD+Dawo/oicX/dDg7VAgOFSPothe6RMhbgWf84UcK5aQd5eP5y+t"
|
||||
+ "Q== john.doe@example.com";
|
||||
+ "jk2qBVMH3BgzPsTsEs+7ag9tfD8OCj+vOcwm626mQBZoR2e3niHa/9gnHBHFtOrGfzKbp"
|
||||
+ "RjTWtiOZbB9HF+rqMVD+Dawo/oicX/dDg7VAgOFSPothe6RMhbgWf84UcK5aQd5eP5y+t"
|
||||
+ "Q== john.doe@example.com";
|
||||
private static final String KEY4 =
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDIJzW9BaAeO+upFletwwEBnGS15lJmS5i"
|
||||
+ "08/NiFef0jXtNNKcLtnd13bq8jOi5VA2is0bwof1c8YbwcvUkdFa8RL5aXoyZBpfYZsWs"
|
||||
+ "/YBLZGiHy5rjooMZQMnH37A50cBPnXr0AQz0WRBxLDBDyOZho+O/DfYAKv4rzPSQ3yw4+"
|
||||
+ "w== john.doe@example.com";
|
||||
+ "08/NiFef0jXtNNKcLtnd13bq8jOi5VA2is0bwof1c8YbwcvUkdFa8RL5aXoyZBpfYZsWs"
|
||||
+ "/YBLZGiHy5rjooMZQMnH37A50cBPnXr0AQz0WRBxLDBDyOZho+O/DfYAKv4rzPSQ3yw4+"
|
||||
+ "w== john.doe@example.com";
|
||||
private static final String KEY5 =
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCgBRKGhiXvY6D9sM+Vbth5Kate57YF7kD"
|
||||
+ "rqIyUiYIMJK93/AXc8qR/J/p3OIFQAxvLz1qozAur3j5HaiwvxVU19IiSA0vafdhaDLRi"
|
||||
+ "zRuEL5e/QOu9yGq9xkWApCmg6edpWAHG+Bx4AldU78MiZvzoB7gMMdxc9RmZ1gYj/DjxV"
|
||||
+ "w== john.doe@example.com";
|
||||
+ "rqIyUiYIMJK93/AXc8qR/J/p3OIFQAxvLz1qozAur3j5HaiwvxVU19IiSA0vafdhaDLRi"
|
||||
+ "zRuEL5e/QOu9yGq9xkWApCmg6edpWAHG+Bx4AldU78MiZvzoB7gMMdxc9RmZ1gYj/DjxV"
|
||||
+ "w== john.doe@example.com";
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
@@ -105,26 +103,25 @@ public class AuthorizedKeysTest {
|
||||
|
||||
authorizedKeys.append(toWindowsLineEndings(addKey(keys, KEY5)));
|
||||
assertParse(authorizedKeys, keys);
|
||||
|
||||
}
|
||||
|
||||
private static String toWindowsLineEndings(String s) {
|
||||
return s.replaceAll("\n", "\r\n");
|
||||
}
|
||||
|
||||
private static void assertSerialization(List<Optional<AccountSshKey>> keys,
|
||||
StringBuilder expected) {
|
||||
private static void assertSerialization(
|
||||
List<Optional<AccountSshKey>> keys, StringBuilder expected) {
|
||||
assertThat(AuthorizedKeys.serialize(keys)).isEqualTo(expected.toString());
|
||||
}
|
||||
|
||||
private static void assertParse(StringBuilder authorizedKeys,
|
||||
List<Optional<AccountSshKey>> expectedKeys) {
|
||||
private static void assertParse(
|
||||
StringBuilder authorizedKeys, List<Optional<AccountSshKey>> expectedKeys) {
|
||||
Account.Id accountId = new Account.Id(1);
|
||||
List<Optional<AccountSshKey>> parsedKeys =
|
||||
AuthorizedKeys.parse(accountId, authorizedKeys.toString());
|
||||
assertThat(parsedKeys).containsExactlyElementsIn(expectedKeys);
|
||||
int seq = 1;
|
||||
for(Optional<AccountSshKey> sshKey : parsedKeys) {
|
||||
for (Optional<AccountSshKey> sshKey : parsedKeys) {
|
||||
if (sshKey.isPresent()) {
|
||||
assertThat(sshKey.get().getAccount()).isEqualTo(accountId);
|
||||
assertThat(sshKey.get().getKey().get()).isEqualTo(seq);
|
||||
@@ -139,8 +136,7 @@ public class AuthorizedKeysTest {
|
||||
* @return the expected line for this key in the authorized_keys file
|
||||
*/
|
||||
private static String addKey(List<Optional<AccountSshKey>> keys, String pub) {
|
||||
AccountSshKey.Id keyId =
|
||||
new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
|
||||
AccountSshKey.Id keyId = new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
|
||||
AccountSshKey key = new AccountSshKey(keyId, pub);
|
||||
keys.add(Optional.of(key));
|
||||
return key.getSshPublicKey() + "\n";
|
||||
@@ -151,15 +147,12 @@ public class AuthorizedKeysTest {
|
||||
*
|
||||
* @return the expected line for this key in the authorized_keys file
|
||||
*/
|
||||
private static String addInvalidKey(List<Optional<AccountSshKey>> keys,
|
||||
String pub) {
|
||||
AccountSshKey.Id keyId =
|
||||
new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
|
||||
private static String addInvalidKey(List<Optional<AccountSshKey>> keys, String pub) {
|
||||
AccountSshKey.Id keyId = new AccountSshKey.Id(new Account.Id(1), keys.size() + 1);
|
||||
AccountSshKey key = new AccountSshKey(keyId, pub);
|
||||
key.setInvalid();
|
||||
keys.add(Optional.of(key));
|
||||
return AuthorizedKeys.INVALID_KEY_COMMENT_PREFIX
|
||||
+ key.getSshPublicKey() + "\n";
|
||||
return AuthorizedKeys.INVALID_KEY_COMMENT_PREFIX + key.getSshPublicKey() + "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,17 +36,14 @@ import com.google.gerrit.reviewdb.client.AccountGroup.UUID;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import java.util.Set;
|
||||
import org.easymock.IAnswer;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class UniversalGroupBackendTest extends GerritBaseTests {
|
||||
private static final AccountGroup.UUID OTHER_UUID =
|
||||
new AccountGroup.UUID("other");
|
||||
private static final AccountGroup.UUID OTHER_UUID = new AccountGroup.UUID("other");
|
||||
|
||||
private UniversalGroupBackend backend;
|
||||
private IdentifiedUser user;
|
||||
@@ -71,10 +68,8 @@ public class UniversalGroupBackendTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void get() {
|
||||
assertEquals("Registered Users",
|
||||
backend.get(REGISTERED_USERS).getName());
|
||||
assertEquals("Project Owners",
|
||||
backend.get(PROJECT_OWNERS).getName());
|
||||
assertEquals("Registered Users", backend.get(REGISTERED_USERS).getName());
|
||||
assertEquals("Project Owners", backend.get(PROJECT_OWNERS).getName());
|
||||
assertNull(backend.get(OTHER_UUID));
|
||||
}
|
||||
|
||||
@@ -113,25 +108,25 @@ public class UniversalGroupBackendTest extends GerritBaseTests {
|
||||
expect(backend.handles(handled)).andStubReturn(true);
|
||||
expect(backend.handles(not(eq(handled)))).andStubReturn(false);
|
||||
expect(backend.membershipsOf(anyObject(IdentifiedUser.class)))
|
||||
.andStubAnswer(new IAnswer<GroupMembership>() {
|
||||
@Override
|
||||
public GroupMembership answer() throws Throwable {
|
||||
Object[] args = getCurrentArguments();
|
||||
GroupMembership membership = createMock(GroupMembership.class);
|
||||
expect(membership.contains(eq(handled))).andStubReturn(args[0] == member);
|
||||
expect(membership.contains(not(eq(notHandled)))).andStubReturn(false);
|
||||
replay(membership);
|
||||
return membership;
|
||||
}
|
||||
});
|
||||
.andStubAnswer(
|
||||
new IAnswer<GroupMembership>() {
|
||||
@Override
|
||||
public GroupMembership answer() throws Throwable {
|
||||
Object[] args = getCurrentArguments();
|
||||
GroupMembership membership = createMock(GroupMembership.class);
|
||||
expect(membership.contains(eq(handled))).andStubReturn(args[0] == member);
|
||||
expect(membership.contains(not(eq(notHandled)))).andStubReturn(false);
|
||||
replay(membership);
|
||||
return membership;
|
||||
}
|
||||
});
|
||||
replay(member, notMember, backend);
|
||||
|
||||
backends = new DynamicSet<>();
|
||||
backends.add(backend);
|
||||
backend = new UniversalGroupBackend(backends);
|
||||
|
||||
GroupMembership checker =
|
||||
backend.membershipsOf(member);
|
||||
GroupMembership checker = backend.membershipsOf(member);
|
||||
assertFalse(checker.contains(REGISTERED_USERS));
|
||||
assertFalse(checker.contains(OTHER_UUID));
|
||||
assertTrue(checker.contains(handled));
|
||||
@@ -140,5 +135,4 @@ public class UniversalGroupBackendTest extends GerritBaseTests {
|
||||
assertFalse(checker.contains(handled));
|
||||
assertFalse(checker.contains(notHandled));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,17 +22,15 @@ import com.google.gerrit.server.account.WatchConfig.NotifyType;
|
||||
import com.google.gerrit.server.account.WatchConfig.NotifyValue;
|
||||
import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey;
|
||||
import com.google.gerrit.server.git.ValidationError;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WatchConfigTest implements ValidationError.Sink {
|
||||
private List<ValidationError> validationErrors = new ArrayList<>();
|
||||
@@ -45,14 +43,15 @@ public class WatchConfigTest implements ValidationError.Sink {
|
||||
@Test
|
||||
public void parseWatchConfig() throws Exception {
|
||||
Config cfg = new Config();
|
||||
cfg.fromText("[project \"myProject\"]\n"
|
||||
+ " notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n"
|
||||
+ " notify = branch:master [NEW_CHANGES]\n"
|
||||
+ " notify = branch:master [NEW_PATCHSETS]\n"
|
||||
+ " notify = branch:foo []\n"
|
||||
+ "[project \"otherProject\"]\n"
|
||||
+ " notify = [NEW_PATCHSETS]\n"
|
||||
+ " notify = * [NEW_PATCHSETS, ALL_COMMENTS]\n");
|
||||
cfg.fromText(
|
||||
"[project \"myProject\"]\n"
|
||||
+ " notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n"
|
||||
+ " notify = branch:master [NEW_CHANGES]\n"
|
||||
+ " notify = branch:master [NEW_PATCHSETS]\n"
|
||||
+ " notify = branch:foo []\n"
|
||||
+ "[project \"otherProject\"]\n"
|
||||
+ " notify = [NEW_PATCHSETS]\n"
|
||||
+ " notify = * [NEW_PATCHSETS, ALL_COMMENTS]\n");
|
||||
Map<ProjectWatchKey, Set<NotifyType>> projectWatches =
|
||||
WatchConfig.parse(new Account.Id(1000000), cfg, this);
|
||||
|
||||
@@ -60,18 +59,19 @@ public class WatchConfigTest implements ValidationError.Sink {
|
||||
|
||||
Project.NameKey myProject = new Project.NameKey("myProject");
|
||||
Project.NameKey otherProject = new Project.NameKey("otherProject");
|
||||
Map<ProjectWatchKey, Set<NotifyType>> expectedProjectWatches =
|
||||
new HashMap<>();
|
||||
expectedProjectWatches.put(ProjectWatchKey.create(myProject, null),
|
||||
Map<ProjectWatchKey, Set<NotifyType>> expectedProjectWatches = new HashMap<>();
|
||||
expectedProjectWatches.put(
|
||||
ProjectWatchKey.create(myProject, null),
|
||||
EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
|
||||
expectedProjectWatches.put(
|
||||
ProjectWatchKey.create(myProject, "branch:master"),
|
||||
EnumSet.of(NotifyType.NEW_CHANGES, NotifyType.NEW_PATCHSETS));
|
||||
expectedProjectWatches.put(ProjectWatchKey.create(myProject, "branch:foo"),
|
||||
EnumSet.noneOf(NotifyType.class));
|
||||
expectedProjectWatches.put(ProjectWatchKey.create(otherProject, null),
|
||||
EnumSet.of(NotifyType.NEW_PATCHSETS));
|
||||
expectedProjectWatches.put(ProjectWatchKey.create(otherProject, null),
|
||||
expectedProjectWatches.put(
|
||||
ProjectWatchKey.create(myProject, "branch:foo"), EnumSet.noneOf(NotifyType.class));
|
||||
expectedProjectWatches.put(
|
||||
ProjectWatchKey.create(otherProject, null), EnumSet.of(NotifyType.NEW_PATCHSETS));
|
||||
expectedProjectWatches.put(
|
||||
ProjectWatchKey.create(otherProject, null),
|
||||
EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
|
||||
assertThat(projectWatches).containsExactlyEntriesIn(expectedProjectWatches);
|
||||
}
|
||||
@@ -79,35 +79,40 @@ public class WatchConfigTest implements ValidationError.Sink {
|
||||
@Test
|
||||
public void parseInvalidWatchConfig() throws Exception {
|
||||
Config cfg = new Config();
|
||||
cfg.fromText("[project \"myProject\"]\n"
|
||||
+ " notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n"
|
||||
+ " notify = branch:master [INVALID, NEW_CHANGES]\n"
|
||||
+ "[project \"otherProject\"]\n"
|
||||
+ " notify = [NEW_PATCHSETS]\n");
|
||||
cfg.fromText(
|
||||
"[project \"myProject\"]\n"
|
||||
+ " notify = * [ALL_COMMENTS, NEW_PATCHSETS]\n"
|
||||
+ " notify = branch:master [INVALID, NEW_CHANGES]\n"
|
||||
+ "[project \"otherProject\"]\n"
|
||||
+ " notify = [NEW_PATCHSETS]\n");
|
||||
|
||||
WatchConfig.parse(new Account.Id(1000000), cfg, this);
|
||||
assertThat(validationErrors).hasSize(1);
|
||||
assertThat(validationErrors.get(0).getMessage()).isEqualTo(
|
||||
"watch.config: Invalid notify type INVALID in project watch of"
|
||||
+ " account 1000000 for project myProject: branch:master"
|
||||
+ " [INVALID, NEW_CHANGES]");
|
||||
assertThat(validationErrors.get(0).getMessage())
|
||||
.isEqualTo(
|
||||
"watch.config: Invalid notify type INVALID in project watch of"
|
||||
+ " account 1000000 for project myProject: branch:master"
|
||||
+ " [INVALID, NEW_CHANGES]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseNotifyValue() throws Exception {
|
||||
assertParseNotifyValue("* []", null, EnumSet.noneOf(NotifyType.class));
|
||||
assertParseNotifyValue("* [ALL_COMMENTS]", null,
|
||||
EnumSet.of(NotifyType.ALL_COMMENTS));
|
||||
assertParseNotifyValue("* [ALL_COMMENTS]", null, EnumSet.of(NotifyType.ALL_COMMENTS));
|
||||
assertParseNotifyValue("[]", null, EnumSet.noneOf(NotifyType.class));
|
||||
assertParseNotifyValue("[ALL_COMMENTS, NEW_PATCHSETS]", null,
|
||||
assertParseNotifyValue(
|
||||
"[ALL_COMMENTS, NEW_PATCHSETS]",
|
||||
null,
|
||||
EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
|
||||
assertParseNotifyValue("branch:master []", "branch:master",
|
||||
assertParseNotifyValue("branch:master []", "branch:master", EnumSet.noneOf(NotifyType.class));
|
||||
assertParseNotifyValue(
|
||||
"branch:master || branch:stable []",
|
||||
"branch:master || branch:stable",
|
||||
EnumSet.noneOf(NotifyType.class));
|
||||
assertParseNotifyValue("branch:master || branch:stable []",
|
||||
"branch:master || branch:stable", EnumSet.noneOf(NotifyType.class));
|
||||
assertParseNotifyValue("branch:master [ALL_COMMENTS]", "branch:master",
|
||||
EnumSet.of(NotifyType.ALL_COMMENTS));
|
||||
assertParseNotifyValue("branch:master [ALL_COMMENTS, NEW_PATCHSETS]",
|
||||
assertParseNotifyValue(
|
||||
"branch:master [ALL_COMMENTS]", "branch:master", EnumSet.of(NotifyType.ALL_COMMENTS));
|
||||
assertParseNotifyValue(
|
||||
"branch:master [ALL_COMMENTS, NEW_PATCHSETS]",
|
||||
"branch:master",
|
||||
EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS));
|
||||
assertParseNotifyValue("* [ALL]", null, EnumSet.of(NotifyType.ALL));
|
||||
@@ -129,31 +134,34 @@ public class WatchConfigTest implements ValidationError.Sink {
|
||||
public void toNotifyValue() throws Exception {
|
||||
assertToNotifyValue(null, EnumSet.noneOf(NotifyType.class), "* []");
|
||||
assertToNotifyValue("*", EnumSet.noneOf(NotifyType.class), "* []");
|
||||
assertToNotifyValue(null, EnumSet.of(NotifyType.ALL_COMMENTS),
|
||||
"* [ALL_COMMENTS]");
|
||||
assertToNotifyValue("branch:master", EnumSet.noneOf(NotifyType.class),
|
||||
"branch:master []");
|
||||
assertToNotifyValue("branch:master",
|
||||
assertToNotifyValue(null, EnumSet.of(NotifyType.ALL_COMMENTS), "* [ALL_COMMENTS]");
|
||||
assertToNotifyValue("branch:master", EnumSet.noneOf(NotifyType.class), "branch:master []");
|
||||
assertToNotifyValue(
|
||||
"branch:master",
|
||||
EnumSet.of(NotifyType.ALL_COMMENTS, NotifyType.NEW_PATCHSETS),
|
||||
"branch:master [ALL_COMMENTS, NEW_PATCHSETS]");
|
||||
assertToNotifyValue("branch:master",
|
||||
EnumSet.of(NotifyType.ABANDONED_CHANGES, NotifyType.ALL_COMMENTS,
|
||||
NotifyType.NEW_CHANGES, NotifyType.NEW_PATCHSETS,
|
||||
assertToNotifyValue(
|
||||
"branch:master",
|
||||
EnumSet.of(
|
||||
NotifyType.ABANDONED_CHANGES,
|
||||
NotifyType.ALL_COMMENTS,
|
||||
NotifyType.NEW_CHANGES,
|
||||
NotifyType.NEW_PATCHSETS,
|
||||
NotifyType.SUBMITTED_CHANGES),
|
||||
"branch:master [ABANDONED_CHANGES, ALL_COMMENTS, NEW_CHANGES,"
|
||||
+ " NEW_PATCHSETS, SUBMITTED_CHANGES]");
|
||||
+ " NEW_PATCHSETS, SUBMITTED_CHANGES]");
|
||||
assertToNotifyValue("*", EnumSet.of(NotifyType.ALL), "* [ALL]");
|
||||
}
|
||||
|
||||
private void assertParseNotifyValue(String notifyValue,
|
||||
String expectedFilter, Set<NotifyType> expectedNotifyTypes) {
|
||||
private void assertParseNotifyValue(
|
||||
String notifyValue, String expectedFilter, Set<NotifyType> expectedNotifyTypes) {
|
||||
NotifyValue nv = parseNotifyValue(notifyValue);
|
||||
assertThat(nv.filter()).isEqualTo(expectedFilter);
|
||||
assertThat(nv.notifyTypes()).containsExactlyElementsIn(expectedNotifyTypes);
|
||||
}
|
||||
|
||||
private static void assertToNotifyValue(String filter,
|
||||
Set<NotifyType> notifyTypes, String expectedNotifyValue) {
|
||||
private static void assertToNotifyValue(
|
||||
String filter, Set<NotifyType> notifyTypes, String expectedNotifyValue) {
|
||||
NotifyValue nv = NotifyValue.create(filter, notifyTypes);
|
||||
assertThat(nv.toString()).isEqualTo(expectedNotifyValue);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.change;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HashtagsTest {
|
||||
@@ -41,59 +40,56 @@ public class HashtagsTest {
|
||||
public void singleHashtag() throws Exception {
|
||||
String commitMessage = "#Subject\n\nLine 1\n\nLine 2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleHashtagNumeric() throws Exception {
|
||||
String commitMessage = "Subject\n\n#123\n\nLine 2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("123"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleHashtags() throws Exception {
|
||||
String commitMessage = "#Subject\n\n#Hashtag\n\nLine 2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject", "Hashtag"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject", "Hashtag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatedHashtag() throws Exception {
|
||||
String commitMessage = "#Subject\n\n#Hashtag1\n\n#Hashtag2\n\n#Hashtag1";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(
|
||||
Sets.newHashSet("Subject", "Hashtag1", "Hashtag2"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Subject", "Hashtag1", "Hashtag2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleHashtagsNoSpaces() throws Exception {
|
||||
String commitMessage = "Subject\n\n#Hashtag1#Hashtag2";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Hashtag1"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Hashtag1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hyphenatedHashtag() throws Exception {
|
||||
String commitMessage = "Subject\n\n#Hyphenated-Hashtag";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Hyphenated-Hashtag"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Hyphenated-Hashtag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underscoredHashtag() throws Exception {
|
||||
String commitMessage = "Subject\n\n#Underscored_Hashtag";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Underscored_Hashtag"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("Underscored_Hashtag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashtagsWithAccentedCharacters() throws Exception {
|
||||
String commitMessage = "Jag #måste #öva på min #Svenska!\n\n"
|
||||
+ "Jag behöver en #läkare.";
|
||||
String commitMessage = "Jag #måste #öva på min #Svenska!\n\n" + "Jag behöver en #läkare.";
|
||||
assertThat(HashtagsUtil.extractTags(commitMessage))
|
||||
.containsExactlyElementsIn(
|
||||
Sets.newHashSet("måste", "öva", "Svenska", "läkare"));
|
||||
.containsExactlyElementsIn(Sets.newHashSet("måste", "öva", "Svenska", "läkare"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
|
||||
import org.eclipse.jgit.junit.RepositoryTestCase;
|
||||
@@ -27,11 +31,6 @@ import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class IncludedInResolverTest extends RepositoryTestCase {
|
||||
|
||||
// Branch names
|
||||
@@ -68,21 +67,21 @@ public class IncludedInResolverTest extends RepositoryTestCase {
|
||||
|
||||
/*- The following graph will be created.
|
||||
|
||||
o tag 2.5, 2.5_annotated, 2.5_annotated_twice
|
||||
|\
|
||||
| o tag 2.0.1
|
||||
| o tag 2.0
|
||||
o | tag 1.3
|
||||
|/
|
||||
o c3
|
||||
o tag 2.5, 2.5_annotated, 2.5_annotated_twice
|
||||
|\
|
||||
| o tag 2.0.1
|
||||
| o tag 2.0
|
||||
o | tag 1.3
|
||||
|/
|
||||
o c3
|
||||
|
||||
| o tag 1.0.1
|
||||
|/
|
||||
o tag 1.0
|
||||
o c2
|
||||
o c1
|
||||
| o tag 1.0.1
|
||||
|/
|
||||
o tag 1.0
|
||||
o c2
|
||||
o c1
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
// TODO(dborowitz): Use try/finally when this doesn't double-close the repo.
|
||||
@SuppressWarnings("resource")
|
||||
@@ -96,8 +95,7 @@ public class IncludedInResolverTest extends RepositoryTestCase {
|
||||
RevCommit c3 = git.commit().setMessage("c3").call();
|
||||
// Version 1.01
|
||||
createAndCheckoutBranch(commit_v1_0, BRANCH_1_0);
|
||||
RevCommit commit_v1_0_1 =
|
||||
git.commit().setMessage("verREFS_HEADS_RELsion 1.0.1").call();
|
||||
RevCommit commit_v1_0_1 = git.commit().setMessage("verREFS_HEADS_RELsion 1.0.1").call();
|
||||
git.tag().setName(TAG_1_0_1).setObjectId(commit_v1_0_1).call();
|
||||
// Version 1.3
|
||||
createAndCheckoutBranch(c3, BRANCH_1_3);
|
||||
@@ -112,18 +110,21 @@ public class IncludedInResolverTest extends RepositoryTestCase {
|
||||
|
||||
// Version 2.5
|
||||
createAndCheckoutBranch(commit_v1_3, BRANCH_2_5);
|
||||
git.merge().include(commit_v2_0_1).setCommit(false)
|
||||
.setFastForward(FastForwardMode.NO_FF).call();
|
||||
commit_v2_5 = git.commit().setMessage("version 2.5").call();
|
||||
git.tag().setName(TAG_2_5).setObjectId(commit_v2_5).setAnnotated(false)
|
||||
git.merge()
|
||||
.include(commit_v2_0_1)
|
||||
.setCommit(false)
|
||||
.setFastForward(FastForwardMode.NO_FF)
|
||||
.call();
|
||||
commit_v2_5 = git.commit().setMessage("version 2.5").call();
|
||||
git.tag().setName(TAG_2_5).setObjectId(commit_v2_5).setAnnotated(false).call();
|
||||
Ref ref_tag_2_5_annotated =
|
||||
git.tag().setName(TAG_2_5_ANNOTATED).setObjectId(commit_v2_5)
|
||||
.setAnnotated(true).call();
|
||||
RevTag tag_2_5_annotated =
|
||||
revWalk.parseTag(ref_tag_2_5_annotated.getObjectId());
|
||||
git.tag().setName(TAG_2_5_ANNOTATED_TWICE).setObjectId(tag_2_5_annotated)
|
||||
.setAnnotated(true).call();
|
||||
git.tag().setName(TAG_2_5_ANNOTATED).setObjectId(commit_v2_5).setAnnotated(true).call();
|
||||
RevTag tag_2_5_annotated = revWalk.parseTag(ref_tag_2_5_annotated.getObjectId());
|
||||
git.tag()
|
||||
.setName(TAG_2_5_ANNOTATED_TWICE)
|
||||
.setObjectId(tag_2_5_annotated)
|
||||
.setAnnotated(true)
|
||||
.call();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -198,8 +199,7 @@ public class IncludedInResolverTest extends RepositoryTestCase {
|
||||
Assert.assertEquals(list1, list2);
|
||||
}
|
||||
|
||||
private void createAndCheckoutBranch(ObjectId objectId, String branchName)
|
||||
throws IOException {
|
||||
private void createAndCheckoutBranch(ObjectId objectId, String branchName) throws IOException {
|
||||
String fullBranchName = "refs/heads/" + branchName;
|
||||
super.createBranch(objectId, fullBranchName);
|
||||
super.checkoutBranch(fullBranchName);
|
||||
|
||||
@@ -30,7 +30,8 @@ import com.google.gerrit.testutil.GerritBaseTests;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager.Repo;
|
||||
import com.google.gerrit.testutil.TestChanges;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -38,9 +39,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WalkSorterTest extends GerritBaseTests {
|
||||
private Account.Id userId;
|
||||
private InMemoryRepositoryManager repoManager;
|
||||
@@ -65,10 +63,11 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd3, c3_1),
|
||||
patchSetData(cd2, c2_1),
|
||||
patchSetData(cd1, c1_1)));
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd3, c3_1), patchSetData(cd2, c2_1), patchSetData(cd1, c1_1)));
|
||||
|
||||
// Add new patch sets whose commits are in reverse order, so output is in
|
||||
// reverse order.
|
||||
@@ -80,10 +79,11 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
addPatchSet(cd2, c2_2);
|
||||
addPatchSet(cd3, c3_2);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd1, c1_2),
|
||||
patchSetData(cd2, c2_2),
|
||||
patchSetData(cd3, c3_2)));
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd1, c1_2), patchSetData(cd2, c2_2), patchSetData(cd3, c3_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,9 +99,8 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd3);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd3, c3_1),
|
||||
patchSetData(cd1, c1_1)));
|
||||
assertSorted(
|
||||
sorter, changes, ImmutableList.of(patchSetData(cd3, c3_1), patchSetData(cd1, c1_1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,12 +114,9 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime())
|
||||
.isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime())
|
||||
.isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime())
|
||||
.isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
@@ -130,11 +126,14 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,12 +147,9 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime())
|
||||
.isLessThan(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime())
|
||||
.isLessThan(c2.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime())
|
||||
.isLessThan(c3.getCommitTime());
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isLessThan(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isLessThan(c2.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isLessThan(c3.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
@@ -163,11 +159,14 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,12 +180,9 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime())
|
||||
.isLessThan(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime())
|
||||
.isLessThan(c2.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime())
|
||||
.isLessThan(c3.getCommitTime());
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isLessThan(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isLessThan(c2.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isLessThan(c3.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
@@ -194,10 +190,8 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
List<PatchSetData> expected = ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1));
|
||||
List<PatchSetData> expected =
|
||||
ImmutableList.of(patchSetData(cd4, c4), patchSetData(cd2, c2), patchSetData(cd1, c1));
|
||||
|
||||
for (List<ChangeData> list : permutations(changes)) {
|
||||
// Not inOrder(); since child of c2 is missing, partial topo sort isn't
|
||||
@@ -216,12 +210,9 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
|
||||
RevWalk rw = p.getRevWalk();
|
||||
rw.parseCommit(c1);
|
||||
assertThat(rw.parseCommit(c2).getCommitTime())
|
||||
.isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime())
|
||||
.isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime())
|
||||
.isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c2).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c3).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
assertThat(rw.parseCommit(c4).getCommitTime()).isEqualTo(c1.getCommitTime());
|
||||
|
||||
ChangeData cd1 = newChange(p, c1);
|
||||
ChangeData cd2 = newChange(p, c2);
|
||||
@@ -231,11 +222,14 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3, cd4);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
assertSorted(
|
||||
sorter,
|
||||
changes,
|
||||
ImmutableList.of(
|
||||
patchSetData(cd4, c4),
|
||||
patchSetData(cd3, c3),
|
||||
patchSetData(cd2, c2),
|
||||
patchSetData(cd1, c1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,17 +275,14 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2);
|
||||
WalkSorter sorter = new WalkSorter(repoManager);
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd1, c1_2),
|
||||
patchSetData(cd2, c2_2)));
|
||||
assertSorted(
|
||||
sorter, changes, ImmutableList.of(patchSetData(cd1, c1_2), patchSetData(cd2, c2_2)));
|
||||
|
||||
// If we restrict to PS1 of each change, the sorter uses that commit.
|
||||
sorter.includePatchSets(ImmutableSet.of(
|
||||
new PatchSet.Id(cd1.getId(), 1),
|
||||
new PatchSet.Id(cd2.getId(), 1)));
|
||||
assertSorted(sorter, changes, ImmutableList.of(
|
||||
patchSetData(cd2, 1, c2_1),
|
||||
patchSetData(cd1, 1, c1_1)));
|
||||
sorter.includePatchSets(
|
||||
ImmutableSet.of(new PatchSet.Id(cd1.getId(), 1), new PatchSet.Id(cd2.getId(), 1)));
|
||||
assertSorted(
|
||||
sorter, changes, ImmutableList.of(patchSetData(cd2, 1, c2_1), patchSetData(cd1, 1, c1_1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -305,8 +296,9 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
ChangeData cd2 = newChange(pb, c2);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd1, cd2);
|
||||
WalkSorter sorter = new WalkSorter(repoManager)
|
||||
.includePatchSets(ImmutableSet.of(cd1.currentPatchSet().getId()));
|
||||
WalkSorter sorter =
|
||||
new WalkSorter(repoManager)
|
||||
.includePatchSets(ImmutableSet.of(cd1.currentPatchSet().getId()));
|
||||
|
||||
assertSorted(sorter, changes, ImmutableList.of(patchSetData(cd1, c1)));
|
||||
}
|
||||
@@ -318,19 +310,13 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
ChangeData cd = newChange(p, c);
|
||||
|
||||
List<ChangeData> changes = ImmutableList.of(cd);
|
||||
RevCommit actual = new WalkSorter(repoManager)
|
||||
.setRetainBody(true)
|
||||
.sort(changes)
|
||||
.iterator().next()
|
||||
.commit();
|
||||
RevCommit actual =
|
||||
new WalkSorter(repoManager).setRetainBody(true).sort(changes).iterator().next().commit();
|
||||
assertThat(actual.getRawBuffer()).isNotNull();
|
||||
assertThat(actual.getShortMessage()).isEqualTo("message");
|
||||
|
||||
actual = new WalkSorter(repoManager)
|
||||
.setRetainBody(false)
|
||||
.sort(changes)
|
||||
.iterator().next()
|
||||
.commit();
|
||||
actual =
|
||||
new WalkSorter(repoManager).setRetainBody(false).sort(changes).iterator().next().commit();
|
||||
assertThat(actual.getRawBuffer()).isNull();
|
||||
}
|
||||
|
||||
@@ -346,8 +332,7 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
assertSorted(sorter, changes, ImmutableList.of(patchSetData(cd, c)));
|
||||
}
|
||||
|
||||
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id)
|
||||
throws Exception {
|
||||
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id) throws Exception {
|
||||
Project.NameKey project = tr.getRepository().getDescription().getProject();
|
||||
Change c = TestChanges.newChange(project, userId);
|
||||
ChangeData cd = ChangeData.createForTest(project, c.getId(), 1);
|
||||
@@ -367,28 +352,23 @@ public class WalkSorterTest extends GerritBaseTests {
|
||||
return ps;
|
||||
}
|
||||
|
||||
private TestRepository<Repo> newRepo(String name)
|
||||
throws Exception {
|
||||
return new TestRepository<>(
|
||||
repoManager.createRepository(new Project.NameKey(name)));
|
||||
private TestRepository<Repo> newRepo(String name) throws Exception {
|
||||
return new TestRepository<>(repoManager.createRepository(new Project.NameKey(name)));
|
||||
}
|
||||
|
||||
private static PatchSetData patchSetData(ChangeData cd, RevCommit commit)
|
||||
throws Exception {
|
||||
private static PatchSetData patchSetData(ChangeData cd, RevCommit commit) throws Exception {
|
||||
return PatchSetData.create(cd, cd.currentPatchSet(), commit);
|
||||
}
|
||||
|
||||
private static PatchSetData patchSetData(ChangeData cd, int psId,
|
||||
RevCommit commit) throws Exception {
|
||||
return PatchSetData.create(
|
||||
cd, cd.patchSet(new PatchSet.Id(cd.getId(), psId)), commit);
|
||||
private static PatchSetData patchSetData(ChangeData cd, int psId, RevCommit commit)
|
||||
throws Exception {
|
||||
return PatchSetData.create(cd, cd.patchSet(new PatchSet.Id(cd.getId(), psId)), commit);
|
||||
}
|
||||
|
||||
private static void assertSorted(WalkSorter sorter, List<ChangeData> changes,
|
||||
List<PatchSetData> expected) throws Exception {
|
||||
private static void assertSorted(
|
||||
WalkSorter sorter, List<ChangeData> changes, List<PatchSetData> expected) throws Exception {
|
||||
for (List<ChangeData> list : permutations(changes)) {
|
||||
assertThat(sorter.sort(list))
|
||||
.containsExactlyElementsIn(expected).inOrder();
|
||||
assertThat(sorter.sort(list)).containsExactlyElementsIn(expected).inOrder();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,11 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.gerrit.extensions.client.Theme;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConfigUtilTest {
|
||||
private static final String SECT = "foo";
|
||||
@@ -54,6 +52,7 @@ public class ConfigUtilTest {
|
||||
public Theme td;
|
||||
public List<String> list;
|
||||
public Map<String, String> map;
|
||||
|
||||
static SectionInfo defaults() {
|
||||
SectionInfo i = new SectionInfo();
|
||||
i.i = 1;
|
||||
|
||||
@@ -26,39 +26,38 @@ import com.google.gerrit.server.config.ListCapabilities.CapabilityInfo;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListCapabilitiesTest {
|
||||
private Injector injector;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
AbstractModule mod = new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
DynamicMap.mapOf(binder(), CapabilityDefinition.class);
|
||||
bind(CapabilityDefinition.class)
|
||||
.annotatedWith(Exports.named("printHello"))
|
||||
.toInstance(new CapabilityDefinition() {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Print Hello";
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
AbstractModule mod =
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
DynamicMap.mapOf(binder(), CapabilityDefinition.class);
|
||||
bind(CapabilityDefinition.class)
|
||||
.annotatedWith(Exports.named("printHello"))
|
||||
.toInstance(
|
||||
new CapabilityDefinition() {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Print Hello";
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
injector = Guice.createInjector(mod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void list() throws Exception {
|
||||
Map<String, CapabilityInfo> m =
|
||||
injector.getInstance(ListCapabilities.class)
|
||||
.apply(new ConfigResource());
|
||||
injector.getInstance(ListCapabilities.class).apply(new ConfigResource());
|
||||
for (String id : GlobalCapability.getAllNames()) {
|
||||
assertTrue("contains " + id, m.containsKey(id));
|
||||
assertEquals(id, m.get(id).id);
|
||||
|
||||
@@ -19,14 +19,12 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.reviewdb.client.Project.NameKey;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RepositoryConfigTest {
|
||||
|
||||
@@ -75,28 +73,26 @@ public class RepositoryConfigTest {
|
||||
|
||||
@Test
|
||||
public void defaultSubmitTypeForStartWithFilter() {
|
||||
configureDefaultSubmitType("somePath/somePath/*",
|
||||
SubmitType.REBASE_IF_NECESSARY);
|
||||
configureDefaultSubmitType("somePath/somePath/*", SubmitType.REBASE_IF_NECESSARY);
|
||||
configureDefaultSubmitType("somePath/*", SubmitType.CHERRY_PICK);
|
||||
configureDefaultSubmitType("*", SubmitType.MERGE_ALWAYS);
|
||||
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someProject")))
|
||||
.isEqualTo(SubmitType.MERGE_ALWAYS);
|
||||
|
||||
assertThat(
|
||||
repoCfg.getDefaultSubmitType(new NameKey("somePath/someProject")))
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("somePath/someProject")))
|
||||
.isEqualTo(SubmitType.CHERRY_PICK);
|
||||
|
||||
assertThat(
|
||||
repoCfg.getDefaultSubmitType(new NameKey(
|
||||
"somePath/somePath/someProject"))).isEqualTo(
|
||||
SubmitType.REBASE_IF_NECESSARY);
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("somePath/somePath/someProject")))
|
||||
.isEqualTo(SubmitType.REBASE_IF_NECESSARY);
|
||||
}
|
||||
|
||||
private void configureDefaultSubmitType(String projectFilter,
|
||||
SubmitType submitType) {
|
||||
cfg.setString(RepositoryConfig.SECTION_NAME, projectFilter,
|
||||
RepositoryConfig.DEFAULT_SUBMIT_TYPE_NAME, submitType.toString());
|
||||
private void configureDefaultSubmitType(String projectFilter, SubmitType submitType) {
|
||||
cfg.setString(
|
||||
RepositoryConfig.SECTION_NAME,
|
||||
projectFilter,
|
||||
RepositoryConfig.DEFAULT_SUBMIT_TYPE_NAME,
|
||||
submitType.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,8 +112,7 @@ public class RepositoryConfigTest {
|
||||
public void ownerGroupsForSpecificFilter() {
|
||||
ImmutableList<String> ownerGroups = ImmutableList.of("group1", "group2");
|
||||
configureOwnerGroups("someProject", ownerGroups);
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someOtherProject")))
|
||||
.isEmpty();
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someOtherProject"))).isEmpty();
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someProject")))
|
||||
.containsExactlyElementsIn(ownerGroups);
|
||||
}
|
||||
@@ -138,38 +133,36 @@ public class RepositoryConfigTest {
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("somePath/someProject")))
|
||||
.containsExactlyElementsIn(ownerGroups2);
|
||||
|
||||
assertThat(
|
||||
repoCfg.getOwnerGroups(new NameKey("somePath/somePath/someProject")))
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("somePath/somePath/someProject")))
|
||||
.containsExactlyElementsIn(ownerGroups3);
|
||||
}
|
||||
|
||||
private void configureOwnerGroups(String projectFilter,
|
||||
List<String> ownerGroups) {
|
||||
cfg.setStringList(RepositoryConfig.SECTION_NAME, projectFilter,
|
||||
RepositoryConfig.OWNER_GROUP_NAME, ownerGroups);
|
||||
private void configureOwnerGroups(String projectFilter, List<String> ownerGroups) {
|
||||
cfg.setStringList(
|
||||
RepositoryConfig.SECTION_NAME,
|
||||
projectFilter,
|
||||
RepositoryConfig.OWNER_GROUP_NAME,
|
||||
ownerGroups);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basePathWhenNotConfigured() {
|
||||
assertThat((Object)repoCfg.getBasePath(new NameKey("someProject"))).isNull();
|
||||
assertThat((Object) repoCfg.getBasePath(new NameKey("someProject"))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basePathForStarFilter() {
|
||||
String basePath = "/someAbsolutePath/someDirectory";
|
||||
configureBasePath("*", basePath);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString())
|
||||
.isEqualTo(basePath);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString()).isEqualTo(basePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basePathForSpecificFilter() {
|
||||
String basePath = "/someAbsolutePath/someDirectory";
|
||||
configureBasePath("someProject", basePath);
|
||||
assertThat((Object) repoCfg.getBasePath(new NameKey("someOtherProject")))
|
||||
.isNull();
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString())
|
||||
.isEqualTo(basePath);
|
||||
assertThat((Object) repoCfg.getBasePath(new NameKey("someOtherProject"))).isNull();
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString()).isEqualTo(basePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,23 +177,19 @@ public class RepositoryConfigTest {
|
||||
configureBasePath("project/*", basePath3);
|
||||
configureBasePath("*", basePath4);
|
||||
|
||||
assertThat(repoCfg.getBasePath(new NameKey("project1")).toString())
|
||||
.isEqualTo(basePath1);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("project/project/someProject"))
|
||||
.toString()).isEqualTo(basePath2);
|
||||
assertThat(
|
||||
repoCfg.getBasePath(new NameKey("project/someProject")).toString())
|
||||
.isEqualTo(basePath3);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString())
|
||||
.isEqualTo(basePath4);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("project1")).toString()).isEqualTo(basePath1);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("project/project/someProject")).toString())
|
||||
.isEqualTo(basePath2);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("project/someProject")).toString())
|
||||
.isEqualTo(basePath3);
|
||||
assertThat(repoCfg.getBasePath(new NameKey("someProject")).toString()).isEqualTo(basePath4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allBasePath() {
|
||||
ImmutableList<Path> allBasePaths = ImmutableList.of(
|
||||
Paths.get("/someBasePath1"),
|
||||
Paths.get("/someBasePath2"),
|
||||
Paths.get("/someBasePath2"));
|
||||
ImmutableList<Path> allBasePaths =
|
||||
ImmutableList.of(
|
||||
Paths.get("/someBasePath1"), Paths.get("/someBasePath2"), Paths.get("/someBasePath2"));
|
||||
|
||||
configureBasePath("*", allBasePaths.get(0).toString());
|
||||
configureBasePath("project/*", allBasePaths.get(1).toString());
|
||||
@@ -210,7 +199,7 @@ public class RepositoryConfigTest {
|
||||
}
|
||||
|
||||
private void configureBasePath(String projectFilter, String basePath) {
|
||||
cfg.setString(RepositoryConfig.SECTION_NAME, projectFilter,
|
||||
RepositoryConfig.BASE_PATH_NAME, basePath);
|
||||
cfg.setString(
|
||||
RepositoryConfig.SECTION_NAME, projectFilter, RepositoryConfig.BASE_PATH_NAME, basePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,11 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ScheduleConfigTest {
|
||||
|
||||
// Friday June 13, 2014 10:00 UTC
|
||||
@@ -43,8 +42,7 @@ public class ScheduleConfigTest {
|
||||
assertEquals(ms(19, HOURS) + ms(30, MINUTES), initialDelay("05:30", "1d"));
|
||||
|
||||
assertEquals(ms(1, HOURS), initialDelay("11:00", "1w"));
|
||||
assertEquals(ms(7, DAYS) - ms(4, HOURS) - ms(30, MINUTES),
|
||||
initialDelay("05:30", "1w"));
|
||||
assertEquals(ms(7, DAYS) - ms(4, HOURS) - ms(30, MINUTES), initialDelay("05:30", "1w"));
|
||||
|
||||
assertEquals(ms(3, DAYS) + ms(1, HOURS), initialDelay("Mon 11:00", "1w"));
|
||||
assertEquals(ms(1, HOURS), initialDelay("Fri 11:00", "1w"));
|
||||
@@ -71,9 +69,8 @@ public class ScheduleConfigTest {
|
||||
}
|
||||
|
||||
private static long initialDelay(String startTime, String interval) {
|
||||
return new ScheduleConfig(
|
||||
config(startTime, interval),
|
||||
"section", "subsection", NOW).getInitialDelay();
|
||||
return new ScheduleConfig(config(startTime, interval), "section", "subsection", NOW)
|
||||
.getInitialDelay();
|
||||
}
|
||||
|
||||
private static Config config(String startTime, String interval) {
|
||||
|
||||
@@ -22,14 +22,12 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.gerrit.server.util.HostPlatform;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NotDirectoryException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SitePathsTest extends GerritBaseTests {
|
||||
@Test
|
||||
@@ -93,8 +91,7 @@ public class SitePathsTest extends GerritBaseTests {
|
||||
assertNull(site.resolve(""));
|
||||
|
||||
assertNotNull(site.resolve("a"));
|
||||
assertEquals(root.resolve("a").toAbsolutePath().normalize(),
|
||||
site.resolve("a"));
|
||||
assertEquals(root.resolve("a").toAbsolutePath().normalize(), site.resolve("a"));
|
||||
|
||||
final String pfx = HostPlatform.isWin32() ? "C:/" : "/";
|
||||
assertNotNull(site.resolve(pfx + "a"));
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ChangeEditTest {
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.google.gerrit.server.data.AccountAttribute;
|
||||
import com.google.gerrit.server.data.RefUpdateAttribute;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class EventDeserializerTest {
|
||||
@@ -39,32 +38,32 @@ public class EventDeserializerTest {
|
||||
accountAttribute.email = "some.user@domain.com";
|
||||
refUpdatedEvent.submitter = createSupplier(accountAttribute);
|
||||
|
||||
Gson gsonSerializer = new GsonBuilder()
|
||||
.registerTypeAdapter(Supplier.class, new SupplierSerializer()).create();
|
||||
Gson gsonSerializer =
|
||||
new GsonBuilder().registerTypeAdapter(Supplier.class, new SupplierSerializer()).create();
|
||||
String serializedEvent = gsonSerializer.toJson(refUpdatedEvent);
|
||||
|
||||
Gson gsonDeserializer = new GsonBuilder()
|
||||
.registerTypeAdapter(Event.class, new EventDeserializer())
|
||||
.registerTypeAdapter(Supplier.class, new SupplierDeserializer())
|
||||
.create();
|
||||
Gson gsonDeserializer =
|
||||
new GsonBuilder()
|
||||
.registerTypeAdapter(Event.class, new EventDeserializer())
|
||||
.registerTypeAdapter(Supplier.class, new SupplierDeserializer())
|
||||
.create();
|
||||
|
||||
RefUpdatedEvent e = (RefUpdatedEvent) gsonDeserializer
|
||||
.fromJson(serializedEvent, Event.class);
|
||||
RefUpdatedEvent e = (RefUpdatedEvent) gsonDeserializer.fromJson(serializedEvent, Event.class);
|
||||
|
||||
assertThat(e).isNotNull();
|
||||
assertThat(e.refUpdate).isInstanceOf(Supplier.class);
|
||||
assertThat(e.refUpdate.get().refName)
|
||||
.isEqualTo(refUpdatedAttribute.refName);
|
||||
assertThat(e.refUpdate.get().refName).isEqualTo(refUpdatedAttribute.refName);
|
||||
assertThat(e.submitter).isInstanceOf(Supplier.class);
|
||||
assertThat(e.submitter.get().email).isEqualTo(accountAttribute.email);
|
||||
}
|
||||
|
||||
private <T> Supplier<T> createSupplier(final T value) {
|
||||
return Suppliers.memoize(new Supplier<T>() {
|
||||
@Override
|
||||
public T get() {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
return Suppliers.memoize(
|
||||
new Supplier<T>() {
|
||||
@Override
|
||||
public T get() {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
public class EventTypesTest {
|
||||
public static class TestEvent extends Event {
|
||||
private static final String TYPE = "test-event";
|
||||
|
||||
public TestEvent() {
|
||||
super(TYPE);
|
||||
}
|
||||
@@ -28,6 +29,7 @@ public class EventTypesTest {
|
||||
|
||||
public static class AnotherTestEvent extends Event {
|
||||
private static final String TYPE = "another-test-event";
|
||||
|
||||
public AnotherTestEvent() {
|
||||
super("another-test-event");
|
||||
}
|
||||
@@ -38,8 +40,7 @@ public class EventTypesTest {
|
||||
EventTypes.register(TestEvent.TYPE, TestEvent.class);
|
||||
EventTypes.register(AnotherTestEvent.TYPE, AnotherTestEvent.class);
|
||||
assertThat(EventTypes.getClass(TestEvent.TYPE)).isEqualTo(TestEvent.class);
|
||||
assertThat(EventTypes.getClass(AnotherTestEvent.TYPE))
|
||||
.isEqualTo(AnotherTestEvent.class);
|
||||
assertThat(EventTypes.getClass(AnotherTestEvent.TYPE)).isEqualTo(AnotherTestEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -34,26 +33,19 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BatchUpdateTest {
|
||||
@Inject
|
||||
private AccountManager accountManager;
|
||||
@Inject private AccountManager accountManager;
|
||||
|
||||
@Inject
|
||||
private IdentifiedUser.GenericFactory userFactory;
|
||||
@Inject private IdentifiedUser.GenericFactory userFactory;
|
||||
|
||||
@Inject
|
||||
private InMemoryDatabase schemaFactory;
|
||||
@Inject private InMemoryDatabase schemaFactory;
|
||||
|
||||
@Inject
|
||||
private InMemoryRepositoryManager repoManager;
|
||||
@Inject private InMemoryRepositoryManager repoManager;
|
||||
|
||||
@Inject
|
||||
private SchemaCreator schemaCreator;
|
||||
@Inject private SchemaCreator schemaCreator;
|
||||
|
||||
@Inject
|
||||
private ThreadLocalRequestContext requestContext;
|
||||
@Inject private ThreadLocalRequestContext requestContext;
|
||||
|
||||
@Inject
|
||||
private BatchUpdate.Factory batchUpdateFactory;
|
||||
@Inject private BatchUpdate.Factory batchUpdateFactory;
|
||||
|
||||
private LifecycleManager lifecycle;
|
||||
private ReviewDb db;
|
||||
@@ -71,8 +63,7 @@ public class BatchUpdateTest {
|
||||
|
||||
db = schemaFactory.open();
|
||||
schemaCreator.create(db);
|
||||
Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user"))
|
||||
.getAccountId();
|
||||
Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
||||
user = userFactory.create(userId);
|
||||
|
||||
project = new Project.NameKey("test");
|
||||
@@ -80,17 +71,18 @@ public class BatchUpdateTest {
|
||||
InMemoryRepository inMemoryRepo = repoManager.createRepository(project);
|
||||
repo = new TestRepository<>(inMemoryRepo);
|
||||
|
||||
requestContext.setContext(new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
requestContext.setContext(
|
||||
new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -111,24 +103,22 @@ public class BatchUpdateTest {
|
||||
@Test
|
||||
public void addRefUpdateFromFastForwardCommit() throws Exception {
|
||||
final RevCommit masterCommit = repo.branch("master").commit().create();
|
||||
final RevCommit branchCommit =
|
||||
repo.branch("branch").commit().parent(masterCommit).create();
|
||||
final RevCommit branchCommit = repo.branch("branch").commit().parent(masterCommit).create();
|
||||
|
||||
try (BatchUpdate bu = batchUpdateFactory
|
||||
.create(db, project, user, TimeUtil.nowTs())) {
|
||||
bu.addRepoOnlyOp(new RepoOnlyOp() {
|
||||
@Override
|
||||
public void updateRepo(RepoContext ctx) throws Exception {
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(masterCommit.getId(), branchCommit.getId(),
|
||||
"refs/heads/master"));
|
||||
}
|
||||
});
|
||||
try (BatchUpdate bu = batchUpdateFactory.create(db, project, user, TimeUtil.nowTs())) {
|
||||
bu.addRepoOnlyOp(
|
||||
new RepoOnlyOp() {
|
||||
@Override
|
||||
public void updateRepo(RepoContext ctx) throws Exception {
|
||||
ctx.addRefUpdate(
|
||||
new ReceiveCommand(
|
||||
masterCommit.getId(), branchCommit.getId(), "refs/heads/master"));
|
||||
}
|
||||
});
|
||||
bu.execute();
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
repo.getRepository().exactRef("refs/heads/master").getObjectId(),
|
||||
branchCommit.getId());
|
||||
repo.getRepository().exactRef("refs/heads/master").getObjectId(), branchCommit.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,11 @@ import static org.easymock.EasyMock.replay;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DestinationListTest extends TestCase {
|
||||
public static final String R_FOO = "refs/heads/foo";
|
||||
@@ -62,6 +59,7 @@ public class DestinationListTest extends TestCase {
|
||||
public static final Branch.NameKey B_COMPLEX = dest(P_COMPLEX, R_FOO);
|
||||
|
||||
public static final Set<Branch.NameKey> D_SIMPLE = new HashSet<>();
|
||||
|
||||
static {
|
||||
D_SIMPLE.clear();
|
||||
D_SIMPLE.add(B_FOO);
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.SortedSetMultimap;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
@@ -37,8 +36,7 @@ public class GroupCollectorTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tr = new TestRepository<>(
|
||||
new InMemoryRepository(new DfsRepositoryDescription("repo")));
|
||||
tr = new TestRepository<>(new InMemoryRepository(new DfsRepositoryDescription("repo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,58 +44,48 @@ public class GroupCollectorTest {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(a, branchTip),
|
||||
patchSets(),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(newWalk(a, branchTip), patchSets(), groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commitWhoseParentIsNewPatchSetGetsParentsGroup()
|
||||
throws Exception {
|
||||
public void commitWhoseParentIsNewPatchSetGetsParentsGroup() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit b = tr.commit().parent(a).create();
|
||||
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(b, branchTip),
|
||||
patchSets(),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(newWalk(b, branchTip), patchSets(), groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
assertThat(groups).containsEntry(b, a.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commitWhoseParentIsExistingPatchSetGetsParentsGroup()
|
||||
throws Exception {
|
||||
public void commitWhoseParentIsExistingPatchSetGetsParentsGroup() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit b = tr.commit().parent(a).create();
|
||||
|
||||
String group = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(b, branchTip),
|
||||
patchSets().put(a, psId(1, 1)),
|
||||
groups().put(psId(1, 1), group));
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(
|
||||
newWalk(b, branchTip), patchSets().put(a, psId(1, 1)), groups().put(psId(1, 1), group));
|
||||
|
||||
assertThat(groups).containsEntry(a, group);
|
||||
assertThat(groups).containsEntry(b, group);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commitWhoseParentIsExistingPatchSetWithNoGroup()
|
||||
throws Exception {
|
||||
public void commitWhoseParentIsExistingPatchSetWithNoGroup() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit b = tr.commit().parent(a).create();
|
||||
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(b, branchTip),
|
||||
patchSets().put(a, psId(1, 1)),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(newWalk(b, branchTip), patchSets().put(a, psId(1, 1)), groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
assertThat(groups).containsEntry(b, a.name());
|
||||
@@ -110,10 +98,8 @@ public class GroupCollectorTest {
|
||||
RevCommit b = tr.commit().parent(branchTip).create();
|
||||
RevCommit m = tr.commit().parent(a).parent(b).create();
|
||||
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets(),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(newWalk(m, branchTip), patchSets(), groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
assertThat(groups).containsEntry(b, a.name());
|
||||
@@ -128,10 +114,9 @@ public class GroupCollectorTest {
|
||||
RevCommit m = tr.commit().parent(a).parent(b).create();
|
||||
|
||||
String group = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets().put(b, psId(1, 1)),
|
||||
groups().put(psId(1, 1), group));
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(
|
||||
newWalk(m, branchTip), patchSets().put(b, psId(1, 1)), groups().put(psId(1, 1), group));
|
||||
|
||||
// Merge commit and other parent get the existing group.
|
||||
assertThat(groups).containsEntry(a, group);
|
||||
@@ -140,8 +125,7 @@ public class GroupCollectorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeCommitWhereBothParentsHaveDifferentGroups()
|
||||
throws Exception {
|
||||
public void mergeCommitWhereBothParentsHaveDifferentGroups() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit b = tr.commit().parent(branchTip).create();
|
||||
@@ -149,20 +133,16 @@ public class GroupCollectorTest {
|
||||
|
||||
String group1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
String group2 = "1234567812345678123456781234567812345678";
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets()
|
||||
.put(a, psId(1, 1))
|
||||
.put(b, psId(2, 1)),
|
||||
groups()
|
||||
.put(psId(1, 1), group1)
|
||||
.put(psId(2, 1), group2));
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets().put(a, psId(1, 1)).put(b, psId(2, 1)),
|
||||
groups().put(psId(1, 1), group1).put(psId(2, 1), group2));
|
||||
|
||||
assertThat(groups).containsEntry(a, group1);
|
||||
assertThat(groups).containsEntry(b, group2);
|
||||
// Merge commit gets joined group of parents.
|
||||
assertThat(groups.asMap())
|
||||
.containsEntry(m, ImmutableSet.of(group1, group2));
|
||||
assertThat(groups.asMap()).containsEntry(m, ImmutableSet.of(group1, group2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,60 +155,48 @@ public class GroupCollectorTest {
|
||||
String group1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
String group2a = "1234567812345678123456781234567812345678";
|
||||
String group2b = "ef123456ef123456ef123456ef123456ef123456";
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets()
|
||||
.put(a, psId(1, 1))
|
||||
.put(b, psId(2, 1)),
|
||||
groups()
|
||||
.put(psId(1, 1), group1)
|
||||
.put(psId(2, 1), group2a)
|
||||
.put(psId(2, 1), group2b));
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets().put(a, psId(1, 1)).put(b, psId(2, 1)),
|
||||
groups().put(psId(1, 1), group1).put(psId(2, 1), group2a).put(psId(2, 1), group2b));
|
||||
|
||||
assertThat(groups).containsEntry(a, group1);
|
||||
assertThat(groups.asMap())
|
||||
.containsEntry(b, ImmutableSet.of(group2a, group2b));
|
||||
assertThat(groups.asMap()).containsEntry(b, ImmutableSet.of(group2a, group2b));
|
||||
// Joined parent groups are split and resorted.
|
||||
assertThat(groups.asMap())
|
||||
.containsEntry(m, ImmutableSet.of(group1, group2a, group2b));
|
||||
assertThat(groups.asMap()).containsEntry(m, ImmutableSet.of(group1, group2a, group2b));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeCommitWithOneUninterestingParentAndOtherParentIsExisting()
|
||||
throws Exception {
|
||||
public void mergeCommitWithOneUninterestingParentAndOtherParentIsExisting() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit m = tr.commit().parent(branchTip).parent(a).create();
|
||||
|
||||
String group = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets().put(a, psId(1, 1)),
|
||||
groups().put(psId(1, 1), group));
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(
|
||||
newWalk(m, branchTip), patchSets().put(a, psId(1, 1)), groups().put(psId(1, 1), group));
|
||||
|
||||
assertThat(groups).containsEntry(a, group);
|
||||
assertThat(groups).containsEntry(m, group);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeCommitWithOneUninterestingParentAndOtherParentIsNew()
|
||||
throws Exception {
|
||||
public void mergeCommitWithOneUninterestingParentAndOtherParentIsNew() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit m = tr.commit().parent(branchTip).parent(a).create();
|
||||
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets(),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(newWalk(m, branchTip), patchSets(), groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
assertThat(groups).containsEntry(m, a.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleMergeCommitsInHistoryAllResolveToSameGroup()
|
||||
throws Exception {
|
||||
public void multipleMergeCommitsInHistoryAllResolveToSameGroup() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit b = tr.commit().parent(branchTip).create();
|
||||
@@ -236,10 +204,8 @@ public class GroupCollectorTest {
|
||||
RevCommit m1 = tr.commit().parent(b).parent(c).create();
|
||||
RevCommit m2 = tr.commit().parent(a).parent(m1).create();
|
||||
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m2, branchTip),
|
||||
patchSets(),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(newWalk(m2, branchTip), patchSets(), groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
assertThat(groups).containsEntry(b, a.name());
|
||||
@@ -249,8 +215,7 @@ public class GroupCollectorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeCommitWithDuplicatedParentGetsParentsGroup()
|
||||
throws Exception {
|
||||
public void mergeCommitWithDuplicatedParentGetsParentsGroup() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit m = tr.commit().parent(a).parent(a).create();
|
||||
@@ -258,18 +223,15 @@ public class GroupCollectorTest {
|
||||
assertThat(m.getParentCount()).isEqualTo(2);
|
||||
assertThat(m.getParent(0)).isEqualTo(m.getParent(1));
|
||||
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets(),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(newWalk(m, branchTip), patchSets(), groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
assertThat(groups).containsEntry(m, a.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeCommitWithOneNewParentAndTwoExistingPatchSets()
|
||||
throws Exception {
|
||||
public void mergeCommitWithOneNewParentAndTwoExistingPatchSets() throws Exception {
|
||||
RevCommit branchTip = tr.commit().create();
|
||||
RevCommit a = tr.commit().parent(branchTip).create();
|
||||
RevCommit b = tr.commit().parent(branchTip).create();
|
||||
@@ -278,20 +240,16 @@ public class GroupCollectorTest {
|
||||
|
||||
String group1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
String group2 = "1234567812345678123456781234567812345678";
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets()
|
||||
.put(a, psId(1, 1))
|
||||
.put(b, psId(2, 1)),
|
||||
groups()
|
||||
.put(psId(1, 1), group1)
|
||||
.put(psId(2, 1), group2));
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(
|
||||
newWalk(m, branchTip),
|
||||
patchSets().put(a, psId(1, 1)).put(b, psId(2, 1)),
|
||||
groups().put(psId(1, 1), group1).put(psId(2, 1), group2));
|
||||
|
||||
assertThat(groups).containsEntry(a, group1);
|
||||
assertThat(groups).containsEntry(b, group2);
|
||||
assertThat(groups).containsEntry(c, group2);
|
||||
assertThat(groups.asMap())
|
||||
.containsEntry(m, ImmutableSet.of(group1, group2));
|
||||
assertThat(groups.asMap()).containsEntry(m, ImmutableSet.of(group1, group2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -306,15 +264,16 @@ public class GroupCollectorTest {
|
||||
rw.markStart(rw.parseCommit(d));
|
||||
// Schema upgrade case: all commits are existing patch sets, but none have
|
||||
// groups assigned yet.
|
||||
SortedSetMultimap<ObjectId, String> groups = collectGroups(
|
||||
rw,
|
||||
patchSets()
|
||||
.put(branchTip, psId(1, 1))
|
||||
.put(a, psId(2, 1))
|
||||
.put(b, psId(3, 1))
|
||||
.put(c, psId(4, 1))
|
||||
.put(d, psId(5, 1)),
|
||||
groups());
|
||||
SortedSetMultimap<ObjectId, String> groups =
|
||||
collectGroups(
|
||||
rw,
|
||||
patchSets()
|
||||
.put(branchTip, psId(1, 1))
|
||||
.put(a, psId(2, 1))
|
||||
.put(b, psId(3, 1))
|
||||
.put(c, psId(4, 1))
|
||||
.put(d, psId(5, 1)),
|
||||
groups());
|
||||
|
||||
assertThat(groups).containsEntry(a, a.name());
|
||||
assertThat(groups).containsEntry(b, a.name());
|
||||
@@ -343,8 +302,7 @@ public class GroupCollectorTest {
|
||||
ImmutableListMultimap.Builder<ObjectId, PatchSet.Id> patchSetsBySha,
|
||||
ImmutableListMultimap.Builder<PatchSet.Id, String> groupLookup)
|
||||
throws Exception {
|
||||
GroupCollector gc =
|
||||
new GroupCollector(patchSetsBySha.build(), groupLookup.build());
|
||||
GroupCollector gc = new GroupCollector(patchSetsBySha.build(), groupLookup.build());
|
||||
RevCommit c;
|
||||
while ((c = rw.next()) != null) {
|
||||
gc.visit(c);
|
||||
@@ -354,8 +312,7 @@ public class GroupCollectorTest {
|
||||
|
||||
// Helper methods for constructing various map arguments, to avoid lots of
|
||||
// type specifications.
|
||||
private static ImmutableListMultimap.Builder<ObjectId, PatchSet.Id>
|
||||
patchSets() {
|
||||
private static ImmutableListMultimap.Builder<ObjectId, PatchSet.Id> patchSets() {
|
||||
return ImmutableListMultimap.builder();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,19 +28,18 @@ import static org.junit.Assert.assertTrue;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GroupListTest {
|
||||
private static final Project.NameKey PROJECT = new Project.NameKey("project");
|
||||
private static final String TEXT =
|
||||
"# UUID \tGroup Name\n" + "#\n"
|
||||
"# UUID \tGroup Name\n"
|
||||
+ "#\n"
|
||||
+ "d96b998f8a66ff433af50befb975d0e2bb6e0999\tNon-Interactive Users\n"
|
||||
+ "ebe31c01aec2c9ac3b3c03e87a47450829ff4310\tAdministrators\n";
|
||||
|
||||
@@ -55,8 +54,7 @@ public class GroupListTest {
|
||||
|
||||
@Test
|
||||
public void byUUID() throws Exception {
|
||||
AccountGroup.UUID uuid =
|
||||
new AccountGroup.UUID("d96b998f8a66ff433af50befb975d0e2bb6e0999");
|
||||
AccountGroup.UUID uuid = new AccountGroup.UUID("d96b998f8a66ff433af50befb975d0e2bb6e0999");
|
||||
|
||||
GroupReference groupReference = groupList.byUUID(uuid);
|
||||
|
||||
@@ -81,8 +79,7 @@ public class GroupListTest {
|
||||
Collection<GroupReference> result = groupList.references();
|
||||
|
||||
assertEquals(2, result.size());
|
||||
AccountGroup.UUID uuid =
|
||||
new AccountGroup.UUID("ebe31c01aec2c9ac3b3c03e87a47450829ff4310");
|
||||
AccountGroup.UUID uuid = new AccountGroup.UUID("ebe31c01aec2c9ac3b3c03e87a47450829ff4310");
|
||||
GroupReference expected = new GroupReference(uuid, "Administrators");
|
||||
|
||||
assertTrue(result.contains(expected));
|
||||
@@ -93,8 +90,7 @@ public class GroupListTest {
|
||||
Set<AccountGroup.UUID> result = groupList.uuids();
|
||||
|
||||
assertEquals(2, result.size());
|
||||
AccountGroup.UUID expected =
|
||||
new AccountGroup.UUID("ebe31c01aec2c9ac3b3c03e87a47450829ff4310");
|
||||
AccountGroup.UUID expected = new AccountGroup.UUID("ebe31c01aec2c9ac3b3c03e87a47450829ff4310");
|
||||
assertTrue(result.contains(expected));
|
||||
}
|
||||
|
||||
@@ -110,13 +106,11 @@ public class GroupListTest {
|
||||
|
||||
@Test
|
||||
public void retainAll() throws Exception {
|
||||
AccountGroup.UUID uuid =
|
||||
new AccountGroup.UUID("d96b998f8a66ff433af50befb975d0e2bb6e0999");
|
||||
AccountGroup.UUID uuid = new AccountGroup.UUID("d96b998f8a66ff433af50befb975d0e2bb6e0999");
|
||||
groupList.retainUUIDs(Collections.singleton(uuid));
|
||||
|
||||
assertNotNull(groupList.byUUID(uuid));
|
||||
assertNull(groupList.byUUID(new AccountGroup.UUID(
|
||||
"ebe31c01aec2c9ac3b3c03e87a47450829ff4310")));
|
||||
assertNull(groupList.byUUID(new AccountGroup.UUID("ebe31c01aec2c9ac3b3c03e87a47450829ff4310")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,14 +51,12 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Unit tests for {@link LabelNormalizer}. */
|
||||
public class LabelNormalizerTest {
|
||||
@Inject private AccountManager accountManager;
|
||||
@@ -88,21 +86,21 @@ public class LabelNormalizerTest {
|
||||
|
||||
db = schemaFactory.open();
|
||||
schemaCreator.create(db);
|
||||
userId = accountManager.authenticate(AuthRequest.forUser("user"))
|
||||
.getAccountId();
|
||||
userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
||||
user = userFactory.create(userId);
|
||||
|
||||
requestContext.setContext(new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
requestContext.setContext(
|
||||
new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
|
||||
configureProject();
|
||||
setUpChange();
|
||||
@@ -115,20 +113,20 @@ public class LabelNormalizerTest {
|
||||
sec.removePermission(forLabel(label));
|
||||
}
|
||||
}
|
||||
LabelType lt = category("Verified",
|
||||
value(1, "Verified"),
|
||||
value(0, "No score"),
|
||||
value(-1, "Fails"));
|
||||
LabelType lt =
|
||||
category("Verified", value(1, "Verified"), value(0, "No score"), value(-1, "Fails"));
|
||||
pc.getLabelSections().put(lt.getName(), lt);
|
||||
save(pc);
|
||||
}
|
||||
|
||||
private void setUpChange() throws Exception {
|
||||
change = new Change(
|
||||
new Change.Key("Iabcd1234abcd1234abcd1234abcd1234abcd1234"),
|
||||
new Change.Id(1), userId,
|
||||
new Branch.NameKey(allProjects, "refs/heads/master"),
|
||||
TimeUtil.nowTs());
|
||||
change =
|
||||
new Change(
|
||||
new Change.Key("Iabcd1234abcd1234abcd1234abcd1234abcd1234"),
|
||||
new Change.Id(1),
|
||||
userId,
|
||||
new Branch.NameKey(allProjects, "refs/heads/master"),
|
||||
TimeUtil.nowTs());
|
||||
PatchSetInfo ps = new PatchSetInfo(new PatchSet.Id(change.getId(), 1));
|
||||
ps.setSubject("Test change");
|
||||
change.setCurrentPatchSet(ps);
|
||||
@@ -156,11 +154,8 @@ public class LabelNormalizerTest {
|
||||
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 2);
|
||||
PatchSetApproval v = psa(userId, "Verified", 1);
|
||||
assertEquals(Result.create(
|
||||
list(v),
|
||||
list(copy(cr, 1)),
|
||||
list()),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
assertEquals(
|
||||
Result.create(list(v), list(copy(cr, 1)), list()), norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,10 +167,8 @@ public class LabelNormalizerTest {
|
||||
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 5);
|
||||
PatchSetApproval v = psa(userId, "Verified", 5);
|
||||
assertEquals(Result.create(
|
||||
list(),
|
||||
list(copy(cr, 2), copy(v, 1)),
|
||||
list()),
|
||||
assertEquals(
|
||||
Result.create(list(), list(copy(cr, 2), copy(v, 1)), list()),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
@@ -183,11 +176,7 @@ public class LabelNormalizerTest {
|
||||
public void emptyPermissionRangeOmitsResult() throws Exception {
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 1);
|
||||
PatchSetApproval v = psa(userId, "Verified", 1);
|
||||
assertEquals(Result.create(
|
||||
list(),
|
||||
list(),
|
||||
list(cr, v)),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
assertEquals(Result.create(list(), list(), list(cr, v)), norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -198,11 +187,7 @@ public class LabelNormalizerTest {
|
||||
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 0);
|
||||
PatchSetApproval v = psa(userId, "Verified", 0);
|
||||
assertEquals(Result.create(
|
||||
list(cr),
|
||||
list(),
|
||||
list(v)),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
assertEquals(Result.create(list(cr), list(), list(v)), norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
private ProjectConfig loadAllProjects() throws Exception {
|
||||
@@ -214,8 +199,7 @@ public class LabelNormalizerTest {
|
||||
}
|
||||
|
||||
private void save(ProjectConfig pc) throws Exception {
|
||||
try (MetaDataUpdate md =
|
||||
metaDataUpdateFactory.create(pc.getProject().getNameKey(), user)) {
|
||||
try (MetaDataUpdate md = metaDataUpdateFactory.create(pc.getProject().getNameKey(), user)) {
|
||||
pc.commit(md);
|
||||
projectCache.evict(pc.getProject().getNameKey());
|
||||
}
|
||||
@@ -223,19 +207,18 @@ public class LabelNormalizerTest {
|
||||
|
||||
private PatchSetApproval psa(Account.Id accountId, String label, int value) {
|
||||
return new PatchSetApproval(
|
||||
new PatchSetApproval.Key(
|
||||
change.currentPatchSetId(), accountId, new LabelId(label)),
|
||||
(short) value, TimeUtil.nowTs());
|
||||
new PatchSetApproval.Key(change.currentPatchSetId(), accountId, new LabelId(label)),
|
||||
(short) value,
|
||||
TimeUtil.nowTs());
|
||||
}
|
||||
|
||||
private PatchSetApproval copy(PatchSetApproval src, int newValue) {
|
||||
PatchSetApproval result =
|
||||
new PatchSetApproval(src.getKey().getParentKey(), src);
|
||||
PatchSetApproval result = new PatchSetApproval(src.getKey().getParentKey(), src);
|
||||
result.setValue((short) newValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<PatchSetApproval> list(PatchSetApproval... psas) {
|
||||
return ImmutableList.<PatchSetApproval> copyOf(psas);
|
||||
return ImmutableList.<PatchSetApproval>copyOf(psas);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ import com.google.gerrit.server.util.HostPlatform;
|
||||
import com.google.gerrit.testutil.TempFileUtil;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
import com.google.gwtorm.server.StandardKeyEncoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.easymock.EasyMockSupport;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
@@ -35,10 +37,6 @@ import org.eclipse.jgit.util.FS;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
||||
|
||||
static {
|
||||
@@ -116,8 +114,7 @@ public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
||||
}
|
||||
|
||||
@Test(expected = RepositoryNotFoundException.class)
|
||||
public void testProjectCreationWithPathSegmentEndingByDotGit()
|
||||
throws Exception {
|
||||
public void testProjectCreationWithPathSegmentEndingByDotGit() throws Exception {
|
||||
repoManager.createRepository(new Project.NameKey("a/b.git/projectA"));
|
||||
}
|
||||
|
||||
@@ -175,8 +172,7 @@ public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testProjectRecreationAfterRestart() throws Exception {
|
||||
repoManager.createRepository(new Project.NameKey("a"));
|
||||
LocalDiskRepositoryManager newRepoManager =
|
||||
new LocalDiskRepositoryManager(site, cfg);
|
||||
LocalDiskRepositoryManager newRepoManager = new LocalDiskRepositoryManager(site, cfg);
|
||||
newRepoManager.createRepository(new Project.NameKey("a"));
|
||||
}
|
||||
|
||||
@@ -212,13 +208,11 @@ public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
||||
Project.NameKey name = new Project.NameKey("a");
|
||||
repoManager.createRepository(name);
|
||||
|
||||
LocalDiskRepositoryManager newRepoManager =
|
||||
new LocalDiskRepositoryManager(site, cfg);
|
||||
LocalDiskRepositoryManager newRepoManager = new LocalDiskRepositoryManager(site, cfg);
|
||||
newRepoManager.createRepository(new Project.NameKey("A"));
|
||||
}
|
||||
|
||||
private void createSymLink(Project.NameKey project, String link)
|
||||
throws IOException {
|
||||
private void createSymLink(Project.NameKey project, String link) throws IOException {
|
||||
Path base = repoManager.getBasePath(project);
|
||||
Path projectDir = base.resolve(project.get() + ".git");
|
||||
Path symlink = base.resolve(link);
|
||||
@@ -244,12 +238,10 @@ public class LocalDiskRepositoryManagerTest extends EasyMockSupport {
|
||||
repoManager.getBasePath(null).resolve(".git").toFile().mkdir();
|
||||
// create an invalid repo name
|
||||
createRepository(repoManager.getBasePath(null), "project?A");
|
||||
assertThat(repoManager.list())
|
||||
.containsExactly(projectA, projectB, projectC);
|
||||
assertThat(repoManager.list()).containsExactly(projectA, projectB, projectC);
|
||||
}
|
||||
|
||||
private void createRepository(Path directory, String projectName)
|
||||
throws IOException {
|
||||
private void createRepository(Path directory, String projectName) throws IOException {
|
||||
String n = projectName + Constants.DOT_GIT_EXT;
|
||||
FileKey loc = FileKey.exact(directory.resolve(n).toFile(), FS.DETECTED);
|
||||
try (Repository db = RepositoryCache.open(loc, false)) {
|
||||
|
||||
@@ -25,7 +25,12 @@ import com.google.gerrit.server.config.RepositoryConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
import com.google.gerrit.testutil.TempFileUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.SortedSet;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
@@ -37,13 +42,6 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.SortedSet;
|
||||
|
||||
public class MultiBaseLocalDiskRepositoryManagerTest extends GerritBaseTests {
|
||||
private Config cfg;
|
||||
private SitePaths site;
|
||||
@@ -59,8 +57,7 @@ public class MultiBaseLocalDiskRepositoryManagerTest extends GerritBaseTests {
|
||||
configMock = createNiceMock(RepositoryConfig.class);
|
||||
expect(configMock.getAllBasePaths()).andReturn(new ArrayList<Path>()).anyTimes();
|
||||
replay(configMock);
|
||||
repoManager =
|
||||
new MultiBaseLocalDiskRepositoryManager(site, cfg, configMock);
|
||||
repoManager = new MultiBaseLocalDiskRepositoryManager(site, cfg, configMock);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -70,25 +67,22 @@ public class MultiBaseLocalDiskRepositoryManagerTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void defaultRepositoryLocation()
|
||||
throws RepositoryCaseMismatchException, RepositoryNotFoundException,
|
||||
IOException {
|
||||
throws RepositoryCaseMismatchException, RepositoryNotFoundException, IOException {
|
||||
Project.NameKey someProjectKey = new Project.NameKey("someProject");
|
||||
Repository repo = repoManager.createRepository(someProjectKey);
|
||||
assertThat(repo.getDirectory()).isNotNull();
|
||||
assertThat(repo.getDirectory().exists()).isTrue();
|
||||
assertThat(repo.getDirectory().getParent()).isEqualTo(
|
||||
repoManager.getBasePath(someProjectKey).toAbsolutePath().toString());
|
||||
assertThat(repo.getDirectory().getParent())
|
||||
.isEqualTo(repoManager.getBasePath(someProjectKey).toAbsolutePath().toString());
|
||||
|
||||
repo = repoManager.openRepository(someProjectKey);
|
||||
assertThat(repo.getDirectory()).isNotNull();
|
||||
assertThat(repo.getDirectory().exists()).isTrue();
|
||||
assertThat(repo.getDirectory().getParent()).isEqualTo(
|
||||
repoManager.getBasePath(someProjectKey).toAbsolutePath().toString());
|
||||
assertThat(repo.getDirectory().getParent())
|
||||
.isEqualTo(repoManager.getBasePath(someProjectKey).toAbsolutePath().toString());
|
||||
|
||||
assertThat(
|
||||
repoManager.getBasePath(someProjectKey).toAbsolutePath().toString())
|
||||
.isEqualTo(
|
||||
repoManager.getBasePath(someProjectKey).toAbsolutePath().toString());
|
||||
assertThat(repoManager.getBasePath(someProjectKey).toAbsolutePath().toString())
|
||||
.isEqualTo(repoManager.getBasePath(someProjectKey).toAbsolutePath().toString());
|
||||
|
||||
SortedSet<Project.NameKey> repoList = repoManager.list();
|
||||
assertThat(repoList.size()).isEqualTo(1);
|
||||
@@ -101,27 +95,22 @@ public class MultiBaseLocalDiskRepositoryManagerTest extends GerritBaseTests {
|
||||
Path alternateBasePath = TempFileUtil.createTempDirectory().toPath();
|
||||
Project.NameKey someProjectKey = new Project.NameKey("someProject");
|
||||
reset(configMock);
|
||||
expect(configMock.getBasePath(someProjectKey)).andReturn(alternateBasePath)
|
||||
.anyTimes();
|
||||
expect(configMock.getAllBasePaths())
|
||||
.andReturn(Arrays.asList(alternateBasePath)).anyTimes();
|
||||
expect(configMock.getBasePath(someProjectKey)).andReturn(alternateBasePath).anyTimes();
|
||||
expect(configMock.getAllBasePaths()).andReturn(Arrays.asList(alternateBasePath)).anyTimes();
|
||||
replay(configMock);
|
||||
|
||||
Repository repo = repoManager.createRepository(someProjectKey);
|
||||
assertThat(repo.getDirectory()).isNotNull();
|
||||
assertThat(repo.getDirectory().exists()).isTrue();
|
||||
assertThat(repo.getDirectory().getParent())
|
||||
.isEqualTo(alternateBasePath.toString());
|
||||
assertThat(repo.getDirectory().getParent()).isEqualTo(alternateBasePath.toString());
|
||||
|
||||
repo = repoManager.openRepository(someProjectKey);
|
||||
assertThat(repo.getDirectory()).isNotNull();
|
||||
assertThat(repo.getDirectory().exists()).isTrue();
|
||||
assertThat(repo.getDirectory().getParent())
|
||||
.isEqualTo(alternateBasePath.toString());
|
||||
assertThat(repo.getDirectory().getParent()).isEqualTo(alternateBasePath.toString());
|
||||
|
||||
assertThat(
|
||||
repoManager.getBasePath(someProjectKey).toAbsolutePath().toString())
|
||||
.isEqualTo(alternateBasePath.toString());
|
||||
assertThat(repoManager.getBasePath(someProjectKey).toAbsolutePath().toString())
|
||||
.isEqualTo(alternateBasePath.toString());
|
||||
|
||||
SortedSet<Project.NameKey> repoList = repoManager.list();
|
||||
assertThat(repoList.size()).isEqualTo(1);
|
||||
@@ -133,28 +122,22 @@ public class MultiBaseLocalDiskRepositoryManagerTest extends GerritBaseTests {
|
||||
public void listReturnRepoFromProperLocation() throws IOException {
|
||||
Project.NameKey basePathProject = new Project.NameKey("basePathProject");
|
||||
Project.NameKey altPathProject = new Project.NameKey("altPathProject");
|
||||
Project.NameKey misplacedProject1 =
|
||||
new Project.NameKey("misplacedProject1");
|
||||
Project.NameKey misplacedProject2 =
|
||||
new Project.NameKey("misplacedProject2");
|
||||
Project.NameKey misplacedProject1 = new Project.NameKey("misplacedProject1");
|
||||
Project.NameKey misplacedProject2 = new Project.NameKey("misplacedProject2");
|
||||
|
||||
Path alternateBasePath = TempFileUtil.createTempDirectory().toPath();
|
||||
|
||||
reset(configMock);
|
||||
expect(configMock.getBasePath(altPathProject)).andReturn(alternateBasePath)
|
||||
.anyTimes();
|
||||
expect(configMock.getBasePath(misplacedProject2))
|
||||
.andReturn(alternateBasePath).anyTimes();
|
||||
expect(configMock.getAllBasePaths())
|
||||
.andReturn(Arrays.asList(alternateBasePath)).anyTimes();
|
||||
expect(configMock.getBasePath(altPathProject)).andReturn(alternateBasePath).anyTimes();
|
||||
expect(configMock.getBasePath(misplacedProject2)).andReturn(alternateBasePath).anyTimes();
|
||||
expect(configMock.getAllBasePaths()).andReturn(Arrays.asList(alternateBasePath)).anyTimes();
|
||||
replay(configMock);
|
||||
|
||||
repoManager.createRepository(basePathProject);
|
||||
repoManager.createRepository(altPathProject);
|
||||
// create the misplaced ones without the repomanager otherwise they would
|
||||
// end up at the proper place.
|
||||
createRepository(repoManager.getBasePath(basePathProject),
|
||||
misplacedProject2);
|
||||
createRepository(repoManager.getBasePath(basePathProject), misplacedProject2);
|
||||
createRepository(alternateBasePath, misplacedProject1);
|
||||
|
||||
SortedSet<Project.NameKey> repoList = repoManager.list();
|
||||
@@ -163,8 +146,7 @@ public class MultiBaseLocalDiskRepositoryManagerTest extends GerritBaseTests {
|
||||
.isEqualTo(new Project.NameKey[] {altPathProject, basePathProject});
|
||||
}
|
||||
|
||||
private void createRepository(Path directory, Project.NameKey projectName)
|
||||
throws IOException {
|
||||
private void createRepository(Path directory, Project.NameKey projectName) throws IOException {
|
||||
String n = projectName.get() + Constants.DOT_GIT_EXT;
|
||||
FileKey loc = FileKey.exact(directory.resolve(n).toFile(), FS.DETECTED);
|
||||
try (Repository db = RepositoryCache.open(loc, false)) {
|
||||
@@ -175,10 +157,8 @@ public class MultiBaseLocalDiskRepositoryManagerTest extends GerritBaseTests {
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testRelativeAlternateLocation() {
|
||||
configMock = createNiceMock(RepositoryConfig.class);
|
||||
expect(configMock.getAllBasePaths())
|
||||
.andReturn(Arrays.asList(Paths.get("repos"))).anyTimes();
|
||||
expect(configMock.getAllBasePaths()).andReturn(Arrays.asList(Paths.get("repos"))).anyTimes();
|
||||
replay(configMock);
|
||||
repoManager =
|
||||
new MultiBaseLocalDiskRepositoryManager(site, cfg, configMock);
|
||||
repoManager = new MultiBaseLocalDiskRepositoryManager(site, cfg, configMock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
@@ -44,27 +46,30 @@ import org.eclipse.jgit.util.RawParseUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
private static final String LABEL_SCORES_CONFIG =
|
||||
" copyMinScore = " + !LabelType.DEF_COPY_MIN_SCORE + "\n" //
|
||||
+ " copyMaxScore = " + !LabelType.DEF_COPY_MAX_SCORE + "\n" //
|
||||
+ " copyAllScoresOnMergeFirstParentUpdate = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE + "\n" //
|
||||
+ " copyAllScoresOnTrivialRebase = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE + "\n" //
|
||||
+ " copyAllScoresIfNoCodeChange = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE + "\n" //
|
||||
+ " copyAllScoresIfNoChange = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE + "\n";
|
||||
" copyMinScore = "
|
||||
+ !LabelType.DEF_COPY_MIN_SCORE
|
||||
+ "\n" //
|
||||
+ " copyMaxScore = "
|
||||
+ !LabelType.DEF_COPY_MAX_SCORE
|
||||
+ "\n" //
|
||||
+ " copyAllScoresOnMergeFirstParentUpdate = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE
|
||||
+ "\n" //
|
||||
+ " copyAllScoresOnTrivialRebase = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE
|
||||
+ "\n" //
|
||||
+ " copyAllScoresIfNoCodeChange = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE
|
||||
+ "\n" //
|
||||
+ " copyAllScoresIfNoChange = "
|
||||
+ !LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE
|
||||
+ "\n";
|
||||
|
||||
private final GroupReference developers = new GroupReference(
|
||||
new AccountGroup.UUID("X"), "Developers");
|
||||
private final GroupReference staff = new GroupReference(
|
||||
new AccountGroup.UUID("Y"), "Staff");
|
||||
private final GroupReference developers =
|
||||
new GroupReference(new AccountGroup.UUID("X"), "Developers");
|
||||
private final GroupReference staff = new GroupReference(new AccountGroup.UUID("Y"), "Staff");
|
||||
|
||||
private Repository db;
|
||||
private TestRepository<Repository> util;
|
||||
@@ -79,24 +84,29 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
|
||||
@Test
|
||||
public void readConfig() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit create\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ " push = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = deny group Developers\n" //
|
||||
+ " sameGroupVisibility = block group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A simple description\n" //
|
||||
+ " accepted = group Developers\n" //
|
||||
+ " accepted = group Staff\n" //
|
||||
+ " autoVerify = group Developers\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n")) //
|
||||
));
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit create\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ " push = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = deny group Developers\n" //
|
||||
+ " sameGroupVisibility = block group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A simple description\n" //
|
||||
+ " accepted = group Developers\n" //
|
||||
+ " accepted = group Staff\n" //
|
||||
+ " autoVerify = group Developers\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n")) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
assertThat(cfg.getAccountsSection().getSameGroupVisibility()).hasSize(2);
|
||||
@@ -126,66 +136,85 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
|
||||
@Test
|
||||
public void readConfigLabelDefaultValue() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n")) //
|
||||
));
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n")) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
|
||||
assertThat((int)dv).isEqualTo(0);
|
||||
assertThat((int) dv).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readConfigLabelDefaultValueInRange() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -1\n")) //
|
||||
));
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -1\n")) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
|
||||
assertThat((int)dv).isEqualTo(-1);
|
||||
assertThat((int) dv).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readConfigLabelDefaultValueNotInRange() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -2\n")) //
|
||||
));
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ " value = -1 Negative\n" //
|
||||
+ " value = 0 No Score\n" //
|
||||
+ " value = 1 Positive\n" //
|
||||
+ " defaultValue = -2\n")) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
assertThat(cfg.getValidationErrors()).hasSize(1);
|
||||
assertThat(Iterables.getOnlyElement(cfg.getValidationErrors()).getMessage())
|
||||
.isEqualTo("project.config: Invalid defaultValue \"-2\" "
|
||||
+ "for label \"CustomLabel\"");
|
||||
.isEqualTo("project.config: Invalid defaultValue \"-2\" " + "for label \"CustomLabel\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readConfigLabelScores() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG)) //
|
||||
));
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG)) //
|
||||
));
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
Map<String, LabelType> labels = cfg.getLabelSections();
|
||||
@@ -193,42 +222,47 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
assertThat(type.isCopyMinScore()).isNotEqualTo(LabelType.DEF_COPY_MIN_SCORE);
|
||||
assertThat(type.isCopyMaxScore()).isNotEqualTo(LabelType.DEF_COPY_MAX_SCORE);
|
||||
assertThat(type.isCopyAllScoresOnMergeFirstParentUpdate())
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE);
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_MERGE_FIRST_PARENT_UPDATE);
|
||||
assertThat(type.isCopyAllScoresOnTrivialRebase())
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE);
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_ON_TRIVIAL_REBASE);
|
||||
assertThat(type.isCopyAllScoresIfNoCodeChange())
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE);
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CODE_CHANGE);
|
||||
assertThat(type.isCopyAllScoresIfNoChange())
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE);
|
||||
.isNotEqualTo(LabelType.DEF_COPY_ALL_SCORES_IF_NO_CHANGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editConfig() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = deny group Developers\n" //
|
||||
+ " sameGroupVisibility = block group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A simple description\n" //
|
||||
+ " accepted = group Developers\n" //
|
||||
+ " autoVerify = group Developers\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG)) //
|
||||
));
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = deny group Developers\n" //
|
||||
+ " sameGroupVisibility = block group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A simple description\n" //
|
||||
+ " accepted = group Developers\n" //
|
||||
+ " autoVerify = group Developers\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n" //
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG)) //
|
||||
));
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
AccessSection section = cfg.getAccessSection("refs/heads/*");
|
||||
cfg.getAccountsSection().setSameGroupVisibility(
|
||||
Collections.singletonList(new PermissionRule(cfg.resolve(staff))));
|
||||
cfg.getAccountsSection()
|
||||
.setSameGroupVisibility(Collections.singletonList(new PermissionRule(cfg.resolve(staff))));
|
||||
Permission submit = section.getPermission(Permission.SUBMIT);
|
||||
submit.add(new PermissionRule(cfg.resolve(staff)));
|
||||
ContributorAgreement ca = cfg.getContributorAgreement("Individual");
|
||||
@@ -236,36 +270,43 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
ca.setAutoVerify(null);
|
||||
ca.setDescription("A new description");
|
||||
rev = commit(cfg);
|
||||
assertThat(text(rev, "project.config")).isEqualTo(""//
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ "\tsubmit = group Staff\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n"//
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A new description\n" //
|
||||
+ " accepted = group Staff\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n"
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG
|
||||
+ "\tfunction = MaxWithBlock\n" // label gets this function when it is created
|
||||
+ "\tdefaultValue = 0\n"); // label gets this value when it is created
|
||||
assertThat(text(rev, "project.config"))
|
||||
.isEqualTo(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group Developers\n" //
|
||||
+ "\tsubmit = group Staff\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n" //
|
||||
+ "[accounts]\n" //
|
||||
+ " sameGroupVisibility = group Staff\n" //
|
||||
+ "[contributor-agreement \"Individual\"]\n" //
|
||||
+ " description = A new description\n" //
|
||||
+ " accepted = group Staff\n" //
|
||||
+ " agreementUrl = http://www.example.com/agree\n"
|
||||
+ "[label \"CustomLabel\"]\n" //
|
||||
+ LABEL_SCORES_CONFIG
|
||||
+ "\tfunction = MaxWithBlock\n" // label gets this function when it is created
|
||||
+ "\tdefaultValue = 0\n"); // label gets this value when it is created
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editConfigMissingGroupTableEntry() throws Exception {
|
||||
RevCommit rev = util.commit(util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file("project.config", util.blob(""//
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group People Who Can Submit\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n")) //
|
||||
));
|
||||
RevCommit rev =
|
||||
util.commit(
|
||||
util.tree( //
|
||||
util.file("groups", util.blob(group(developers))), //
|
||||
util.file(
|
||||
"project.config",
|
||||
util.blob(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group People Who Can Submit\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n")) //
|
||||
));
|
||||
update(rev);
|
||||
|
||||
ProjectConfig cfg = read(rev);
|
||||
@@ -273,28 +314,27 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
Permission submit = section.getPermission(Permission.SUBMIT);
|
||||
submit.add(new PermissionRule(cfg.resolve(staff)));
|
||||
rev = commit(cfg);
|
||||
assertThat(text(rev, "project.config")).isEqualTo(""//
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group People Who Can Submit\n" //
|
||||
+ "\tsubmit = group Staff\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n");
|
||||
assertThat(text(rev, "project.config"))
|
||||
.isEqualTo(
|
||||
"" //
|
||||
+ "[access \"refs/heads/*\"]\n" //
|
||||
+ " exclusiveGroupPermissions = read submit\n" //
|
||||
+ " submit = group People Who Can Submit\n" //
|
||||
+ "\tsubmit = group Staff\n" //
|
||||
+ " upload = group Developers\n" //
|
||||
+ " read = group Developers\n");
|
||||
}
|
||||
|
||||
private ProjectConfig read(RevCommit rev) throws IOException,
|
||||
ConfigInvalidException {
|
||||
private ProjectConfig read(RevCommit rev) throws IOException, ConfigInvalidException {
|
||||
ProjectConfig cfg = new ProjectConfig(new Project.NameKey("test"));
|
||||
cfg.load(db, rev);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private RevCommit commit(ProjectConfig cfg) throws IOException,
|
||||
MissingObjectException, IncorrectObjectTypeException {
|
||||
try (MetaDataUpdate md = new MetaDataUpdate(
|
||||
GitReferenceUpdated.DISABLED,
|
||||
cfg.getProject().getNameKey(),
|
||||
db)) {
|
||||
private RevCommit commit(ProjectConfig cfg)
|
||||
throws IOException, MissingObjectException, IncorrectObjectTypeException {
|
||||
try (MetaDataUpdate md =
|
||||
new MetaDataUpdate(GitReferenceUpdated.DISABLED, cfg.getProject().getNameKey(), db)) {
|
||||
util.tick(5);
|
||||
util.setAuthorAndCommitter(md.getCommitBuilder());
|
||||
md.setMessage("Edit\n");
|
||||
@@ -311,9 +351,9 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
|
||||
u.setNewObjectId(rev);
|
||||
Result result = u.forceUpdate();
|
||||
assert_()
|
||||
.withFailureMessage("Cannot update ref for test: " + result)
|
||||
.that(result)
|
||||
.isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
|
||||
.withFailureMessage("Cannot update ref for test: " + result)
|
||||
.that(result)
|
||||
.isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
|
||||
}
|
||||
|
||||
private String text(RevCommit rev, String path) throws Exception {
|
||||
|
||||
@@ -18,11 +18,9 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.easymock.EasyMock.createNiceMock;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class QueryListTest extends TestCase {
|
||||
public static final String Q_P = "project:foo";
|
||||
|
||||
@@ -20,12 +20,10 @@ import static com.google.gerrit.server.index.SchemaUtil.getPersonParts;
|
||||
import static com.google.gerrit.server.index.SchemaUtil.schema;
|
||||
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import java.util.Map;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SchemaUtilTest extends GerritBaseTests {
|
||||
static class TestSchemas {
|
||||
static final Schema<String> V1 = schema();
|
||||
@@ -40,8 +38,7 @@ public class SchemaUtilTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void schemasFromClassBuildsMap() {
|
||||
Map<Integer, Schema<String>> all =
|
||||
SchemaUtil.schemasFromClass(TestSchemas.class, String.class);
|
||||
Map<Integer, Schema<String>> all = SchemaUtil.schemasFromClass(TestSchemas.class, String.class);
|
||||
assertThat(all.keySet()).containsExactly(1, 2, 4);
|
||||
assertThat(all.get(1)).isEqualTo(TestSchemas.V1);
|
||||
assertThat(all.get(2)).isEqualTo(TestSchemas.V2);
|
||||
@@ -56,18 +53,22 @@ public class SchemaUtilTest extends GerritBaseTests {
|
||||
// PersonIdent allows empty email, which should be extracted as the empty
|
||||
// string. However, it converts empty names to null internally.
|
||||
assertThat(getPersonParts(new PersonIdent("", ""))).containsExactly("");
|
||||
assertThat(getPersonParts(new PersonIdent("foo bar", "")))
|
||||
.containsExactly("foo", "bar", "");
|
||||
assertThat(getPersonParts(new PersonIdent("foo bar", ""))).containsExactly("foo", "bar", "");
|
||||
|
||||
assertThat(getPersonParts(new PersonIdent("", "foo@example.com")))
|
||||
.containsExactly("foo@example.com", "foo", "example.com", "example", "com");
|
||||
assertThat(getPersonParts(new PersonIdent("foO J. bAr", "bA-z@exAmple.cOm")))
|
||||
.containsExactly(
|
||||
"foo@example.com", "foo", "example.com", "example", "com");
|
||||
assertThat(
|
||||
getPersonParts(new PersonIdent("foO J. bAr", "bA-z@exAmple.cOm")))
|
||||
.containsExactly(
|
||||
"foo", "j", "bar",
|
||||
"ba-z@example.com", "ba-z", "ba", "z",
|
||||
"example.com", "example", "com");
|
||||
"foo",
|
||||
"j",
|
||||
"bar",
|
||||
"ba-z@example.com",
|
||||
"ba-z",
|
||||
"ba",
|
||||
"z",
|
||||
"example.com",
|
||||
"example",
|
||||
"com");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,14 +28,12 @@ import com.google.gerrit.server.ReviewerSet;
|
||||
import com.google.gerrit.server.notedb.ReviewerStateInternal;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
import com.google.gerrit.testutil.TestTimeUtil;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ChangeFieldTest extends GerritBaseTests {
|
||||
@Before
|
||||
@@ -50,8 +48,7 @@ public class ChangeFieldTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void reviewerFieldValues() {
|
||||
Table<ReviewerStateInternal, Account.Id, Timestamp> t =
|
||||
HashBasedTable.create();
|
||||
Table<ReviewerStateInternal, Account.Id, Timestamp> t = HashBasedTable.create();
|
||||
Timestamp t1 = TimeUtil.nowTs();
|
||||
t.put(ReviewerStateInternal.REVIEWER, new Account.Id(1), t1);
|
||||
Timestamp t2 = TimeUtil.nowTs();
|
||||
@@ -59,14 +56,11 @@ public class ChangeFieldTest extends GerritBaseTests {
|
||||
ReviewerSet reviewers = ReviewerSet.fromTable(t);
|
||||
|
||||
List<String> values = ChangeField.getReviewerFieldValues(reviewers);
|
||||
assertThat(values).containsExactly(
|
||||
"REVIEWER,1",
|
||||
"REVIEWER,1," + t1.getTime(),
|
||||
"CC,2",
|
||||
"CC,2," + t2.getTime());
|
||||
assertThat(values)
|
||||
.containsExactly(
|
||||
"REVIEWER,1", "REVIEWER,1," + t1.getTime(), "CC,2", "CC,2," + t2.getTime());
|
||||
|
||||
assertThat(ChangeField.parseReviewerFieldValues(values))
|
||||
.isEqualTo(reviewers);
|
||||
assertThat(ChangeField.parseReviewerFieldValues(values)).isEqualTo(reviewers);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,12 +73,7 @@ public class ChangeFieldTest extends GerritBaseTests {
|
||||
label(SubmitRecord.Label.Status.MAY, "Label-1", null),
|
||||
label(SubmitRecord.Label.Status.OK, "Label-2", 1))),
|
||||
new Account.Id(1)))
|
||||
.containsExactly(
|
||||
"OK",
|
||||
"MAY,label-1",
|
||||
"OK,label-2",
|
||||
"OK,label-2,0",
|
||||
"OK,label-2,1");
|
||||
.containsExactly("OK", "MAY,label-1", "OK,label-2", "OK,label-2,0", "OK,label-2,1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,8 +86,7 @@ public class ChangeFieldTest extends GerritBaseTests {
|
||||
label(SubmitRecord.Label.Status.OK, "Label-2", 1)));
|
||||
}
|
||||
|
||||
private static SubmitRecord record(SubmitRecord.Status status,
|
||||
SubmitRecord.Label... labels) {
|
||||
private static SubmitRecord record(SubmitRecord.Status status, SubmitRecord.Label... labels) {
|
||||
SubmitRecord r = new SubmitRecord();
|
||||
r.status = status;
|
||||
if (labels.length > 0) {
|
||||
@@ -107,8 +95,8 @@ public class ChangeFieldTest extends GerritBaseTests {
|
||||
return r;
|
||||
}
|
||||
|
||||
private static SubmitRecord.Label label(SubmitRecord.Label.Status status,
|
||||
String label, Integer appliedBy) {
|
||||
private static SubmitRecord.Label label(
|
||||
SubmitRecord.Label.Status status, String label, Integer appliedBy) {
|
||||
SubmitRecord.Label l = new SubmitRecord.Label();
|
||||
l.status = status;
|
||||
l.label = label;
|
||||
@@ -120,9 +108,11 @@ public class ChangeFieldTest extends GerritBaseTests {
|
||||
|
||||
private static void assertStoredRecordRoundTrip(SubmitRecord... records) {
|
||||
List<SubmitRecord> recordList = ImmutableList.copyOf(records);
|
||||
List<String> stored = ChangeField.storedSubmitRecords(recordList).stream()
|
||||
.map(s -> new String(s, UTF_8))
|
||||
.collect(toList());
|
||||
List<String> stored =
|
||||
ChangeField.storedSubmitRecords(recordList)
|
||||
.stream()
|
||||
.map(s -> new String(s, UTF_8))
|
||||
.collect(toList());
|
||||
assertThat(ChangeField.parseSubmitRecords(stored))
|
||||
.named("JSON %s" + stored)
|
||||
.isEqualTo(recordList);
|
||||
|
||||
@@ -38,13 +38,11 @@ import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
||||
import com.google.gerrit.server.query.change.ChangeStatusPredicate;
|
||||
import com.google.gerrit.server.query.change.OrSource;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
private static final IndexConfig CONFIG = IndexConfig.createDefault();
|
||||
@@ -60,8 +58,7 @@ public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
indexes = new ChangeIndexCollection();
|
||||
indexes.setSearchIndex(index);
|
||||
queryBuilder = new FakeQueryBuilder(indexes);
|
||||
rewrite = new ChangeIndexRewriter(indexes,
|
||||
IndexConfig.create(0, 0, 3));
|
||||
rewrite = new ChangeIndexRewriter(indexes, IndexConfig.create(0, 0, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,19 +98,13 @@ public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
Predicate<ChangeData> in = parse("foo:a file:b");
|
||||
Predicate<ChangeData> out = rewrite(in);
|
||||
assertThat(AndChangeSource.class).isSameAs(out.getClass());
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(in.getChild(1)),
|
||||
in.getChild(0))
|
||||
.inOrder();
|
||||
assertThat(out.getChildren()).containsExactly(query(in.getChild(1)), in.getChild(0)).inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void threeLevelTreeWithAllIndexPredicates() throws Exception {
|
||||
Predicate<ChangeData> in =
|
||||
parse("-status:abandoned (file:a OR file:b)");
|
||||
assertThat(rewrite.rewrite(in, options(0, DEFAULT_MAX_QUERY_LIMIT)))
|
||||
.isEqualTo(query(in));
|
||||
Predicate<ChangeData> in = parse("-status:abandoned (file:a OR file:b)");
|
||||
assertThat(rewrite.rewrite(in, options(0, DEFAULT_MAX_QUERY_LIMIT))).isEqualTo(query(in));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,24 +112,16 @@ public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
Predicate<ChangeData> in = parse("-foo:a (file:b OR file:c)");
|
||||
Predicate<ChangeData> out = rewrite(in);
|
||||
assertThat(out.getClass()).isSameAs(AndChangeSource.class);
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(in.getChild(1)),
|
||||
in.getChild(0))
|
||||
.inOrder();
|
||||
assertThat(out.getChildren()).containsExactly(query(in.getChild(1)), in.getChild(0)).inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleIndexPredicates() throws Exception {
|
||||
Predicate<ChangeData> in =
|
||||
parse("file:a OR foo:b OR file:c OR foo:d");
|
||||
Predicate<ChangeData> in = parse("file:a OR foo:b OR file:c OR foo:d");
|
||||
Predicate<ChangeData> out = rewrite(in);
|
||||
assertThat(out.getClass()).isSameAs(OrSource.class);
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(or(in.getChild(0), in.getChild(2))),
|
||||
in.getChild(1),
|
||||
in.getChild(3))
|
||||
.containsExactly(query(or(in.getChild(0), in.getChild(2))), in.getChild(1), in.getChild(3))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@@ -148,49 +131,37 @@ public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
Predicate<ChangeData> out = rewrite(in);
|
||||
assertThat(AndChangeSource.class).isSameAs(out.getClass());
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(and(in.getChild(0), in.getChild(2))),
|
||||
in.getChild(1))
|
||||
.containsExactly(query(and(in.getChild(0), in.getChild(2))), in.getChild(1))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateCompoundNonIndexOnlyPredicates() throws Exception {
|
||||
Predicate<ChangeData> in =
|
||||
parse("(status:new OR status:draft) bar:p file:a");
|
||||
Predicate<ChangeData> in = parse("(status:new OR status:draft) bar:p file:a");
|
||||
Predicate<ChangeData> out = rewrite(in);
|
||||
assertThat(out.getClass()).isEqualTo(AndChangeSource.class);
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(and(in.getChild(0), in.getChild(2))),
|
||||
in.getChild(1))
|
||||
.containsExactly(query(and(in.getChild(0), in.getChild(2))), in.getChild(1))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateCompoundIndexOnlyPredicates() throws Exception {
|
||||
Predicate<ChangeData> in =
|
||||
parse("(status:new OR file:a) bar:p file:b");
|
||||
Predicate<ChangeData> in = parse("(status:new OR file:a) bar:p file:b");
|
||||
Predicate<ChangeData> out = rewrite(in);
|
||||
assertThat(out.getClass()).isEqualTo(AndChangeSource.class);
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(and(in.getChild(0), in.getChild(2))),
|
||||
in.getChild(1))
|
||||
.containsExactly(query(and(in.getChild(0), in.getChild(2))), in.getChild(1))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsArgumentOverridesAllLimitPredicates()
|
||||
throws Exception {
|
||||
public void optionsArgumentOverridesAllLimitPredicates() throws Exception {
|
||||
Predicate<ChangeData> in = parse("limit:1 file:a limit:3");
|
||||
Predicate<ChangeData> out = rewrite(in, options(0, 5));
|
||||
assertThat(out.getClass()).isEqualTo(AndChangeSource.class);
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(in.getChild(1), 5),
|
||||
parse("limit:5"),
|
||||
parse("limit:5"))
|
||||
.containsExactly(query(in.getChild(1), 5), parse("limit:5"), parse("limit:5"))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@@ -200,28 +171,23 @@ public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
Predicate<ChangeData> f = parse("file:a");
|
||||
Predicate<ChangeData> l = parse("limit:" + n);
|
||||
Predicate<ChangeData> in = andSource(f, l);
|
||||
assertThat(rewrite.rewrite(in, options(0, n)))
|
||||
.isEqualTo(andSource(query(f, 3), l));
|
||||
assertThat(rewrite.rewrite(in, options(1, n)))
|
||||
.isEqualTo(andSource(query(f, 4), l));
|
||||
assertThat(rewrite.rewrite(in, options(2, n)))
|
||||
.isEqualTo(andSource(query(f, 5), l));
|
||||
assertThat(rewrite.rewrite(in, options(0, n))).isEqualTo(andSource(query(f, 3), l));
|
||||
assertThat(rewrite.rewrite(in, options(1, n))).isEqualTo(andSource(query(f, 4), l));
|
||||
assertThat(rewrite.rewrite(in, options(2, n))).isEqualTo(andSource(query(f, 5), l));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPossibleStatus() throws Exception {
|
||||
assertThat(status("file:a")).isEqualTo(EnumSet.allOf(Change.Status.class));
|
||||
assertThat(status("is:new")).containsExactly(NEW);
|
||||
assertThat(status("-is:new"))
|
||||
.containsExactly(DRAFT, MERGED, ABANDONED);
|
||||
assertThat(status("-is:new")).containsExactly(DRAFT, MERGED, ABANDONED);
|
||||
assertThat(status("is:new OR is:merged")).containsExactly(NEW, MERGED);
|
||||
|
||||
assertThat(status("is:new is:merged")).isEmpty();
|
||||
assertThat(status("(is:new is:draft) (is:merged)")).isEmpty();
|
||||
assertThat(status("(is:new is:draft) (is:merged)")).isEmpty();
|
||||
|
||||
assertThat(status("(is:new is:draft) OR (is:merged)"))
|
||||
.containsExactly(MERGED);
|
||||
assertThat(status("(is:new is:draft) OR (is:merged)")).containsExactly(MERGED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,11 +198,7 @@ public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
indexes.setSearchIndex(new FakeChangeIndex(FakeChangeIndex.V1));
|
||||
Predicate<ChangeData> out = rewrite(in);
|
||||
assertThat(out).isInstanceOf(AndPredicate.class);
|
||||
assertThat(out.getChildren())
|
||||
.containsExactly(
|
||||
query(in.getChild(0)),
|
||||
in.getChild(1))
|
||||
.inOrder();
|
||||
assertThat(out.getChildren()).containsExactly(query(in.getChild(0)), in.getChild(1)).inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -275,29 +237,25 @@ public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
return new AndChangeSource(Arrays.asList(preds));
|
||||
}
|
||||
|
||||
private Predicate<ChangeData> rewrite(Predicate<ChangeData> in)
|
||||
throws QueryParseException {
|
||||
private Predicate<ChangeData> rewrite(Predicate<ChangeData> in) throws QueryParseException {
|
||||
return rewrite.rewrite(in, options(0, DEFAULT_MAX_QUERY_LIMIT));
|
||||
}
|
||||
|
||||
private Predicate<ChangeData> rewrite(Predicate<ChangeData> in,
|
||||
QueryOptions opts) throws QueryParseException {
|
||||
private Predicate<ChangeData> rewrite(Predicate<ChangeData> in, QueryOptions opts)
|
||||
throws QueryParseException {
|
||||
return rewrite.rewrite(in, opts);
|
||||
}
|
||||
|
||||
private IndexedChangeQuery query(Predicate<ChangeData> p)
|
||||
throws QueryParseException {
|
||||
private IndexedChangeQuery query(Predicate<ChangeData> p) throws QueryParseException {
|
||||
return query(p, DEFAULT_MAX_QUERY_LIMIT);
|
||||
}
|
||||
|
||||
private IndexedChangeQuery query(Predicate<ChangeData> p, int limit)
|
||||
throws QueryParseException {
|
||||
private IndexedChangeQuery query(Predicate<ChangeData> p, int limit) throws QueryParseException {
|
||||
return new IndexedChangeQuery(index, p, options(0, limit));
|
||||
}
|
||||
|
||||
private static QueryOptions options(int start, int limit) {
|
||||
return IndexedChangeQuery.createOptions(CONFIG, start, limit,
|
||||
ImmutableSet.<String> of());
|
||||
return IndexedChangeQuery.createOptions(CONFIG, start, limit, ImmutableSet.<String>of());
|
||||
}
|
||||
|
||||
private Set<Change.Status> status(String query) throws QueryParseException {
|
||||
|
||||
@@ -25,20 +25,15 @@ import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeDataSource;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class FakeChangeIndex implements ChangeIndex {
|
||||
static Schema<ChangeData> V1 = new Schema<>(1,
|
||||
ImmutableList.<FieldDef<ChangeData, ?>> of(
|
||||
ChangeField.STATUS));
|
||||
static Schema<ChangeData> V1 =
|
||||
new Schema<>(1, ImmutableList.<FieldDef<ChangeData, ?>>of(ChangeField.STATUS));
|
||||
|
||||
static Schema<ChangeData> V2 = new Schema<>(2,
|
||||
ImmutableList.of(
|
||||
ChangeField.STATUS,
|
||||
ChangeField.PATH,
|
||||
ChangeField.UPDATED));
|
||||
static Schema<ChangeData> V2 =
|
||||
new Schema<>(2, ImmutableList.of(ChangeField.STATUS, ChangeField.PATH, ChangeField.UPDATED));
|
||||
|
||||
private static class Source implements ChangeDataSource {
|
||||
private final Predicate<ChangeData> p;
|
||||
@@ -101,8 +96,7 @@ public class FakeChangeIndex implements ChangeIndex {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public void markReady(boolean ready) {
|
||||
|
||||
@@ -18,19 +18,17 @@ import com.google.gerrit.server.query.OperatorPredicate;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class FakeQueryBuilder extends ChangeQueryBuilder {
|
||||
FakeQueryBuilder(ChangeIndexCollection indexes) {
|
||||
super(
|
||||
new FakeQueryBuilder.Definition<>(
|
||||
FakeQueryBuilder.class),
|
||||
new ChangeQueryBuilder.Arguments(null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, indexes, null, null, null, null, null, null,
|
||||
null, null));
|
||||
new FakeQueryBuilder.Definition<>(FakeQueryBuilder.class),
|
||||
new ChangeQueryBuilder.Arguments(
|
||||
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, null, indexes, null, null, null, null, null, null,
|
||||
null, null));
|
||||
}
|
||||
|
||||
@Operator
|
||||
|
||||
@@ -35,15 +35,13 @@ import com.google.gerrit.testutil.GerritBaseTests;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
||||
import com.google.gwtorm.protobuf.CodecFactory;
|
||||
import com.google.gwtorm.protobuf.ProtobufCodec;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class StalenessCheckerTest extends GerritBaseTests {
|
||||
private static final String SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||
private static final String SHA2 = "badc0feebadc0feebadc0feebadc0feebadc0fee";
|
||||
@@ -53,8 +51,7 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
|
||||
private static final Change.Id C = new Change.Id(1234);
|
||||
|
||||
private static final ProtobufCodec<Change> CHANGE_CODEC =
|
||||
CodecFactory.encoder(Change.class);
|
||||
private static final ProtobufCodec<Change> CHANGE_CODEC = CodecFactory.encoder(Change.class);
|
||||
|
||||
private GitRepositoryManager repoManager;
|
||||
private Repository r1;
|
||||
@@ -105,15 +102,11 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
public void refStateToByteArray() {
|
||||
assertThat(
|
||||
new String(
|
||||
RefState.create("refs/heads/foo", ObjectId.fromString(SHA1))
|
||||
.toByteArray(P1),
|
||||
RefState.create("refs/heads/foo", ObjectId.fromString(SHA1)).toByteArray(P1),
|
||||
UTF_8))
|
||||
.isEqualTo(P1 + ":refs/heads/foo:" + SHA1);
|
||||
assertThat(
|
||||
new String(
|
||||
RefState.create("refs/heads/foo", (ObjectId) null)
|
||||
.toByteArray(P1),
|
||||
UTF_8))
|
||||
new String(RefState.create("refs/heads/foo", (ObjectId) null).toByteArray(P1), UTF_8))
|
||||
.isEqualTo(P1 + ":refs/heads/foo:" + ObjectId.zeroId().name());
|
||||
}
|
||||
|
||||
@@ -146,8 +139,7 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
p = r.get(P2).get(0);
|
||||
assertThat(p.pattern()).isEqualTo("refs/heads/foo/*/bar");
|
||||
assertThat(p.prefix()).isEqualTo("refs/heads/foo/");
|
||||
assertThat(p.regex().pattern())
|
||||
.isEqualTo("^\\Qrefs/heads/foo/\\E.*\\Q/bar\\E$");
|
||||
assertThat(p.regex().pattern()).isEqualTo("^\\Qrefs/heads/foo/\\E.*\\Q/bar\\E$");
|
||||
assertThat(p.match("refs/heads/foo//bar")).isTrue();
|
||||
assertThat(p.match("refs/heads/foo/x/bar")).isTrue();
|
||||
assertThat(p.match("refs/heads/foo/x/y/bar")).isTrue();
|
||||
@@ -156,8 +148,7 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
p = r.get(P2).get(1);
|
||||
assertThat(p.pattern()).isEqualTo("refs/heads/foo/*-baz/*/quux");
|
||||
assertThat(p.prefix()).isEqualTo("refs/heads/foo/");
|
||||
assertThat(p.regex().pattern())
|
||||
.isEqualTo("^\\Qrefs/heads/foo/\\E.*\\Q-baz/\\E.*\\Q/quux\\E$");
|
||||
assertThat(p.regex().pattern()).isEqualTo("^\\Qrefs/heads/foo/\\E.*\\Q-baz/\\E.*\\Q/quux\\E$");
|
||||
assertThat(p.match("refs/heads/foo/-baz//quux")).isTrue();
|
||||
assertThat(p.match("refs/heads/foo/x-baz/x/quux")).isTrue();
|
||||
assertThat(p.match("refs/heads/foo/x/y-baz/x/y/quux")).isTrue();
|
||||
@@ -166,8 +157,7 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void refStatePatternToByteArray() {
|
||||
assertThat(
|
||||
new String(RefStatePattern.create("refs/*").toByteArray(P1), UTF_8))
|
||||
assertThat(new String(RefStatePattern.create("refs/*").toByteArray(P1), UTF_8))
|
||||
.isEqualTo(P1 + ":refs/*");
|
||||
}
|
||||
|
||||
@@ -190,7 +180,8 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
// Not stale.
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name()),
|
||||
P2, RefState.create(ref2, id2.name())),
|
||||
@@ -200,7 +191,8 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
// Wrong ref value.
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, SHA1),
|
||||
P2, RefState.create(ref2, id2.name())),
|
||||
@@ -210,7 +202,8 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
// Swapped repos.
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id2.name()),
|
||||
P2, RefState.create(ref2, id1.name())),
|
||||
@@ -223,7 +216,8 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
tr1.update(ref3, id3);
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name()),
|
||||
P1, RefState.create(ref3, id3.name())),
|
||||
@@ -233,16 +227,17 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
// Ignore ref not mentioned.
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name())),
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of()))
|
||||
.isFalse();
|
||||
|
||||
// One ref wrong.
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name()),
|
||||
P1, RefState.create(ref3, SHA1)),
|
||||
@@ -258,11 +253,10 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
// ref1 is only ref matching pattern.
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(
|
||||
P1, RefStatePattern.create("refs/heads/*"))))
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(P1, RefStatePattern.create("refs/heads/*"))))
|
||||
.isFalse();
|
||||
|
||||
// Now ref2 matches pattern, so stale unless ref2 is present in state map.
|
||||
@@ -270,20 +264,19 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
ObjectId id2 = tr1.update(ref2, tr1.commit().message("commit 2"));
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(
|
||||
P1, RefStatePattern.create("refs/heads/*"))))
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(P1, RefStatePattern.create("refs/heads/*"))))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name()),
|
||||
P1, RefState.create(ref2, id2.name())),
|
||||
ImmutableListMultimap.of(
|
||||
P1, RefStatePattern.create("refs/heads/*"))))
|
||||
ImmutableListMultimap.of(P1, RefStatePattern.create("refs/heads/*"))))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@@ -296,11 +289,10 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
// ref1 is only ref matching pattern.
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(
|
||||
P1, RefStatePattern.create("refs/*/foo"))))
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(P1, RefStatePattern.create("refs/*/foo"))))
|
||||
.isFalse();
|
||||
|
||||
// Now ref2 matches pattern, so stale unless ref2 is present in state map.
|
||||
@@ -308,20 +300,19 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
ObjectId id3 = tr1.update(ref3, tr1.commit().message("commit 3"));
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(
|
||||
P1, RefStatePattern.create("refs/*/foo"))))
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(P1, RefState.create(ref1, id1.name())),
|
||||
ImmutableListMultimap.of(P1, RefStatePattern.create("refs/*/foo"))))
|
||||
.isTrue();
|
||||
assertThat(
|
||||
refsAreStale(
|
||||
repoManager, C,
|
||||
repoManager,
|
||||
C,
|
||||
ImmutableSetMultimap.of(
|
||||
P1, RefState.create(ref1, id1.name()),
|
||||
P1, RefState.create(ref3, id3.name())),
|
||||
ImmutableListMultimap.of(
|
||||
P1, RefStatePattern.create("refs/*/foo"))))
|
||||
ImmutableListMultimap.of(P1, RefStatePattern.create("refs/*/foo"))))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@@ -330,30 +321,22 @@ public class StalenessCheckerTest extends GerritBaseTests {
|
||||
Change indexChange = newChange(P1, new Account.Id(1));
|
||||
indexChange.setNoteDbState(SHA1);
|
||||
|
||||
assertThat(StalenessChecker.reviewDbChangeIsStale(indexChange, null))
|
||||
.isFalse();
|
||||
assertThat(StalenessChecker.reviewDbChangeIsStale(indexChange, null)).isFalse();
|
||||
|
||||
Change noteDbPrimary = clone(indexChange);
|
||||
noteDbPrimary.setNoteDbState(NoteDbChangeState.NOTE_DB_PRIMARY_STATE);
|
||||
assertThat(
|
||||
StalenessChecker.reviewDbChangeIsStale(indexChange, noteDbPrimary))
|
||||
.isFalse();
|
||||
assertThat(StalenessChecker.reviewDbChangeIsStale(indexChange, noteDbPrimary)).isFalse();
|
||||
|
||||
assertThat(
|
||||
StalenessChecker.reviewDbChangeIsStale(
|
||||
indexChange, clone(indexChange)))
|
||||
.isFalse();
|
||||
assertThat(StalenessChecker.reviewDbChangeIsStale(indexChange, clone(indexChange))).isFalse();
|
||||
|
||||
// Can't easily change row version to check true case.
|
||||
}
|
||||
|
||||
private static Iterable<byte[]> byteArrays(String... strs) {
|
||||
return Stream.of(strs).map(s -> s != null ? s.getBytes(UTF_8) : null)
|
||||
.collect(toList());
|
||||
return Stream.of(strs).map(s -> s != null ? s.getBytes(UTF_8) : null).collect(toList());
|
||||
}
|
||||
|
||||
private static Change clone(Change change) {
|
||||
return CHANGE_CODEC.decode(CHANGE_CODEC.encodeToByteArray(change));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,12 +23,11 @@ import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BasicSerializationTest {
|
||||
@Test
|
||||
@@ -60,20 +59,17 @@ public class BasicSerializationTest {
|
||||
assertEquals(0L, readFixInt64(r(b(0, 0, 0, 0, 0, 0, 0, 0))));
|
||||
assertEquals(3L, readFixInt64(r(b(0, 0, 0, 0, 0, 0, 0, 3))));
|
||||
|
||||
assertEquals(0xdeadbeefL, readFixInt64(r(b(0, 0, 0, 0, 0xde, 0xad, 0xbe,
|
||||
0xef))));
|
||||
assertEquals(0xdeadbeefL, readFixInt64(r(b(0, 0, 0, 0, 0xde, 0xad, 0xbe, 0xef))));
|
||||
|
||||
assertEquals(0x0310adefL, readFixInt64(r(b(0, 0, 0, 0, 0x03, 0x10, 0xad,
|
||||
0xef))));
|
||||
assertEquals(0x0310adefL, readFixInt64(r(b(0, 0, 0, 0, 0x03, 0x10, 0xad, 0xef))));
|
||||
|
||||
assertEquals(0xc0ffee78deadbeefL, readFixInt64(r(b(0xc0, 0xff, 0xee, 0x78,
|
||||
0xde, 0xad, 0xbe, 0xef))));
|
||||
assertEquals(
|
||||
0xc0ffee78deadbeefL, readFixInt64(r(b(0xc0, 0xff, 0xee, 0x78, 0xde, 0xad, 0xbe, 0xef))));
|
||||
|
||||
assertEquals(0x00000000ffffffffL, readFixInt64(r(b(0, 0, 0, 0, 0xff, 0xff,
|
||||
0xff, 0xff))));
|
||||
assertEquals(0x00000000ffffffffL, readFixInt64(r(b(0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff))));
|
||||
|
||||
assertEquals(0xffffffffffffffffL, readFixInt64(r(b(0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff))));
|
||||
assertEquals(
|
||||
0xffffffffffffffffL, readFixInt64(r(b(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,8 +105,7 @@ public class BasicSerializationTest {
|
||||
public void testReadString() throws IOException {
|
||||
assertNull(readString(r(b(0))));
|
||||
assertEquals("a", readString(r(b(1, 'a'))));
|
||||
assertEquals("coffee4",
|
||||
readString(r(b(7, 'c', 'o', 'f', 'f', 'e', 'e', '4'))));
|
||||
assertEquals("coffee4", readString(r(b(7, 'c', 'o', 'f', 'f', 'e', 'e', '4'))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,8 +129,7 @@ public class BasicSerializationTest {
|
||||
assertOutput(b(7, 'c', 'o', 'f', 'f', 'e', 'e', '4'), out);
|
||||
}
|
||||
|
||||
private static void assertOutput(final byte[] expect,
|
||||
final ByteArrayOutputStream out) {
|
||||
private static void assertOutput(final byte[] expect, final ByteArrayOutputStream out) {
|
||||
final byte[] buf = out.toByteArray();
|
||||
for (int i = 0; i < expect.length; i++) {
|
||||
assertEquals(expect[i], buf[i]);
|
||||
@@ -155,7 +149,9 @@ public class BasicSerializationTest {
|
||||
}
|
||||
|
||||
private static byte[] b(int a, int b, int c, int d, int e, int f, int g, int h) {
|
||||
return new byte[] {(byte) a, (byte) b, (byte) c, (byte) d, //
|
||||
(byte) e, (byte) f, (byte) g, (byte) h,};
|
||||
return new byte[] {
|
||||
(byte) a, (byte) b, (byte) c, (byte) d, //
|
||||
(byte) e, (byte) f, (byte) g, (byte) h,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,15 @@
|
||||
|
||||
package com.google.gerrit.server.ioutil;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class ColumnFormatterTest {
|
||||
/**
|
||||
* Holds an in-memory {@link java.io.PrintWriter} object and allows
|
||||
* comparisons of its contents to a supplied string via an assert statement.
|
||||
* Holds an in-memory {@link java.io.PrintWriter} object and allows comparisons of its contents to
|
||||
* a supplied string via an assert statement.
|
||||
*/
|
||||
static class PrintWriterComparator {
|
||||
private PrintWriter printWriter;
|
||||
@@ -44,14 +43,11 @@ public class ColumnFormatterTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that only lines with at least one column of text emit output.
|
||||
*/
|
||||
/** Test that only lines with at least one column of text emit output. */
|
||||
@Test
|
||||
public void emptyLine() {
|
||||
final PrintWriterComparator comparator = new PrintWriterComparator();
|
||||
final ColumnFormatter formatter =
|
||||
new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
final ColumnFormatter formatter = new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
formatter.addColumn("foo");
|
||||
formatter.addColumn("bar");
|
||||
formatter.nextLine();
|
||||
@@ -63,14 +59,11 @@ public class ColumnFormatterTest {
|
||||
comparator.assertEquals("foo\tbar\nfoo\tbar\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that there is no output if no columns are ever added.
|
||||
*/
|
||||
/** Test that there is no output if no columns are ever added. */
|
||||
@Test
|
||||
public void emptyOutput() {
|
||||
final PrintWriterComparator comparator = new PrintWriterComparator();
|
||||
final ColumnFormatter formatter =
|
||||
new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
final ColumnFormatter formatter = new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
formatter.nextLine();
|
||||
formatter.nextLine();
|
||||
formatter.finish();
|
||||
@@ -78,44 +71,40 @@ public class ColumnFormatterTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that there is no output (nor any exceptions) if we finalize
|
||||
* the output immediately after the creation of the {@link ColumnFormatter}.
|
||||
* Test that there is no output (nor any exceptions) if we finalize the output immediately after
|
||||
* the creation of the {@link ColumnFormatter}.
|
||||
*/
|
||||
@Test
|
||||
public void noNextLine() {
|
||||
final PrintWriterComparator comparator = new PrintWriterComparator();
|
||||
final ColumnFormatter formatter =
|
||||
new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
final ColumnFormatter formatter = new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
formatter.finish();
|
||||
comparator.assertEquals("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the text in added columns is escaped while the column separator
|
||||
* (which of course shouldn't be escaped) is left alone.
|
||||
* Test that the text in added columns is escaped while the column separator (which of course
|
||||
* shouldn't be escaped) is left alone.
|
||||
*/
|
||||
@Test
|
||||
public void escapingTakesPlace() {
|
||||
final PrintWriterComparator comparator = new PrintWriterComparator();
|
||||
final ColumnFormatter formatter =
|
||||
new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
final ColumnFormatter formatter = new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
formatter.addColumn("foo");
|
||||
formatter.addColumn(
|
||||
"\tan indented multi-line\ntext");
|
||||
formatter.addColumn("\tan indented multi-line\ntext");
|
||||
formatter.nextLine();
|
||||
formatter.finish();
|
||||
comparator.assertEquals("foo\t\\tan indented multi-line\\ntext\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we get the correct output with multi-line input where the number
|
||||
* of columns in each line varies.
|
||||
* Test that we get the correct output with multi-line input where the number of columns in each
|
||||
* line varies.
|
||||
*/
|
||||
@Test
|
||||
public void multiLineDifferentColumnCount() {
|
||||
final PrintWriterComparator comparator = new PrintWriterComparator();
|
||||
final ColumnFormatter formatter =
|
||||
new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
final ColumnFormatter formatter = new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
formatter.addColumn("foo");
|
||||
formatter.addColumn("bar");
|
||||
formatter.addColumn("baz");
|
||||
@@ -127,14 +116,11 @@ public class ColumnFormatterTest {
|
||||
comparator.assertEquals("foo\tbar\tbaz\nfoo\tbar\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we get the correct output with a single column of input.
|
||||
*/
|
||||
/** Test that we get the correct output with a single column of input. */
|
||||
@Test
|
||||
public void oneColumn() {
|
||||
final PrintWriterComparator comparator = new PrintWriterComparator();
|
||||
final ColumnFormatter formatter =
|
||||
new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
final ColumnFormatter formatter = new ColumnFormatter(comparator.getPrintWriter(), '\t');
|
||||
formatter.addColumn("foo");
|
||||
formatter.nextLine();
|
||||
formatter.finish();
|
||||
|
||||
@@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AddressTest extends GerritBaseTests {
|
||||
@@ -133,14 +132,13 @@ public class AddressTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void toHeaderString_NameEmail6() {
|
||||
assertThat(format("A \u20ac B", "a@a"))
|
||||
.isEqualTo("=?UTF-8?Q?A_=E2=82=AC_B?= <a@a>");
|
||||
assertThat(format("A \u20ac B", "a@a")).isEqualTo("=?UTF-8?Q?A_=E2=82=AC_B?= <a@a>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toHeaderString_NameEmail7() {
|
||||
assertThat(format("A \u20ac B (Code Review)", "a@a"))
|
||||
.isEqualTo("=?UTF-8?Q?A_=E2=82=AC_B_=28Code_Review=29?= <a@a>");
|
||||
.isEqualTo("=?UTF-8?Q?A_=E2=82=AC_B_=28Code_Review=29?= <a@a>");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,12 +18,10 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
|
||||
import com.google.gerrit.server.mail.send.OutgoingEmailValidator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ValidatorTest {
|
||||
private static final String UNSUPPORTED_PREFIX = "#! ";
|
||||
@@ -35,8 +33,7 @@ public class ValidatorTest {
|
||||
|
||||
@Test
|
||||
public void validateTopLevelDomains() throws Exception {
|
||||
try (InputStream in =
|
||||
this.getClass().getResourceAsStream("tlds-alpha-by-domain.txt")) {
|
||||
try (InputStream in = this.getClass().getResourceAsStream("tlds-alpha-by-domain.txt")) {
|
||||
if (in == null) {
|
||||
throw new Exception("TLD list not found");
|
||||
}
|
||||
@@ -48,18 +45,17 @@ public class ValidatorTest {
|
||||
continue;
|
||||
}
|
||||
if (tld.startsWith(UNSUPPORTED_PREFIX)) {
|
||||
String test = "test@example."
|
||||
+ tld.toLowerCase().substring(UNSUPPORTED_PREFIX.length());
|
||||
String test = "test@example." + tld.toLowerCase().substring(UNSUPPORTED_PREFIX.length());
|
||||
assert_()
|
||||
.withFailureMessage("expected invalid TLD \"" + test + "\"")
|
||||
.that(OutgoingEmailValidator.isValid(test))
|
||||
.isFalse();
|
||||
.withFailureMessage("expected invalid TLD \"" + test + "\"")
|
||||
.that(OutgoingEmailValidator.isValid(test))
|
||||
.isFalse();
|
||||
} else {
|
||||
String test = "test@example." + tld.toLowerCase();
|
||||
assert_()
|
||||
.withFailureMessage("failed to validate TLD \"" + test + "\"")
|
||||
.that(OutgoingEmailValidator.isValid(test))
|
||||
.isTrue();
|
||||
.withFailureMessage("failed to validate TLD \"" + test + "\"")
|
||||
.that(OutgoingEmailValidator.isValid(test))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,47 +19,48 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Comment;
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Ignore;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class AbstractParserTest {
|
||||
protected static final String changeURL =
|
||||
"https://gerrit-review.googlesource.com/#/changes/123";
|
||||
protected static final String changeURL = "https://gerrit-review.googlesource.com/#/changes/123";
|
||||
|
||||
protected static void assertChangeMessage(String message,
|
||||
MailComment comment) {
|
||||
protected static void assertChangeMessage(String message, MailComment comment) {
|
||||
assertThat(comment.fileName).isNull();
|
||||
assertThat(comment.message).isEqualTo(message);
|
||||
assertThat(comment.inReplyTo).isNull();
|
||||
assertThat(comment.type).isEqualTo(MailComment.CommentType.CHANGE_MESSAGE);
|
||||
}
|
||||
|
||||
protected static void assertInlineComment(String message, MailComment comment,
|
||||
Comment inReplyTo) {
|
||||
protected static void assertInlineComment(
|
||||
String message, MailComment comment, Comment inReplyTo) {
|
||||
assertThat(comment.fileName).isNull();
|
||||
assertThat(comment.message).isEqualTo(message);
|
||||
assertThat(comment.inReplyTo).isEqualTo(inReplyTo);
|
||||
assertThat(comment.type).isEqualTo(MailComment.CommentType.INLINE_COMMENT);
|
||||
}
|
||||
|
||||
protected static void assertFileComment(String message, MailComment comment,
|
||||
String file) {
|
||||
protected static void assertFileComment(String message, MailComment comment, String file) {
|
||||
assertThat(comment.fileName).isEqualTo(file);
|
||||
assertThat(comment.message).isEqualTo(message);
|
||||
assertThat(comment.inReplyTo).isNull();
|
||||
assertThat(comment.type).isEqualTo(MailComment.CommentType.FILE_COMMENT);
|
||||
}
|
||||
|
||||
protected static Comment newComment(String uuid, String file,
|
||||
String message, int line) {
|
||||
Comment c = new Comment(new Comment.Key(uuid, file, 1),
|
||||
new Account.Id(0), new Timestamp(0L), (short) 0, message, "", false);
|
||||
protected static Comment newComment(String uuid, String file, String message, int line) {
|
||||
Comment c =
|
||||
new Comment(
|
||||
new Comment.Key(uuid, file, 1),
|
||||
new Account.Id(0),
|
||||
new Timestamp(0L),
|
||||
(short) 0,
|
||||
message,
|
||||
"",
|
||||
false);
|
||||
c.lineNbr = line;
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -17,71 +17,96 @@ package com.google.gerrit.server.mail.receive;
|
||||
/** Test parser for a generic Html email client response */
|
||||
public class GenericHtmlParserTest extends HtmlParserTest {
|
||||
@Override
|
||||
protected String newHtmlBody(String changeMessage, String c1,
|
||||
String c2, String c3, String f1, String f2, String fc1) {
|
||||
String email = "" +
|
||||
"<div dir=\"ltr\">" + (changeMessage != null ? changeMessage : "") +
|
||||
"<div class=\"extra\"><br><div class=\"quote\">" +
|
||||
"On Fri, Nov 18, 2016 at 11:15 AM, foobar (Gerrit) noreply@gerrit.com" +
|
||||
"<span dir=\"ltr\"><<a href=\"mailto:noreply@gerrit.com\" " +
|
||||
"target=\"_blank\">noreply@gerrit.com</a>></span> wrote:<br>" +
|
||||
"<blockquote class=\"quote\" " +
|
||||
"<p>foobar <strong>posted comments</strong> on this change.</p>" +
|
||||
"<p><a href=\"" + changeURL + "/1\" " +
|
||||
"target=\"_blank\">View Change</a></p><div>Patch Set 2: CR-1\n" +
|
||||
"\n" +
|
||||
"(3 comments)</div><ul><li>" +
|
||||
"<p>" + // File #1: test.txt
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt\">" +
|
||||
"File gerrit-server/<wbr>test.txt:</a></p>" +
|
||||
commentBlock(f1) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt\">" +
|
||||
"Patch Set #2:</a> </p>" +
|
||||
"<blockquote><pre>Some inline comment from Gerrit</pre>" +
|
||||
"</blockquote><p>Some comment on file 1</p>" +
|
||||
"</li>" +
|
||||
commentBlock(fc1) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt@2\">" +
|
||||
"Patch Set #2, Line 31:</a> </p>" +
|
||||
"<blockquote><pre>Some inline comment from Gerrit</pre>" +
|
||||
"</blockquote><p>Some text from original comment</p>" +
|
||||
"</li>" +
|
||||
commentBlock(c1) +
|
||||
"" + // Inline comment #2
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt@3\">" +
|
||||
"Patch Set #2, Line 47:</a> </p>" +
|
||||
"<blockquote><pre>Some comment posted on Gerrit</pre>" +
|
||||
"</blockquote><p>Some more comments from Gerrit</p>" +
|
||||
"</li>" +
|
||||
commentBlock(c2) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt@115\">" +
|
||||
"Patch Set #2, Line 115:</a> <code>some code</code></p>" +
|
||||
"<p>some comment</p></li></ul></li>" +
|
||||
"" +
|
||||
"<li><p>" + // File #2: test.txt
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/readme.txt\">" +
|
||||
"File gerrit-server/<wbr>readme.txt:</a></p>" +
|
||||
commentBlock(f2) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/readme.txt@3\">" +
|
||||
"Patch Set #2, Line 31:</a> </p>" +
|
||||
"<blockquote><pre>Some inline comment from Gerrit</pre>" +
|
||||
"</blockquote><p>Some text from original comment</p>" +
|
||||
"</li>" +
|
||||
commentBlock(c3) +
|
||||
"" + // Inline comment #2
|
||||
"</ul></li></ul>" +
|
||||
"" + // Footer
|
||||
"<p>To view, visit <a href=\"" + changeURL + "/1\">this change</a>. " +
|
||||
"To unsubscribe, visit <a href=\"https://someurl\">settings</a>." +
|
||||
"</p><p>Gerrit-MessageType: comment<br>" +
|
||||
"Footer omitted</p>" +
|
||||
"<div><div></div></div>" +
|
||||
"<p>Gerrit-HasComments: Yes</p></blockquote></div><br></div></div>";
|
||||
protected String newHtmlBody(
|
||||
String changeMessage, String c1, String c2, String c3, String f1, String f2, String fc1) {
|
||||
String email =
|
||||
""
|
||||
+ "<div dir=\"ltr\">"
|
||||
+ (changeMessage != null ? changeMessage : "")
|
||||
+ "<div class=\"extra\"><br><div class=\"quote\">"
|
||||
+ "On Fri, Nov 18, 2016 at 11:15 AM, foobar (Gerrit) noreply@gerrit.com"
|
||||
+ "<span dir=\"ltr\"><<a href=\"mailto:noreply@gerrit.com\" "
|
||||
+ "target=\"_blank\">noreply@gerrit.com</a>></span> wrote:<br>"
|
||||
+ "<blockquote class=\"quote\" "
|
||||
+ "<p>foobar <strong>posted comments</strong> on this change.</p>"
|
||||
+ "<p><a href=\""
|
||||
+ changeURL
|
||||
+ "/1\" "
|
||||
+ "target=\"_blank\">View Change</a></p><div>Patch Set 2: CR-1\n"
|
||||
+ "\n"
|
||||
+ "(3 comments)</div><ul><li>"
|
||||
+ "<p>"
|
||||
+ // File #1: test.txt
|
||||
"<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt\">"
|
||||
+ "File gerrit-server/<wbr>test.txt:</a></p>"
|
||||
+ commentBlock(f1)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt\">"
|
||||
+ "Patch Set #2:</a> </p>"
|
||||
+ "<blockquote><pre>Some inline comment from Gerrit</pre>"
|
||||
+ "</blockquote><p>Some comment on file 1</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(fc1)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@2\">"
|
||||
+ "Patch Set #2, Line 31:</a> </p>"
|
||||
+ "<blockquote><pre>Some inline comment from Gerrit</pre>"
|
||||
+ "</blockquote><p>Some text from original comment</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(c1)
|
||||
+ ""
|
||||
+ // Inline comment #2
|
||||
"<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@3\">"
|
||||
+ "Patch Set #2, Line 47:</a> </p>"
|
||||
+ "<blockquote><pre>Some comment posted on Gerrit</pre>"
|
||||
+ "</blockquote><p>Some more comments from Gerrit</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(c2)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@115\">"
|
||||
+ "Patch Set #2, Line 115:</a> <code>some code</code></p>"
|
||||
+ "<p>some comment</p></li></ul></li>"
|
||||
+ ""
|
||||
+ "<li><p>"
|
||||
+ // File #2: test.txt
|
||||
"<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/readme.txt\">"
|
||||
+ "File gerrit-server/<wbr>readme.txt:</a></p>"
|
||||
+ commentBlock(f2)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/readme.txt@3\">"
|
||||
+ "Patch Set #2, Line 31:</a> </p>"
|
||||
+ "<blockquote><pre>Some inline comment from Gerrit</pre>"
|
||||
+ "</blockquote><p>Some text from original comment</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(c3)
|
||||
+ ""
|
||||
+ // Inline comment #2
|
||||
"</ul></li></ul>"
|
||||
+ ""
|
||||
+ // Footer
|
||||
"<p>To view, visit <a href=\""
|
||||
+ changeURL
|
||||
+ "/1\">this change</a>. "
|
||||
+ "To unsubscribe, visit <a href=\"https://someurl\">settings</a>."
|
||||
+ "</p><p>Gerrit-MessageType: comment<br>"
|
||||
+ "Footer omitted</p>"
|
||||
+ "<div><div></div></div>"
|
||||
+ "<p>Gerrit-HasComments: Yes</p></blockquote></div><br></div></div>";
|
||||
return email;
|
||||
}
|
||||
|
||||
@@ -89,7 +114,8 @@ public class GenericHtmlParserTest extends HtmlParserTest {
|
||||
if (comment == null) {
|
||||
return "";
|
||||
}
|
||||
return "</ul></li></ul></blockquote><div>" + comment +
|
||||
"</div><blockquote class=\"quote\"><ul><li><ul>";
|
||||
return "</ul></li></ul></blockquote><div>"
|
||||
+ comment
|
||||
+ "</div><blockquote class=\"quote\"><ul><li><ul>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,71 +16,96 @@ package com.google.gerrit.server.mail.receive;
|
||||
|
||||
public class GmailHtmlParserTest extends HtmlParserTest {
|
||||
@Override
|
||||
protected String newHtmlBody(String changeMessage, String c1,
|
||||
String c2, String c3, String f1, String f2, String fc1) {
|
||||
String email = "" +
|
||||
"<div dir=\"ltr\">" + (changeMessage != null ? changeMessage : "") +
|
||||
"<div class=\"gmail_extra\"><br><div class=\"gmail_quote\">" +
|
||||
"On Fri, Nov 18, 2016 at 11:15 AM, foobar (Gerrit) noreply@gerrit.com" +
|
||||
"<span dir=\"ltr\"><<a href=\"mailto:noreply@gerrit.com\" " +
|
||||
"target=\"_blank\">noreply@gerrit.com</a>></span> wrote:<br>" +
|
||||
"<blockquote class=\"gmail_quote\" " +
|
||||
"<p>foobar <strong>posted comments</strong> on this change.</p>" +
|
||||
"<p><a href=\"" + changeURL + "/1\" " +
|
||||
"target=\"_blank\">View Change</a></p><div>Patch Set 2: CR-1\n" +
|
||||
"\n" +
|
||||
"(3 comments)</div><ul><li>" +
|
||||
"<p>" + // File #1: test.txt
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt\">" +
|
||||
"File gerrit-server/<wbr>test.txt:</a></p>" +
|
||||
commentBlock(f1) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt\">" +
|
||||
"Patch Set #2:</a> </p>" +
|
||||
"<blockquote><pre>Some inline comment from Gerrit</pre>" +
|
||||
"</blockquote><p>Some comment on file 1</p>" +
|
||||
"</li>" +
|
||||
commentBlock(fc1) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt@2\">" +
|
||||
"Patch Set #2, Line 31:</a> </p>" +
|
||||
"<blockquote><pre>Some inline comment from Gerrit</pre>" +
|
||||
"</blockquote><p>Some text from original comment</p>" +
|
||||
"</li>" +
|
||||
commentBlock(c1) +
|
||||
"" + // Inline comment #2
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt@3\">" +
|
||||
"Patch Set #2, Line 47:</a> </p>" +
|
||||
"<blockquote><pre>Some comment posted on Gerrit</pre>" +
|
||||
"</blockquote><p>Some more comments from Gerrit</p>" +
|
||||
"</li>" +
|
||||
commentBlock(c2) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/test.txt@115\">" +
|
||||
"Patch Set #2, Line 115:</a> <code>some code</code></p>" +
|
||||
"<p>some comment</p></li></ul></li>" +
|
||||
"" +
|
||||
"<li><p>" + // File #2: test.txt
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/readme.txt\">" +
|
||||
"File gerrit-server/<wbr>readme.txt:</a></p>" +
|
||||
commentBlock(f2) +
|
||||
"<li><p>" +
|
||||
"<a href=\"" + changeURL + "/1/gerrit-server/readme.txt@3\">" +
|
||||
"Patch Set #2, Line 31:</a> </p>" +
|
||||
"<blockquote><pre>Some inline comment from Gerrit</pre>" +
|
||||
"</blockquote><p>Some text from original comment</p>" +
|
||||
"</li>" +
|
||||
commentBlock(c3) +
|
||||
"" + // Inline comment #2
|
||||
"</ul></li></ul>" +
|
||||
"" + // Footer
|
||||
"<p>To view, visit <a href=\"" + changeURL + "/1\">this change</a>. " +
|
||||
"To unsubscribe, visit <a href=\"https://someurl\">settings</a>." +
|
||||
"</p><p>Gerrit-MessageType: comment<br>" +
|
||||
"Footer omitted</p>" +
|
||||
"<div><div></div></div>" +
|
||||
"<p>Gerrit-HasComments: Yes</p></blockquote></div><br></div></div>";
|
||||
protected String newHtmlBody(
|
||||
String changeMessage, String c1, String c2, String c3, String f1, String f2, String fc1) {
|
||||
String email =
|
||||
""
|
||||
+ "<div dir=\"ltr\">"
|
||||
+ (changeMessage != null ? changeMessage : "")
|
||||
+ "<div class=\"gmail_extra\"><br><div class=\"gmail_quote\">"
|
||||
+ "On Fri, Nov 18, 2016 at 11:15 AM, foobar (Gerrit) noreply@gerrit.com"
|
||||
+ "<span dir=\"ltr\"><<a href=\"mailto:noreply@gerrit.com\" "
|
||||
+ "target=\"_blank\">noreply@gerrit.com</a>></span> wrote:<br>"
|
||||
+ "<blockquote class=\"gmail_quote\" "
|
||||
+ "<p>foobar <strong>posted comments</strong> on this change.</p>"
|
||||
+ "<p><a href=\""
|
||||
+ changeURL
|
||||
+ "/1\" "
|
||||
+ "target=\"_blank\">View Change</a></p><div>Patch Set 2: CR-1\n"
|
||||
+ "\n"
|
||||
+ "(3 comments)</div><ul><li>"
|
||||
+ "<p>"
|
||||
+ // File #1: test.txt
|
||||
"<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt\">"
|
||||
+ "File gerrit-server/<wbr>test.txt:</a></p>"
|
||||
+ commentBlock(f1)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt\">"
|
||||
+ "Patch Set #2:</a> </p>"
|
||||
+ "<blockquote><pre>Some inline comment from Gerrit</pre>"
|
||||
+ "</blockquote><p>Some comment on file 1</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(fc1)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@2\">"
|
||||
+ "Patch Set #2, Line 31:</a> </p>"
|
||||
+ "<blockquote><pre>Some inline comment from Gerrit</pre>"
|
||||
+ "</blockquote><p>Some text from original comment</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(c1)
|
||||
+ ""
|
||||
+ // Inline comment #2
|
||||
"<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@3\">"
|
||||
+ "Patch Set #2, Line 47:</a> </p>"
|
||||
+ "<blockquote><pre>Some comment posted on Gerrit</pre>"
|
||||
+ "</blockquote><p>Some more comments from Gerrit</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(c2)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@115\">"
|
||||
+ "Patch Set #2, Line 115:</a> <code>some code</code></p>"
|
||||
+ "<p>some comment</p></li></ul></li>"
|
||||
+ ""
|
||||
+ "<li><p>"
|
||||
+ // File #2: test.txt
|
||||
"<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/readme.txt\">"
|
||||
+ "File gerrit-server/<wbr>readme.txt:</a></p>"
|
||||
+ commentBlock(f2)
|
||||
+ "<li><p>"
|
||||
+ "<a href=\""
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/readme.txt@3\">"
|
||||
+ "Patch Set #2, Line 31:</a> </p>"
|
||||
+ "<blockquote><pre>Some inline comment from Gerrit</pre>"
|
||||
+ "</blockquote><p>Some text from original comment</p>"
|
||||
+ "</li>"
|
||||
+ commentBlock(c3)
|
||||
+ ""
|
||||
+ // Inline comment #2
|
||||
"</ul></li></ul>"
|
||||
+ ""
|
||||
+ // Footer
|
||||
"<p>To view, visit <a href=\""
|
||||
+ changeURL
|
||||
+ "/1\">this change</a>. "
|
||||
+ "To unsubscribe, visit <a href=\"https://someurl\">settings</a>."
|
||||
+ "</p><p>Gerrit-MessageType: comment<br>"
|
||||
+ "Footer omitted</p>"
|
||||
+ "<div><div></div></div>"
|
||||
+ "<p>Gerrit-HasComments: Yes</p></blockquote></div><br></div></div>";
|
||||
return email;
|
||||
}
|
||||
|
||||
@@ -88,7 +113,8 @@ public class GmailHtmlParserTest extends HtmlParserTest {
|
||||
if (comment == null) {
|
||||
return "";
|
||||
}
|
||||
return "</ul></li></ul></blockquote><div>" + comment +
|
||||
"</div><blockquote class=\"gmail_quote\"><ul><li><ul>";
|
||||
return "</ul></li></ul></blockquote><div>"
|
||||
+ comment
|
||||
+ "</div><blockquote class=\"gmail_quote\"><ul><li><ul>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,23 +17,19 @@ package com.google.gerrit.server.mail.receive;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Comment;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Ignore
|
||||
public abstract class HtmlParserTest extends AbstractParserTest {
|
||||
@Test
|
||||
public void simpleChangeMessage() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.htmlContent(newHtmlBody("Looks good to me", null, null,
|
||||
null, null, null, null));
|
||||
b.htmlContent(newHtmlBody("Looks good to me", null, null, null, null, null, null));
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
HtmlParser.parse(b.build(), comments, "");
|
||||
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, "");
|
||||
|
||||
assertThat(parsedComments).hasSize(1);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
@@ -42,39 +38,45 @@ public abstract class HtmlParserTest extends AbstractParserTest {
|
||||
@Test
|
||||
public void simpleInlineComments() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.htmlContent(newHtmlBody("Looks good to me",
|
||||
"I have a comment on this.", null, "Also have a comment here.",
|
||||
null, null, null));
|
||||
b.htmlContent(
|
||||
newHtmlBody(
|
||||
"Looks good to me",
|
||||
"I have a comment on this.",
|
||||
null,
|
||||
"Also have a comment here.",
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
HtmlParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(3);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
assertInlineComment("I have a comment on this.", parsedComments.get(1),
|
||||
comments.get(1));
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2),
|
||||
comments.get(3));
|
||||
assertInlineComment("I have a comment on this.", parsedComments.get(1), comments.get(1));
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2), comments.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleFileComment() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.htmlContent(newHtmlBody("Looks good to me",
|
||||
null, null, "Also have a comment here.",
|
||||
"This is a nice file", null, null));
|
||||
b.htmlContent(
|
||||
newHtmlBody(
|
||||
"Looks good to me",
|
||||
null,
|
||||
null,
|
||||
"Also have a comment here.",
|
||||
"This is a nice file",
|
||||
null,
|
||||
null));
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
HtmlParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(3);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
assertFileComment("This is a nice file", parsedComments.get(1),
|
||||
comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2),
|
||||
comments.get(3));
|
||||
assertFileComment("This is a nice file", parsedComments.get(1), comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2), comments.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,8 +85,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
|
||||
b.htmlContent(newHtmlBody(null, null, null, null, null, null, null));
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
HtmlParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).isEmpty();
|
||||
}
|
||||
@@ -92,18 +93,16 @@ public abstract class HtmlParserTest extends AbstractParserTest {
|
||||
@Test
|
||||
public void noChangeMessage() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.htmlContent(newHtmlBody(null, null, null,
|
||||
"Also have a comment here.", "This is a nice file", null, null));
|
||||
b.htmlContent(
|
||||
newHtmlBody(
|
||||
null, null, null, "Also have a comment here.", "This is a nice file", null, null));
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
HtmlParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(2);
|
||||
assertFileComment("This is a nice file", parsedComments.get(0),
|
||||
comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(1),
|
||||
comments.get(3));
|
||||
assertFileComment("This is a nice file", parsedComments.get(0), comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(1), comments.get(3));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +117,6 @@ public abstract class HtmlParserTest extends AbstractParserTest {
|
||||
* @param fc1 Comment in reply to a comment on file 1.
|
||||
* @return A string with all inline comments and the original quoted email.
|
||||
*/
|
||||
protected abstract String newHtmlBody(String changeMessage, String c1,
|
||||
String c2, String c3, String f1, String f2, String fc1);
|
||||
protected abstract String newHtmlBody(
|
||||
String changeMessage, String c1, String c2, String c3, String f1, String f2, String fc1);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import static com.google.gerrit.server.mail.MetadataName.toHeaderWithDelimiter;
|
||||
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.mail.MetadataName;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Test;
|
||||
@@ -35,13 +34,11 @@ public class MetadataParserTest {
|
||||
b.dateReceived(new DateTime());
|
||||
b.subject("");
|
||||
|
||||
b.addAdditionalHeader(
|
||||
toHeaderWithDelimiter(MetadataName.CHANGE_ID) + "cid");
|
||||
b.addAdditionalHeader(toHeaderWithDelimiter(MetadataName.CHANGE_ID) + "cid");
|
||||
b.addAdditionalHeader(toHeaderWithDelimiter(MetadataName.PATCH_SET) + "1");
|
||||
b.addAdditionalHeader(toHeaderWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment");
|
||||
b.addAdditionalHeader(
|
||||
toHeaderWithDelimiter(MetadataName.MESSAGE_TYPE) +"comment");
|
||||
b.addAdditionalHeader(toHeaderWithDelimiter(MetadataName.TIMESTAMP) +
|
||||
"Tue, 25 Oct 2016 02:11:35 -0700");
|
||||
toHeaderWithDelimiter(MetadataName.TIMESTAMP) + "Tue, 25 Oct 2016 02:11:35 -0700");
|
||||
|
||||
Address author = new Address("Diffy", "test@gerritcodereview.com");
|
||||
b.from(author);
|
||||
@@ -51,8 +48,8 @@ public class MetadataParserTest {
|
||||
assertThat(meta.changeId).isEqualTo("cid");
|
||||
assertThat(meta.patchSet).isEqualTo(1);
|
||||
assertThat(meta.messageType).isEqualTo("comment");
|
||||
assertThat(meta.timestamp.getTime()).isEqualTo(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
|
||||
assertThat(meta.timestamp.getTime())
|
||||
.isEqualTo(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,14 +62,11 @@ public class MetadataParserTest {
|
||||
b.subject("");
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid" + "\n");
|
||||
stringBuilder.append(toFooterWithDelimiter(MetadataName.PATCH_SET) + "1" + "\n");
|
||||
stringBuilder.append(toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment" + "\n");
|
||||
stringBuilder.append(
|
||||
toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid" + "\n");
|
||||
stringBuilder.append(
|
||||
toFooterWithDelimiter(MetadataName.PATCH_SET) + "1" + "\n");
|
||||
stringBuilder.append(
|
||||
toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment" + "\n");
|
||||
stringBuilder.append(toFooterWithDelimiter(MetadataName.TIMESTAMP) +
|
||||
"Tue, 25 Oct 2016 02:11:35 -0700" + "\n");
|
||||
toFooterWithDelimiter(MetadataName.TIMESTAMP) + "Tue, 25 Oct 2016 02:11:35 -0700" + "\n");
|
||||
b.textContent(stringBuilder.toString());
|
||||
|
||||
Address author = new Address("Diffy", "test@gerritcodereview.com");
|
||||
@@ -83,8 +77,8 @@ public class MetadataParserTest {
|
||||
assertThat(meta.changeId).isEqualTo("cid");
|
||||
assertThat(meta.patchSet).isEqualTo(1);
|
||||
assertThat(meta.messageType).isEqualTo("comment");
|
||||
assertThat(meta.timestamp.getTime()).isEqualTo(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
|
||||
assertThat(meta.timestamp.getTime())
|
||||
.isEqualTo(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,14 +91,15 @@ public class MetadataParserTest {
|
||||
b.subject("");
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<p>" +
|
||||
toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid" + "</p>");
|
||||
stringBuilder.append("<p>" + toFooterWithDelimiter(MetadataName.PATCH_SET) +
|
||||
"1" + "</p>");
|
||||
stringBuilder.append("<p>" +
|
||||
toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment" + "</p>");
|
||||
stringBuilder.append("<p>" + toFooterWithDelimiter(MetadataName.TIMESTAMP) +
|
||||
"Tue, 25 Oct 2016 02:11:35 -0700" + "</p>");
|
||||
stringBuilder.append("<p>" + toFooterWithDelimiter(MetadataName.CHANGE_ID) + "cid" + "</p>");
|
||||
stringBuilder.append("<p>" + toFooterWithDelimiter(MetadataName.PATCH_SET) + "1" + "</p>");
|
||||
stringBuilder.append(
|
||||
"<p>" + toFooterWithDelimiter(MetadataName.MESSAGE_TYPE) + "comment" + "</p>");
|
||||
stringBuilder.append(
|
||||
"<p>"
|
||||
+ toFooterWithDelimiter(MetadataName.TIMESTAMP)
|
||||
+ "Tue, 25 Oct 2016 02:11:35 -0700"
|
||||
+ "</p>");
|
||||
b.htmlContent(stringBuilder.toString());
|
||||
|
||||
Address author = new Address("Diffy", "test@gerritcodereview.com");
|
||||
@@ -115,7 +110,7 @@ public class MetadataParserTest {
|
||||
assertThat(meta.changeId).isEqualTo("cid");
|
||||
assertThat(meta.patchSet).isEqualTo(1);
|
||||
assertThat(meta.messageType).isEqualTo("comment");
|
||||
assertThat(meta.timestamp.getTime()).isEqualTo(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
|
||||
assertThat(meta.timestamp.getTime())
|
||||
.isEqualTo(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC).getMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,40 +24,39 @@ import com.google.gerrit.server.mail.receive.data.QuotedPrintableHeaderMessage;
|
||||
import com.google.gerrit.server.mail.receive.data.RawMailMessage;
|
||||
import com.google.gerrit.server.mail.receive.data.SimpleTextMessage;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RawMailParserTest extends GerritBaseTests {
|
||||
@Test
|
||||
public void parseEmail() throws Exception {
|
||||
RawMailMessage[] messages = new RawMailMessage[] {
|
||||
new SimpleTextMessage(),
|
||||
new Base64HeaderMessage(),
|
||||
new QuotedPrintableHeaderMessage(),
|
||||
new HtmlMimeMessage(),
|
||||
new AttachmentMessage(),
|
||||
new NonUTF8Message(),
|
||||
};
|
||||
RawMailMessage[] messages =
|
||||
new RawMailMessage[] {
|
||||
new SimpleTextMessage(),
|
||||
new Base64HeaderMessage(),
|
||||
new QuotedPrintableHeaderMessage(),
|
||||
new HtmlMimeMessage(),
|
||||
new AttachmentMessage(),
|
||||
new NonUTF8Message(),
|
||||
};
|
||||
for (RawMailMessage rawMailMessage : messages) {
|
||||
if (rawMailMessage.rawChars() != null) {
|
||||
// Assert Character to Mail Parser
|
||||
MailMessage parsedMailMessage =
|
||||
RawMailParser.parse(rawMailMessage.rawChars());
|
||||
MailMessage parsedMailMessage = RawMailParser.parse(rawMailMessage.rawChars());
|
||||
assertMail(parsedMailMessage, rawMailMessage.expectedMailMessage());
|
||||
}
|
||||
if (rawMailMessage.raw() != null) {
|
||||
// Assert String to Mail Parser
|
||||
MailMessage parsedMailMessage = RawMailParser
|
||||
.parse(rawMailMessage.raw());
|
||||
MailMessage parsedMailMessage = RawMailParser.parse(rawMailMessage.raw());
|
||||
assertMail(parsedMailMessage, rawMailMessage.expectedMailMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method makes it easier to debug failing tests by checking each
|
||||
* property individual instead of calling equals as it will immediately
|
||||
* reveal the property that diverges between the two objects.
|
||||
* This method makes it easier to debug failing tests by checking each property individual instead
|
||||
* of calling equals as it will immediately reveal the property that diverges between the two
|
||||
* objects.
|
||||
*
|
||||
* @param have MailMessage retrieved from the parser
|
||||
* @param want MailMessage that would be expected
|
||||
*/
|
||||
@@ -66,8 +65,7 @@ public class RawMailParserTest extends GerritBaseTests {
|
||||
assertThat(have.to()).isEqualTo(want.to());
|
||||
assertThat(have.from()).isEqualTo(want.from());
|
||||
assertThat(have.cc()).isEqualTo(want.cc());
|
||||
assertThat(have.dateReceived().getMillis())
|
||||
.isEqualTo(want.dateReceived().getMillis());
|
||||
assertThat(have.dateReceived().getMillis()).isEqualTo(want.dateReceived().getMillis());
|
||||
assertThat(have.additionalHeaders()).isEqualTo(want.additionalHeaders());
|
||||
assertThat(have.subject()).isEqualTo(want.subject());
|
||||
assertThat(have.textContent()).isEqualTo(want.textContent());
|
||||
|
||||
@@ -17,23 +17,22 @@ package com.google.gerrit.server.mail.receive;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Comment;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TextParserTest extends AbstractParserTest {
|
||||
private static final String quotedFooter = "" +
|
||||
"> To view, visit https://gerrit-review.googlesource.com/123\n" +
|
||||
"> To unsubscribe, visit https://gerrit-review.googlesource.com\n" +
|
||||
"> \n" +
|
||||
"> Gerrit-MessageType: comment\n" +
|
||||
"> Gerrit-Change-Id: Ie1234021bf1e8d1425641af58fd648fc011db153\n" +
|
||||
"> Gerrit-PatchSet: 1\n" +
|
||||
"> Gerrit-Project: gerrit\n" +
|
||||
"> Gerrit-Branch: master\n" +
|
||||
"> Gerrit-Owner: Foo Bar <foo@bar.com>\n" +
|
||||
"> Gerrit-HasComments: Yes";
|
||||
private static final String quotedFooter =
|
||||
""
|
||||
+ "> To view, visit https://gerrit-review.googlesource.com/123\n"
|
||||
+ "> To unsubscribe, visit https://gerrit-review.googlesource.com\n"
|
||||
+ "> \n"
|
||||
+ "> Gerrit-MessageType: comment\n"
|
||||
+ "> Gerrit-Change-Id: Ie1234021bf1e8d1425641af58fd648fc011db153\n"
|
||||
+ "> Gerrit-PatchSet: 1\n"
|
||||
+ "> Gerrit-Project: gerrit\n"
|
||||
+ "> Gerrit-Branch: master\n"
|
||||
+ "> Gerrit-Owner: Foo Bar <foo@bar.com>\n"
|
||||
+ "> Gerrit-HasComments: Yes";
|
||||
|
||||
@Test
|
||||
public void simpleChangeMessage() {
|
||||
@@ -41,8 +40,7 @@ public class TextParserTest extends AbstractParserTest {
|
||||
b.textContent("Looks good to me\n" + quotedFooter);
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
TextParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(1);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
@@ -51,50 +49,56 @@ public class TextParserTest extends AbstractParserTest {
|
||||
@Test
|
||||
public void simpleInlineComments() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.textContent(newPlaintextBody("Looks good to me",
|
||||
"I have a comment on this.", null, "Also have a comment here.",
|
||||
null, null, null) + quotedFooter);
|
||||
b.textContent(
|
||||
newPlaintextBody(
|
||||
"Looks good to me",
|
||||
"I have a comment on this.",
|
||||
null,
|
||||
"Also have a comment here.",
|
||||
null,
|
||||
null,
|
||||
null)
|
||||
+ quotedFooter);
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
TextParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(3);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
assertInlineComment("I have a comment on this.", parsedComments.get(1),
|
||||
comments.get(1));
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2),
|
||||
comments.get(3));
|
||||
assertInlineComment("I have a comment on this.", parsedComments.get(1), comments.get(1));
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2), comments.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleFileComment() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.textContent(newPlaintextBody("Looks good to me",
|
||||
null, null, "Also have a comment here.",
|
||||
"This is a nice file", null, null) + quotedFooter);
|
||||
b.textContent(
|
||||
newPlaintextBody(
|
||||
"Looks good to me",
|
||||
null,
|
||||
null,
|
||||
"Also have a comment here.",
|
||||
"This is a nice file",
|
||||
null,
|
||||
null)
|
||||
+ quotedFooter);
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
TextParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(3);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
assertFileComment("This is a nice file", parsedComments.get(1),
|
||||
comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2),
|
||||
comments.get(3));
|
||||
assertFileComment("This is a nice file", parsedComments.get(1), comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2), comments.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noComments() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.textContent(newPlaintextBody(null, null, null, null, null, null, null) +
|
||||
quotedFooter);
|
||||
b.textContent(newPlaintextBody(null, null, null, null, null, null, null) + quotedFooter);
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
TextParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).isEmpty();
|
||||
}
|
||||
@@ -102,55 +106,63 @@ public class TextParserTest extends AbstractParserTest {
|
||||
@Test
|
||||
public void noChangeMessage() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.textContent(newPlaintextBody(null, null, null,
|
||||
"Also have a comment here.", "This is a nice file", null, null) +
|
||||
quotedFooter);
|
||||
b.textContent(
|
||||
newPlaintextBody(
|
||||
null, null, null, "Also have a comment here.", "This is a nice file", null, null)
|
||||
+ quotedFooter);
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
TextParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(2);
|
||||
assertFileComment("This is a nice file", parsedComments.get(0),
|
||||
comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(1),
|
||||
comments.get(3));
|
||||
assertFileComment("This is a nice file", parsedComments.get(0), comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(1), comments.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allCommentsGmail() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.textContent((newPlaintextBody("Looks good to me",
|
||||
null, null, "Also have a comment here.",
|
||||
"This is a nice file", null, null) + quotedFooter)
|
||||
.replace("> ", ">> "));
|
||||
b.textContent(
|
||||
(newPlaintextBody(
|
||||
"Looks good to me",
|
||||
null,
|
||||
null,
|
||||
"Also have a comment here.",
|
||||
"This is a nice file",
|
||||
null,
|
||||
null)
|
||||
+ quotedFooter)
|
||||
.replace("> ", ">> "));
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
TextParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(3);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
assertFileComment("This is a nice file", parsedComments.get(1),
|
||||
comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2),
|
||||
comments.get(3));
|
||||
assertFileComment("This is a nice file", parsedComments.get(1), comments.get(1).key.filename);
|
||||
assertInlineComment("Also have a comment here.", parsedComments.get(2), comments.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replyToFileComment() {
|
||||
MailMessage.Builder b = newMailMessageBuilder();
|
||||
b.textContent(newPlaintextBody("Looks good to me", null, null, null, null,
|
||||
null, "Comment in reply to file comment") + quotedFooter);
|
||||
b.textContent(
|
||||
newPlaintextBody(
|
||||
"Looks good to me",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"Comment in reply to file comment")
|
||||
+ quotedFooter);
|
||||
|
||||
List<Comment> comments = defaultComments();
|
||||
List<MailComment> parsedComments =
|
||||
TextParser.parse(b.build(), comments, changeURL);
|
||||
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, changeURL);
|
||||
|
||||
assertThat(parsedComments).hasSize(2);
|
||||
assertChangeMessage("Looks good to me", parsedComments.get(0));
|
||||
assertInlineComment("Comment in reply to file comment",
|
||||
parsedComments.get(1), comments.get(0));
|
||||
assertInlineComment("Comment in reply to file comment", parsedComments.get(1), comments.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,55 +177,69 @@ public class TextParserTest extends AbstractParserTest {
|
||||
* @param fc1 Comment in reply to a comment of file 1.
|
||||
* @return A string with all inline comments and the original quoted email.
|
||||
*/
|
||||
private static String newPlaintextBody(String changeMessage, String c1,
|
||||
String c2, String c3, String f1, String f2, String fc1) {
|
||||
return (changeMessage == null ? "" : changeMessage + "\n") +
|
||||
"> Foo Bar has posted comments on this change. ( \n" +
|
||||
"> " + changeURL +"/1 )\n" +
|
||||
"> \n" +
|
||||
"> Change subject: Test change\n" +
|
||||
"> ...............................................................\n" +
|
||||
"> \n" +
|
||||
"> \n" +
|
||||
"> Patch Set 1: Code-Review+1\n" +
|
||||
"> \n" +
|
||||
"> (3 comments)\n" +
|
||||
"> \n" +
|
||||
"> " + changeURL + "/1/gerrit-server/test.txt\n" +
|
||||
"> File \n" +
|
||||
"> gerrit-server/test.txt:\n" +
|
||||
(f1 == null ? "" : f1 + "\n") +
|
||||
"> \n" +
|
||||
"> Patch Set #4:\n" +
|
||||
"> " + changeURL + "/1/gerrit-server/test.txt\n" +
|
||||
"> \n" +
|
||||
"> Some comment" +
|
||||
"> \n" +
|
||||
(fc1 == null ? "" : fc1 + "\n") +
|
||||
"> " + changeURL + "/1/gerrit-server/test.txt@2\n" +
|
||||
"> PS1, Line 2: throw new Exception(\"Object has unsupported: \" +\n" +
|
||||
"> : entry.getValue() +\n" +
|
||||
"> : \" must be java.util.Date\");\n" +
|
||||
"> Should entry.getKey() be included in this message?\n" +
|
||||
"> \n" +
|
||||
(c1 == null ? "" : c1 + "\n") +
|
||||
"> \n" +
|
||||
"> " + changeURL + "/1/gerrit-server/test.txt@3\n" +
|
||||
"> PS1, Line 3: throw new Exception(\"Object has: \" +\n" +
|
||||
"> : entry.getValue().getClass() +\n" +
|
||||
"> : \" must be java.util.Date\");\n" +
|
||||
"> same here\n" +
|
||||
"> \n" +
|
||||
(c2 == null ? "" : c2 + "\n") +
|
||||
"> \n" +
|
||||
"> " + changeURL + "/1/gerrit-server/readme.txt\n" +
|
||||
"> File \n" +
|
||||
"> gerrit-server/readme.txt:\n" +
|
||||
(f2 == null ? "" : f2 + "\n") +
|
||||
"> \n" +
|
||||
"> " + changeURL + "/1/gerrit-server/readme.txt@3\n" +
|
||||
"> PS1, Line 3: E\n" +
|
||||
"> Should this be EEE like in other places?\n" +
|
||||
(c3 == null ? "" : c3 + "\n");
|
||||
private static String newPlaintextBody(
|
||||
String changeMessage, String c1, String c2, String c3, String f1, String f2, String fc1) {
|
||||
return (changeMessage == null ? "" : changeMessage + "\n")
|
||||
+ "> Foo Bar has posted comments on this change. ( \n"
|
||||
+ "> "
|
||||
+ changeURL
|
||||
+ "/1 )\n"
|
||||
+ "> \n"
|
||||
+ "> Change subject: Test change\n"
|
||||
+ "> ...............................................................\n"
|
||||
+ "> \n"
|
||||
+ "> \n"
|
||||
+ "> Patch Set 1: Code-Review+1\n"
|
||||
+ "> \n"
|
||||
+ "> (3 comments)\n"
|
||||
+ "> \n"
|
||||
+ "> "
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt\n"
|
||||
+ "> File \n"
|
||||
+ "> gerrit-server/test.txt:\n"
|
||||
+ (f1 == null ? "" : f1 + "\n")
|
||||
+ "> \n"
|
||||
+ "> Patch Set #4:\n"
|
||||
+ "> "
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt\n"
|
||||
+ "> \n"
|
||||
+ "> Some comment"
|
||||
+ "> \n"
|
||||
+ (fc1 == null ? "" : fc1 + "\n")
|
||||
+ "> "
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@2\n"
|
||||
+ "> PS1, Line 2: throw new Exception(\"Object has unsupported: \" +\n"
|
||||
+ "> : entry.getValue() +\n"
|
||||
+ "> : \" must be java.util.Date\");\n"
|
||||
+ "> Should entry.getKey() be included in this message?\n"
|
||||
+ "> \n"
|
||||
+ (c1 == null ? "" : c1 + "\n")
|
||||
+ "> \n"
|
||||
+ "> "
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/test.txt@3\n"
|
||||
+ "> PS1, Line 3: throw new Exception(\"Object has: \" +\n"
|
||||
+ "> : entry.getValue().getClass() +\n"
|
||||
+ "> : \" must be java.util.Date\");\n"
|
||||
+ "> same here\n"
|
||||
+ "> \n"
|
||||
+ (c2 == null ? "" : c2 + "\n")
|
||||
+ "> \n"
|
||||
+ "> "
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/readme.txt\n"
|
||||
+ "> File \n"
|
||||
+ "> gerrit-server/readme.txt:\n"
|
||||
+ (f2 == null ? "" : f2 + "\n")
|
||||
+ "> \n"
|
||||
+ "> "
|
||||
+ changeURL
|
||||
+ "/1/gerrit-server/readme.txt@3\n"
|
||||
+ "> PS1, Line 3: E\n"
|
||||
+ "> Should this be EEE like in other places?\n"
|
||||
+ (c3 == null ? "" : c3 + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,52 +14,48 @@
|
||||
|
||||
package com.google.gerrit.server.mail.receive.data;
|
||||
|
||||
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.mail.receive.MailMessage;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Tests that all mime parts that are neither text/plain, nor text/html are
|
||||
* dropped.
|
||||
*/
|
||||
/** Tests that all mime parts that are neither text/plain, nor text/html are dropped. */
|
||||
@Ignore
|
||||
public class AttachmentMessage extends RawMailMessage {
|
||||
private static String raw = "MIME-Version: 1.0\n" +
|
||||
"Date: Tue, 25 Oct 2016 02:11:35 -0700\n" +
|
||||
"Message-ID: <CAM7sg=3meaAVUxW3KXeJEVs8sv_ADw1BnvpcHHiYVR2TQQi__w" +
|
||||
"@mail.gmail.com>\n" +
|
||||
"Subject: Test Subject\n" +
|
||||
"From: Patrick Hiesel <hiesel@google.com>\n" +
|
||||
"To: Patrick Hiesel <hiesel@google.com>\n" +
|
||||
"Content-Type: multipart/mixed; boundary=001a114e019a56962d054062708f\n" +
|
||||
"\n" +
|
||||
"--001a114e019a56962d054062708f\n" +
|
||||
"Content-Type: multipart/alternative; boundary=001a114e019a5696250540" +
|
||||
"62708d\n" +
|
||||
"\n" +
|
||||
"--001a114e019a569625054062708d\n" +
|
||||
"Content-Type: text/plain; charset=UTF-8\n" +
|
||||
"\n" +
|
||||
"Contains unwanted attachment" +
|
||||
"\n" +
|
||||
"--001a114e019a569625054062708d\n" +
|
||||
"Content-Type: text/html; charset=UTF-8\n" +
|
||||
"\n" +
|
||||
"<div dir=\"ltr\">Contains unwanted attachment</div>" +
|
||||
"\n" +
|
||||
"--001a114e019a569625054062708d--\n" +
|
||||
"--001a114e019a56962d054062708f\n" +
|
||||
"Content-Type: text/plain; charset=US-ASCII; name=\"test.txt\"\n" +
|
||||
"Content-Disposition: attachment; filename=\"test.txt\"\n" +
|
||||
"Content-Transfer-Encoding: base64\n" +
|
||||
"X-Attachment-Id: f_iv264bt50\n" +
|
||||
"\n" +
|
||||
"VEVTVAo=\n" +
|
||||
"--001a114e019a56962d054062708f--";
|
||||
private static String raw =
|
||||
"MIME-Version: 1.0\n"
|
||||
+ "Date: Tue, 25 Oct 2016 02:11:35 -0700\n"
|
||||
+ "Message-ID: <CAM7sg=3meaAVUxW3KXeJEVs8sv_ADw1BnvpcHHiYVR2TQQi__w"
|
||||
+ "@mail.gmail.com>\n"
|
||||
+ "Subject: Test Subject\n"
|
||||
+ "From: Patrick Hiesel <hiesel@google.com>\n"
|
||||
+ "To: Patrick Hiesel <hiesel@google.com>\n"
|
||||
+ "Content-Type: multipart/mixed; boundary=001a114e019a56962d054062708f\n"
|
||||
+ "\n"
|
||||
+ "--001a114e019a56962d054062708f\n"
|
||||
+ "Content-Type: multipart/alternative; boundary=001a114e019a5696250540"
|
||||
+ "62708d\n"
|
||||
+ "\n"
|
||||
+ "--001a114e019a569625054062708d\n"
|
||||
+ "Content-Type: text/plain; charset=UTF-8\n"
|
||||
+ "\n"
|
||||
+ "Contains unwanted attachment"
|
||||
+ "\n"
|
||||
+ "--001a114e019a569625054062708d\n"
|
||||
+ "Content-Type: text/html; charset=UTF-8\n"
|
||||
+ "\n"
|
||||
+ "<div dir=\"ltr\">Contains unwanted attachment</div>"
|
||||
+ "\n"
|
||||
+ "--001a114e019a569625054062708d--\n"
|
||||
+ "--001a114e019a56962d054062708f\n"
|
||||
+ "Content-Type: text/plain; charset=US-ASCII; name=\"test.txt\"\n"
|
||||
+ "Content-Disposition: attachment; filename=\"test.txt\"\n"
|
||||
+ "Content-Transfer-Encoding: base64\n"
|
||||
+ "X-Attachment-Id: f_iv264bt50\n"
|
||||
+ "\n"
|
||||
+ "VEVTVAo=\n"
|
||||
+ "--001a114e019a56962d054062708f--";
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
@@ -76,16 +72,14 @@ public class AttachmentMessage extends RawMailMessage {
|
||||
System.out.println("\uD83D\uDE1B test");
|
||||
MailMessage.Builder expect = MailMessage.builder();
|
||||
expect
|
||||
.id("<CAM7sg=3meaAVUxW3KXeJEVs8sv_ADw1BnvpcHHiYVR2TQQi__w" +
|
||||
"@mail.gmail.com>")
|
||||
.id("<CAM7sg=3meaAVUxW3KXeJEVs8sv_ADw1BnvpcHHiYVR2TQQi__w" + "@mail.gmail.com>")
|
||||
.from(new Address("Patrick Hiesel", "hiesel@google.com"))
|
||||
.addTo(new Address("Patrick Hiesel", "hiesel@google.com"))
|
||||
.textContent("Contains unwanted attachment")
|
||||
.htmlContent("<div dir=\"ltr\">Contains unwanted attachment</div>")
|
||||
.subject("Test Subject")
|
||||
.addAdditionalHeader("MIME-Version: 1.0")
|
||||
.dateReceived(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
.dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
return expect.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,26 +16,25 @@ package com.google.gerrit.server.mail.receive.data;
|
||||
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.mail.receive.MailMessage;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Tests parsing a Base64 encoded subject.
|
||||
*/
|
||||
/** Tests parsing a Base64 encoded subject. */
|
||||
@Ignore
|
||||
public class Base64HeaderMessage extends RawMailMessage {
|
||||
private static String textContent = "Some Text";
|
||||
private static String raw = "" +
|
||||
"Date: Tue, 25 Oct 2016 02:11:35 -0700\n" +
|
||||
"Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n" +
|
||||
"Subject: =?UTF-8?B?8J+YmyB0ZXN0?=\n" +
|
||||
"From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-" +
|
||||
"CtTy0igsBrnvL7dKoWEIEg@google.com>\n" +
|
||||
"To: ekempin <ekempin@google.com>\n" +
|
||||
"Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n" +
|
||||
"\n" + textContent;
|
||||
private static String raw =
|
||||
""
|
||||
+ "Date: Tue, 25 Oct 2016 02:11:35 -0700\n"
|
||||
+ "Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n"
|
||||
+ "Subject: =?UTF-8?B?8J+YmyB0ZXN0?=\n"
|
||||
+ "From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-"
|
||||
+ "CtTy0igsBrnvL7dKoWEIEg@google.com>\n"
|
||||
+ "To: ekempin <ekempin@google.com>\n"
|
||||
+ "Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n"
|
||||
+ "\n"
|
||||
+ textContent;
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
@@ -52,13 +51,14 @@ public class Base64HeaderMessage extends RawMailMessage {
|
||||
MailMessage.Builder expect = MailMessage.builder();
|
||||
expect
|
||||
.id("<001a114da7ae26e2eb053fe0c29c@google.com>")
|
||||
.from(new Address("Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin","ekempin@google.com"))
|
||||
.from(
|
||||
new Address(
|
||||
"Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin", "ekempin@google.com"))
|
||||
.textContent(textContent)
|
||||
.subject("\uD83D\uDE1B test")
|
||||
.dateReceived(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
.dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
return expect.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,63 +16,63 @@ package com.google.gerrit.server.mail.receive.data;
|
||||
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.mail.receive.MailMessage;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Tests a message containing mime/alternative (text + html) content.
|
||||
*/
|
||||
/** Tests a message containing mime/alternative (text + html) content. */
|
||||
@Ignore
|
||||
public class HtmlMimeMessage extends RawMailMessage {
|
||||
private static String textContent = "Simple test";
|
||||
|
||||
// htmlContent is encoded in quoted-printable
|
||||
private static String htmlContent = "<div dir=3D\"ltr\">Test <span style" +
|
||||
"=3D\"background-color:rgb(255,255,0)\">Messa=\n" +
|
||||
"ge</span> in <u>HTML=C2=A0</u><a href=3D\"https://en.wikipedia.org/" +
|
||||
"wiki/%C3%=\n9Cmlaut_(band)\" class=3D\"gmail-mw-redirect\" title=3D\"" +
|
||||
"=C3=9Cmlaut (band)\" st=\nyle=3D\"text-decoration:none;color:rgb(11," +
|
||||
"0,128);background-image:none;backg=\nround-position:initial;background" +
|
||||
"-size:initial;background-repeat:initial;ba=\nckground-origin:initial;" +
|
||||
"background-clip:initial;font-family:sans-serif;font=\n" +
|
||||
"-size:14px\">=C3=9C</a></div>";
|
||||
private static String htmlContent =
|
||||
"<div dir=3D\"ltr\">Test <span style"
|
||||
+ "=3D\"background-color:rgb(255,255,0)\">Messa=\n"
|
||||
+ "ge</span> in <u>HTML=C2=A0</u><a href=3D\"https://en.wikipedia.org/"
|
||||
+ "wiki/%C3%=\n9Cmlaut_(band)\" class=3D\"gmail-mw-redirect\" title=3D\""
|
||||
+ "=C3=9Cmlaut (band)\" st=\nyle=3D\"text-decoration:none;color:rgb(11,"
|
||||
+ "0,128);background-image:none;backg=\nround-position:initial;background"
|
||||
+ "-size:initial;background-repeat:initial;ba=\nckground-origin:initial;"
|
||||
+ "background-clip:initial;font-family:sans-serif;font=\n"
|
||||
+ "-size:14px\">=C3=9C</a></div>";
|
||||
|
||||
private static String unencodedHtmlContent = "" +
|
||||
"<div dir=\"ltr\">Test <span style=\"background-color:rgb(255,255,0)\">" +
|
||||
"Message</span> in <u>HTML </u><a href=\"https://en.wikipedia.org/wiki/" +
|
||||
"%C3%9Cmlaut_(band)\" class=\"gmail-mw-redirect\" title=\"Ümlaut " +
|
||||
"(band)\" style=\"text-decoration:none;color:rgb(11,0,128);" +
|
||||
"background-image:none;background-position:initial;background-size:" +
|
||||
"initial;background-repeat:initial;background-origin:initial;background" +
|
||||
"-clip:initial;font-family:sans-serif;font-size:14px\">Ü</a></div>";
|
||||
private static String unencodedHtmlContent =
|
||||
""
|
||||
+ "<div dir=\"ltr\">Test <span style=\"background-color:rgb(255,255,0)\">"
|
||||
+ "Message</span> in <u>HTML </u><a href=\"https://en.wikipedia.org/wiki/"
|
||||
+ "%C3%9Cmlaut_(band)\" class=\"gmail-mw-redirect\" title=\"Ümlaut "
|
||||
+ "(band)\" style=\"text-decoration:none;color:rgb(11,0,128);"
|
||||
+ "background-image:none;background-position:initial;background-size:"
|
||||
+ "initial;background-repeat:initial;background-origin:initial;background"
|
||||
+ "-clip:initial;font-family:sans-serif;font-size:14px\">Ü</a></div>";
|
||||
|
||||
private static String raw = "" +
|
||||
"MIME-Version: 1.0\n" +
|
||||
"Date: Tue, 25 Oct 2016 02:11:35 -0700\n" +
|
||||
"Message-ID: <001a114cd8be55b4ab053face5cd@google.com>\n" +
|
||||
"Subject: Change in gerrit[master]: Implement receiver class structure " +
|
||||
"and bindings\n" +
|
||||
"From: \"ekempin (Gerrit)\" <noreply-gerritcodereview-qUgXfQecoDLHwp0Ml" +
|
||||
"dAzig@google.com>\n" +
|
||||
"To: Patrick Hiesel <hiesel@google.com>\n" +
|
||||
"Cc: ekempin <ekempin@google.com>\n" +
|
||||
"Content-Type: multipart/alternative; boundary=001a114cd8b" +
|
||||
"e55b486053face5ca\n" +
|
||||
"\n" +
|
||||
"--001a114cd8be55b486053face5ca\n" +
|
||||
"Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n" +
|
||||
"\n" +
|
||||
textContent +
|
||||
"\n" +
|
||||
"--001a114cd8be55b486053face5ca\n" +
|
||||
"Content-Type: text/html; charset=UTF-8\n" +
|
||||
"Content-Transfer-Encoding: quoted-printable\n" +
|
||||
"\n" +
|
||||
htmlContent +
|
||||
"\n" +
|
||||
"--001a114cd8be55b486053face5ca--";
|
||||
private static String raw =
|
||||
""
|
||||
+ "MIME-Version: 1.0\n"
|
||||
+ "Date: Tue, 25 Oct 2016 02:11:35 -0700\n"
|
||||
+ "Message-ID: <001a114cd8be55b4ab053face5cd@google.com>\n"
|
||||
+ "Subject: Change in gerrit[master]: Implement receiver class structure "
|
||||
+ "and bindings\n"
|
||||
+ "From: \"ekempin (Gerrit)\" <noreply-gerritcodereview-qUgXfQecoDLHwp0Ml"
|
||||
+ "dAzig@google.com>\n"
|
||||
+ "To: Patrick Hiesel <hiesel@google.com>\n"
|
||||
+ "Cc: ekempin <ekempin@google.com>\n"
|
||||
+ "Content-Type: multipart/alternative; boundary=001a114cd8b"
|
||||
+ "e55b486053face5ca\n"
|
||||
+ "\n"
|
||||
+ "--001a114cd8be55b486053face5ca\n"
|
||||
+ "Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n"
|
||||
+ "\n"
|
||||
+ textContent
|
||||
+ "\n"
|
||||
+ "--001a114cd8be55b486053face5ca\n"
|
||||
+ "Content-Type: text/html; charset=UTF-8\n"
|
||||
+ "Content-Transfer-Encoding: quoted-printable\n"
|
||||
+ "\n"
|
||||
+ htmlContent
|
||||
+ "\n"
|
||||
+ "--001a114cd8be55b486053face5ca--";
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
@@ -89,17 +89,16 @@ public class HtmlMimeMessage extends RawMailMessage {
|
||||
MailMessage.Builder expect = MailMessage.builder();
|
||||
expect
|
||||
.id("<001a114cd8be55b4ab053face5cd@google.com>")
|
||||
.from(new Address("ekempin (Gerrit)",
|
||||
"noreply-gerritcodereview-qUgXfQecoDLHwp0MldAzig@google.com"))
|
||||
.addCc(new Address("ekempin","ekempin@google.com"))
|
||||
.addTo(new Address("Patrick Hiesel","hiesel@google.com"))
|
||||
.from(
|
||||
new Address(
|
||||
"ekempin (Gerrit)", "noreply-gerritcodereview-qUgXfQecoDLHwp0MldAzig@google.com"))
|
||||
.addCc(new Address("ekempin", "ekempin@google.com"))
|
||||
.addTo(new Address("Patrick Hiesel", "hiesel@google.com"))
|
||||
.textContent(textContent)
|
||||
.htmlContent(unencodedHtmlContent)
|
||||
.subject("Change in gerrit[master]: Implement " +
|
||||
"receiver class structure and bindings")
|
||||
.subject("Change in gerrit[master]: Implement " + "receiver class structure and bindings")
|
||||
.addAdditionalHeader("MIME-Version: 1.0")
|
||||
.dateReceived(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
.dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
return expect.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,26 +15,25 @@ package com.google.gerrit.server.mail.receive.data;
|
||||
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.mail.receive.MailMessage;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Tests that non-UTF8 encodings are handled correctly.
|
||||
*/
|
||||
/** Tests that non-UTF8 encodings are handled correctly. */
|
||||
@Ignore
|
||||
public class NonUTF8Message extends RawMailMessage {
|
||||
private static String textContent = "Some Text";
|
||||
private static String raw = "" +
|
||||
"Date: Tue, 25 Oct 2016 02:11:35 -0700\n" +
|
||||
"Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n" +
|
||||
"Subject: =?UTF-8?B?8J+YmyB0ZXN0?=\n" +
|
||||
"From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-" +
|
||||
"CtTy0igsBrnvL7dKoWEIEg@google.com>\n" +
|
||||
"To: ekempin <ekempin@google.com>\n" +
|
||||
"Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n" +
|
||||
"\n" + textContent;
|
||||
private static String raw =
|
||||
""
|
||||
+ "Date: Tue, 25 Oct 2016 02:11:35 -0700\n"
|
||||
+ "Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n"
|
||||
+ "Subject: =?UTF-8?B?8J+YmyB0ZXN0?=\n"
|
||||
+ "From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-"
|
||||
+ "CtTy0igsBrnvL7dKoWEIEg@google.com>\n"
|
||||
+ "To: ekempin <ekempin@google.com>\n"
|
||||
+ "Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n"
|
||||
+ "\n"
|
||||
+ textContent;
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
@@ -56,13 +55,14 @@ public class NonUTF8Message extends RawMailMessage {
|
||||
MailMessage.Builder expect = MailMessage.builder();
|
||||
expect
|
||||
.id("<001a114da7ae26e2eb053fe0c29c@google.com>")
|
||||
.from(new Address("Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin","ekempin@google.com"))
|
||||
.from(
|
||||
new Address(
|
||||
"Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin", "ekempin@google.com"))
|
||||
.textContent(textContent)
|
||||
.subject("\uD83D\uDE1B test")
|
||||
.dateReceived(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
.dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
return expect.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,26 +16,25 @@ package com.google.gerrit.server.mail.receive.data;
|
||||
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.mail.receive.MailMessage;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Tests parsing a quoted printable encoded subject
|
||||
*/
|
||||
/** Tests parsing a quoted printable encoded subject */
|
||||
@Ignore
|
||||
public class QuotedPrintableHeaderMessage extends RawMailMessage {
|
||||
private static String textContent = "Some Text";
|
||||
private static String raw = "" +
|
||||
"Date: Tue, 25 Oct 2016 02:11:35 -0700\n" +
|
||||
"Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n" +
|
||||
"Subject: =?UTF-8?Q?=C3=A2me vulgaire?=\n" +
|
||||
"From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-" +
|
||||
"CtTy0igsBrnvL7dKoWEIEg@google.com>\n" +
|
||||
"To: ekempin <ekempin@google.com>\n" +
|
||||
"Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n" +
|
||||
"\n" + textContent;
|
||||
private static String raw =
|
||||
""
|
||||
+ "Date: Tue, 25 Oct 2016 02:11:35 -0700\n"
|
||||
+ "Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n"
|
||||
+ "Subject: =?UTF-8?Q?=C3=A2me vulgaire?=\n"
|
||||
+ "From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-"
|
||||
+ "CtTy0igsBrnvL7dKoWEIEg@google.com>\n"
|
||||
+ "To: ekempin <ekempin@google.com>\n"
|
||||
+ "Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n"
|
||||
+ "\n"
|
||||
+ textContent;
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
@@ -53,13 +52,14 @@ public class QuotedPrintableHeaderMessage extends RawMailMessage {
|
||||
MailMessage.Builder expect = MailMessage.builder();
|
||||
expect
|
||||
.id("<001a114da7ae26e2eb053fe0c29c@google.com>")
|
||||
.from(new Address("Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin","ekempin@google.com"))
|
||||
.from(
|
||||
new Address(
|
||||
"Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin", "ekempin@google.com"))
|
||||
.textContent(textContent)
|
||||
.subject("âme vulgaire")
|
||||
.dateReceived(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
.dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC));
|
||||
return expect.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,14 @@
|
||||
package com.google.gerrit.server.mail.receive.data;
|
||||
|
||||
import com.google.gerrit.server.mail.receive.MailMessage;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Base class for all email parsing tests.
|
||||
*/
|
||||
/** Base class for all email parsing tests. */
|
||||
@Ignore
|
||||
public abstract class RawMailMessage {
|
||||
// Raw content to feed the parser
|
||||
public abstract String raw();
|
||||
|
||||
public abstract int[] rawChars();
|
||||
// Parsed representation for asserting the expected parser output
|
||||
public abstract MailMessage expectedMailMessage();
|
||||
|
||||
@@ -16,88 +16,88 @@ package com.google.gerrit.server.mail.receive.data;
|
||||
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
import com.google.gerrit.server.mail.receive.MailMessage;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Tests parsing a simple text message with different headers.
|
||||
*/
|
||||
/** Tests parsing a simple text message with different headers. */
|
||||
@Ignore
|
||||
public class SimpleTextMessage extends RawMailMessage {
|
||||
private static String textContent = "" +
|
||||
"Jonathan Nieder has posted comments on this change. ( \n" +
|
||||
"https://gerrit-review.googlesource.com/90018 )\n" +
|
||||
"\n" +
|
||||
"Change subject: (Re)enable voting buttons for merged changes\n" +
|
||||
"...........................................................\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"Patch Set 2:\n" +
|
||||
"\n" +
|
||||
"This is producing NPEs server-side and 500s for the client. \n" +
|
||||
"when I try to load this change:\n" +
|
||||
"\n" +
|
||||
" Error in GET /changes/90018/detail?O=10004\n" +
|
||||
" com.google.gwtorm.OrmException: java.lang.NullPointerException\n" +
|
||||
"\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:303)\n" +
|
||||
"\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:285)\n" +
|
||||
"\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:263)\n" +
|
||||
"\tat com.google.gerrit.change.GetChange.apply(GetChange.java:50)\n" +
|
||||
"\tat com.google.gerrit.change.GetDetail.apply(GetDetail.java:51)\n" +
|
||||
"\tat com.google.gerrit.change.GetDetail.apply(GetDetail.java:26)\n" +
|
||||
"\tat \n" +
|
||||
"com.google.gerrit.RestApiServlet.service(RestApiServlet.java:367)\n" +
|
||||
"\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\n" +
|
||||
"[...]\n" +
|
||||
" Caused by: java.lang.NullPointerException\n" +
|
||||
"\tat \n" +
|
||||
"com.google.gerrit.ChangeJson.setLabelScores(ChangeJson.java:670)\n" +
|
||||
"\tat \n" +
|
||||
"com.google.gerrit.ChangeJson.labelsFor(ChangeJson.java:845)\n" +
|
||||
"\tat \n" +
|
||||
"com.google.gerrit.change.ChangeJson.labelsFor(ChangeJson.java:598)\n" +
|
||||
"\tat \n" +
|
||||
"com.google.gerrit.change.ChangeJson.toChange(ChangeJson.java:499)\n" +
|
||||
"\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:294)\n" +
|
||||
"\t... 105 more\n" +
|
||||
"-- \n" +
|
||||
"To view, visit https://gerrit-review.googlesource.com/90018\n" +
|
||||
"To unsubscribe, visit https://gerrit-review.googlesource.com\n" +
|
||||
"\n" +
|
||||
"Gerrit-MessageType: comment\n" +
|
||||
"Gerrit-Change-Id: Iba501e00bee77be3bd0ced72f88fd04ba0accaed\n" +
|
||||
"Gerrit-PatchSet: 2\n" +
|
||||
"Gerrit-Project: gerrit\n" +
|
||||
"Gerrit-Branch: master\n" +
|
||||
"Gerrit-Owner: ekempin <ekempin@google.com>\n" +
|
||||
"Gerrit-Reviewer: Dave Borowitz <dborowitz@google.com>\n" +
|
||||
"Gerrit-Reviewer: Edwin Kempin <ekempin@google.com>\n" +
|
||||
"Gerrit-Reviewer: GerritForge CI <gerritforge@gmail.com>\n" +
|
||||
"Gerrit-Reviewer: Jonathan Nieder <jrn@google.com>\n" +
|
||||
"Gerrit-Reviewer: Patrick Hiesel <hiesel@google.com>\n" +
|
||||
"Gerrit-Reviewer: ekempin <ekempin@google.com>\n" +
|
||||
"Gerrit-HasComments: No";
|
||||
private static String textContent =
|
||||
""
|
||||
+ "Jonathan Nieder has posted comments on this change. ( \n"
|
||||
+ "https://gerrit-review.googlesource.com/90018 )\n"
|
||||
+ "\n"
|
||||
+ "Change subject: (Re)enable voting buttons for merged changes\n"
|
||||
+ "...........................................................\n"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "Patch Set 2:\n"
|
||||
+ "\n"
|
||||
+ "This is producing NPEs server-side and 500s for the client. \n"
|
||||
+ "when I try to load this change:\n"
|
||||
+ "\n"
|
||||
+ " Error in GET /changes/90018/detail?O=10004\n"
|
||||
+ " com.google.gwtorm.OrmException: java.lang.NullPointerException\n"
|
||||
+ "\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:303)\n"
|
||||
+ "\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:285)\n"
|
||||
+ "\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:263)\n"
|
||||
+ "\tat com.google.gerrit.change.GetChange.apply(GetChange.java:50)\n"
|
||||
+ "\tat com.google.gerrit.change.GetDetail.apply(GetDetail.java:51)\n"
|
||||
+ "\tat com.google.gerrit.change.GetDetail.apply(GetDetail.java:26)\n"
|
||||
+ "\tat \n"
|
||||
+ "com.google.gerrit.RestApiServlet.service(RestApiServlet.java:367)\n"
|
||||
+ "\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\n"
|
||||
+ "[...]\n"
|
||||
+ " Caused by: java.lang.NullPointerException\n"
|
||||
+ "\tat \n"
|
||||
+ "com.google.gerrit.ChangeJson.setLabelScores(ChangeJson.java:670)\n"
|
||||
+ "\tat \n"
|
||||
+ "com.google.gerrit.ChangeJson.labelsFor(ChangeJson.java:845)\n"
|
||||
+ "\tat \n"
|
||||
+ "com.google.gerrit.change.ChangeJson.labelsFor(ChangeJson.java:598)\n"
|
||||
+ "\tat \n"
|
||||
+ "com.google.gerrit.change.ChangeJson.toChange(ChangeJson.java:499)\n"
|
||||
+ "\tat com.google.gerrit.change.ChangeJson.format(ChangeJson.java:294)\n"
|
||||
+ "\t... 105 more\n"
|
||||
+ "-- \n"
|
||||
+ "To view, visit https://gerrit-review.googlesource.com/90018\n"
|
||||
+ "To unsubscribe, visit https://gerrit-review.googlesource.com\n"
|
||||
+ "\n"
|
||||
+ "Gerrit-MessageType: comment\n"
|
||||
+ "Gerrit-Change-Id: Iba501e00bee77be3bd0ced72f88fd04ba0accaed\n"
|
||||
+ "Gerrit-PatchSet: 2\n"
|
||||
+ "Gerrit-Project: gerrit\n"
|
||||
+ "Gerrit-Branch: master\n"
|
||||
+ "Gerrit-Owner: ekempin <ekempin@google.com>\n"
|
||||
+ "Gerrit-Reviewer: Dave Borowitz <dborowitz@google.com>\n"
|
||||
+ "Gerrit-Reviewer: Edwin Kempin <ekempin@google.com>\n"
|
||||
+ "Gerrit-Reviewer: GerritForge CI <gerritforge@gmail.com>\n"
|
||||
+ "Gerrit-Reviewer: Jonathan Nieder <jrn@google.com>\n"
|
||||
+ "Gerrit-Reviewer: Patrick Hiesel <hiesel@google.com>\n"
|
||||
+ "Gerrit-Reviewer: ekempin <ekempin@google.com>\n"
|
||||
+ "Gerrit-HasComments: No";
|
||||
|
||||
private static String raw = "" +
|
||||
"Authentication-Results: mx.google.com; dkim=pass header.i=" +
|
||||
"@google.com;\n" +
|
||||
"Date: Tue, 25 Oct 2016 02:11:35 -0700\n" +
|
||||
"In-Reply-To: <gerrit.1477487889000.Iba501e00bee77be3bd0ced" +
|
||||
"72f88fd04ba0accaed@gerrit-review.googlesource.com>\n" +
|
||||
"References: <gerrit.1477487889000.Iba501e00bee77be3bd0ced72f8" +
|
||||
"8fd04ba0accaed@gerrit-review.googlesource.com>\n" +
|
||||
"Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n" +
|
||||
"Subject: Change in gerrit[master]: (Re)enable voting buttons for " +
|
||||
"merged changes\n" +
|
||||
"From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-CtTy0" +
|
||||
"igsBrnvL7dKoWEIEg@google.com>\n" +
|
||||
"To: ekempin <ekempin@google.com>\n" +
|
||||
"Cc: Dave Borowitz <dborowitz@google.com>, Jonathan Nieder " +
|
||||
"<jrn@google.com>, Patrick Hiesel <hiesel@google.com>\n" +
|
||||
"Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n" +
|
||||
"\n" + textContent;
|
||||
private static String raw =
|
||||
""
|
||||
+ "Authentication-Results: mx.google.com; dkim=pass header.i="
|
||||
+ "@google.com;\n"
|
||||
+ "Date: Tue, 25 Oct 2016 02:11:35 -0700\n"
|
||||
+ "In-Reply-To: <gerrit.1477487889000.Iba501e00bee77be3bd0ced"
|
||||
+ "72f88fd04ba0accaed@gerrit-review.googlesource.com>\n"
|
||||
+ "References: <gerrit.1477487889000.Iba501e00bee77be3bd0ced72f8"
|
||||
+ "8fd04ba0accaed@gerrit-review.googlesource.com>\n"
|
||||
+ "Message-ID: <001a114da7ae26e2eb053fe0c29c@google.com>\n"
|
||||
+ "Subject: Change in gerrit[master]: (Re)enable voting buttons for "
|
||||
+ "merged changes\n"
|
||||
+ "From: \"Jonathan Nieder (Gerrit)\" <noreply-gerritcodereview-CtTy0"
|
||||
+ "igsBrnvL7dKoWEIEg@google.com>\n"
|
||||
+ "To: ekempin <ekempin@google.com>\n"
|
||||
+ "Cc: Dave Borowitz <dborowitz@google.com>, Jonathan Nieder "
|
||||
+ "<jrn@google.com>, Patrick Hiesel <hiesel@google.com>\n"
|
||||
+ "Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes\n"
|
||||
+ "\n"
|
||||
+ textContent;
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
@@ -114,23 +114,25 @@ public class SimpleTextMessage extends RawMailMessage {
|
||||
MailMessage.Builder expect = MailMessage.builder();
|
||||
expect
|
||||
.id("<001a114da7ae26e2eb053fe0c29c@google.com>")
|
||||
.from(new Address("Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin","ekempin@google.com"))
|
||||
.from(
|
||||
new Address(
|
||||
"Jonathan Nieder (Gerrit)",
|
||||
"noreply-gerritcodereview-CtTy0igsBrnvL7dKoWEIEg@google.com"))
|
||||
.addTo(new Address("ekempin", "ekempin@google.com"))
|
||||
.addCc(new Address("Dave Borowitz", "dborowitz@google.com"))
|
||||
.addCc(new Address("Jonathan Nieder", "jrn@google.com"))
|
||||
.addCc(new Address("Patrick Hiesel", "hiesel@google.com"))
|
||||
.textContent(textContent)
|
||||
.subject("Change in gerrit[master]: (Re)enable voting"
|
||||
+ " buttons for merged changes")
|
||||
.dateReceived(
|
||||
new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC))
|
||||
.addAdditionalHeader("Authentication-Results: mx.google.com; " +
|
||||
"dkim=pass header.i=@google.com;")
|
||||
.addAdditionalHeader("In-Reply-To: <gerrit.1477487889000.Iba501e00bee" +
|
||||
"77be3bd0ced72f88fd04ba0accaed@gerrit-review.googlesource.com>")
|
||||
.addAdditionalHeader("References: <gerrit.1477487889000.Iba501e00bee" +
|
||||
"77be3bd0ced72f88fd04ba0accaed@gerrit-review.googlesource.com>");
|
||||
.subject("Change in gerrit[master]: (Re)enable voting" + " buttons for merged changes")
|
||||
.dateReceived(new DateTime(2016, 10, 25, 9, 11, 35, 0, DateTimeZone.UTC))
|
||||
.addAdditionalHeader(
|
||||
"Authentication-Results: mx.google.com; " + "dkim=pass header.i=@google.com;")
|
||||
.addAdditionalHeader(
|
||||
"In-Reply-To: <gerrit.1477487889000.Iba501e00bee"
|
||||
+ "77be3bd0ced72f88fd04ba0accaed@gerrit-review.googlesource.com>")
|
||||
.addAdditionalHeader(
|
||||
"References: <gerrit.1477487889000.Iba501e00bee"
|
||||
+ "77be3bd0ced72f88fd04ba0accaed@gerrit-review.googlesource.com>");
|
||||
return expect.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,12 @@ import static com.google.gerrit.server.mail.send.CommentFormatter.BlockType.PARA
|
||||
import static com.google.gerrit.server.mail.send.CommentFormatter.BlockType.PRE_FORMATTED;
|
||||
import static com.google.gerrit.server.mail.send.CommentFormatter.BlockType.QUOTE;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommentFormatterTest {
|
||||
private void assertBlock(List<CommentFormatter.Block> list, int index,
|
||||
CommentFormatter.BlockType type, String text) {
|
||||
private void assertBlock(
|
||||
List<CommentFormatter.Block> list, int index, CommentFormatter.BlockType type, String text) {
|
||||
CommentFormatter.Block block = list.get(index);
|
||||
assertThat(block.type).isEqualTo(type);
|
||||
assertThat(block.text).isEqualTo(text);
|
||||
@@ -34,8 +33,8 @@ public class CommentFormatterTest {
|
||||
assertThat(block.quotedBlocks).isNull();
|
||||
}
|
||||
|
||||
private void assertListBlock(List<CommentFormatter.Block> list, int index,
|
||||
int itemIndex, String text) {
|
||||
private void assertListBlock(
|
||||
List<CommentFormatter.Block> list, int index, int itemIndex, String text) {
|
||||
CommentFormatter.Block block = list.get(index);
|
||||
assertThat(block.type).isEqualTo(LIST);
|
||||
assertThat(block.items.get(itemIndex)).isEqualTo(text);
|
||||
@@ -43,8 +42,7 @@ public class CommentFormatterTest {
|
||||
assertThat(block.quotedBlocks).isNull();
|
||||
}
|
||||
|
||||
private void assertQuoteBlock(List<CommentFormatter.Block> list, int index,
|
||||
int size) {
|
||||
private void assertQuoteBlock(List<CommentFormatter.Block> list, int index, int size) {
|
||||
CommentFormatter.Block block = list.get(index);
|
||||
assertThat(block.type).isEqualTo(QUOTE);
|
||||
assertThat(block.items).isNull();
|
||||
@@ -128,8 +126,8 @@ public class CommentFormatterTest {
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
assertQuoteBlock(result, 0, 1);
|
||||
assertBlock(result.get(0).quotedBlocks, 0, PARAGRAPH,
|
||||
"Quote line 1\nQuote line 2\nQuote line 3\n");
|
||||
assertBlock(
|
||||
result.get(0).quotedBlocks, 0, PARAGRAPH, "Quote line 1\nQuote line 2\nQuote line 3\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,26 +202,26 @@ public class CommentFormatterTest {
|
||||
|
||||
@Test
|
||||
public void parseMixedBlockTypes() {
|
||||
String comment = "Paragraph\nacross\na\nfew\nlines."
|
||||
+ "\n\n"
|
||||
+ "> Quote\n> across\n> not many lines."
|
||||
+ "\n\n"
|
||||
+ "Another paragraph"
|
||||
+ "\n\n"
|
||||
+ "* Series\n* of\n* list\n* items"
|
||||
+ "\n\n"
|
||||
+ "Yet another paragraph"
|
||||
+ "\n\n"
|
||||
+ "\tPreformatted text."
|
||||
+ "\n\n"
|
||||
+ "Parting words.";
|
||||
String comment =
|
||||
"Paragraph\nacross\na\nfew\nlines."
|
||||
+ "\n\n"
|
||||
+ "> Quote\n> across\n> not many lines."
|
||||
+ "\n\n"
|
||||
+ "Another paragraph"
|
||||
+ "\n\n"
|
||||
+ "* Series\n* of\n* list\n* items"
|
||||
+ "\n\n"
|
||||
+ "Yet another paragraph"
|
||||
+ "\n\n"
|
||||
+ "\tPreformatted text."
|
||||
+ "\n\n"
|
||||
+ "Parting words.";
|
||||
List<CommentFormatter.Block> result = CommentFormatter.parse(comment);
|
||||
|
||||
assertThat(result).hasSize(7);
|
||||
assertBlock(result, 0, PARAGRAPH, "Paragraph\nacross\na\nfew\nlines.");
|
||||
assertQuoteBlock(result, 1, 1);
|
||||
assertBlock(result.get(1).quotedBlocks, 0, PARAGRAPH,
|
||||
"Quote\nacross\nnot many lines.");
|
||||
assertBlock(result.get(1).quotedBlocks, 0, PARAGRAPH, "Quote\nacross\nnot many lines.");
|
||||
assertBlock(result, 2, PARAGRAPH, "Another paragraph");
|
||||
assertListBlock(result, 3, 0, "Series");
|
||||
assertListBlock(result, 3, 1, "of");
|
||||
@@ -270,9 +268,10 @@ public class CommentFormatterTest {
|
||||
|
||||
@Test
|
||||
public void bulletList4() {
|
||||
String comment = "To see this bug, you have to:\n" //
|
||||
+ "* Be on IMAP or EAS (not on POP)\n"//
|
||||
+ "* Be very unlucky\n";
|
||||
String comment =
|
||||
"To see this bug, you have to:\n" //
|
||||
+ "* Be on IMAP or EAS (not on POP)\n" //
|
||||
+ "* Be very unlucky\n";
|
||||
List<CommentFormatter.Block> result = CommentFormatter.parse(comment);
|
||||
|
||||
assertThat(result).hasSize(2);
|
||||
@@ -283,10 +282,11 @@ public class CommentFormatterTest {
|
||||
|
||||
@Test
|
||||
public void bulletList5() {
|
||||
String comment = "To see this bug,\n" //
|
||||
+ "you have to:\n" //
|
||||
+ "* Be on IMAP or EAS (not on POP)\n"//
|
||||
+ "* Be very unlucky\n";
|
||||
String comment =
|
||||
"To see this bug,\n" //
|
||||
+ "you have to:\n" //
|
||||
+ "* Be on IMAP or EAS (not on POP)\n" //
|
||||
+ "* Be very unlucky\n";
|
||||
List<CommentFormatter.Block> result = CommentFormatter.parse(comment);
|
||||
|
||||
assertThat(result).hasSize(2);
|
||||
@@ -378,8 +378,7 @@ public class CommentFormatterTest {
|
||||
|
||||
assertThat(result).hasSize(2);
|
||||
assertQuoteBlock(result, 0, 1);
|
||||
assertBlock(result.get(0).quotedBlocks, 0, PARAGRAPH,
|
||||
"I'm happy\nwith quotes!");
|
||||
assertBlock(result.get(0).quotedBlocks, 0, PARAGRAPH, "I'm happy\nwith quotes!");
|
||||
assertBlock(result, 1, PARAGRAPH, "See above.");
|
||||
}
|
||||
|
||||
@@ -391,8 +390,7 @@ public class CommentFormatterTest {
|
||||
assertThat(result).hasSize(3);
|
||||
assertBlock(result, 0, PARAGRAPH, "See this said:");
|
||||
assertQuoteBlock(result, 1, 1);
|
||||
assertBlock(result.get(1).quotedBlocks, 0, PARAGRAPH,
|
||||
"a quoted\nstring block");
|
||||
assertBlock(result.get(1).quotedBlocks, 0, PARAGRAPH, "a quoted\nstring block");
|
||||
assertBlock(result, 2, PARAGRAPH, "OK?");
|
||||
}
|
||||
|
||||
@@ -404,41 +402,39 @@ public class CommentFormatterTest {
|
||||
assertThat(result).hasSize(1);
|
||||
assertQuoteBlock(result, 0, 2);
|
||||
assertQuoteBlock(result.get(0).quotedBlocks, 0, 1);
|
||||
assertBlock(result.get(0).quotedBlocks.get(0).quotedBlocks, 0, PARAGRAPH,
|
||||
"prior");
|
||||
assertBlock(result.get(0).quotedBlocks.get(0).quotedBlocks, 0, PARAGRAPH, "prior");
|
||||
assertBlock(result.get(0).quotedBlocks, 1, PARAGRAPH, "next\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void largeMixedQuote() {
|
||||
String comment =
|
||||
"> > Paragraph 1.\n" +
|
||||
"> > \n" +
|
||||
"> > > Paragraph 2.\n" +
|
||||
"> > \n" +
|
||||
"> > Paragraph 3.\n" +
|
||||
"> > \n" +
|
||||
"> > pre line 1;\n" +
|
||||
"> > pre line 2;\n" +
|
||||
"> > \n" +
|
||||
"> > Paragraph 4.\n" +
|
||||
"> > \n" +
|
||||
"> > * List item 1.\n" +
|
||||
"> > * List item 2.\n" +
|
||||
"> > \n" +
|
||||
"> > Paragraph 5.\n" +
|
||||
"> \n" +
|
||||
"> Paragraph 6.\n" +
|
||||
"\n" +
|
||||
"Paragraph 7.\n";
|
||||
"> > Paragraph 1.\n"
|
||||
+ "> > \n"
|
||||
+ "> > > Paragraph 2.\n"
|
||||
+ "> > \n"
|
||||
+ "> > Paragraph 3.\n"
|
||||
+ "> > \n"
|
||||
+ "> > pre line 1;\n"
|
||||
+ "> > pre line 2;\n"
|
||||
+ "> > \n"
|
||||
+ "> > Paragraph 4.\n"
|
||||
+ "> > \n"
|
||||
+ "> > * List item 1.\n"
|
||||
+ "> > * List item 2.\n"
|
||||
+ "> > \n"
|
||||
+ "> > Paragraph 5.\n"
|
||||
+ "> \n"
|
||||
+ "> Paragraph 6.\n"
|
||||
+ "\n"
|
||||
+ "Paragraph 7.\n";
|
||||
List<CommentFormatter.Block> result = CommentFormatter.parse(comment);
|
||||
|
||||
assertThat(result).hasSize(2);
|
||||
assertQuoteBlock(result, 0, 2);
|
||||
|
||||
assertQuoteBlock(result.get(0).quotedBlocks, 0, 7);
|
||||
List<CommentFormatter.Block> bigQuote =
|
||||
result.get(0).quotedBlocks.get(0).quotedBlocks;
|
||||
List<CommentFormatter.Block> bigQuote = result.get(0).quotedBlocks.get(0).quotedBlocks;
|
||||
assertBlock(bigQuote, 0, PARAGRAPH, "Paragraph 1.");
|
||||
assertQuoteBlock(bigQuote, 1, 1);
|
||||
assertBlock(bigQuote.get(1).quotedBlocks, 0, PARAGRAPH, "Paragraph 2.");
|
||||
|
||||
@@ -30,17 +30,15 @@ import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.WatchConfig.NotifyType;
|
||||
import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey;
|
||||
import com.google.gerrit.server.mail.Address;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FromAddressGeneratorProviderTest {
|
||||
private Config config;
|
||||
@@ -55,8 +53,7 @@ public class FromAddressGeneratorProviderTest {
|
||||
}
|
||||
|
||||
private FromAddressGenerator create() {
|
||||
return new FromAddressGeneratorProvider(config, "Anonymous Coward", ident,
|
||||
accountCache).get();
|
||||
return new FromAddressGeneratorProvider(config, "Anonymous Coward", ident, accountCache).get();
|
||||
}
|
||||
|
||||
private void setFrom(final String newFrom) {
|
||||
@@ -390,8 +387,10 @@ public class FromAddressGeneratorProviderTest {
|
||||
final Account account = new Account(userId, TimeUtil.nowTs());
|
||||
account.setFullName(name);
|
||||
account.setPreferredEmail(email);
|
||||
return new AccountState(account, Collections.<AccountGroup.UUID> emptySet(),
|
||||
Collections.<AccountExternalId> emptySet(),
|
||||
return new AccountState(
|
||||
account,
|
||||
Collections.<AccountGroup.UUID>emptySet(),
|
||||
Collections.<AccountExternalId>emptySet(),
|
||||
new HashMap<ProjectWatchKey, Set<NotifyType>>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,8 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.TimeZone;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
@@ -75,9 +76,6 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@Ignore
|
||||
@RunWith(ConfigSuite.class)
|
||||
public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
@@ -95,14 +93,11 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@ConfigSuite.Parameter
|
||||
public Config testConfig;
|
||||
@ConfigSuite.Parameter public Config testConfig;
|
||||
|
||||
private static final TimeZone TZ =
|
||||
TimeZone.getTimeZone("America/Los_Angeles");
|
||||
private static final TimeZone TZ = TimeZone.getTimeZone("America/Los_Angeles");
|
||||
|
||||
private static final NotesMigration MIGRATION =
|
||||
new TestNotesMigration().setAllEnabled(true);
|
||||
private static final NotesMigration MIGRATION = new TestNotesMigration().setAllEnabled(true);
|
||||
|
||||
protected Account.Id otherUserId;
|
||||
protected FakeAccountCache accountCache;
|
||||
@@ -116,21 +111,15 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
protected RevWalk rw;
|
||||
protected TestRepository<InMemoryRepository> tr;
|
||||
|
||||
@Inject
|
||||
protected IdentifiedUser.GenericFactory userFactory;
|
||||
@Inject protected IdentifiedUser.GenericFactory userFactory;
|
||||
|
||||
@Inject
|
||||
protected NoteDbUpdateManager.Factory updateManagerFactory;
|
||||
@Inject protected NoteDbUpdateManager.Factory updateManagerFactory;
|
||||
|
||||
@Inject
|
||||
protected AllUsersName allUsers;
|
||||
@Inject protected AllUsersName allUsers;
|
||||
|
||||
@Inject
|
||||
protected AbstractChangeNotes.Args args;
|
||||
@Inject protected AbstractChangeNotes.Args args;
|
||||
|
||||
@Inject
|
||||
@GerritServerId
|
||||
private String serverId;
|
||||
@Inject @GerritServerId private String serverId;
|
||||
|
||||
protected Injector injector;
|
||||
private String systemTimeZone;
|
||||
@@ -139,8 +128,7 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
public void setUp() throws Exception {
|
||||
setTimeForTesting();
|
||||
|
||||
serverIdent = new PersonIdent(
|
||||
"Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(), TZ);
|
||||
serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(), TZ);
|
||||
project = new Project.NameKey("test-project");
|
||||
repoManager = new InMemoryRepositoryManager();
|
||||
repo = repoManager.createRepository(project);
|
||||
@@ -156,38 +144,41 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
ou.setPreferredEmail("other@account.com");
|
||||
accountCache.put(ou);
|
||||
|
||||
injector = Guice.createInjector(new FactoryModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
install(new GitModule());
|
||||
install(NoteDbModule.forTest(testConfig));
|
||||
bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
|
||||
bind(String.class).annotatedWith(GerritServerId.class)
|
||||
.toInstance("gerrit");
|
||||
bind(NotesMigration.class).toInstance(MIGRATION);
|
||||
bind(GitRepositoryManager.class).toInstance(repoManager);
|
||||
bind(ProjectCache.class).toProvider(Providers.<ProjectCache> of(null));
|
||||
bind(CapabilityControl.Factory.class)
|
||||
.toProvider(Providers.<CapabilityControl.Factory> of(null));
|
||||
bind(Config.class).annotatedWith(GerritServerConfig.class)
|
||||
.toInstance(testConfig);
|
||||
bind(String.class).annotatedWith(AnonymousCowardName.class)
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
bind(String.class).annotatedWith(CanonicalWebUrl.class)
|
||||
.toInstance("http://localhost:8080/");
|
||||
bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class)
|
||||
.toInstance(Boolean.FALSE);
|
||||
bind(Realm.class).to(FakeRealm.class);
|
||||
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
|
||||
bind(AccountCache.class).toInstance(accountCache);
|
||||
bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class)
|
||||
.toInstance(serverIdent);
|
||||
bind(GitReferenceUpdated.class)
|
||||
.toInstance(GitReferenceUpdated.DISABLED);
|
||||
bind(MetricMaker.class).to(DisabledMetricMaker.class);
|
||||
bind(ReviewDb.class).toProvider(Providers.<ReviewDb> of(null));
|
||||
}
|
||||
});
|
||||
injector =
|
||||
Guice.createInjector(
|
||||
new FactoryModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
install(new GitModule());
|
||||
install(NoteDbModule.forTest(testConfig));
|
||||
bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
|
||||
bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
|
||||
bind(NotesMigration.class).toInstance(MIGRATION);
|
||||
bind(GitRepositoryManager.class).toInstance(repoManager);
|
||||
bind(ProjectCache.class).toProvider(Providers.<ProjectCache>of(null));
|
||||
bind(CapabilityControl.Factory.class)
|
||||
.toProvider(Providers.<CapabilityControl.Factory>of(null));
|
||||
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
|
||||
bind(String.class)
|
||||
.annotatedWith(AnonymousCowardName.class)
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
bind(String.class)
|
||||
.annotatedWith(CanonicalWebUrl.class)
|
||||
.toInstance("http://localhost:8080/");
|
||||
bind(Boolean.class)
|
||||
.annotatedWith(DisableReverseDnsLookup.class)
|
||||
.toInstance(Boolean.FALSE);
|
||||
bind(Realm.class).to(FakeRealm.class);
|
||||
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
|
||||
bind(AccountCache.class).toInstance(accountCache);
|
||||
bind(PersonIdent.class)
|
||||
.annotatedWith(GerritPersonIdent.class)
|
||||
.toInstance(serverIdent);
|
||||
bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
|
||||
bind(MetricMaker.class).to(DisabledMetricMaker.class);
|
||||
bind(ReviewDb.class).toProvider(Providers.<ReviewDb>of(null));
|
||||
}
|
||||
});
|
||||
|
||||
injector.injectMembers(this);
|
||||
repoManager.createRepository(allUsers);
|
||||
@@ -217,8 +208,7 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
return c;
|
||||
}
|
||||
|
||||
protected ChangeUpdate newUpdate(Change c, CurrentUser user)
|
||||
throws Exception {
|
||||
protected ChangeUpdate newUpdate(Change c, CurrentUser user) throws Exception {
|
||||
ChangeUpdate update = TestChanges.newUpdate(injector, c, user);
|
||||
update.setPatchSetId(c.currentPatchSetId());
|
||||
update.setAllowWriteToNewRef(true);
|
||||
@@ -229,8 +219,8 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
return new ChangeNotes(args, c).load();
|
||||
}
|
||||
|
||||
protected static SubmitRecord submitRecord(String status,
|
||||
String errorMessage, SubmitRecord.Label... labels) {
|
||||
protected static SubmitRecord submitRecord(
|
||||
String status, String errorMessage, SubmitRecord.Label... labels) {
|
||||
SubmitRecord rec = new SubmitRecord();
|
||||
rec.status = SubmitRecord.Status.valueOf(status);
|
||||
rec.errorMessage = errorMessage;
|
||||
@@ -240,8 +230,8 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
return rec;
|
||||
}
|
||||
|
||||
protected static SubmitRecord.Label submitLabel(String name, String status,
|
||||
Account.Id appliedBy) {
|
||||
protected static SubmitRecord.Label submitLabel(
|
||||
String name, String status, Account.Id appliedBy) {
|
||||
SubmitRecord.Label label = new SubmitRecord.Label();
|
||||
label.label = name;
|
||||
label.status = SubmitRecord.Label.Status.valueOf(status);
|
||||
@@ -249,24 +239,33 @@ public abstract class AbstractChangeNotesTest extends GerritBaseTests {
|
||||
return label;
|
||||
}
|
||||
|
||||
protected Comment newComment(PatchSet.Id psId, String filename, String UUID,
|
||||
CommentRange range, int line, IdentifiedUser commenter, String parentUUID,
|
||||
Timestamp t, String message, short side, String commitSHA1,
|
||||
protected Comment newComment(
|
||||
PatchSet.Id psId,
|
||||
String filename,
|
||||
String UUID,
|
||||
CommentRange range,
|
||||
int line,
|
||||
IdentifiedUser commenter,
|
||||
String parentUUID,
|
||||
Timestamp t,
|
||||
String message,
|
||||
short side,
|
||||
String commitSHA1,
|
||||
boolean unresolved) {
|
||||
Comment c = new Comment(
|
||||
new Comment.Key(UUID, filename, psId.get()),
|
||||
commenter.getAccountId(),
|
||||
t,
|
||||
side,
|
||||
message,
|
||||
serverId,
|
||||
unresolved);
|
||||
Comment c =
|
||||
new Comment(
|
||||
new Comment.Key(UUID, filename, psId.get()),
|
||||
commenter.getAccountId(),
|
||||
t,
|
||||
side,
|
||||
message,
|
||||
serverId,
|
||||
unresolved);
|
||||
c.lineNbr = line;
|
||||
c.parentUuid = parentUUID;
|
||||
c.revId = commitSHA1;
|
||||
c.setRange(range);
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
protected static Timestamp truncate(Timestamp ts) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,6 @@ import static org.junit.Assert.fail;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
@@ -49,434 +48,426 @@ public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||
|
||||
@Test
|
||||
public void parseAuthor() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails(writeCommit("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
new PersonIdent("Change Owner", "owner@example.com",
|
||||
serverIdent.getWhen(), serverIdent.getTimeZone())));
|
||||
assertParseFails(writeCommit("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
new PersonIdent("Change Owner", "x@gerrit",
|
||||
serverIdent.getWhen(), serverIdent.getTimeZone())));
|
||||
assertParseFails(writeCommit("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
new PersonIdent("Change\n\u1234<Owner>", "\n\nx<@>\u0002gerrit",
|
||||
serverIdent.getWhen(), serverIdent.getTimeZone())));
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails(
|
||||
writeCommit(
|
||||
"Update change\n" + "\n" + "Patch-set: 1\n",
|
||||
new PersonIdent(
|
||||
"Change Owner",
|
||||
"owner@example.com",
|
||||
serverIdent.getWhen(),
|
||||
serverIdent.getTimeZone())));
|
||||
assertParseFails(
|
||||
writeCommit(
|
||||
"Update change\n" + "\n" + "Patch-set: 1\n",
|
||||
new PersonIdent(
|
||||
"Change Owner", "x@gerrit", serverIdent.getWhen(), serverIdent.getTimeZone())));
|
||||
assertParseFails(
|
||||
writeCommit(
|
||||
"Update change\n" + "\n" + "Patch-set: 1\n",
|
||||
new PersonIdent(
|
||||
"Change\n\u1234<Owner>",
|
||||
"\n\nx<@>\u0002gerrit",
|
||||
serverIdent.getWhen(),
|
||||
serverIdent.getTimeZone())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseStatus() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: NEW\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: new\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: OOPS\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: NEW\n"
|
||||
+ "Status: NEW\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: NEW\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: new\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Status: OOPS\n");
|
||||
assertParseFails(
|
||||
"Update change\n" + "\n" + "Patch-set: 1\n" + "Status: NEW\n" + "Status: NEW\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsePatchSetId() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Patch-set: 1\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: x\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n" + "\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Patch-set: 1\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: x\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseApproval() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: Label1=+1\n"
|
||||
+ "Label: Label2=1\n"
|
||||
+ "Label: Label3=0\n"
|
||||
+ "Label: Label4=-1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: -Label1\n"
|
||||
+ "Label: -Label1 Other Account <2@gerrit>\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: Label1=X\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: Label1 = 1\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: X+Y\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: Label1 Other Account <2@gerrit>\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: -Label!1\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: -Label!1 Other Account <2@gerrit>\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: Label1=+1\n"
|
||||
+ "Label: Label2=1\n"
|
||||
+ "Label: Label3=0\n"
|
||||
+ "Label: Label4=-1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: -Label1\n"
|
||||
+ "Label: -Label1 Other Account <2@gerrit>\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Label: Label1=X\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Label: Label1 = 1\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Label: X+Y\n");
|
||||
assertParseFails(
|
||||
"Update change\n" + "\n" + "Patch-set: 1\n" + "Label: Label1 Other Account <2@gerrit>\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Label: -Label!1\n");
|
||||
assertParseFails(
|
||||
"Update change\n" + "\n" + "Patch-set: 1\n" + "Label: -Label!1 Other Account <2@gerrit>\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSubmitRecords() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Code-Review\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Alternative-Code-Review\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submitted-with: OOPS\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submitted-with: NEED: X+Y\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submitted-with: OK: X+Y: Change Owner <1@gerrit>\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submitted-with: OK: Code-Review: 1@gerrit\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Code-Review\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Alternative-Code-Review\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Submitted-with: OOPS\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Submitted-with: NEED: X+Y\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submitted-with: OK: X+Y: Change Owner <1@gerrit>\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submitted-with: OK: Code-Review: 1@gerrit\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSubmissionId() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n"
|
||||
+ "Submission-id: 1-1453387607626-96fabc25");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submission-id: 1-1453387607626-96fabc25\n"
|
||||
+ "Submission-id: 1-1453387901516-5d1e2450");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n"
|
||||
+ "Submission-id: 1-1453387607626-96fabc25");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Submission-id: 1-1453387607626-96fabc25\n"
|
||||
+ "Submission-id: 1-1453387901516-5d1e2450");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseReviewer() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Reviewer: Change Owner <1@gerrit>\n"
|
||||
+ "CC: Other Account <2@gerrit>\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Reviewer: 1@gerrit\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Reviewer: Change Owner <1@gerrit>\n"
|
||||
+ "CC: Other Account <2@gerrit>\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Reviewer: 1@gerrit\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTopic() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Topic: Some Topic\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Topic:\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Topic: Some Topic\n"
|
||||
+ "Topic: Other Topic");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Topic: Some Topic\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Topic:\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails(
|
||||
"Update change\n" + "\n" + "Patch-set: 1\n" + "Topic: Some Topic\n" + "Topic: Other Topic");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseBranch() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Branch: refs/heads/stable");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Branch: refs/heads/stable");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseChangeId() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Change-id: I159532ef4844d7c18f7f3fd37a0b275590d41b1b");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: This is a test change\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Change-id: I159532ef4844d7c18f7f3fd37a0b275590d41b1b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSubject() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Subject: Some other subject\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Subject: Some other subject\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseCommit() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Commit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
|
||||
assertParseFails("Update patch set 1\n"
|
||||
+ "Uploaded patch set 1.\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Commit: beef");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Commit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
|
||||
assertParseFails(
|
||||
"Update patch set 1\n"
|
||||
+ "Uploaded patch set 1.\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Subject: Some subject of a change\n"
|
||||
+ "Commit: beef");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsePatchSetState() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (PUBLISHED)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (DRAFT)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (DELETED)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (NOT A STATUS)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (PUBLISHED)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (DRAFT)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (DELETED)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1 (NOT A STATUS)\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Subject: Some subject of a change\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsePatchSetGroups() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Groups: a,b,c\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Groups: a,b,c\n"
|
||||
+ "Groups: d,e,f\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Groups: a,b,c\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 2\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Groups: a,b,c\n"
|
||||
+ "Groups: d,e,f\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseServerIdent() throws Exception {
|
||||
String msg = "Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n";
|
||||
String msg =
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n";
|
||||
assertParseSucceeds(msg);
|
||||
assertParseSucceeds(writeCommit(msg, serverIdent));
|
||||
|
||||
msg = "Update change\n"
|
||||
+ "\n"
|
||||
+ "With a message."
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n";
|
||||
msg =
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "With a message."
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n";
|
||||
assertParseSucceeds(msg);
|
||||
assertParseSucceeds(writeCommit(msg, serverIdent));
|
||||
|
||||
msg = "Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Label: Label1=+1\n";
|
||||
msg =
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Label: Label1=+1\n";
|
||||
assertParseSucceeds(msg);
|
||||
assertParseFails(writeCommit(msg, serverIdent));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTag() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Tag:\n");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Tag: jenkins\n");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Tag: ci\n"
|
||||
+ "Tag: jenkins\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Tag:\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Tag: jenkins\n");
|
||||
assertParseFails(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Change-id: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Tag: ci\n"
|
||||
+ "Tag: jenkins\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caseInsensitiveFooters() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "BRaNch: refs/heads/master\n"
|
||||
+ "Change-ID: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "patcH-set: 1\n"
|
||||
+ "subject: This is a test change\n");
|
||||
assertParseSucceeds(
|
||||
"Update change\n"
|
||||
+ "\n"
|
||||
+ "BRaNch: refs/heads/master\n"
|
||||
+ "Change-ID: I577fb248e474018276351785930358ec0450e9f7\n"
|
||||
+ "patcH-set: 1\n"
|
||||
+ "subject: This is a test change\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentPatchSet() throws Exception {
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Current: true");
|
||||
assertParseSucceeds("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Current: tRUe");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Current: false");
|
||||
assertParseFails("Update change\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Current: blah");
|
||||
assertParseSucceeds("Update change\n" + "\n" + "Patch-set: 1\n" + "Current: true");
|
||||
assertParseSucceeds("Update change\n" + "\n" + "Patch-set: 1\n" + "Current: tRUe");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Current: false");
|
||||
assertParseFails("Update change\n" + "\n" + "Patch-set: 1\n" + "Current: blah");
|
||||
}
|
||||
|
||||
private RevCommit writeCommit(String body) throws Exception {
|
||||
ChangeNoteUtil noteUtil = injector.getInstance(ChangeNoteUtil.class);
|
||||
return writeCommit(body, noteUtil.newIdent(
|
||||
changeOwner.getAccount(), TimeUtil.nowTs(), serverIdent,
|
||||
"Anonymous Coward"));
|
||||
return writeCommit(
|
||||
body,
|
||||
noteUtil.newIdent(
|
||||
changeOwner.getAccount(), TimeUtil.nowTs(), serverIdent, "Anonymous Coward"));
|
||||
}
|
||||
|
||||
private RevCommit writeCommit(String body, PersonIdent author)
|
||||
throws Exception {
|
||||
private RevCommit writeCommit(String body, PersonIdent author) throws Exception {
|
||||
Change change = newChange();
|
||||
ChangeNotes notes = newNotes(change).load();
|
||||
try (ObjectInserter ins = testRepo.getRepository().newObjectInserter()) {
|
||||
@@ -518,7 +509,6 @@ public class ChangeNotesParserTest extends AbstractChangeNotesTest {
|
||||
private ChangeNotesParser newParser(ObjectId tip) throws Exception {
|
||||
walk.reset();
|
||||
ChangeNoteUtil noteUtil = injector.getInstance(ChangeNoteUtil.class);
|
||||
return new ChangeNotesParser(
|
||||
newChange().getId(), tip, walk, noteUtil, args.metrics);
|
||||
return new ChangeNotesParser(newChange().getId(), tip, walk, noteUtil, args.metrics);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,8 @@ import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.util.RequestId;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.gerrit.testutil.TestChanges;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -34,9 +35,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(ConfigSuite.class)
|
||||
public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
@Test
|
||||
@@ -51,26 +49,29 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
assertThat(update.getRefName()).isEqualTo("refs/changes/01/1/meta");
|
||||
|
||||
RevCommit commit = parseCommit(update.getResult());
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: " + c.getKey().get() + "\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: " + update.getCommit().name() + "\n"
|
||||
+ "Reviewer: Change Owner <1@gerrit>\n"
|
||||
+ "CC: Other Account <2@gerrit>\n"
|
||||
+ "Label: Code-Review=-1\n"
|
||||
+ "Label: Verified=+1\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: "
|
||||
+ c.getKey().get()
|
||||
+ "\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: "
|
||||
+ update.getCommit().name()
|
||||
+ "\n"
|
||||
+ "Reviewer: Change Owner <1@gerrit>\n"
|
||||
+ "CC: Other Account <2@gerrit>\n"
|
||||
+ "Label: Code-Review=-1\n"
|
||||
+ "Label: Verified=+1\n",
|
||||
commit);
|
||||
|
||||
PersonIdent author = commit.getAuthorIdent();
|
||||
assertThat(author.getName()).isEqualTo("Change Owner");
|
||||
assertThat(author.getEmailAddress()).isEqualTo("1@gerrit");
|
||||
assertThat(author.getWhen())
|
||||
.isEqualTo(new Date(c.getCreatedOn().getTime() + 1000));
|
||||
assertThat(author.getTimeZone())
|
||||
.isEqualTo(TimeZone.getTimeZone("GMT-7:00"));
|
||||
assertThat(author.getWhen()).isEqualTo(new Date(c.getCreatedOn().getTime() + 1000));
|
||||
assertThat(author.getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT-7:00"));
|
||||
|
||||
PersonIdent committer = commit.getCommitterIdent();
|
||||
assertThat(committer.getName()).isEqualTo("Gerrit Server");
|
||||
@@ -83,21 +84,25 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
public void changeMessageCommitFormatSimple() throws Exception {
|
||||
Change c = TestChanges.newChange(project, changeOwner.getAccountId(), 1);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setChangeMessage("Just a little code change.\n"
|
||||
+ "How about a new line");
|
||||
update.setChangeMessage("Just a little code change.\n" + "How about a new line");
|
||||
update.commit();
|
||||
assertThat(update.getRefName()).isEqualTo("refs/changes/01/1/meta");
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Just a little code change.\n"
|
||||
+ "How about a new line\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: " + c.getKey().get() + "\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: " + update.getCommit().name() + "\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Just a little code change.\n"
|
||||
+ "How about a new line\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: "
|
||||
+ c.getKey().get()
|
||||
+ "\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: "
|
||||
+ update.getCommit().name()
|
||||
+ "\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@@ -111,15 +116,20 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.commit();
|
||||
assertThat(update.getRefName()).isEqualTo("refs/changes/01/1/meta");
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Foo\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: " + c.getKey().get() + "\n"
|
||||
+ "Subject: Subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: " + commit.name() + "\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Foo\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: "
|
||||
+ c.getKey().get()
|
||||
+ "\n"
|
||||
+ "Subject: Subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: "
|
||||
+ commit.name()
|
||||
+ "\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@@ -130,10 +140,8 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.removeApproval("Code-Review");
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Label: -Code-Review\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n" + "\n" + "Patch-set: 1\n" + "Label: -Code-Review\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@@ -144,36 +152,43 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.setSubjectForCommit("Submit patch set 1");
|
||||
|
||||
RequestId submissionId = RequestId.forChange(c);
|
||||
update.merge(submissionId, ImmutableList.of(
|
||||
submitRecord("NOT_READY", null,
|
||||
submitLabel("Verified", "OK", changeOwner.getAccountId()),
|
||||
submitLabel("Code-Review", "NEED", null)),
|
||||
submitRecord("NOT_READY", null,
|
||||
submitLabel("Verified", "OK", changeOwner.getAccountId()),
|
||||
submitLabel("Alternative-Code-Review", "NEED", null))));
|
||||
update.merge(
|
||||
submissionId,
|
||||
ImmutableList.of(
|
||||
submitRecord(
|
||||
"NOT_READY",
|
||||
null,
|
||||
submitLabel("Verified", "OK", changeOwner.getAccountId()),
|
||||
submitLabel("Code-Review", "NEED", null)),
|
||||
submitRecord(
|
||||
"NOT_READY",
|
||||
null,
|
||||
submitLabel("Verified", "OK", changeOwner.getAccountId()),
|
||||
submitLabel("Alternative-Code-Review", "NEED", null))));
|
||||
update.commit();
|
||||
|
||||
RevCommit commit = parseCommit(update.getResult());
|
||||
assertBodyEquals("Submit patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: merged\n"
|
||||
+ "Submission-id: " + submissionId.toStringForStorage() + "\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Code-Review\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Alternative-Code-Review\n",
|
||||
assertBodyEquals(
|
||||
"Submit patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: merged\n"
|
||||
+ "Submission-id: "
|
||||
+ submissionId.toStringForStorage()
|
||||
+ "\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Code-Review\n"
|
||||
+ "Submitted-with: NOT_READY\n"
|
||||
+ "Submitted-with: OK: Verified: Change Owner <1@gerrit>\n"
|
||||
+ "Submitted-with: NEED: Alternative-Code-Review\n",
|
||||
commit);
|
||||
|
||||
PersonIdent author = commit.getAuthorIdent();
|
||||
assertThat(author.getName()).isEqualTo("Change Owner");
|
||||
assertThat(author.getEmailAddress()).isEqualTo("1@gerrit");
|
||||
assertThat(author.getWhen())
|
||||
.isEqualTo(new Date(c.getCreatedOn().getTime() + 2000));
|
||||
assertThat(author.getTimeZone())
|
||||
.isEqualTo(TimeZone.getTimeZone("GMT-7:00"));
|
||||
assertThat(author.getWhen()).isEqualTo(new Date(c.getCreatedOn().getTime() + 2000));
|
||||
assertThat(author.getTimeZone()).isEqualTo(TimeZone.getTimeZone("GMT-7:00"));
|
||||
|
||||
PersonIdent committer = commit.getCommitterIdent();
|
||||
assertThat(committer.getName()).isEqualTo("Gerrit Server");
|
||||
@@ -192,11 +207,8 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.commit();
|
||||
|
||||
RevCommit commit = parseCommit(update.getResult());
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Comment on the change.\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n" + "\n" + "Comment on the change.\n" + "\n" + "Patch-set: 1\n",
|
||||
commit);
|
||||
|
||||
PersonIdent author = commit.getAuthorIdent();
|
||||
@@ -211,16 +223,19 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.setSubjectForCommit("Submit patch set 1");
|
||||
|
||||
RequestId submissionId = RequestId.forChange(c);
|
||||
update.merge(submissionId, ImmutableList.of(
|
||||
submitRecord("RULE_ERROR", "Problem with patch set:\n1")));
|
||||
update.merge(
|
||||
submissionId, ImmutableList.of(submitRecord("RULE_ERROR", "Problem with patch set:\n1")));
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Submit patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: merged\n"
|
||||
+ "Submission-id: " + submissionId.toStringForStorage() + "\n"
|
||||
+ "Submitted-with: RULE_ERROR Problem with patch set: 1\n",
|
||||
assertBodyEquals(
|
||||
"Submit patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Status: merged\n"
|
||||
+ "Submission-id: "
|
||||
+ submissionId.toStringForStorage()
|
||||
+ "\n"
|
||||
+ "Submitted-with: RULE_ERROR Problem with patch set: 1\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@@ -231,10 +246,8 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Reviewer: Change Owner <1@gerrit>\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n" + "\n" + "Patch-set: 1\n" + "Reviewer: Change Owner <1@gerrit>\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@@ -242,17 +255,17 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
public void changeMessageWithTrailingDoubleNewline() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setChangeMessage("Testing trailing double newline\n"
|
||||
+ "\n");
|
||||
update.setChangeMessage("Testing trailing double newline\n" + "\n");
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Testing trailing double newline\n"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Testing trailing double newline\n"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@@ -260,22 +273,20 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
public void changeMessageWithMultipleParagraphs() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setChangeMessage("Testing paragraph 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 2\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 3");
|
||||
update.setChangeMessage(
|
||||
"Testing paragraph 1\n" + "\n" + "Testing paragraph 2\n" + "\n" + "Testing paragraph 3");
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 2\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 3\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 1\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 2\n"
|
||||
+ "\n"
|
||||
+ "Testing paragraph 3\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@@ -287,57 +298,65 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.setTag("jenkins");
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Change message with tag\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Tag: jenkins\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Change message with tag\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Tag: jenkins\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leadingWhitespace() throws Exception {
|
||||
Change c = TestChanges.newChange(project, changeOwner.getAccountId());
|
||||
c.setCurrentPatchSet(c.currentPatchSetId(), " " + c.getSubject(),
|
||||
c.getOriginalSubject());
|
||||
c.setCurrentPatchSet(c.currentPatchSetId(), " " + c.getSubject(), c.getOriginalSubject());
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.setChangeId(c.getKey().get());
|
||||
update.setBranch(c.getDest().get());
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: " + c.getKey().get() + "\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: " + update.getCommit().name() + "\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: "
|
||||
+ c.getKey().get()
|
||||
+ "\n"
|
||||
+ "Subject: Change subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: "
|
||||
+ update.getCommit().name()
|
||||
+ "\n",
|
||||
update.getResult());
|
||||
|
||||
c = TestChanges.newChange(project, changeOwner.getAccountId());
|
||||
c.setCurrentPatchSet(c.currentPatchSetId(), "\t\t" + c.getSubject(),
|
||||
c.getOriginalSubject());
|
||||
c.setCurrentPatchSet(c.currentPatchSetId(), "\t\t" + c.getSubject(), c.getOriginalSubject());
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.setChangeId(c.getKey().get());
|
||||
update.setBranch(c.getDest().get());
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: " + c.getKey().get() + "\n"
|
||||
+ "Subject: \t\tChange subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: " + update.getCommit().name() + "\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Change-id: "
|
||||
+ c.getKey().get()
|
||||
+ "\n"
|
||||
+ "Subject: \t\tChange subject\n"
|
||||
+ "Branch: refs/heads/master\n"
|
||||
+ "Commit: "
|
||||
+ update.getCommit().name()
|
||||
+ "\n",
|
||||
update.getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void realUser() throws Exception {
|
||||
Change c = newChange();
|
||||
CurrentUser ownerAsOtherUser =
|
||||
userFactory.runAs(null, otherUserId, changeOwner);
|
||||
CurrentUser ownerAsOtherUser = userFactory.runAs(null, otherUserId, changeOwner);
|
||||
ChangeUpdate update = newUpdate(c, ownerAsOtherUser);
|
||||
update.setChangeMessage("Message on behalf of other user");
|
||||
update.commit();
|
||||
@@ -347,12 +366,13 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
assertThat(author.getName()).isEqualTo("Other Account");
|
||||
assertThat(author.getEmailAddress()).isEqualTo("2@gerrit");
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Message on behalf of other user\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Real-user: Change Owner <1@gerrit>\n",
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Message on behalf of other user\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Real-user: Change Owner <1@gerrit>\n",
|
||||
commit);
|
||||
}
|
||||
|
||||
@@ -363,11 +383,8 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
update.setCurrentPatchSet();
|
||||
update.commit();
|
||||
|
||||
assertBodyEquals("Update patch set 1\n"
|
||||
+ "\n"
|
||||
+ "Patch-set: 1\n"
|
||||
+ "Current: true\n",
|
||||
update.getResult());
|
||||
assertBodyEquals(
|
||||
"Update patch set 1\n" + "\n" + "Patch-set: 1\n" + "Current: true\n", update.getResult());
|
||||
}
|
||||
|
||||
private RevCommit parseCommit(ObjectId id) throws Exception {
|
||||
@@ -381,8 +398,7 @@ public class CommitMessageOutputTest extends AbstractChangeNotesTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertBodyEquals(String expected, ObjectId commitId)
|
||||
throws Exception {
|
||||
private void assertBodyEquals(String expected, ObjectId commitId) throws Exception {
|
||||
RevCommit commit = parseCommit(commitId);
|
||||
assertThat(commit.getFullMessage()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ package com.google.gerrit.server.notedb;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.common.TimeUtil.nowTs;
|
||||
import static com.google.gerrit.server.notedb.NoteDbChangeState.applyDelta;
|
||||
import static com.google.gerrit.server.notedb.NoteDbChangeState.parse;
|
||||
import static com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage.NOTE_DB;
|
||||
import static com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage.REVIEW_DB;
|
||||
import static com.google.gerrit.server.notedb.NoteDbChangeState.applyDelta;
|
||||
import static com.google.gerrit.server.notedb.NoteDbChangeState.parse;
|
||||
import static org.eclipse.jgit.lib.ObjectId.zeroId;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -32,24 +32,19 @@ import com.google.gerrit.server.notedb.NoteDbChangeState.RefState;
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
import com.google.gerrit.testutil.TestChanges;
|
||||
import com.google.gerrit.testutil.TestTimeUtil;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** Unit tests for {@link NoteDbChangeState}. */
|
||||
public class NoteDbChangeStateTest extends GerritBaseTests {
|
||||
ObjectId SHA1 =
|
||||
ObjectId.fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
|
||||
ObjectId SHA2 =
|
||||
ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
|
||||
ObjectId SHA3 =
|
||||
ObjectId.fromString("badc0feebadc0feebadc0feebadc0feebadc0fee");
|
||||
ObjectId SHA1 = ObjectId.fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
|
||||
ObjectId SHA2 = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
|
||||
ObjectId SHA3 = ObjectId.fromString("badc0feebadc0feebadc0feebadc0feebadc0fee");
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -83,15 +78,15 @@ public class NoteDbChangeStateTest extends GerritBaseTests {
|
||||
@Test
|
||||
public void parseReviewDbWithDrafts() {
|
||||
String str = SHA1.name() + ",2003=" + SHA2.name() + ",1001=" + SHA3.name();
|
||||
String expected =
|
||||
SHA1.name() + ",1001=" + SHA3.name() + ",2003=" + SHA2.name();
|
||||
String expected = SHA1.name() + ",1001=" + SHA3.name() + ",2003=" + SHA2.name();
|
||||
NoteDbChangeState state = parse(new Change.Id(1), str);
|
||||
assertThat(state.getPrimaryStorage()).isEqualTo(REVIEW_DB);
|
||||
assertThat(state.getChangeId()).isEqualTo(new Change.Id(1));
|
||||
assertThat(state.getChangeMetaId()).isEqualTo(SHA1);
|
||||
assertThat(state.getDraftIds()).containsExactly(
|
||||
new Account.Id(1001), SHA3,
|
||||
new Account.Id(2003), SHA2);
|
||||
assertThat(state.getDraftIds())
|
||||
.containsExactly(
|
||||
new Account.Id(1001), SHA3,
|
||||
new Account.Id(2003), SHA2);
|
||||
assertThat(state.getReadOnlyUntil().isPresent()).isFalse();
|
||||
assertThat(state.toString()).isEqualTo(expected);
|
||||
|
||||
@@ -99,9 +94,10 @@ public class NoteDbChangeStateTest extends GerritBaseTests {
|
||||
assertThat(state.getPrimaryStorage()).isEqualTo(REVIEW_DB);
|
||||
assertThat(state.getChangeId()).isEqualTo(new Change.Id(1));
|
||||
assertThat(state.getChangeMetaId()).isEqualTo(SHA1);
|
||||
assertThat(state.getDraftIds()).containsExactly(
|
||||
new Account.Id(1001), SHA3,
|
||||
new Account.Id(2003), SHA2);
|
||||
assertThat(state.getDraftIds())
|
||||
.containsExactly(
|
||||
new Account.Id(1001), SHA3,
|
||||
new Account.Id(2003), SHA2);
|
||||
assertThat(state.getReadOnlyUntil().isPresent()).isFalse();
|
||||
assertThat(state.toString()).isEqualTo(expected);
|
||||
}
|
||||
@@ -133,11 +129,7 @@ public class NoteDbChangeStateTest extends GerritBaseTests {
|
||||
applyDelta(c, Delta.create(c.getId(), noMetaId(), noDrafts()));
|
||||
assertThat(c.getNoteDbState()).isNull();
|
||||
|
||||
applyDelta(
|
||||
c,
|
||||
Delta.create(
|
||||
c.getId(), noMetaId(),
|
||||
drafts(new Account.Id(1001), zeroId())));
|
||||
applyDelta(c, Delta.create(c.getId(), noMetaId(), drafts(new Account.Id(1001), zeroId())));
|
||||
assertThat(c.getNoteDbState()).isNull();
|
||||
}
|
||||
|
||||
@@ -162,53 +154,40 @@ public class NoteDbChangeStateTest extends GerritBaseTests {
|
||||
@Test
|
||||
public void applyDeltaToDrafts() throws Exception {
|
||||
Change c = newChange();
|
||||
applyDelta(
|
||||
c,
|
||||
Delta.create(
|
||||
c.getId(), metaId(SHA1),
|
||||
drafts(new Account.Id(1001), SHA2)));
|
||||
assertThat(c.getNoteDbState()).isEqualTo(
|
||||
SHA1.name() + ",1001=" + SHA2.name());
|
||||
applyDelta(c, Delta.create(c.getId(), metaId(SHA1), drafts(new Account.Id(1001), SHA2)));
|
||||
assertThat(c.getNoteDbState()).isEqualTo(SHA1.name() + ",1001=" + SHA2.name());
|
||||
|
||||
applyDelta(
|
||||
c,
|
||||
Delta.create(
|
||||
c.getId(), noMetaId(),
|
||||
drafts(new Account.Id(2003), SHA3)));
|
||||
assertThat(c.getNoteDbState()).isEqualTo(
|
||||
SHA1.name() + ",1001=" + SHA2.name() + ",2003=" + SHA3.name());
|
||||
applyDelta(c, Delta.create(c.getId(), noMetaId(), drafts(new Account.Id(2003), SHA3)));
|
||||
assertThat(c.getNoteDbState())
|
||||
.isEqualTo(SHA1.name() + ",1001=" + SHA2.name() + ",2003=" + SHA3.name());
|
||||
|
||||
applyDelta(
|
||||
c,
|
||||
Delta.create(
|
||||
c.getId(), noMetaId(),
|
||||
drafts(new Account.Id(2003), zeroId())));
|
||||
assertThat(c.getNoteDbState()).isEqualTo(
|
||||
SHA1.name() + ",1001=" + SHA2.name());
|
||||
applyDelta(c, Delta.create(c.getId(), noMetaId(), drafts(new Account.Id(2003), zeroId())));
|
||||
assertThat(c.getNoteDbState()).isEqualTo(SHA1.name() + ",1001=" + SHA2.name());
|
||||
|
||||
applyDelta(
|
||||
c, Delta.create(c.getId(), metaId(SHA3), noDrafts()));
|
||||
assertThat(c.getNoteDbState()).isEqualTo(
|
||||
SHA3.name() + ",1001=" + SHA2.name());
|
||||
applyDelta(c, Delta.create(c.getId(), metaId(SHA3), noDrafts()));
|
||||
assertThat(c.getNoteDbState()).isEqualTo(SHA3.name() + ",1001=" + SHA2.name());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyDeltaToReadOnly() throws Exception {
|
||||
Timestamp ts = nowTs();
|
||||
Change c = newChange();
|
||||
NoteDbChangeState state = new NoteDbChangeState(c.getId(),
|
||||
REVIEW_DB,
|
||||
Optional.of(RefState.create(SHA1, ImmutableMap.of())),
|
||||
Optional.of(new Timestamp(ts.getTime() + 10000)));
|
||||
NoteDbChangeState state =
|
||||
new NoteDbChangeState(
|
||||
c.getId(),
|
||||
REVIEW_DB,
|
||||
Optional.of(RefState.create(SHA1, ImmutableMap.of())),
|
||||
Optional.of(new Timestamp(ts.getTime() + 10000)));
|
||||
c.setNoteDbState(state.toString());
|
||||
Delta delta = Delta.create(c.getId(), metaId(SHA2), noDrafts());
|
||||
applyDelta(c, delta);
|
||||
assertThat(NoteDbChangeState.parse(c)).isEqualTo(
|
||||
new NoteDbChangeState(
|
||||
state.getChangeId(),
|
||||
state.getPrimaryStorage(),
|
||||
Optional.of(RefState.create(SHA2, ImmutableMap.of())),
|
||||
state.getReadOnlyUntil()));
|
||||
assertThat(NoteDbChangeState.parse(c))
|
||||
.isEqualTo(
|
||||
new NoteDbChangeState(
|
||||
state.getChangeId(),
|
||||
state.getPrimaryStorage(),
|
||||
Optional.of(RefState.create(SHA2, ImmutableMap.of())),
|
||||
state.getReadOnlyUntil()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -228,14 +207,12 @@ public class NoteDbChangeStateTest extends GerritBaseTests {
|
||||
public void applyDeltaToNoteDbPrimaryIsNoOp() throws Exception {
|
||||
Change c = newChange();
|
||||
c.setNoteDbState("N");
|
||||
applyDelta(c, Delta.create(c.getId(), metaId(SHA1),
|
||||
drafts(new Account.Id(1001), SHA2)));
|
||||
applyDelta(c, Delta.create(c.getId(), metaId(SHA1), drafts(new Account.Id(1001), SHA2)));
|
||||
assertThat(c.getNoteDbState()).isEqualTo("N");
|
||||
}
|
||||
|
||||
private static Change newChange() {
|
||||
return TestChanges.newChange(
|
||||
new Project.NameKey("project"), new Account.Id(12345));
|
||||
return TestChanges.newChange(new Project.NameKey("project"), new Account.Id(12345));
|
||||
}
|
||||
|
||||
// Static factory methods to avoid type arguments when using as method args.
|
||||
|
||||
@@ -19,17 +19,19 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.github.rholder.retry.BlockStrategy;
|
||||
import com.github.rholder.retry.Retryer;
|
||||
import com.github.rholder.retry.RetryerBuilder;
|
||||
import com.github.rholder.retry.StopStrategies;
|
||||
import com.google.common.util.concurrent.Runnables;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
|
||||
import com.github.rholder.retry.BlockStrategy;
|
||||
import com.github.rholder.retry.Retryer;
|
||||
import com.github.rholder.retry.RetryerBuilder;
|
||||
import com.github.rholder.retry.StopStrategies;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -42,22 +44,19 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class RepoSequenceTest {
|
||||
private static final Retryer<RefUpdate.Result> RETRYER =
|
||||
RepoSequence.retryerBuilder().withBlockStrategy(new BlockStrategy() {
|
||||
@Override
|
||||
public void block(long sleepTime) {
|
||||
// Don't sleep in tests.
|
||||
}
|
||||
}).build();
|
||||
RepoSequence.retryerBuilder()
|
||||
.withBlockStrategy(
|
||||
new BlockStrategy() {
|
||||
@Override
|
||||
public void block(long sleepTime) {
|
||||
// Don't sleep in tests.
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@Rule public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private InMemoryRepositoryManager repoManager;
|
||||
private Project.NameKey project;
|
||||
@@ -79,8 +78,7 @@ public class RepoSequenceTest {
|
||||
try {
|
||||
assertThat(s.next()).named("i=" + i + " for " + name).isEqualTo(i);
|
||||
} catch (OrmException e) {
|
||||
throw new AssertionError(
|
||||
"failed batchSize=" + batchSize + ", i=" + i, e);
|
||||
throw new AssertionError("failed batchSize=" + batchSize + ", i=" + i, e);
|
||||
}
|
||||
}
|
||||
assertThat(s.acquireCount)
|
||||
@@ -162,14 +160,15 @@ public class RepoSequenceTest {
|
||||
writeBlob("id", "1");
|
||||
|
||||
final AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
|
||||
Runnable bgUpdate = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!doneBgUpdate.getAndSet(true)) {
|
||||
writeBlob("id", "1234");
|
||||
}
|
||||
}
|
||||
};
|
||||
Runnable bgUpdate =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!doneBgUpdate.getAndSet(true)) {
|
||||
writeBlob("id", "1234");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RepoSequence s = newSequence("id", 1, 10, bgUpdate, RETRYER);
|
||||
assertThat(doneBgUpdate.get()).isFalse();
|
||||
@@ -183,8 +182,7 @@ public class RepoSequenceTest {
|
||||
public void failOnInvalidValue() throws Exception {
|
||||
ObjectId id = writeBlob("id", "not a number");
|
||||
exception.expect(OrmException.class);
|
||||
exception.expectMessage(
|
||||
"invalid value in refs/sequences/id blob at " + id.name());
|
||||
exception.expectMessage("invalid value in refs/sequences/id blob at " + id.name());
|
||||
newSequence("id", 1, 3).next();
|
||||
}
|
||||
|
||||
@@ -198,8 +196,7 @@ public class RepoSequenceTest {
|
||||
fail();
|
||||
} catch (OrmException e) {
|
||||
assertThat(e.getCause()).isInstanceOf(ExecutionException.class);
|
||||
assertThat(e.getCause().getCause())
|
||||
.isInstanceOf(IncorrectObjectTypeException.class);
|
||||
assertThat(e.getCause().getCause()).isInstanceOf(IncorrectObjectTypeException.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,17 +204,22 @@ public class RepoSequenceTest {
|
||||
@Test
|
||||
public void failAfterRetryerGivesUp() throws Exception {
|
||||
final AtomicInteger bgCounter = new AtomicInteger(1234);
|
||||
Runnable bgUpdate = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000)));
|
||||
}
|
||||
};
|
||||
RepoSequence s = newSequence(
|
||||
"id", 1, 10, bgUpdate,
|
||||
RetryerBuilder.<RefUpdate.Result> newBuilder()
|
||||
.withStopStrategy(StopStrategies.stopAfterAttempt(3))
|
||||
.build());
|
||||
Runnable bgUpdate =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000)));
|
||||
}
|
||||
};
|
||||
RepoSequence s =
|
||||
newSequence(
|
||||
"id",
|
||||
1,
|
||||
10,
|
||||
bgUpdate,
|
||||
RetryerBuilder.<RefUpdate.Result>newBuilder()
|
||||
.withStopStrategy(StopStrategies.stopAfterAttempt(3))
|
||||
.build());
|
||||
exception.expect(OrmException.class);
|
||||
exception.expectMessage("failed to update refs/sequences/id: LOCK_FAILURE");
|
||||
s.next();
|
||||
@@ -270,12 +272,15 @@ public class RepoSequenceTest {
|
||||
}
|
||||
|
||||
private RepoSequence newSequence(String name, int start, int batchSize) {
|
||||
return newSequence(
|
||||
name, start, batchSize, Runnables.doNothing(), RETRYER);
|
||||
return newSequence(name, start, batchSize, Runnables.doNothing(), RETRYER);
|
||||
}
|
||||
|
||||
private RepoSequence newSequence(String name, final int start, int batchSize,
|
||||
Runnable afterReadRef, Retryer<RefUpdate.Result> retryer) {
|
||||
private RepoSequence newSequence(
|
||||
String name,
|
||||
final int start,
|
||||
int batchSize,
|
||||
Runnable afterReadRef,
|
||||
Retryer<RefUpdate.Result> retryer) {
|
||||
return new RepoSequence(
|
||||
repoManager,
|
||||
project,
|
||||
@@ -299,8 +304,7 @@ public class RepoSequenceTest {
|
||||
ins.flush();
|
||||
RefUpdate ru = repo.updateRef(refName);
|
||||
ru.setNewObjectId(newId);
|
||||
assertThat(ru.forceUpdate())
|
||||
.isAnyOf(RefUpdate.Result.NEW, RefUpdate.Result.FORCED);
|
||||
assertThat(ru.forceUpdate()).isAnyOf(RefUpdate.Result.NEW, RefUpdate.Result.FORCED);
|
||||
return newId;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -26,23 +26,24 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
import com.google.gerrit.testutil.TestTimeUtil;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EventSorterTest {
|
||||
private class TestEvent extends Event {
|
||||
protected TestEvent(Timestamp when) {
|
||||
super(
|
||||
new PatchSet.Id(new Change.Id(1), 1),
|
||||
new Account.Id(1000), new Account.Id(1000),
|
||||
when, changeCreatedOn, null);
|
||||
new Account.Id(1000),
|
||||
new Account.Id(1000),
|
||||
when,
|
||||
changeCreatedOn,
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,10 +114,11 @@ public class EventSorterTest {
|
||||
}
|
||||
|
||||
private List<Event> threeEventsOneDep(int depFromIdx, int depOnIdx) {
|
||||
List<Event> events = Lists.newArrayList(
|
||||
new TestEvent(TimeUtil.nowTs()),
|
||||
new TestEvent(TimeUtil.nowTs()),
|
||||
new TestEvent(TimeUtil.nowTs()));
|
||||
List<Event> events =
|
||||
Lists.newArrayList(
|
||||
new TestEvent(TimeUtil.nowTs()),
|
||||
new TestEvent(TimeUtil.nowTs()),
|
||||
new TestEvent(TimeUtil.nowTs()));
|
||||
events.get(depFromIdx).addDep(events.get(depOnIdx));
|
||||
return events;
|
||||
}
|
||||
@@ -155,9 +157,7 @@ public class EventSorterTest {
|
||||
e2.addDep(e3);
|
||||
e3.addDep(e4);
|
||||
|
||||
assertSorted(
|
||||
events(e1, e2, e3, e4),
|
||||
events(e4, e3, e2, e1));
|
||||
assertSorted(events(e1, e2, e3, e4), events(e4, e3, e2, e1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,9 +171,7 @@ public class EventSorterTest {
|
||||
e2.addDep(e3);
|
||||
|
||||
// Processing 3 pops 2, processing 4 pops 1.
|
||||
assertSorted(
|
||||
events(e2, e3, e1, e4),
|
||||
events(e3, e2, e4, e1));
|
||||
assertSorted(events(e2, e3, e1, e4), events(e3, e2, e4, e1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,9 +185,7 @@ public class EventSorterTest {
|
||||
e3.addDep(e4);
|
||||
|
||||
// Processing 4 pops 1, 2, 3 in natural order.
|
||||
assertSorted(
|
||||
events(e4, e3, e2, e1),
|
||||
events(e4, e1, e2, e3));
|
||||
assertSorted(events(e4, e3, e2, e1), events(e4, e1, e2, e3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,9 +196,7 @@ public class EventSorterTest {
|
||||
// Implementation is not really defined, but infinite looping would be bad.
|
||||
// According to current implementation details, 2 pops 1, 1 pops 2 which was
|
||||
// already seen.
|
||||
assertSorted(
|
||||
events(e2, e1),
|
||||
events(e1, e2));
|
||||
assertSorted(events(e2, e1), events(e1, e2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,8 +226,6 @@ public class EventSorterTest {
|
||||
private static void assertSorted(List<Event> unsorted, List<Event> expected) {
|
||||
List<Event> actual = new ArrayList<>(unsorted);
|
||||
new EventSorter(actual).sort();
|
||||
assertThat(actual)
|
||||
.named("sorted" + unsorted)
|
||||
.isEqualTo(expected);
|
||||
assertThat(actual).named("sorted" + unsorted).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,67 +17,56 @@ package com.google.gerrit.server.patch;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.diff.Edit;
|
||||
import org.eclipse.jgit.diff.EditList;
|
||||
import org.eclipse.jgit.diff.ReplaceEdit;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IntraLineLoaderTest {
|
||||
|
||||
@Test
|
||||
public void rewriteAtStartOfLineIsRecognized() throws Exception {
|
||||
String a = "abc1\n";
|
||||
String b = "def1\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.replace("abc", "def").common("1\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b)).isEqualTo(ref().replace("abc", "def").common("1\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rewriteAtEndOfLineIsRecognized() throws Exception {
|
||||
String a = "abc1\n";
|
||||
String b = "abc2\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.common("abc").replace("1", "2").common("\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b)).isEqualTo(ref().common("abc").replace("1", "2").common("\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void completeRewriteIncludesNewline() throws Exception {
|
||||
String a = "abc1\n";
|
||||
String b = "def2\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.replace("abc1\n", "def2\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b)).isEqualTo(ref().replace("abc1\n", "def2\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeEditsAreCombined() throws Exception {
|
||||
String a = "ab1cdef2gh\n";
|
||||
String b = "ab2cdef3gh\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.common("ab").replace("1cdef2", "2cdef3").common("gh\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b))
|
||||
.isEqualTo(ref().common("ab").replace("1cdef2", "2cdef3").common("gh\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferInsertAfterCommonPart1() throws Exception {
|
||||
String a = "start middle end\n";
|
||||
String b = "start middlemiddle end\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.common("start middle").insert("middle").common(" end\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b))
|
||||
.isEqualTo(ref().common("start middle").insert("middle").common(" end\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferInsertAfterCommonPart2() throws Exception {
|
||||
String a = "abc def\n";
|
||||
String b = "abc def\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.common("abc ").insert(" ").common("def\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b)).isEqualTo(ref().common("abc ").insert(" ").common("def\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,10 +89,8 @@ public class IntraLineLoaderTest {
|
||||
public void preferInsertAtLineBreak2() throws Exception {
|
||||
String a = " abc\n def\n";
|
||||
String b = " abc\n def\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.insert(" ").common(" abc\n")
|
||||
.insert(" ").common(" def\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b))
|
||||
.isEqualTo(ref().insert(" ").common(" abc\n").insert(" ").common(" def\n").edits);
|
||||
}
|
||||
|
||||
//TODO: expected failure
|
||||
@@ -112,19 +99,16 @@ public class IntraLineLoaderTest {
|
||||
public void preferDeleteAtLineBreak() throws Exception {
|
||||
String a = " abc\n def\n";
|
||||
String b = " abc\n def\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.remove(" ").common(" abc\n")
|
||||
.remove(" ").common(" def\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b))
|
||||
.isEqualTo(ref().remove(" ").common(" abc\n").remove(" ").common(" def\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertedWhitespaceIsRecognized() throws Exception {
|
||||
String a = " int *foobar\n";
|
||||
String b = " int * foobar\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.common(" int *").insert(" ").common("foobar\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b))
|
||||
.isEqualTo(ref().common(" int *").insert(" ").common("foobar\n").edits);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,10 +116,16 @@ public class IntraLineLoaderTest {
|
||||
// |0 5 10 | 5 20 5 30
|
||||
String a = " int *foobar\n int *foobar\n";
|
||||
String b = " int * foobar\n int * foobar\n";
|
||||
assertThat(intraline(a, b)).isEqualTo(ref()
|
||||
.common(" int *").insert(" ").common("foobar\n")
|
||||
.common(" int *").insert(" ").common("foobar\n").edits
|
||||
);
|
||||
assertThat(intraline(a, b))
|
||||
.isEqualTo(
|
||||
ref()
|
||||
.common(" int *")
|
||||
.insert(" ")
|
||||
.common("foobar\n")
|
||||
.common(" int *")
|
||||
.insert(" ")
|
||||
.common("foobar\n")
|
||||
.edits);
|
||||
}
|
||||
|
||||
// helper functions to call IntraLineLoader.compute
|
||||
@@ -154,8 +144,7 @@ public class IntraLineLoaderTest {
|
||||
return intraline(a, b, new Edit(0, countLines(a), 0, countLines(b)));
|
||||
}
|
||||
|
||||
private static List<Edit> intraline(String a, String b, Edit lines)
|
||||
throws Exception {
|
||||
private static List<Edit> intraline(String a, String b, Edit lines) throws Exception {
|
||||
Text aText = new Text(a.getBytes(UTF_8));
|
||||
Text bText = new Text(b.getBytes(UTF_8));
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PatchListEntryTest {
|
||||
|
||||
@@ -45,7 +45,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -94,8 +93,7 @@ public class ProjectControlTest {
|
||||
admins = groupCache.get(new AccountGroup.NameKey("Administrators")).getGroupUUID();
|
||||
setUpPermissions();
|
||||
|
||||
Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user"))
|
||||
.getAccountId();
|
||||
Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
|
||||
user = userFactory.create(userId);
|
||||
|
||||
Project.NameKey name = new Project.NameKey("project");
|
||||
@@ -104,17 +102,18 @@ public class ProjectControlTest {
|
||||
project.load(inMemoryRepo);
|
||||
repo = new TestRepository<>(inMemoryRepo);
|
||||
|
||||
requestContext.setContext(new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
requestContext.setContext(
|
||||
new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -235,15 +234,13 @@ public class ProjectControlTest {
|
||||
return projectControlFactory.controlFor(project.getName(), user);
|
||||
}
|
||||
|
||||
protected void allow(ProjectConfig project, String permission,
|
||||
AccountGroup.UUID id, String ref)
|
||||
protected void allow(ProjectConfig project, String permission, AccountGroup.UUID id, String ref)
|
||||
throws Exception {
|
||||
Util.allow(project, permission, id, ref);
|
||||
saveProjectConfig(project);
|
||||
}
|
||||
|
||||
protected void deny(ProjectConfig project, String permission,
|
||||
AccountGroup.UUID id, String ref)
|
||||
protected void deny(ProjectConfig project, String permission, AccountGroup.UUID id, String ref)
|
||||
throws Exception {
|
||||
Util.deny(project, permission, id, ref);
|
||||
saveProjectConfig(project);
|
||||
|
||||
@@ -70,14 +70,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -85,6 +77,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RefControlTest {
|
||||
private void assertAdminsAreOwnersAndDevsAreNot() {
|
||||
@@ -96,10 +94,9 @@ public class RefControlTest {
|
||||
}
|
||||
|
||||
private void assertOwner(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).isOwner())
|
||||
.named("OWN " + ref)
|
||||
.isTrue();
|
||||
assertThat(u.controlForRef(ref).isOwner()).named("OWN " + ref).isTrue();
|
||||
}
|
||||
|
||||
private void assertNotOwner(ProjectControl u) {
|
||||
assertThat(u.isOwner()).named("not owner").isFalse();
|
||||
}
|
||||
@@ -109,123 +106,84 @@ public class RefControlTest {
|
||||
}
|
||||
|
||||
private void assertNotOwner(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).isOwner())
|
||||
.named("NOT OWN " + ref)
|
||||
.isFalse();
|
||||
assertThat(u.controlForRef(ref).isOwner()).named("NOT OWN " + ref).isFalse();
|
||||
}
|
||||
|
||||
private void assertCanRead(ProjectControl u) {
|
||||
assertThat(u.isVisible())
|
||||
.named("can read")
|
||||
.isTrue();
|
||||
assertThat(u.isVisible()).named("can read").isTrue();
|
||||
}
|
||||
|
||||
private void assertCannotRead(ProjectControl u) {
|
||||
assertThat(u.isVisible())
|
||||
.named("cannot read")
|
||||
.isFalse();
|
||||
assertThat(u.isVisible()).named("cannot read").isFalse();
|
||||
}
|
||||
|
||||
private void assertCanRead(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).isVisible())
|
||||
.named("can read " + ref)
|
||||
.isTrue();
|
||||
assertThat(u.controlForRef(ref).isVisible()).named("can read " + ref).isTrue();
|
||||
}
|
||||
|
||||
private void assertCannotRead(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).isVisible())
|
||||
.named("cannot read " + ref)
|
||||
.isFalse();
|
||||
assertThat(u.controlForRef(ref).isVisible()).named("cannot read " + ref).isFalse();
|
||||
}
|
||||
|
||||
private void assertCanSubmit(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canSubmit(false))
|
||||
.named("can submit " + ref)
|
||||
.isTrue();
|
||||
assertThat(u.controlForRef(ref).canSubmit(false)).named("can submit " + ref).isTrue();
|
||||
}
|
||||
|
||||
private void assertCannotSubmit(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canSubmit(false))
|
||||
.named("can submit " + ref)
|
||||
.isFalse();
|
||||
assertThat(u.controlForRef(ref).canSubmit(false)).named("can submit " + ref).isFalse();
|
||||
}
|
||||
|
||||
private void assertCanUpload(ProjectControl u) {
|
||||
assertThat(u.canPushToAtLeastOneRef())
|
||||
.named("can upload")
|
||||
.isEqualTo(Capable.OK);
|
||||
assertThat(u.canPushToAtLeastOneRef()).named("can upload").isEqualTo(Capable.OK);
|
||||
}
|
||||
|
||||
private void assertCanUpload(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canUpload())
|
||||
.named("can upload " + ref)
|
||||
.isTrue();
|
||||
assertThat(u.controlForRef(ref).canUpload()).named("can upload " + ref).isTrue();
|
||||
}
|
||||
|
||||
private void assertCannotUpload(ProjectControl u) {
|
||||
assertThat(u.canPushToAtLeastOneRef())
|
||||
.named("cannot upload")
|
||||
.isNotEqualTo(Capable.OK);
|
||||
assertThat(u.canPushToAtLeastOneRef()).named("cannot upload").isNotEqualTo(Capable.OK);
|
||||
}
|
||||
|
||||
private void assertCannotUpload(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canUpload())
|
||||
.named("cannot upload " + ref)
|
||||
.isFalse();
|
||||
assertThat(u.controlForRef(ref).canUpload()).named("cannot upload " + ref).isFalse();
|
||||
}
|
||||
|
||||
private void assertBlocked(String p, String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).isBlocked(p))
|
||||
.named(p + " is blocked for " + ref)
|
||||
.isTrue();
|
||||
assertThat(u.controlForRef(ref).isBlocked(p)).named(p + " is blocked for " + ref).isTrue();
|
||||
}
|
||||
|
||||
private void assertNotBlocked(String p, String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).isBlocked(p))
|
||||
.named(p + " is blocked for " + ref)
|
||||
.isFalse();
|
||||
assertThat(u.controlForRef(ref).isBlocked(p)).named(p + " is blocked for " + ref).isFalse();
|
||||
}
|
||||
|
||||
private void assertCanUpdate(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canUpdate())
|
||||
.named("can update " + ref)
|
||||
.isTrue();
|
||||
assertThat(u.controlForRef(ref).canUpdate()).named("can update " + ref).isTrue();
|
||||
}
|
||||
|
||||
private void assertCannotUpdate(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canUpdate())
|
||||
.named("cannot update " + ref)
|
||||
.isFalse();
|
||||
assertThat(u.controlForRef(ref).canUpdate()).named("cannot update " + ref).isFalse();
|
||||
}
|
||||
|
||||
private void assertCanForceUpdate(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canForceUpdate())
|
||||
.named("can force push " + ref)
|
||||
.isTrue();
|
||||
assertThat(u.controlForRef(ref).canForceUpdate()).named("can force push " + ref).isTrue();
|
||||
}
|
||||
|
||||
private void assertCannotForceUpdate(String ref, ProjectControl u) {
|
||||
assertThat(u.controlForRef(ref).canForceUpdate())
|
||||
.named("cannot force push " + ref)
|
||||
.isFalse();
|
||||
assertThat(u.controlForRef(ref).canForceUpdate()).named("cannot force push " + ref).isFalse();
|
||||
}
|
||||
|
||||
private void assertCanVote(int score, PermissionRange range) {
|
||||
assertThat(range.contains(score))
|
||||
.named("can vote " + score)
|
||||
.isTrue();
|
||||
assertThat(range.contains(score)).named("can vote " + score).isTrue();
|
||||
}
|
||||
|
||||
private void assertCannotVote(int score, PermissionRange range) {
|
||||
assertThat(range.contains(score))
|
||||
.named("cannot vote " + score)
|
||||
.isFalse();
|
||||
assertThat(range.contains(score)).named("cannot vote " + score).isFalse();
|
||||
}
|
||||
|
||||
private final AllProjectsName allProjectsName =
|
||||
new AllProjectsName(AllProjectsNameProvider.DEFAULT);
|
||||
private final AllUsersName allUsersName =
|
||||
new AllUsersName(AllUsersNameProvider.DEFAULT);
|
||||
private final AllUsersName allUsersName = new AllUsersName(AllUsersNameProvider.DEFAULT);
|
||||
private final AccountGroup.UUID fixers = new AccountGroup.UUID("test.fixers");
|
||||
private final Map<Project.NameKey, ProjectState> all = new HashMap<>();
|
||||
private Project.NameKey localKey = new Project.NameKey("local");
|
||||
@@ -249,67 +207,62 @@ public class RefControlTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
repoManager = new InMemoryRepositoryManager();
|
||||
projectCache = new ProjectCache() {
|
||||
@Override
|
||||
public ProjectState getAllProjects() {
|
||||
return get(allProjectsName);
|
||||
}
|
||||
projectCache =
|
||||
new ProjectCache() {
|
||||
@Override
|
||||
public ProjectState getAllProjects() {
|
||||
return get(allProjectsName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectState getAllUsers() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ProjectState getAllUsers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectState get(Project.NameKey projectName) {
|
||||
return all.get(projectName);
|
||||
}
|
||||
@Override
|
||||
public ProjectState get(Project.NameKey projectName) {
|
||||
return all.get(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evict(Project p) {
|
||||
}
|
||||
@Override
|
||||
public void evict(Project p) {}
|
||||
|
||||
@Override
|
||||
public void remove(Project p) {
|
||||
}
|
||||
@Override
|
||||
public void remove(Project p) {}
|
||||
|
||||
@Override
|
||||
public Iterable<Project.NameKey> all() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
@Override
|
||||
public Iterable<Project.NameKey> all() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Project.NameKey> byName(String prefix) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
@Override
|
||||
public Iterable<Project.NameKey> byName(String prefix) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateProject(Project.NameKey newProjectName) {
|
||||
}
|
||||
@Override
|
||||
public void onCreateProject(Project.NameKey newProjectName) {}
|
||||
|
||||
@Override
|
||||
public Set<AccountGroup.UUID> guessRelevantGroupUUIDs() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
@Override
|
||||
public Set<AccountGroup.UUID> guessRelevantGroupUUIDs() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectState checkedGet(Project.NameKey projectName)
|
||||
throws IOException {
|
||||
return all.get(projectName);
|
||||
}
|
||||
@Override
|
||||
public ProjectState checkedGet(Project.NameKey projectName) throws IOException {
|
||||
return all.get(projectName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evict(Project.NameKey p) {
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void evict(Project.NameKey p) {}
|
||||
};
|
||||
|
||||
Injector injector = Guice.createInjector(new InMemoryModule());
|
||||
injector.injectMembers(this);
|
||||
|
||||
try {
|
||||
Repository repo = repoManager.createRepository(allProjectsName);
|
||||
ProjectConfig allProjects =
|
||||
new ProjectConfig(new Project.NameKey(allProjectsName.get()));
|
||||
ProjectConfig allProjects = new ProjectConfig(new Project.NameKey(allProjectsName.get()));
|
||||
allProjects.load(repo);
|
||||
LabelType cr = Util.codeReview();
|
||||
allProjects.getLabelSections().put(cr.getName(), cr);
|
||||
@@ -339,17 +292,18 @@ public class RefControlTest {
|
||||
add(local);
|
||||
local.getProject().setParentName(parentKey);
|
||||
|
||||
requestContext.setContext(new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return null;
|
||||
}
|
||||
requestContext.setContext(
|
||||
new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
|
||||
changeControlFactory = injector.getInstance(ChangeControl.Factory.class);
|
||||
}
|
||||
@@ -632,13 +586,11 @@ public class RefControlTest {
|
||||
public void blockLabelRange_ParentBlocksChildEvenIfAlreadyBlockedInChild() {
|
||||
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||
block(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||
block(parent, LABEL + "Code-Review", -2, +2, DEVS,
|
||||
"refs/heads/*");
|
||||
block(parent, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||
|
||||
ProjectControl u = user(local, DEVS);
|
||||
|
||||
PermissionRange range =
|
||||
u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
|
||||
PermissionRange range = u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
|
||||
assertCanVote(-1, range);
|
||||
assertCanVote(1, range);
|
||||
assertCannotVote(-2, range);
|
||||
@@ -765,8 +717,8 @@ public class RefControlTest {
|
||||
|
||||
ProjectControl u = user(local, REGISTERED_USERS);
|
||||
assertThat(u.controlForRef("refs/heads/master").isVisibleByRegisteredUsers())
|
||||
.named("u can read")
|
||||
.isTrue();
|
||||
.named("u can read")
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -776,8 +728,8 @@ public class RefControlTest {
|
||||
|
||||
ProjectControl u = user(local, REGISTERED_USERS);
|
||||
assertThat(u.controlForRef("refs/heads/master").isVisibleByRegisteredUsers())
|
||||
.named("u can't read")
|
||||
.isFalse();
|
||||
.named("u can't read")
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -787,8 +739,8 @@ public class RefControlTest {
|
||||
|
||||
ProjectControl u = user(local, DEVS);
|
||||
assertThat(u.controlForRef("refs/heads/master").canForceEditTopicName())
|
||||
.named("u can edit topic name")
|
||||
.isTrue();
|
||||
.named("u can edit topic name")
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -798,8 +750,8 @@ public class RefControlTest {
|
||||
|
||||
ProjectControl u = user(local, REGISTERED_USERS);
|
||||
assertThat(u.controlForRef("refs/heads/master").canForceEditTopicName())
|
||||
.named("u can't edit topic name")
|
||||
.isFalse();
|
||||
.named("u can't edit topic name")
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -837,13 +789,11 @@ public class RefControlTest {
|
||||
|
||||
@Test
|
||||
public void unblockInLocalRange_Fails() {
|
||||
block(parent, LABEL + "Code-Review", -1, 1, ANONYMOUS_USERS,
|
||||
"refs/heads/*");
|
||||
block(parent, LABEL + "Code-Review", -1, 1, ANONYMOUS_USERS, "refs/heads/*");
|
||||
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||
|
||||
ProjectControl u = user(local, DEVS);
|
||||
PermissionRange range =
|
||||
u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
|
||||
PermissionRange range = u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
|
||||
assertCannotVote(-2, range);
|
||||
assertCannotVote(2, range);
|
||||
}
|
||||
@@ -853,8 +803,8 @@ public class RefControlTest {
|
||||
allow(local, LABEL + "Code-Review", -2, +2, CHANGE_OWNER, "refs/heads/*");
|
||||
|
||||
ProjectControl u = user(local, DEVS);
|
||||
PermissionRange range = u.controlForRef("refs/heads/master")
|
||||
.getRange(LABEL + "Code-Review", true);
|
||||
PermissionRange range =
|
||||
u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review", true);
|
||||
assertCanVote(-2, range);
|
||||
assertCanVote(2, range);
|
||||
}
|
||||
@@ -864,8 +814,7 @@ public class RefControlTest {
|
||||
allow(local, LABEL + "Code-Review", -2, +2, CHANGE_OWNER, "refs/heads/*");
|
||||
|
||||
ProjectControl u = user(local, DEVS);
|
||||
PermissionRange range = u.controlForRef("refs/heads/master")
|
||||
.getRange(LABEL + "Code-Review");
|
||||
PermissionRange range = u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
|
||||
assertCannotVote(-2, range);
|
||||
assertCannotVote(2, range);
|
||||
}
|
||||
@@ -893,8 +842,7 @@ public class RefControlTest {
|
||||
|
||||
@Test(expected = InvalidNameException.class)
|
||||
public void testValidateBadRefPatternDanglingCharacter() throws Exception {
|
||||
RefPattern
|
||||
.validate("^refs/heads/tmp/sdk/[0-9]{3,3}_R[1-9][A-Z][0-9]{3,3}*");
|
||||
RefPattern.validate("^refs/heads/tmp/sdk/[0-9]{3,3}_R[1-9][A-Z][0-9]{3,3}*");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -918,26 +866,43 @@ public class RefControlTest {
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
all.put(pc.getName(),
|
||||
new ProjectState(sitePaths, projectCache, allProjectsName, allUsersName,
|
||||
projectControlFactory, envFactory, repoManager, rulesCache,
|
||||
commentLinks, capabilityCollectionFactory, pc));
|
||||
all.put(
|
||||
pc.getName(),
|
||||
new ProjectState(
|
||||
sitePaths,
|
||||
projectCache,
|
||||
allProjectsName,
|
||||
allUsersName,
|
||||
projectControlFactory,
|
||||
envFactory,
|
||||
repoManager,
|
||||
rulesCache,
|
||||
commentLinks,
|
||||
capabilityCollectionFactory,
|
||||
pc));
|
||||
return repo;
|
||||
}
|
||||
|
||||
private ProjectControl user(ProjectConfig local,
|
||||
AccountGroup.UUID... memberOf) {
|
||||
private ProjectControl user(ProjectConfig local, AccountGroup.UUID... memberOf) {
|
||||
return user(local, null, memberOf);
|
||||
}
|
||||
|
||||
private ProjectControl user(ProjectConfig local, String name,
|
||||
AccountGroup.UUID... memberOf) {
|
||||
private ProjectControl user(ProjectConfig local, String name, AccountGroup.UUID... memberOf) {
|
||||
String canonicalWebUrl = "http://localhost";
|
||||
|
||||
return new ProjectControl(Collections.<AccountGroup.UUID> emptySet(),
|
||||
Collections.<AccountGroup.UUID> emptySet(), projectCache,
|
||||
sectionSorter, null, changeControlFactory, null, queryProvider, null,
|
||||
canonicalWebUrl, new MockUser(name, memberOf), newProjectState(local));
|
||||
return new ProjectControl(
|
||||
Collections.<AccountGroup.UUID>emptySet(),
|
||||
Collections.<AccountGroup.UUID>emptySet(),
|
||||
projectCache,
|
||||
sectionSorter,
|
||||
null,
|
||||
changeControlFactory,
|
||||
null,
|
||||
queryProvider,
|
||||
null,
|
||||
canonicalWebUrl,
|
||||
new MockUser(name, memberOf),
|
||||
newProjectState(local));
|
||||
}
|
||||
|
||||
private ProjectState newProjectState(ProjectConfig local) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Util {
|
||||
@@ -32,7 +31,8 @@ public class Util {
|
||||
public static final AccountGroup.UUID DEVS = new AccountGroup.UUID("test.devs");
|
||||
|
||||
public static final LabelType codeReview() {
|
||||
return category("Code-Review",
|
||||
return category(
|
||||
"Code-Review",
|
||||
value(2, "Looks good to me, approved"),
|
||||
value(1, "Looks good to me, but someone else must approve"),
|
||||
value(0, "No score"),
|
||||
@@ -41,16 +41,12 @@ public class Util {
|
||||
}
|
||||
|
||||
public static final LabelType verified() {
|
||||
return category("Verified",
|
||||
value(1, "Verified"),
|
||||
value(0, "No score"),
|
||||
value(-1, "Fails"));
|
||||
return category("Verified", value(1, "Verified"), value(0, "No score"), value(-1, "Fails"));
|
||||
}
|
||||
|
||||
public static final LabelType patchSetLock() {
|
||||
LabelType label = category("Patch-Set-Lock",
|
||||
value(1, "Patch Set Locked"),
|
||||
value(0, "Patch Set Unlocked"));
|
||||
LabelType label =
|
||||
category("Patch-Set-Lock", value(1, "Patch Set Locked"), value(0, "Patch Set Unlocked"));
|
||||
label.setFunctionName("PatchSetLock");
|
||||
return label;
|
||||
}
|
||||
@@ -63,16 +59,19 @@ public class Util {
|
||||
return new LabelType(name, Arrays.asList(values));
|
||||
}
|
||||
|
||||
public static PermissionRule newRule(ProjectConfig project,
|
||||
AccountGroup.UUID groupUUID) {
|
||||
public static PermissionRule newRule(ProjectConfig project, AccountGroup.UUID groupUUID) {
|
||||
GroupReference group = new GroupReference(groupUUID, groupUUID.get());
|
||||
group = project.resolve(group);
|
||||
|
||||
return new PermissionRule(group);
|
||||
}
|
||||
|
||||
public static PermissionRule allow(ProjectConfig project,
|
||||
String permissionName, int min, int max, AccountGroup.UUID group,
|
||||
public static PermissionRule allow(
|
||||
ProjectConfig project,
|
||||
String permissionName,
|
||||
int min,
|
||||
int max,
|
||||
AccountGroup.UUID group,
|
||||
String ref) {
|
||||
PermissionRule rule = newRule(project, group);
|
||||
rule.setMin(min);
|
||||
@@ -80,8 +79,12 @@ public class Util {
|
||||
return grant(project, permissionName, rule, ref);
|
||||
}
|
||||
|
||||
public static PermissionRule block(ProjectConfig project,
|
||||
String permissionName, int min, int max, AccountGroup.UUID group,
|
||||
public static PermissionRule block(
|
||||
ProjectConfig project,
|
||||
String permissionName,
|
||||
int min,
|
||||
int max,
|
||||
AccountGroup.UUID group,
|
||||
String ref) {
|
||||
PermissionRule rule = newRule(project, group);
|
||||
rule.setMin(min);
|
||||
@@ -91,102 +94,104 @@ public class Util {
|
||||
return r;
|
||||
}
|
||||
|
||||
public static PermissionRule allow(ProjectConfig project,
|
||||
String permissionName, AccountGroup.UUID group, String ref) {
|
||||
public static PermissionRule allow(
|
||||
ProjectConfig project, String permissionName, AccountGroup.UUID group, String ref) {
|
||||
return grant(project, permissionName, newRule(project, group), ref);
|
||||
}
|
||||
|
||||
public static PermissionRule allow(ProjectConfig project,
|
||||
String permissionName, AccountGroup.UUID group, String ref,
|
||||
public static PermissionRule allow(
|
||||
ProjectConfig project,
|
||||
String permissionName,
|
||||
AccountGroup.UUID group,
|
||||
String ref,
|
||||
boolean exclusive) {
|
||||
return grant(project, permissionName, newRule(project, group), ref,
|
||||
exclusive);
|
||||
return grant(project, permissionName, newRule(project, group), ref, exclusive);
|
||||
}
|
||||
|
||||
public static PermissionRule allow(ProjectConfig project,
|
||||
String capabilityName, AccountGroup.UUID group) {
|
||||
public static PermissionRule allow(
|
||||
ProjectConfig project, String capabilityName, AccountGroup.UUID group) {
|
||||
PermissionRule rule = newRule(project, group);
|
||||
project.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
|
||||
project
|
||||
.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
|
||||
.getPermission(capabilityName, true)
|
||||
.add(rule);
|
||||
if (GlobalCapability.hasRange(capabilityName)) {
|
||||
PermissionRange.WithDefaults range =
|
||||
GlobalCapability.getRange(capabilityName);
|
||||
if (range != null) {
|
||||
rule.setRange(range.getDefaultMin(), range.getDefaultMax());
|
||||
}
|
||||
if (GlobalCapability.hasRange(capabilityName)) {
|
||||
PermissionRange.WithDefaults range = GlobalCapability.getRange(capabilityName);
|
||||
if (range != null) {
|
||||
rule.setRange(range.getDefaultMin(), range.getDefaultMax());
|
||||
}
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
public static PermissionRule remove(ProjectConfig project,
|
||||
String capabilityName, AccountGroup.UUID group) {
|
||||
public static PermissionRule remove(
|
||||
ProjectConfig project, String capabilityName, AccountGroup.UUID group) {
|
||||
PermissionRule rule = newRule(project, group);
|
||||
project.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
|
||||
project
|
||||
.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
|
||||
.getPermission(capabilityName, true)
|
||||
.remove(rule);
|
||||
return rule;
|
||||
}
|
||||
|
||||
public static PermissionRule remove(ProjectConfig project,
|
||||
String permissionName, AccountGroup.UUID group, String ref) {
|
||||
public static PermissionRule remove(
|
||||
ProjectConfig project, String permissionName, AccountGroup.UUID group, String ref) {
|
||||
PermissionRule rule = newRule(project, group);
|
||||
project.getAccessSection(ref, true)
|
||||
.getPermission(permissionName, true)
|
||||
.remove(rule);
|
||||
project.getAccessSection(ref, true).getPermission(permissionName, true).remove(rule);
|
||||
return rule;
|
||||
}
|
||||
|
||||
public static PermissionRule block(ProjectConfig project,
|
||||
String capabilityName, AccountGroup.UUID group) {
|
||||
public static PermissionRule block(
|
||||
ProjectConfig project, String capabilityName, AccountGroup.UUID group) {
|
||||
PermissionRule rule = newRule(project, group);
|
||||
project.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
|
||||
project
|
||||
.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
|
||||
.getPermission(capabilityName, true)
|
||||
.add(rule);
|
||||
return rule;
|
||||
}
|
||||
|
||||
public static PermissionRule block(ProjectConfig project,
|
||||
String permissionName, AccountGroup.UUID group, String ref) {
|
||||
public static PermissionRule block(
|
||||
ProjectConfig project, String permissionName, AccountGroup.UUID group, String ref) {
|
||||
PermissionRule r = grant(project, permissionName, newRule(project, group), ref);
|
||||
r.setBlock();
|
||||
return r;
|
||||
}
|
||||
|
||||
public static PermissionRule blockLabel(ProjectConfig project,
|
||||
String labelName, AccountGroup.UUID group, String ref) {
|
||||
PermissionRule r =
|
||||
grant(project, Permission.LABEL + labelName, newRule(project, group),
|
||||
ref);
|
||||
public static PermissionRule blockLabel(
|
||||
ProjectConfig project, String labelName, AccountGroup.UUID group, String ref) {
|
||||
PermissionRule r = grant(project, Permission.LABEL + labelName, newRule(project, group), ref);
|
||||
r.setBlock();
|
||||
r.setRange(-1, 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static PermissionRule deny(ProjectConfig project,
|
||||
String permissionName, AccountGroup.UUID group, String ref) {
|
||||
public static PermissionRule deny(
|
||||
ProjectConfig project, String permissionName, AccountGroup.UUID group, String ref) {
|
||||
PermissionRule r = grant(project, permissionName, newRule(project, group), ref);
|
||||
r.setDeny();
|
||||
return r;
|
||||
}
|
||||
|
||||
public static void doNotInherit(ProjectConfig project, String permissionName,
|
||||
String ref) {
|
||||
project.getAccessSection(ref, true) //
|
||||
public static void doNotInherit(ProjectConfig project, String permissionName, String ref) {
|
||||
project
|
||||
.getAccessSection(ref, true) //
|
||||
.getPermission(permissionName, true) //
|
||||
.setExclusiveGroup(true);
|
||||
}
|
||||
|
||||
private static PermissionRule grant(ProjectConfig project,
|
||||
String permissionName, PermissionRule rule, String ref) {
|
||||
private static PermissionRule grant(
|
||||
ProjectConfig project, String permissionName, PermissionRule rule, String ref) {
|
||||
return grant(project, permissionName, rule, ref, false);
|
||||
}
|
||||
|
||||
private static PermissionRule grant(ProjectConfig project,
|
||||
String permissionName, PermissionRule rule, String ref,
|
||||
private static PermissionRule grant(
|
||||
ProjectConfig project,
|
||||
String permissionName,
|
||||
PermissionRule rule,
|
||||
String ref,
|
||||
boolean exclusive) {
|
||||
Permission permission = project.getAccessSection(ref, true)
|
||||
.getPermission(permissionName, true);
|
||||
Permission permission = project.getAccessSection(ref, true).getPermission(permissionName, true);
|
||||
if (exclusive) {
|
||||
permission.setExclusiveGroup(exclusive);
|
||||
}
|
||||
@@ -194,6 +199,5 @@ public class Util {
|
||||
return rule;
|
||||
}
|
||||
|
||||
private Util() {
|
||||
}
|
||||
private Util() {}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AndPredicateTest extends PredicateTest {
|
||||
@Test
|
||||
@@ -69,8 +68,8 @@ public class AndPredicateTest extends PredicateTest {
|
||||
assertChildren("iterator().remove()", n, of(a, b));
|
||||
}
|
||||
|
||||
private static void assertChildren(String o, Predicate<String> p,
|
||||
List<? extends Predicate<String>> l) {
|
||||
private static void assertChildren(
|
||||
String o, Predicate<String> p, List<? extends Predicate<String>> l) {
|
||||
assertEquals(o + " did not affect child", l, p.getChildren());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FieldPredicateTest extends PredicateTest {
|
||||
@Test
|
||||
@@ -58,7 +57,7 @@ public class FieldPredicateTest extends PredicateTest {
|
||||
@Test
|
||||
public void testCopy() {
|
||||
final OperatorPredicate<String> f = f("author", "alice");
|
||||
assertSame(f, f.copy(Collections.<Predicate<String>> emptyList()));
|
||||
assertSame(f, f.copy(Collections.<Predicate<String>>emptyList()));
|
||||
assertSame(f, f.copy(f.getChildren()));
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
|
||||
@@ -23,10 +23,9 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NotPredicateTest extends PredicateTest {
|
||||
@Test
|
||||
@@ -64,8 +63,7 @@ public class NotPredicateTest extends PredicateTest {
|
||||
assertOnlyChild("remove(0)", p, n);
|
||||
}
|
||||
|
||||
private static void assertOnlyChild(String o, Predicate<String> c,
|
||||
Predicate<String> p) {
|
||||
private static void assertOnlyChild(String o, Predicate<String> c, Predicate<String> p) {
|
||||
assertEquals(o + " did not affect child", 1, p.getChildCount());
|
||||
assertSame(o + " did not affect child", c, p.getChild(0));
|
||||
}
|
||||
@@ -105,7 +103,7 @@ public class NotPredicateTest extends PredicateTest {
|
||||
assertEquals(sb, n.copy(sb).getChildren());
|
||||
|
||||
try {
|
||||
n.copy(Collections.<Predicate> emptyList());
|
||||
n.copy(Collections.<Predicate>emptyList());
|
||||
fail("Expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Expected exactly one child", e.getMessage());
|
||||
|
||||
@@ -23,9 +23,8 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OrPredicateTest extends PredicateTest {
|
||||
@Test
|
||||
@@ -69,8 +68,8 @@ public class OrPredicateTest extends PredicateTest {
|
||||
assertChildren("iterator().remove()", n, of(a, b));
|
||||
}
|
||||
|
||||
private static void assertChildren(String o, Predicate<String> p,
|
||||
List<? extends Predicate<String>> l) {
|
||||
private static void assertChildren(
|
||||
String o, Predicate<String> p, List<? extends Predicate<String>> l) {
|
||||
assertEquals(o + " did not affect child", l, p.getChildren());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.server.query;
|
||||
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.query;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.antlr.runtime.tree.Tree;
|
||||
@@ -30,8 +31,7 @@ public class QueryParserTest {
|
||||
assertSingleWord("project", "tools/*", r);
|
||||
}
|
||||
|
||||
private static void assertSingleWord(final String name, final String value,
|
||||
final Tree r) {
|
||||
private static void assertSingleWord(final String name, final String value, final Tree r) {
|
||||
assertEquals(QueryParser.FIELD_NAME, r.getType());
|
||||
assertEquals(name, r.getText());
|
||||
assertEquals(1, r.getChildCount());
|
||||
|
||||
@@ -51,7 +51,11 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -60,12 +64,6 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@Ignore
|
||||
public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
@ConfigSuite.Default
|
||||
@@ -75,41 +73,29 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final TestName testName = new TestName();
|
||||
@Rule public final TestName testName = new TestName();
|
||||
|
||||
@Inject
|
||||
protected AccountCache accountCache;
|
||||
@Inject protected AccountCache accountCache;
|
||||
|
||||
@Inject
|
||||
protected AccountManager accountManager;
|
||||
@Inject protected AccountManager accountManager;
|
||||
|
||||
@Inject
|
||||
protected GerritApi gApi;
|
||||
@Inject protected GerritApi gApi;
|
||||
|
||||
@Inject
|
||||
protected IdentifiedUser.GenericFactory userFactory;
|
||||
@Inject protected IdentifiedUser.GenericFactory userFactory;
|
||||
|
||||
@Inject
|
||||
private Provider<AnonymousUser> anonymousUser;
|
||||
@Inject private Provider<AnonymousUser> anonymousUser;
|
||||
|
||||
@Inject
|
||||
protected InMemoryDatabase schemaFactory;
|
||||
@Inject protected InMemoryDatabase schemaFactory;
|
||||
|
||||
@Inject
|
||||
protected SchemaCreator schemaCreator;
|
||||
@Inject protected SchemaCreator schemaCreator;
|
||||
|
||||
@Inject
|
||||
protected ThreadLocalRequestContext requestContext;
|
||||
@Inject protected ThreadLocalRequestContext requestContext;
|
||||
|
||||
@Inject
|
||||
protected OneOffRequestContext oneOffRequestContext;
|
||||
@Inject protected OneOffRequestContext oneOffRequestContext;
|
||||
|
||||
@Inject
|
||||
protected InternalAccountQuery internalAccountQuery;
|
||||
@Inject protected InternalAccountQuery internalAccountQuery;
|
||||
|
||||
@Inject
|
||||
protected AllProjectsName allProjects;
|
||||
@Inject protected AllProjectsName allProjects;
|
||||
|
||||
protected LifecycleManager lifecycle;
|
||||
protected ReviewDb db;
|
||||
@@ -136,8 +122,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
}
|
||||
|
||||
protected RequestContext newRequestContext(Account.Id requestUserId) {
|
||||
final CurrentUser requestUser =
|
||||
userFactory.create(requestUserId);
|
||||
final CurrentUser requestUser = userFactory.create(requestUserId);
|
||||
return new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
@@ -152,17 +137,18 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
}
|
||||
|
||||
protected void setAnonymous() {
|
||||
requestContext.setContext(new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return anonymousUser.get();
|
||||
}
|
||||
requestContext.setContext(
|
||||
new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return anonymousUser.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -200,11 +186,9 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
AccountInfo user3 = newAccountWithEmail("user3", "user3@" + domain);
|
||||
|
||||
String prefix = name("prefix");
|
||||
AccountInfo user4 =
|
||||
newAccountWithEmail("user4", prefix + "user4@example.com");
|
||||
AccountInfo user4 = newAccountWithEmail("user4", prefix + "user4@example.com");
|
||||
|
||||
AccountInfo user5 =
|
||||
newAccountWithEmail("user5", name("user5MixedCase@example.com"));
|
||||
AccountInfo user5 = newAccountWithEmail("user5", name("user5MixedCase@example.com"));
|
||||
|
||||
assertQuery("notexisting@test.com");
|
||||
|
||||
@@ -332,8 +316,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
|
||||
@Test
|
||||
public void withDetails() throws Exception {
|
||||
AccountInfo user1 =
|
||||
newAccount("myuser", "My User", "my.user@example.com", true);
|
||||
AccountInfo user1 = newAccount("myuser", "My User", "my.user@example.com", true);
|
||||
|
||||
List<AccountInfo> result = assertQuery(user1.username, user1);
|
||||
AccountInfo ai = result.get(0);
|
||||
@@ -343,8 +326,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
assertThat(ai.email).isNull();
|
||||
assertThat(ai.avatars).isNull();
|
||||
|
||||
result = assertQuery(
|
||||
newQuery(user1.username).withOption(ListAccountsOption.DETAILS), user1);
|
||||
result = assertQuery(newQuery(user1.username).withOption(ListAccountsOption.DETAILS), user1);
|
||||
ai = result.get(0);
|
||||
assertThat(ai._accountId).isEqualTo(user1._accountId);
|
||||
assertThat(ai.name).isEqualTo(user1.name);
|
||||
@@ -355,30 +337,29 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
|
||||
@Test
|
||||
public void withSecondaryEmails() throws Exception {
|
||||
AccountInfo user1 =
|
||||
newAccount("myuser", "My User", "my.user@example.com", true);
|
||||
String[] secondaryEmails =
|
||||
new String[] {"bar@example.com", "foo@example.com"};
|
||||
AccountInfo user1 = newAccount("myuser", "My User", "my.user@example.com", true);
|
||||
String[] secondaryEmails = new String[] {"bar@example.com", "foo@example.com"};
|
||||
addEmails(user1, secondaryEmails);
|
||||
|
||||
|
||||
List<AccountInfo> result = assertQuery(user1.username, user1);
|
||||
assertThat(result.get(0).secondaryEmails).isNull();
|
||||
|
||||
result = assertQuery(
|
||||
newQuery(user1.username).withOption(ListAccountsOption.DETAILS), user1);
|
||||
result = assertQuery(newQuery(user1.username).withOption(ListAccountsOption.DETAILS), user1);
|
||||
assertThat(result.get(0).secondaryEmails).isNull();
|
||||
|
||||
result = assertQuery(
|
||||
newQuery(user1.username).withOption(ListAccountsOption.ALL_EMAILS),
|
||||
user1);
|
||||
result = assertQuery(newQuery(user1.username).withOption(ListAccountsOption.ALL_EMAILS), user1);
|
||||
assertThat(result.get(0).secondaryEmails)
|
||||
.containsExactlyElementsIn(Arrays.asList(secondaryEmails)).inOrder();
|
||||
.containsExactlyElementsIn(Arrays.asList(secondaryEmails))
|
||||
.inOrder();
|
||||
|
||||
result = assertQuery(newQuery(user1.username).withOptions(
|
||||
ListAccountsOption.DETAILS, ListAccountsOption.ALL_EMAILS), user1);
|
||||
result =
|
||||
assertQuery(
|
||||
newQuery(user1.username)
|
||||
.withOptions(ListAccountsOption.DETAILS, ListAccountsOption.ALL_EMAILS),
|
||||
user1);
|
||||
assertThat(result.get(0).secondaryEmails)
|
||||
.containsExactlyElementsIn(Arrays.asList(secondaryEmails)).inOrder();
|
||||
.containsExactlyElementsIn(Arrays.asList(secondaryEmails))
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -414,23 +395,20 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
return newAccountWithEmail(username, null);
|
||||
}
|
||||
|
||||
protected AccountInfo newAccountWithEmail(String username, String email)
|
||||
throws Exception {
|
||||
protected AccountInfo newAccountWithEmail(String username, String email) throws Exception {
|
||||
return newAccount(username, email, true);
|
||||
}
|
||||
|
||||
protected AccountInfo newAccountWithFullName(String username, String fullName)
|
||||
throws Exception {
|
||||
protected AccountInfo newAccountWithFullName(String username, String fullName) throws Exception {
|
||||
return newAccount(username, fullName, null, true);
|
||||
}
|
||||
|
||||
protected AccountInfo newAccount(String username, String email,
|
||||
boolean active) throws Exception {
|
||||
protected AccountInfo newAccount(String username, String email, boolean active) throws Exception {
|
||||
return newAccount(username, null, email, active);
|
||||
}
|
||||
|
||||
protected AccountInfo newAccount(String username, String fullName,
|
||||
String email, boolean active) throws Exception {
|
||||
protected AccountInfo newAccount(String username, String fullName, String email, boolean active)
|
||||
throws Exception {
|
||||
String uniqueName = name(username);
|
||||
|
||||
try {
|
||||
@@ -449,8 +427,8 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
return new Project.NameKey(name);
|
||||
}
|
||||
|
||||
protected void watch(AccountInfo account, Project.NameKey project,
|
||||
String filter) throws RestApiException {
|
||||
protected void watch(AccountInfo account, Project.NameKey project, String filter)
|
||||
throws RestApiException {
|
||||
List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
|
||||
ProjectWatchInfo pwi = new ProjectWatchInfo();
|
||||
pwi.project = project.get();
|
||||
@@ -477,11 +455,10 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
return name + "_" + suffix;
|
||||
}
|
||||
|
||||
private Account.Id createAccount(String username, String fullName,
|
||||
String email, boolean active) throws Exception {
|
||||
private Account.Id createAccount(String username, String fullName, String email, boolean active)
|
||||
throws Exception {
|
||||
try (ManualRequestContext ctx = oneOffRequestContext.open()) {
|
||||
Account.Id id =
|
||||
accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
|
||||
Account.Id id = accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
|
||||
if (email != null) {
|
||||
accountManager.link(id, AuthRequest.forEmail(email));
|
||||
}
|
||||
@@ -495,8 +472,7 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void addEmails(AccountInfo account, String... emails)
|
||||
throws Exception {
|
||||
private void addEmails(AccountInfo account, String... emails) throws Exception {
|
||||
Account.Id id = new Account.Id(account._accountId);
|
||||
for (String email : emails) {
|
||||
accountManager.link(id, AuthRequest.forEmail(email));
|
||||
@@ -508,39 +484,36 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
return gApi.accounts().query(query.toString());
|
||||
}
|
||||
|
||||
protected List<AccountInfo> assertQuery(Object query, AccountInfo... accounts)
|
||||
throws Exception {
|
||||
protected List<AccountInfo> assertQuery(Object query, AccountInfo... accounts) throws Exception {
|
||||
return assertQuery(newQuery(query), accounts);
|
||||
}
|
||||
|
||||
protected List<AccountInfo> assertQuery(QueryRequest query,
|
||||
AccountInfo... accounts) throws Exception {
|
||||
protected List<AccountInfo> assertQuery(QueryRequest query, AccountInfo... accounts)
|
||||
throws Exception {
|
||||
return assertQuery(query, Arrays.asList(accounts));
|
||||
}
|
||||
|
||||
|
||||
protected List<AccountInfo> assertQuery(QueryRequest query,
|
||||
List<AccountInfo> accounts) throws Exception {
|
||||
protected List<AccountInfo> assertQuery(QueryRequest query, List<AccountInfo> accounts)
|
||||
throws Exception {
|
||||
List<AccountInfo> result = query.get();
|
||||
Iterable<Integer> ids = ids(result);
|
||||
assertThat(ids).named(format(query, result, accounts))
|
||||
.containsExactlyElementsIn(ids(accounts)).inOrder();
|
||||
assertThat(ids)
|
||||
.named(format(query, result, accounts))
|
||||
.containsExactlyElementsIn(ids(accounts))
|
||||
.inOrder();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void assertAccounts(List<AccountState> accounts,
|
||||
AccountInfo... expectedAccounts) {
|
||||
assertThat(accounts.stream().map(a -> a.getAccount().getId().get())
|
||||
.collect(toList()))
|
||||
.containsExactlyElementsIn(Arrays.asList(expectedAccounts).stream()
|
||||
.map(a -> a._accountId).collect(toList()));
|
||||
protected void assertAccounts(List<AccountState> accounts, AccountInfo... expectedAccounts) {
|
||||
assertThat(accounts.stream().map(a -> a.getAccount().getId().get()).collect(toList()))
|
||||
.containsExactlyElementsIn(
|
||||
Arrays.asList(expectedAccounts).stream().map(a -> a._accountId).collect(toList()));
|
||||
}
|
||||
|
||||
private String format(QueryRequest query, List<AccountInfo> actualIds,
|
||||
List<AccountInfo> expectedAccounts) {
|
||||
private String format(
|
||||
QueryRequest query, List<AccountInfo> actualIds, List<AccountInfo> expectedAccounts) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("query '").append(query.getQuery())
|
||||
.append("' with expected accounts ");
|
||||
b.append("query '").append(query.getQuery()).append("' with expected accounts ");
|
||||
b.append(format(expectedAccounts));
|
||||
b.append(" and result ");
|
||||
b.append(format(actualIds));
|
||||
@@ -553,9 +526,18 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
||||
Iterator<AccountInfo> it = accounts.iterator();
|
||||
while (it.hasNext()) {
|
||||
AccountInfo a = it.next();
|
||||
b.append("{").append(a._accountId).append(", ").append("name=")
|
||||
.append(a.name).append(", ").append("email=").append(a.email)
|
||||
.append(", ").append("username=").append(a.username).append("}");
|
||||
b.append("{")
|
||||
.append(a._accountId)
|
||||
.append(", ")
|
||||
.append("name=")
|
||||
.append(a.name)
|
||||
.append(", ")
|
||||
.append("email=")
|
||||
.append(a.email)
|
||||
.append(", ")
|
||||
.append("username=")
|
||||
.append(a.username)
|
||||
.append("}");
|
||||
if (it.hasNext()) {
|
||||
b.append(", ");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.query.account;
|
||||
import com.google.gerrit.testutil.InMemoryModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class LuceneQueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
@@ -25,7 +24,6 @@ public class LuceneQueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
protected Injector createInjector() {
|
||||
Config luceneConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(luceneConfig);
|
||||
return Guice.createInjector(
|
||||
new InMemoryModule(luceneConfig, notesMigration));
|
||||
return Guice.createInjector(new InMemoryModule(luceneConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,6 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.testutil.TestChanges;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ChangeDataTest {
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.gerrit.testutil.InMemoryModule;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager.Repo;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -31,18 +30,15 @@ public class LuceneQueryChangesTest extends AbstractQueryChangesTest {
|
||||
protected Injector createInjector() {
|
||||
Config luceneConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(luceneConfig);
|
||||
return Guice.createInjector(
|
||||
new InMemoryModule(luceneConfig, notesMigration));
|
||||
return Guice.createInjector(new InMemoryModule(luceneConfig, notesMigration));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullTextWithSpecialChars() throws Exception {
|
||||
TestRepository<Repo> repo = createProject("repo");
|
||||
RevCommit commit1 =
|
||||
repo.parseBody(repo.commit().message("foo_bar_foo").create());
|
||||
RevCommit commit1 = repo.parseBody(repo.commit().message("foo_bar_foo").create());
|
||||
Change change1 = insert(repo, newChangeForCommit(repo, commit1));
|
||||
RevCommit commit2 =
|
||||
repo.parseBody(repo.commit().message("one.two.three").create());
|
||||
RevCommit commit2 = repo.parseBody(repo.commit().message("one.two.three").create());
|
||||
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
|
||||
|
||||
assertQuery("message:foo_ba");
|
||||
|
||||
@@ -20,10 +20,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RegexPathPredicateTest {
|
||||
@Test
|
||||
@@ -85,8 +83,7 @@ public class RegexPathPredicateTest {
|
||||
|
||||
private static ChangeData change(String... files) throws OrmException {
|
||||
Arrays.sort(files);
|
||||
ChangeData cd = ChangeData.createForTest(new Project.NameKey("project"),
|
||||
new Change.Id(1), 1);
|
||||
ChangeData cd = ChangeData.createForTest(new Project.NameKey("project"), new Change.Id(1), 1);
|
||||
cd.setCurrentFilePaths(Arrays.asList(files));
|
||||
return cd;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,11 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -58,12 +62,6 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Ignore
|
||||
public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
@ConfigSuite.Default
|
||||
@@ -73,44 +71,31 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final TestName testName = new TestName();
|
||||
@Rule public final TestName testName = new TestName();
|
||||
|
||||
@Inject
|
||||
protected AccountCache accountCache;
|
||||
@Inject protected AccountCache accountCache;
|
||||
|
||||
@Inject
|
||||
protected AccountManager accountManager;
|
||||
@Inject protected AccountManager accountManager;
|
||||
|
||||
@Inject
|
||||
protected GerritApi gApi;
|
||||
@Inject protected GerritApi gApi;
|
||||
|
||||
@Inject
|
||||
protected IdentifiedUser.GenericFactory userFactory;
|
||||
@Inject protected IdentifiedUser.GenericFactory userFactory;
|
||||
|
||||
@Inject
|
||||
private Provider<AnonymousUser> anonymousUser;
|
||||
@Inject private Provider<AnonymousUser> anonymousUser;
|
||||
|
||||
@Inject
|
||||
protected InMemoryDatabase schemaFactory;
|
||||
@Inject protected InMemoryDatabase schemaFactory;
|
||||
|
||||
@Inject
|
||||
protected SchemaCreator schemaCreator;
|
||||
@Inject protected SchemaCreator schemaCreator;
|
||||
|
||||
@Inject
|
||||
protected ThreadLocalRequestContext requestContext;
|
||||
@Inject protected ThreadLocalRequestContext requestContext;
|
||||
|
||||
@Inject
|
||||
protected OneOffRequestContext oneOffRequestContext;
|
||||
@Inject protected OneOffRequestContext oneOffRequestContext;
|
||||
|
||||
@Inject
|
||||
protected InternalAccountQuery internalAccountQuery;
|
||||
@Inject protected InternalAccountQuery internalAccountQuery;
|
||||
|
||||
@Inject
|
||||
protected AllProjectsName allProjects;
|
||||
@Inject protected AllProjectsName allProjects;
|
||||
|
||||
@Inject
|
||||
protected GroupCache groupCache;
|
||||
@Inject protected GroupCache groupCache;
|
||||
|
||||
protected LifecycleManager lifecycle;
|
||||
protected ReviewDb db;
|
||||
@@ -137,8 +122,7 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
}
|
||||
|
||||
protected RequestContext newRequestContext(Account.Id requestUserId) {
|
||||
final CurrentUser requestUser =
|
||||
userFactory.create(requestUserId);
|
||||
final CurrentUser requestUser = userFactory.create(requestUserId);
|
||||
return new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
@@ -153,17 +137,18 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
}
|
||||
|
||||
protected void setAnonymous() {
|
||||
requestContext.setContext(new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return anonymousUser.get();
|
||||
}
|
||||
requestContext.setContext(
|
||||
new RequestContext() {
|
||||
@Override
|
||||
public CurrentUser getUser() {
|
||||
return anonymousUser.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Provider<ReviewDb> getReviewDbProvider() {
|
||||
return Providers.of(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -211,18 +196,14 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
GroupInfo group2 = createGroup("group-" + namePart + "-2");
|
||||
GroupInfo group3 = createGroup("group-" + namePart + "3");
|
||||
assertQuery("inname:" + namePart, group1, group2, group3);
|
||||
assertQuery("inname:" + namePart.toUpperCase(Locale.US), group1, group2,
|
||||
group3);
|
||||
assertQuery("inname:" + namePart.toLowerCase(Locale.US), group1, group2,
|
||||
group3);
|
||||
assertQuery("inname:" + namePart.toUpperCase(Locale.US), group1, group2, group3);
|
||||
assertQuery("inname:" + namePart.toLowerCase(Locale.US), group1, group2, group3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byDescription() throws Exception {
|
||||
GroupInfo group1 =
|
||||
createGroupWithDescription(name("group1"), "This is a test group.");
|
||||
GroupInfo group2 =
|
||||
createGroupWithDescription(name("group2"), "ANOTHER TEST GROUP.");
|
||||
GroupInfo group1 = createGroupWithDescription(name("group1"), "This is a test group.");
|
||||
GroupInfo group2 = createGroupWithDescription(name("group2"), "ANOTHER TEST GROUP.");
|
||||
createGroupWithDescription(name("group3"), "Maintainers of project foo.");
|
||||
assertQuery("description:test", group1, group2);
|
||||
|
||||
@@ -260,8 +241,9 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
public void byDefaultField() throws Exception {
|
||||
GroupInfo group1 = createGroup(name("foo-group"));
|
||||
GroupInfo group2 = createGroup(name("group2"));
|
||||
GroupInfo group3 = createGroupWithDescription(name("group3"),
|
||||
"decription that contains foo and the UUID of group2: " + group2.id);
|
||||
GroupInfo group3 =
|
||||
createGroupWithDescription(
|
||||
name("group3"), "decription that contains foo and the UUID of group2: " + group2.id);
|
||||
|
||||
assertQuery("non-existing");
|
||||
assertQuery("foo", group1, group3);
|
||||
@@ -274,8 +256,7 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
GroupInfo group2 = createGroup(name("group2"));
|
||||
GroupInfo group3 = createGroup(name("group3"));
|
||||
|
||||
String query =
|
||||
"uuid:" + group1.id + " OR uuid:" + group2.id + " OR uuid:" + group3.id;
|
||||
String query = "uuid:" + group1.id + " OR uuid:" + group2.id + " OR uuid:" + group3.id;
|
||||
List<GroupInfo> result = assertQuery(query, group1, group2, group3);
|
||||
assertThat(result.get(result.size() - 1)._moreGroups).isNull();
|
||||
|
||||
@@ -289,8 +270,7 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
GroupInfo group2 = createGroup(name("group2"));
|
||||
GroupInfo group3 = createGroup(name("group3"));
|
||||
|
||||
String query =
|
||||
"uuid:" + group1.id + " OR uuid:" + group2.id + " OR uuid:" + group3.id;
|
||||
String query = "uuid:" + group1.id + " OR uuid:" + group2.id + " OR uuid:" + group3.id;
|
||||
List<GroupInfo> result = assertQuery(query, group1, group2, group3);
|
||||
|
||||
assertQuery(newQuery(query).withStart(1), result.subList(1, 3));
|
||||
@@ -311,8 +291,7 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
|
||||
// update group in the database so that group index is stale
|
||||
String newDescription = "barY";
|
||||
AccountGroup group =
|
||||
db.accountGroups().get(new AccountGroup.Id(group1.groupId));
|
||||
AccountGroup group = db.accountGroups().get(new AccountGroup.Id(group1.groupId));
|
||||
group.setDescription(newDescription);
|
||||
db.accountGroups().update(Collections.singleton(group));
|
||||
|
||||
@@ -324,11 +303,10 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
assertQuery("description:" + newDescription, group1);
|
||||
}
|
||||
|
||||
private Account.Id createAccount(String username, String fullName,
|
||||
String email, boolean active) throws Exception {
|
||||
private Account.Id createAccount(String username, String fullName, String email, boolean active)
|
||||
throws Exception {
|
||||
try (ManualRequestContext ctx = oneOffRequestContext.open()) {
|
||||
Account.Id id =
|
||||
accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
|
||||
Account.Id id = accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
|
||||
if (email != null) {
|
||||
accountManager.link(id, AuthRequest.forEmail(email));
|
||||
}
|
||||
@@ -342,31 +320,28 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
protected GroupInfo createGroup(String name, AccountInfo... members)
|
||||
throws Exception {
|
||||
protected GroupInfo createGroup(String name, AccountInfo... members) throws Exception {
|
||||
return createGroupWithDescription(name, null, members);
|
||||
}
|
||||
|
||||
protected GroupInfo createGroupWithDescription(String name,
|
||||
String description, AccountInfo... members) throws Exception {
|
||||
protected GroupInfo createGroupWithDescription(
|
||||
String name, String description, AccountInfo... members) throws Exception {
|
||||
GroupInput in = new GroupInput();
|
||||
in.name = name;
|
||||
in.description = description;
|
||||
in.members = Arrays.asList(members).stream()
|
||||
.map(a -> String.valueOf(a._accountId)).collect(toList());
|
||||
in.members =
|
||||
Arrays.asList(members).stream().map(a -> String.valueOf(a._accountId)).collect(toList());
|
||||
return gApi.groups().create(in).get();
|
||||
}
|
||||
|
||||
protected GroupInfo createGroupWithOwner(String name, GroupInfo ownerGroup)
|
||||
throws Exception {
|
||||
protected GroupInfo createGroupWithOwner(String name, GroupInfo ownerGroup) throws Exception {
|
||||
GroupInput in = new GroupInput();
|
||||
in.name = name;
|
||||
in.ownerId = ownerGroup.id;
|
||||
return gApi.groups().create(in).get();
|
||||
}
|
||||
|
||||
protected GroupInfo createGroupThatIsVisibleToAll(String name)
|
||||
throws Exception {
|
||||
protected GroupInfo createGroupThatIsVisibleToAll(String name) throws Exception {
|
||||
GroupInput in = new GroupInput();
|
||||
in.name = name;
|
||||
in.visibleToAll = true;
|
||||
@@ -377,22 +352,19 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
return gApi.groups().id(uuid.get()).get();
|
||||
}
|
||||
|
||||
protected List<GroupInfo> assertQuery(Object query, GroupInfo... groups)
|
||||
throws Exception {
|
||||
protected List<GroupInfo> assertQuery(Object query, GroupInfo... groups) throws Exception {
|
||||
return assertQuery(newQuery(query), groups);
|
||||
}
|
||||
|
||||
protected List<GroupInfo> assertQuery(QueryRequest query,
|
||||
GroupInfo... groups) throws Exception {
|
||||
protected List<GroupInfo> assertQuery(QueryRequest query, GroupInfo... groups) throws Exception {
|
||||
return assertQuery(query, Arrays.asList(groups));
|
||||
}
|
||||
|
||||
protected List<GroupInfo> assertQuery(QueryRequest query,
|
||||
List<GroupInfo> groups) throws Exception {
|
||||
protected List<GroupInfo> assertQuery(QueryRequest query, List<GroupInfo> groups)
|
||||
throws Exception {
|
||||
List<GroupInfo> result = query.get();
|
||||
Iterable<String> uuids = uuids(result);
|
||||
assertThat(uuids).named(format(query, result, groups))
|
||||
.containsExactlyElementsIn(uuids(groups));
|
||||
assertThat(uuids).named(format(query, result, groups)).containsExactlyElementsIn(uuids(groups));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -400,11 +372,10 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
return gApi.groups().query(query.toString());
|
||||
}
|
||||
|
||||
protected String format(QueryRequest query, List<GroupInfo> actualGroups,
|
||||
List<GroupInfo> expectedGroups) {
|
||||
protected String format(
|
||||
QueryRequest query, List<GroupInfo> actualGroups, List<GroupInfo> expectedGroups) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("query '").append(query.getQuery())
|
||||
.append("' with expected groups ");
|
||||
b.append("query '").append(query.getQuery()).append("' with expected groups ");
|
||||
b.append(format(expectedGroups));
|
||||
b.append(" and result ");
|
||||
b.append(format(actualGroups));
|
||||
@@ -417,13 +388,30 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
||||
Iterator<GroupInfo> it = groups.iterator();
|
||||
while (it.hasNext()) {
|
||||
GroupInfo g = it.next();
|
||||
b.append("{").append(g.id).append(", ").append("name=").append(g.name)
|
||||
.append(", ").append("groupId=").append(g.groupId).append(", ")
|
||||
.append("url=").append(g.url).append(", ").append("ownerId=")
|
||||
.append(g.ownerId).append(", ").append("owner=").append(g.owner)
|
||||
.append(", ").append("description=").append(g.description)
|
||||
.append(", ").append("visibleToAll=")
|
||||
.append(toBoolean(g.options.visibleToAll)).append("}");
|
||||
b.append("{")
|
||||
.append(g.id)
|
||||
.append(", ")
|
||||
.append("name=")
|
||||
.append(g.name)
|
||||
.append(", ")
|
||||
.append("groupId=")
|
||||
.append(g.groupId)
|
||||
.append(", ")
|
||||
.append("url=")
|
||||
.append(g.url)
|
||||
.append(", ")
|
||||
.append("ownerId=")
|
||||
.append(g.ownerId)
|
||||
.append(", ")
|
||||
.append("owner=")
|
||||
.append(g.owner)
|
||||
.append(", ")
|
||||
.append("description=")
|
||||
.append(g.description)
|
||||
.append(", ")
|
||||
.append("visibleToAll=")
|
||||
.append(toBoolean(g.options.visibleToAll))
|
||||
.append("}");
|
||||
if (it.hasNext()) {
|
||||
b.append(", ");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.query.group;
|
||||
import com.google.gerrit.testutil.InMemoryModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class LuceneQueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
@@ -25,7 +24,6 @@ public class LuceneQueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
protected Injector createInjector() {
|
||||
Config luceneConfig = new Config(config);
|
||||
InMemoryModule.setDefaults(luceneConfig);
|
||||
return Guice.createInjector(
|
||||
new InMemoryModule(luceneConfig, notesMigration));
|
||||
return Guice.createInjector(new InMemoryModule(luceneConfig, notesMigration));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +30,6 @@ import com.google.gerrit.testutil.InMemoryModule;
|
||||
import com.google.gwtorm.jdbc.JdbcSchema;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
@@ -43,16 +37,17 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SchemaCreatorTest {
|
||||
@Inject
|
||||
private AllProjectsName allProjects;
|
||||
@Inject private AllProjectsName allProjects;
|
||||
|
||||
@Inject
|
||||
private GitRepositoryManager repoManager;
|
||||
@Inject private GitRepositoryManager repoManager;
|
||||
|
||||
@Inject
|
||||
private InMemoryDatabase db;
|
||||
@Inject private InMemoryDatabase db;
|
||||
|
||||
private LifecycleManager lifecycle;
|
||||
|
||||
@@ -72,13 +67,11 @@ public class SchemaCreatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCauses_CreateSchema() throws OrmException, SQLException,
|
||||
IOException {
|
||||
public void getCauses_CreateSchema() throws OrmException, SQLException, IOException {
|
||||
// Initially the schema should be empty.
|
||||
String[] types = {"TABLE", "VIEW"};
|
||||
try (JdbcSchema d = (JdbcSchema) db.open();
|
||||
ResultSet rs = d.getConnection().getMetaData()
|
||||
.getTables(null, null, null, types)) {
|
||||
ResultSet rs = d.getConnection().getMetaData().getTables(null, null, null, types)) {
|
||||
assertThat(rs.next()).isFalse();
|
||||
}
|
||||
|
||||
@@ -93,8 +86,7 @@ public class SchemaCreatorTest {
|
||||
if (sitePath.getName().equals(".")) {
|
||||
sitePath = sitePath.getParentFile();
|
||||
}
|
||||
assertThat(db.getSystemConfig().sitePath)
|
||||
.isEqualTo(sitePath.getCanonicalPath());
|
||||
assertThat(db.getSystemConfig().sitePath).isEqualTo(sitePath.getCanonicalPath());
|
||||
}
|
||||
|
||||
private LabelTypes getLabelTypes() throws Exception {
|
||||
@@ -102,8 +94,7 @@ public class SchemaCreatorTest {
|
||||
ProjectConfig c = new ProjectConfig(allProjects);
|
||||
try (Repository repo = repoManager.openRepository(allProjects)) {
|
||||
c.load(repo);
|
||||
return new LabelTypes(
|
||||
ImmutableList.copyOf(c.getLabelSections().values()));
|
||||
return new LabelTypes(ImmutableList.copyOf(c.getLabelSections().values()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +119,7 @@ public class SchemaCreatorTest {
|
||||
}
|
||||
|
||||
private void assertValueRange(LabelType label, Integer... range) {
|
||||
assertThat(label.getValuesAsList())
|
||||
.containsExactlyElementsIn(Arrays.asList(range)).inOrder();
|
||||
assertThat(label.getValuesAsList()).containsExactlyElementsIn(Arrays.asList(range)).inOrder();
|
||||
assertThat(label.getMax().getValue()).isEqualTo(range[0]);
|
||||
assertThat(label.getMin().getValue()).isEqualTo(range[range.length - 1]);
|
||||
for (LabelValue v : label.getValues()) {
|
||||
|
||||
@@ -39,19 +39,17 @@ import com.google.gwtorm.server.StatementExecutor;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SchemaUpdaterTest {
|
||||
private LifecycleManager lifecycle;
|
||||
@@ -73,53 +71,52 @@ public class SchemaUpdaterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update() throws OrmException, FileNotFoundException,
|
||||
IOException {
|
||||
public void update() throws OrmException, FileNotFoundException, IOException {
|
||||
db.create();
|
||||
|
||||
final Path site = Paths.get(UUID.randomUUID().toString());
|
||||
final SitePaths paths = new SitePaths(site);
|
||||
SchemaUpdater u = Guice.createInjector(new FactoryModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<SchemaFactory<ReviewDb>>() {}).toInstance(db);
|
||||
bind(SitePaths.class).toInstance(paths);
|
||||
SchemaUpdater u =
|
||||
Guice.createInjector(
|
||||
new FactoryModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(new TypeLiteral<SchemaFactory<ReviewDb>>() {}).toInstance(db);
|
||||
bind(SitePaths.class).toInstance(paths);
|
||||
|
||||
Config cfg = new Config();
|
||||
cfg.setString("user", null, "name", "Gerrit Code Review");
|
||||
cfg.setString("user", null, "email", "gerrit@localhost");
|
||||
Config cfg = new Config();
|
||||
cfg.setString("user", null, "name", "Gerrit Code Review");
|
||||
cfg.setString("user", null, "email", "gerrit@localhost");
|
||||
|
||||
bind(Config.class) //
|
||||
.annotatedWith(GerritServerConfig.class) //
|
||||
.toInstance(cfg);
|
||||
bind(Config.class) //
|
||||
.annotatedWith(GerritServerConfig.class) //
|
||||
.toInstance(cfg);
|
||||
|
||||
bind(PersonIdent.class) //
|
||||
.annotatedWith(GerritPersonIdent.class) //
|
||||
.toProvider(GerritPersonIdentProvider.class);
|
||||
bind(PersonIdent.class) //
|
||||
.annotatedWith(GerritPersonIdent.class) //
|
||||
.toProvider(GerritPersonIdentProvider.class);
|
||||
|
||||
bind(AllProjectsName.class)
|
||||
.toInstance(new AllProjectsName("All-Projects"));
|
||||
bind(AllUsersName.class)
|
||||
.toInstance(new AllUsersName("All-Users"));
|
||||
bind(AllProjectsName.class).toInstance(new AllProjectsName("All-Projects"));
|
||||
bind(AllUsersName.class).toInstance(new AllUsersName("All-Users"));
|
||||
|
||||
bind(GitRepositoryManager.class)
|
||||
.toInstance(new InMemoryRepositoryManager());
|
||||
bind(GitRepositoryManager.class).toInstance(new InMemoryRepositoryManager());
|
||||
|
||||
bind(String.class) //
|
||||
.annotatedWith(AnonymousCowardName.class) //
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
bind(String.class) //
|
||||
.annotatedWith(AnonymousCowardName.class) //
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
|
||||
bind(DataSourceType.class).to(InMemoryH2Type.class);
|
||||
bind(DataSourceType.class).to(InMemoryH2Type.class);
|
||||
|
||||
bind(SystemGroupBackend.class);
|
||||
}
|
||||
}).getInstance(SchemaUpdater.class);
|
||||
bind(SystemGroupBackend.class);
|
||||
}
|
||||
})
|
||||
.getInstance(SchemaUpdater.class);
|
||||
|
||||
for (SchemaVersion s = u.getLatestSchemaVersion();
|
||||
s.getVersionNbr() > 1; s = s.getPrior()) {
|
||||
for (SchemaVersion s = u.getLatestSchemaVersion(); s.getVersionNbr() > 1; s = s.getPrior()) {
|
||||
try {
|
||||
assertThat(s.getPrior().getVersionNbr())
|
||||
.named("schema %s has prior version %s. Not true that",
|
||||
.named(
|
||||
"schema %s has prior version %s. Not true that",
|
||||
s.getVersionNbr(), s.getPrior().getVersionNbr())
|
||||
.isEqualTo(s.getVersionNbr() - 1);
|
||||
} catch (ProvisionException e) {
|
||||
@@ -130,33 +127,31 @@ public class SchemaUpdaterTest {
|
||||
}
|
||||
}
|
||||
|
||||
u.update(new UpdateUI() {
|
||||
@Override
|
||||
public void message(String msg) {
|
||||
}
|
||||
u.update(
|
||||
new UpdateUI() {
|
||||
@Override
|
||||
public void message(String msg) {}
|
||||
|
||||
@Override
|
||||
public boolean yesno(boolean def, String msg) {
|
||||
return def;
|
||||
}
|
||||
@Override
|
||||
public boolean yesno(boolean def, String msg) {
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatch() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isBatch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pruneSchema(StatementExecutor e, List<String> pruneList)
|
||||
throws OrmException {
|
||||
for (String sql : pruneList) {
|
||||
e.execute(sql);
|
||||
}
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void pruneSchema(StatementExecutor e, List<String> pruneList) throws OrmException {
|
||||
for (String sql : pruneList) {
|
||||
e.execute(sql);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
db.assertSchemaVersion();
|
||||
final SystemConfig sc = db.getSystemConfig();
|
||||
assertThat(sc.sitePath)
|
||||
.isEqualTo(paths.site_path.toAbsolutePath().toString());
|
||||
assertThat(sc.sitePath).isEqualTo(paths.site_path.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.gerrit.server.util.HostPlatform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import org.eclipse.jgit.dircache.DirCacheBuilder;
|
||||
import org.eclipse.jgit.dircache.DirCacheEntry;
|
||||
import org.eclipse.jgit.lib.CommitBuilder;
|
||||
@@ -35,11 +38,6 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class CommitMsgHookTest extends HookTestCase {
|
||||
private final String SOB1 = "Signed-off-by: J Author <ja@example.com>\n";
|
||||
private final String SOB2 = "Signed-off-by: J Committer <jc@example.com>\n";
|
||||
@@ -80,8 +78,9 @@ public class CommitMsgHookTest extends HookTestCase {
|
||||
hookDoesNotModify("\n# on branch master\n# Untracked files:\n");
|
||||
hookDoesNotModify("\n\n# on branch master\n# Untracked files:\n");
|
||||
|
||||
hookDoesNotModify("\n# on branch master\ndiff --git a/src b/src\n"
|
||||
+ "new file mode 100644\nindex 0000000..c78b7f0\n");
|
||||
hookDoesNotModify(
|
||||
"\n# on branch master\ndiff --git a/src b/src\n"
|
||||
+ "new file mode 100644\nindex 0000000..c78b7f0\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,316 +88,537 @@ public class CommitMsgHookTest extends HookTestCase {
|
||||
// If a Change-Id is already present in the footer, the hook must
|
||||
// not modify the message but instead must leave the identity alone.
|
||||
//
|
||||
hookDoesNotModify("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: Iaeac9b4149291060228ef0154db2985a31111335\n");
|
||||
hookDoesNotModify("fix: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I388bdaf52ed05b55e62a22d0a20d2c1ae0d33e7e\n");
|
||||
hookDoesNotModify("fix-a-widget: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: Id3bc5359d768a6400450283e12bdfb6cd135ea4b\n");
|
||||
hookDoesNotModify("FIX: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I1b55098b5a2cce0b3f3da783dda50d5f79f873fa\n");
|
||||
hookDoesNotModify("Fix-A-Widget: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I4f4e2e1e8568ddc1509baecb8c1270a1fb4b6da7\n");
|
||||
hookDoesNotModify(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: Iaeac9b4149291060228ef0154db2985a31111335\n");
|
||||
hookDoesNotModify(
|
||||
"fix: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I388bdaf52ed05b55e62a22d0a20d2c1ae0d33e7e\n");
|
||||
hookDoesNotModify(
|
||||
"fix-a-widget: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: Id3bc5359d768a6400450283e12bdfb6cd135ea4b\n");
|
||||
hookDoesNotModify(
|
||||
"FIX: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I1b55098b5a2cce0b3f3da783dda50d5f79f873fa\n");
|
||||
hookDoesNotModify(
|
||||
"Fix-A-Widget: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I4f4e2e1e8568ddc1509baecb8c1270a1fb4b6da7\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeAltersId() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n", //
|
||||
call("a\n"));
|
||||
|
||||
tick();
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I3251906b99dda598a58a6346d8126237ee1ea800\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I3251906b99dda598a58a6346d8126237ee1ea800\n", //
|
||||
call("a\n"));
|
||||
|
||||
tick();
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I69adf9208d828f41a3d7e41afbca63aff37c0c5c\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I69adf9208d828f41a3d7e41afbca63aff37c0c5c\n", //
|
||||
call("a\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstParentAltersId() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n", //
|
||||
call("a\n"));
|
||||
|
||||
setHEAD();
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I51e86482bde7f92028541aaf724d3a3f996e7ea2\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I51e86482bde7f92028541aaf724d3a3f996e7ea2\n", //
|
||||
call("a\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dirCacheAltersId() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n", //
|
||||
call("a\n"));
|
||||
|
||||
final DirCacheBuilder builder = repository.lockDirCache().builder();
|
||||
builder.add(file("A"));
|
||||
assertTrue(builder.commit());
|
||||
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: If56597ea9759f23b070677ea6f064c60c38da631\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: If56597ea9759f23b070677ea6f064c60c38da631\n", //
|
||||
call("a\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleLineMessages() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n", //
|
||||
call("a\n"));
|
||||
|
||||
assertEquals("fix: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I0f13d0e6c739ca3ae399a05a93792e80feb97f37\n",//
|
||||
assertEquals(
|
||||
"fix: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I0f13d0e6c739ca3ae399a05a93792e80feb97f37\n", //
|
||||
call("fix: this thing\n"));
|
||||
assertEquals("fix-a-widget: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I1a1a0c751e4273d532e4046a501a612b9b8a775e\n",//
|
||||
assertEquals(
|
||||
"fix-a-widget: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I1a1a0c751e4273d532e4046a501a612b9b8a775e\n", //
|
||||
call("fix-a-widget: this thing\n"));
|
||||
|
||||
assertEquals("FIX: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: If816d944c57d3893b60cf10c65931fead1290d97\n",//
|
||||
assertEquals(
|
||||
"FIX: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: If816d944c57d3893b60cf10c65931fead1290d97\n", //
|
||||
call("FIX: this thing\n"));
|
||||
assertEquals("Fix-A-Widget: this thing\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I3e18d00cbda2ba1f73aeb63ed8c7d57d7fd16c76\n",//
|
||||
assertEquals(
|
||||
"Fix-A-Widget: this thing\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I3e18d00cbda2ba1f73aeb63ed8c7d57d7fd16c76\n", //
|
||||
call("Fix-A-Widget: this thing\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiLineMessagesWithoutFooter() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"b\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: Id0b4f42d3d6fc1569595c9b97cb665e738486f5d\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: Id0b4f42d3d6fc1569595c9b97cb665e738486f5d\n", //
|
||||
call("a\n" + "\n" + "b\n"));
|
||||
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"b\nc\nd\ne\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7d237b20058a0f46cc3f5fabc4a0476877289d75\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b\nc\nd\ne\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7d237b20058a0f46cc3f5fabc4a0476877289d75\n", //
|
||||
call("a\n" + "\n" + "b\nc\nd\ne\n"));
|
||||
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"b\nc\nd\ne\n" + //
|
||||
"\n" + //
|
||||
"f\ng\nh\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n",//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b\nc\nd\ne\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"f\ng\nh\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n", //
|
||||
call("a\n" + "\n" + "b\nc\nd\ne\n" + "\n" + "f\ng\nh\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleLineMessagesWithSignedOffBy() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
|
||||
SOB1,//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n"
|
||||
+ //
|
||||
SOB1, //
|
||||
call("a\n" + "\n" + SOB1));
|
||||
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
|
||||
SOB1 + //
|
||||
SOB2,//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
SOB2, //
|
||||
call("a\n" + "\n" + SOB1 + SOB2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiLineMessagesWithSignedOffBy() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"b\nc\nd\ne\n" + //
|
||||
"\n" + //
|
||||
"f\ng\nh\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n" + //
|
||||
SOB1,//
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b\nc\nd\ne\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"f\ng\nh\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n"
|
||||
+ //
|
||||
SOB1, //
|
||||
call("a\n" + "\n" + "b\nc\nd\ne\n" + "\n" + "f\ng\nh\n" + "\n" + SOB1));
|
||||
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"b\nc\nd\ne\n" + //
|
||||
"\n" + //
|
||||
"f\ng\nh\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n" + //
|
||||
SOB1 + //
|
||||
SOB2,//
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"b\nc\nd\ne\n" + //
|
||||
"\n" + //
|
||||
"f\ng\nh\n" + //
|
||||
"\n" + //
|
||||
SOB1 + //
|
||||
SOB2));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b\nc\nd\ne\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"f\ng\nh\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I382e662f47bf164d6878b7fe61637873ab7fa4e8\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
SOB2, //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b\nc\nd\ne\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"f\ng\nh\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
SOB2));
|
||||
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"b: not a footer\nc\nd\ne\n" + //
|
||||
"\n" + //
|
||||
"f\ng\nh\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I8869aabd44b3017cd55d2d7e0d546a03e3931ee2\n" + //
|
||||
SOB1 + //
|
||||
SOB2,//
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"b: not a footer\nc\nd\ne\n" + //
|
||||
"\n" + //
|
||||
"f\ng\nh\n" + //
|
||||
"\n" + //
|
||||
SOB1 + //
|
||||
SOB2));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b: not a footer\nc\nd\ne\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"f\ng\nh\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I8869aabd44b3017cd55d2d7e0d546a03e3931ee2\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
SOB2, //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"b: not a footer\nc\nd\ne\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"f\ng\nh\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
SOB2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noteInMiddle() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"NOTE: This\n" + //
|
||||
"does not fix it.\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I988a127969a6ee5e58db546aab74fc46e66847f8\n", //
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"NOTE: This\n" + //
|
||||
"does not fix it.\n"));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"NOTE: This\n"
|
||||
+ //
|
||||
"does not fix it.\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I988a127969a6ee5e58db546aab74fc46e66847f8\n", //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"NOTE: This\n"
|
||||
+ //
|
||||
"does not fix it.\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kernelStyleFooter() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I1bd787f9e7590a2ac82b02c404c955ffb21877c4\n" + //
|
||||
SOB1 + //
|
||||
"[ja: Fixed\n" + //
|
||||
" the indentation]\n" + //
|
||||
SOB2, //
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
SOB1 + //
|
||||
"[ja: Fixed\n" + //
|
||||
" the indentation]\n" + //
|
||||
SOB2));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I1bd787f9e7590a2ac82b02c404c955ffb21877c4\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
"[ja: Fixed\n"
|
||||
+ //
|
||||
" the indentation]\n"
|
||||
+ //
|
||||
SOB2, //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
"[ja: Fixed\n"
|
||||
+ //
|
||||
" the indentation]\n"
|
||||
+ //
|
||||
SOB2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeIdAfterBugOrIssue() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Bug: 42\n" + //
|
||||
"Change-Id: I8c0321227c4324e670b9ae8cf40eccc87af21b1b\n" + //
|
||||
SOB1,//
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"Bug: 42\n" + //
|
||||
SOB1));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Bug: 42\n"
|
||||
+ //
|
||||
"Change-Id: I8c0321227c4324e670b9ae8cf40eccc87af21b1b\n"
|
||||
+ //
|
||||
SOB1, //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Bug: 42\n"
|
||||
+ //
|
||||
SOB1));
|
||||
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Issue: 42\n" + //
|
||||
"Change-Id: Ie66e07d89ae5b114c0975b49cf326e90331dd822\n" + //
|
||||
SOB1,//
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"Issue: 42\n" + //
|
||||
SOB1));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Issue: 42\n"
|
||||
+ //
|
||||
"Change-Id: Ie66e07d89ae5b114c0975b49cf326e90331dd822\n"
|
||||
+ //
|
||||
SOB1, //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Issue: 42\n"
|
||||
+ //
|
||||
SOB1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commitDashV() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n" + //
|
||||
SOB1 + //
|
||||
SOB2, //
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
SOB1 + //
|
||||
SOB2 + //
|
||||
"\n" + //
|
||||
"# on branch master\n" + //
|
||||
"diff --git a/src b/src\n" + //
|
||||
"new file mode 100644\n" + //
|
||||
"index 0000000..c78b7f0\n"));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
SOB2, //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
SOB1
|
||||
+ //
|
||||
SOB2
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"# on branch master\n"
|
||||
+ //
|
||||
"diff --git a/src b/src\n"
|
||||
+ //
|
||||
"new file mode 100644\n"
|
||||
+ //
|
||||
"index 0000000..c78b7f0\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withEndingURL() throws Exception {
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"http://example.com/ fixes this\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I3b7e4e16b503ce00f07ba6ad01d97a356dad7701\n", //
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"http://example.com/ fixes this\n"));
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"https://example.com/ fixes this\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I62b9039e2fc0dce274af55e8f99312a8a80a805d\n", //
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"https://example.com/ fixes this\n"));
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"ftp://example.com/ fixes this\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I71b05dc1f6b9a5540a53a693e64d58b65a8910e8\n", //
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"ftp://example.com/ fixes this\n"));
|
||||
assertEquals("a\n" + //
|
||||
"\n" + //
|
||||
"git://example.com/ fixes this\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: Id34e942baa68d790633737d815ddf11bac9183e5\n", //
|
||||
call("a\n" + //
|
||||
"\n" + //
|
||||
"git://example.com/ fixes this\n"));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"http://example.com/ fixes this\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I3b7e4e16b503ce00f07ba6ad01d97a356dad7701\n", //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"http://example.com/ fixes this\n"));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"https://example.com/ fixes this\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I62b9039e2fc0dce274af55e8f99312a8a80a805d\n", //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"https://example.com/ fixes this\n"));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"ftp://example.com/ fixes this\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I71b05dc1f6b9a5540a53a693e64d58b65a8910e8\n", //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"ftp://example.com/ fixes this\n"));
|
||||
assertEquals(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"git://example.com/ fixes this\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: Id34e942baa68d790633737d815ddf11bac9183e5\n", //
|
||||
call(
|
||||
"a\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"git://example.com/ fixes this\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withFalseTags() throws Exception {
|
||||
assertEquals("foo\n" + //
|
||||
"\n" + //
|
||||
"FakeLine:\n" + //
|
||||
" foo\n" + //
|
||||
" bar\n" + //
|
||||
"\n" + //
|
||||
"Change-Id: I67632a37fd2e08a35f766f52fc9a47f4ea868c55\n" + //
|
||||
"RealTag: abc\n", //
|
||||
call("foo\n" + //
|
||||
"\n" + //
|
||||
"FakeLine:\n" + //
|
||||
" foo\n" + //
|
||||
" bar\n" + //
|
||||
"\n" + //
|
||||
"RealTag: abc\n"));
|
||||
assertEquals(
|
||||
"foo\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"FakeLine:\n"
|
||||
+ //
|
||||
" foo\n"
|
||||
+ //
|
||||
" bar\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"Change-Id: I67632a37fd2e08a35f766f52fc9a47f4ea868c55\n"
|
||||
+ //
|
||||
"RealTag: abc\n", //
|
||||
call(
|
||||
"foo\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"FakeLine:\n"
|
||||
+ //
|
||||
" foo\n"
|
||||
+ //
|
||||
" bar\n"
|
||||
+ //
|
||||
"\n"
|
||||
+ //
|
||||
"RealTag: abc\n"));
|
||||
}
|
||||
|
||||
private void hookDoesNotModify(final String in) throws Exception {
|
||||
@@ -439,9 +659,9 @@ public class CommitMsgHookTest extends HookTestCase {
|
||||
ref.setNewObjectId(commitId);
|
||||
Result result = ref.forceUpdate();
|
||||
assert_()
|
||||
.withFailureMessage(Constants.HEAD + " did not change: " + ref.getResult())
|
||||
.that(result)
|
||||
.isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
|
||||
.withFailureMessage(Constants.HEAD + " did not change: " + ref.getResult())
|
||||
.that(result)
|
||||
.isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +53,6 @@ package com.google.gerrit.server.tools.hooks;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -69,6 +62,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public abstract class HookTestCase extends LocalDiskRepositoryTestCase {
|
||||
@@ -105,20 +103,14 @@ public abstract class HookTestCase extends LocalDiskRepositoryTestCase {
|
||||
String path = scproot + "/hooks/" + name;
|
||||
String errorMessage = "Cannot locate " + path + " in CLASSPATH";
|
||||
URL url = cl().getResource(path);
|
||||
assert_()
|
||||
.withFailureMessage(errorMessage)
|
||||
.that(url).isNotNull();
|
||||
assert_().withFailureMessage(errorMessage).that(url).isNotNull();
|
||||
|
||||
String protocol = url.getProtocol();
|
||||
assert_()
|
||||
.withFailureMessage("Cannot invoke " + url)
|
||||
.that(protocol).isAnyOf("file", "jar");
|
||||
assert_().withFailureMessage("Cannot invoke " + url).that(protocol).isAnyOf("file", "jar");
|
||||
|
||||
if ("file".equals(protocol)) {
|
||||
hook = new File(url.getPath());
|
||||
assert_()
|
||||
.withFailureMessage(errorMessage)
|
||||
.that(hook.isFile()).isTrue();
|
||||
assert_().withFailureMessage(errorMessage).that(hook.isFile()).isTrue();
|
||||
long time = hook.lastModified();
|
||||
hook.setExecutable(true);
|
||||
hook.setLastModified(time);
|
||||
|
||||
@@ -17,9 +17,8 @@ package com.google.gerrit.server.util;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IdGeneratorTest {
|
||||
@Test
|
||||
|
||||
@@ -79,15 +79,10 @@ public class LabelVoteTest {
|
||||
|
||||
@Test
|
||||
public void formatWithEquals() {
|
||||
assertEquals("Code-Review=-2",
|
||||
LabelVote.parseWithEquals("Code-Review=-2").formatWithEquals());
|
||||
assertEquals("Code-Review=-1",
|
||||
LabelVote.parseWithEquals("Code-Review=-1").formatWithEquals());
|
||||
assertEquals("Code-Review=0",
|
||||
LabelVote.parseWithEquals("Code-Review=0").formatWithEquals());
|
||||
assertEquals("Code-Review=+1",
|
||||
LabelVote.parseWithEquals("Code-Review=+1").formatWithEquals());
|
||||
assertEquals("Code-Review=+2",
|
||||
LabelVote.parseWithEquals("Code-Review=+2").formatWithEquals());
|
||||
assertEquals("Code-Review=-2", LabelVote.parseWithEquals("Code-Review=-2").formatWithEquals());
|
||||
assertEquals("Code-Review=-1", LabelVote.parseWithEquals("Code-Review=-1").formatWithEquals());
|
||||
assertEquals("Code-Review=0", LabelVote.parseWithEquals("Code-Review=0").formatWithEquals());
|
||||
assertEquals("Code-Review=+1", LabelVote.parseWithEquals("Code-Review=+1").formatWithEquals());
|
||||
assertEquals("Code-Review=+2", LabelVote.parseWithEquals("Code-Review=+2").formatWithEquals());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,8 @@ public class MostSpecificComparatorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming two patterns have the same Levenshtein distance,
|
||||
* the pattern which represents a finite language wins over a pattern
|
||||
* which represents an infinite language.
|
||||
* Assuming two patterns have the same Levenshtein distance, the pattern which represents a finite
|
||||
* language wins over a pattern which represents an infinite language.
|
||||
*/
|
||||
@Test
|
||||
public void finiteWinsOverInfinite() {
|
||||
@@ -45,9 +44,8 @@ public class MostSpecificComparatorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming two patterns have the same Levenshtein distance
|
||||
* and are both either finite or infinite the one with the higher
|
||||
* number of state transitions (in an equivalent automaton) wins
|
||||
* Assuming two patterns have the same Levenshtein distance and are both either finite or infinite
|
||||
* the one with the higher number of state transitions (in an equivalent automaton) wins
|
||||
*/
|
||||
@Test
|
||||
public void higherNumberOfTransitionsWins() {
|
||||
@@ -65,8 +63,8 @@ public class MostSpecificComparatorTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming the same Levenshtein distance, (in)finity and the number
|
||||
* of transitions, the longer pattern wins
|
||||
* Assuming the same Levenshtein distance, (in)finity and the number of transitions, the longer
|
||||
* pattern wins
|
||||
*/
|
||||
@Test
|
||||
public void longerPatternWins() {
|
||||
|
||||
@@ -29,14 +29,14 @@ import org.parboiled.support.ParsingResult;
|
||||
public class ParboiledTest {
|
||||
|
||||
private static final String EXPECTED =
|
||||
"[Expression] '42'\n" +
|
||||
" [Term] '42'\n" +
|
||||
" [Factor] '42'\n" +
|
||||
" [Number] '42'\n" +
|
||||
" [0..9] '4'\n" +
|
||||
" [0..9] '2'\n" +
|
||||
" [zeroOrMore]\n" +
|
||||
" [zeroOrMore]\n";
|
||||
"[Expression] '42'\n"
|
||||
+ " [Term] '42'\n"
|
||||
+ " [Factor] '42'\n"
|
||||
+ " [Number] '42'\n"
|
||||
+ " [0..9] '4'\n"
|
||||
+ " [0..9] '2'\n"
|
||||
+ " [zeroOrMore]\n"
|
||||
+ " [zeroOrMore]\n";
|
||||
|
||||
private CalculatorParser parser;
|
||||
|
||||
@@ -47,8 +47,7 @@ public class ParboiledTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ParsingResult<String> result =
|
||||
new ReportingParseRunner<String>(parser.Expression()).run("42");
|
||||
ParsingResult<String> result = new ReportingParseRunner<String>(parser.Expression()).run("42");
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
// next test is optional; we could stop here.
|
||||
assertThat(ParseTreeUtils.printNodeTree(result)).isEqualTo(EXPECTED);
|
||||
|
||||
@@ -20,10 +20,8 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RegexListSearcherTest {
|
||||
private static final List<String> EMPTY = ImmutableList.of();
|
||||
@@ -55,30 +53,20 @@ public class RegexListSearcherTest {
|
||||
List<String> list = ImmutableList.of("bar", "foo", "quux");
|
||||
assertSearchReturns(ImmutableList.of("foo"), "f.*", list);
|
||||
assertSearchReturns(ImmutableList.of("foo"), ".*o.*", list);
|
||||
assertSearchReturns(ImmutableList.of("bar", "foo", "quux"), ".*[aou].*",
|
||||
list);
|
||||
assertSearchReturns(ImmutableList.of("bar", "foo", "quux"), ".*[aou].*", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commonPrefix() {
|
||||
List<String> list = ImmutableList.of(
|
||||
"bar",
|
||||
"baz",
|
||||
"foo1",
|
||||
"foo2",
|
||||
"foo3",
|
||||
"quux");
|
||||
List<String> list = ImmutableList.of("bar", "baz", "foo1", "foo2", "foo3", "quux");
|
||||
assertSearchReturns(ImmutableList.of("bar", "baz"), "b.*", list);
|
||||
assertSearchReturns(ImmutableList.of("foo1", "foo2"), "foo[12]", list);
|
||||
assertSearchReturns(ImmutableList.of("foo1", "foo2", "foo3"), "foo.*",
|
||||
list);
|
||||
assertSearchReturns(ImmutableList.of("foo1", "foo2", "foo3"), "foo.*", list);
|
||||
assertSearchReturns(ImmutableList.of("quux"), "q.*", list);
|
||||
}
|
||||
|
||||
private void assertSearchReturns(List<?> expected, String re,
|
||||
List<String> inputs) {
|
||||
private void assertSearchReturns(List<?> expected, String re, List<String> inputs) {
|
||||
assertTrue(Ordering.natural().isOrdered(inputs));
|
||||
assertEquals(expected,
|
||||
ImmutableList.copyOf(RegexListSearcher.ofStrings(re).search(inputs)));
|
||||
assertEquals(expected, ImmutableList.copyOf(RegexListSearcher.ofStrings(re).search(inputs)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,12 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.gerrit.testutil.GerritBaseTests;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SocketUtilTest extends GerritBaseTests {
|
||||
@Test
|
||||
@@ -61,15 +59,19 @@ public class SocketUtilTest extends GerritBaseTests {
|
||||
assertEquals("foo:1234", SocketUtil.format(createUnresolved("foo", 1234), 80));
|
||||
assertEquals("foo", SocketUtil.format(createUnresolved("foo", 80), 80));
|
||||
|
||||
assertEquals("[1:2:3:4:5:6:7:8]:1234",//
|
||||
assertEquals(
|
||||
"[1:2:3:4:5:6:7:8]:1234", //
|
||||
SocketUtil.format(new InetSocketAddress(getByName("1:2:3:4:5:6:7:8"), 1234), 80));
|
||||
assertEquals("[1:2:3:4:5:6:7:8]",//
|
||||
assertEquals(
|
||||
"[1:2:3:4:5:6:7:8]", //
|
||||
SocketUtil.format(new InetSocketAddress(getByName("1:2:3:4:5:6:7:8"), 80), 80));
|
||||
|
||||
assertEquals("localhost:1234",//
|
||||
assertEquals(
|
||||
"localhost:1234", //
|
||||
SocketUtil.format(new InetSocketAddress("localhost", 1234), 80));
|
||||
assertEquals("localhost",//
|
||||
SocketUtil. format(new InetSocketAddress("localhost", 80), 80));
|
||||
assertEquals(
|
||||
"localhost", //
|
||||
SocketUtil.format(new InetSocketAddress("localhost", 80), 80));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,19 +81,25 @@ public class SocketUtilTest extends GerritBaseTests {
|
||||
assertEquals(new InetSocketAddress(1234), parse(":1234", 80));
|
||||
assertEquals(new InetSocketAddress(80), parse("", 80));
|
||||
|
||||
assertEquals(createUnresolved("1:2:3:4:5:6:7:8", 1234), //
|
||||
assertEquals(
|
||||
createUnresolved("1:2:3:4:5:6:7:8", 1234), //
|
||||
parse("[1:2:3:4:5:6:7:8]:1234", 80));
|
||||
assertEquals(createUnresolved("1:2:3:4:5:6:7:8", 80), //
|
||||
assertEquals(
|
||||
createUnresolved("1:2:3:4:5:6:7:8", 80), //
|
||||
parse("[1:2:3:4:5:6:7:8]", 80));
|
||||
|
||||
assertEquals(createUnresolved("localhost", 1234), //
|
||||
assertEquals(
|
||||
createUnresolved("localhost", 1234), //
|
||||
parse("[localhost]:1234", 80));
|
||||
assertEquals(createUnresolved("localhost", 80), //
|
||||
assertEquals(
|
||||
createUnresolved("localhost", 80), //
|
||||
parse("[localhost]", 80));
|
||||
|
||||
assertEquals(createUnresolved("foo.bar.example.com", 1234), //
|
||||
assertEquals(
|
||||
createUnresolved("foo.bar.example.com", 1234), //
|
||||
parse("[foo.bar.example.com]:1234", 80));
|
||||
assertEquals(createUnresolved("foo.bar.example.com", 80), //
|
||||
assertEquals(
|
||||
createUnresolved("foo.bar.example.com", 80), //
|
||||
parse("[foo.bar.example.com]", 80));
|
||||
}
|
||||
|
||||
@@ -116,14 +124,18 @@ public class SocketUtilTest extends GerritBaseTests {
|
||||
assertEquals(new InetSocketAddress(1234), resolve(":1234", 80));
|
||||
assertEquals(new InetSocketAddress(80), resolve("", 80));
|
||||
|
||||
assertEquals(new InetSocketAddress(getByName("1:2:3:4:5:6:7:8"), 1234), //
|
||||
assertEquals(
|
||||
new InetSocketAddress(getByName("1:2:3:4:5:6:7:8"), 1234), //
|
||||
resolve("[1:2:3:4:5:6:7:8]:1234", 80));
|
||||
assertEquals(new InetSocketAddress(getByName("1:2:3:4:5:6:7:8"), 80), //
|
||||
assertEquals(
|
||||
new InetSocketAddress(getByName("1:2:3:4:5:6:7:8"), 80), //
|
||||
resolve("[1:2:3:4:5:6:7:8]", 80));
|
||||
|
||||
assertEquals(new InetSocketAddress(getByName("localhost"), 1234), //
|
||||
assertEquals(
|
||||
new InetSocketAddress(getByName("localhost"), 1234), //
|
||||
resolve("[localhost]:1234", 80));
|
||||
assertEquals(new InetSocketAddress(getByName("localhost"), 80), //
|
||||
assertEquals(
|
||||
new InetSocketAddress(getByName("localhost"), 80), //
|
||||
resolve("[localhost]", 80));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user