Search in sources :

Example 1 with CacheSerializer

use of com.google.gerrit.server.cache.serialize.CacheSerializer in project gerrit by GerritCodeReview.

the class OAuthTokenCacheTest method oAuthTokenSerializer.

@Test
public void oAuthTokenSerializer() throws Exception {
    OAuthToken token = new OAuthToken("token", "secret", "raw", 12345L, "provider");
    CacheSerializer<OAuthToken> s = new OAuthTokenCache.Serializer();
    byte[] serialized = s.serialize(token);
    assertThat(OAuthTokenProto.parseFrom(serialized)).isEqualTo(OAuthTokenProto.newBuilder().setToken("token").setSecret("secret").setRaw("raw").setExpiresAtMillis(12345L).setProviderId("provider").build());
    assertThat(s.deserialize(serialized)).isEqualTo(token);
}
Also used : OAuthToken(com.google.gerrit.extensions.auth.oauth.OAuthToken) CacheSerializer(com.google.gerrit.server.cache.serialize.CacheSerializer) Test(org.junit.Test)

Example 2 with CacheSerializer

use of com.google.gerrit.server.cache.serialize.CacheSerializer in project gerrit by GerritCodeReview.

the class OAuthTokenCacheTest method oAuthTokenSerializerWithNullProvider.

@Test
public void oAuthTokenSerializerWithNullProvider() throws Exception {
    OAuthToken tokenWithNull = new OAuthToken("token", "secret", "raw", 12345L, null);
    CacheSerializer<OAuthToken> s = new OAuthTokenCache.Serializer();
    OAuthTokenProto expectedProto = OAuthTokenProto.newBuilder().setToken("token").setSecret("secret").setRaw("raw").setExpiresAtMillis(12345L).setProviderId("").build();
    byte[] serializedWithNull = s.serialize(tokenWithNull);
    assertThat(OAuthTokenProto.parseFrom(serializedWithNull)).isEqualTo(expectedProto);
    assertThat(s.deserialize(serializedWithNull)).isEqualTo(tokenWithNull);
    OAuthToken tokenWithEmptyString = new OAuthToken("token", "secret", "raw", 12345L, "");
    assertThat(tokenWithEmptyString).isEqualTo(tokenWithNull);
    byte[] serializedWithEmptyString = s.serialize(tokenWithEmptyString);
    assertThat(OAuthTokenProto.parseFrom(serializedWithEmptyString)).isEqualTo(expectedProto);
    assertThat(s.deserialize(serializedWithEmptyString)).isEqualTo(tokenWithNull);
}
Also used : OAuthToken(com.google.gerrit.extensions.auth.oauth.OAuthToken) CacheSerializer(com.google.gerrit.server.cache.serialize.CacheSerializer) OAuthTokenProto(com.google.gerrit.server.cache.proto.Cache.OAuthTokenProto) Test(org.junit.Test)

Aggregations

OAuthToken (com.google.gerrit.extensions.auth.oauth.OAuthToken)2 CacheSerializer (com.google.gerrit.server.cache.serialize.CacheSerializer)2 Test (org.junit.Test)2 OAuthTokenProto (com.google.gerrit.server.cache.proto.Cache.OAuthTokenProto)1