Add serializer for StoredCommentLinkInfo

This commit adds a serializer for the StoredCommentLinkInfo entitiy.
The eventual goal is that we serialize CachedProjectConfig. The
entity is too large to be serialized directly, though, so we
divide and conquer.

This commit moves the AutoValue representation to the entities
package to allow the serializer packages to keep its dependencies
minimal.

Change-Id: I860e2c4c1a845d2e518c1a331711e1bc66ac85be
This commit is contained in:
Patrick Hiesel
2020-07-16 12:49:49 +02:00
parent 1c6840566c
commit 0a9b9db8f1
9 changed files with 124 additions and 3 deletions

View File

@@ -0,0 +1,58 @@
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.cache.serialize.entities;
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.server.cache.serialize.entities.StoredCommentLinkInfoSerializer.deserialize;
import static com.google.gerrit.server.cache.serialize.entities.StoredCommentLinkInfoSerializer.serialize;
import com.google.gerrit.entities.StoredCommentLinkInfo;
import org.junit.Test;
public class StoredCommentLinkInfoSerializerTest {
@Test
public void htmlOnly_roundTrip() {
StoredCommentLinkInfo autoValue =
StoredCommentLinkInfo.builder("name")
.setEnabled(true)
.setHtml("<p>html")
.setMatch("*")
.build();
assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
@Test
public void linkOnly_roundTrip() {
StoredCommentLinkInfo autoValue =
StoredCommentLinkInfo.builder("name")
.setEnabled(true)
.setLink("<p>html")
.setMatch("*")
.build();
assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
@Test
public void overrideOnly_roundTrip() {
StoredCommentLinkInfo autoValue =
StoredCommentLinkInfo.builder("name")
.setEnabled(true)
.setOverrideOnly(true)
.setLink("<p>html")
.setMatch("*")
.build();
assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
}

View File

@@ -30,6 +30,7 @@ import com.google.gerrit.entities.BranchOrderSection;
import com.google.gerrit.entities.GroupReference;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames;
import com.google.gerrit.entities.StoredCommentLinkInfo;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.PluginConfig;