Skip to content

Commit

Permalink
Issue 103: Class cast Exception
Browse files Browse the repository at this point in the history
Signed-off-by: Shivesh Ranjan <[email protected]>
  • Loading branch information
shiveshr committed Aug 21, 2020
1 parent 7597736 commit eb61c9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static io.pravega.schemaregistry.contract.data.BackwardAndForward.Backwar
return new io.pravega.schemaregistry.contract.data.BackwardAndForward.Backward();
} else if (obj instanceof BackwardTill) {
return new io.pravega.schemaregistry.contract.data.BackwardAndForward.BackwardTill(
decode(((io.pravega.schemaregistry.contract.generated.rest.model.BackwardTill) backward.getBackwardPolicy()).getVersionInfo()));
decode(((io.pravega.schemaregistry.contract.generated.rest.model.BackwardTill) obj).getVersionInfo()));
} else if (obj instanceof BackwardTransitive) {
return new io.pravega.schemaregistry.contract.data.BackwardAndForward.BackwardTransitive();
} else {
Expand Down Expand Up @@ -176,7 +176,7 @@ public static io.pravega.schemaregistry.contract.data.BackwardAndForward.Forward
return new io.pravega.schemaregistry.contract.data.BackwardAndForward.Forward();
} else if (obj instanceof ForwardTill) {
return new io.pravega.schemaregistry.contract.data.BackwardAndForward.ForwardTill(
decode(((io.pravega.schemaregistry.contract.generated.rest.model.ForwardTill) forward.getForwardPolicy()).getVersionInfo()));
decode(((io.pravega.schemaregistry.contract.generated.rest.model.ForwardTill) obj).getVersionInfo()));
} else if (obj instanceof ForwardTransitive) {
return new io.pravega.schemaregistry.contract.data.BackwardAndForward.ForwardTransitive();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package io.pravega.schemaregistry.contract.transform;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import io.pravega.schemaregistry.contract.generated.rest.model.Backward;
import io.pravega.schemaregistry.contract.generated.rest.model.BackwardAndForward;
Expand All @@ -28,13 +29,16 @@
import io.pravega.schemaregistry.contract.generated.rest.model.VersionInfo;
import org.junit.Test;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.*;

public class ModelHelperTest {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

@Test
public void testDecode() {
SerializationFormat type = new SerializationFormat().serializationFormat(SerializationFormat.SerializationFormatEnum.CUSTOM).fullTypeName("a");
Expand Down Expand Up @@ -159,73 +163,77 @@ public void testEncode() {
}

@Test
public void testEncodeAndDecodeCompatibility() {
public void testEncodeAndDecodeCompatibility() throws IOException {
io.pravega.schemaregistry.contract.data.Compatibility compatibility =
io.pravega.schemaregistry.contract.data.Compatibility.allowAny();
Compatibility encoded = ModelHelper.encode(compatibility);
Compatibility encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
io.pravega.schemaregistry.contract.data.Compatibility decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.denyAll();
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.backward();
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.forward();
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.backwardTransitive();
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.forwardTransitive();
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.full();
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.fullTransitive();
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

io.pravega.schemaregistry.contract.data.VersionInfo versionInfo = new io.pravega.schemaregistry.contract.data.VersionInfo("a", 1, 1);
compatibility = io.pravega.schemaregistry.contract.data.Compatibility.backwardTill(versionInfo);
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.forwardTill(versionInfo);
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.backwardTillAndForwardTill(versionInfo, versionInfo);
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.backwardOneAndForwardTill(versionInfo);
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

compatibility = io.pravega.schemaregistry.contract.data.Compatibility.backwardTillAndForwardOne(versionInfo);
encoded = ModelHelper.encode(compatibility);
encoded = convert(ModelHelper.encode(compatibility), Compatibility.class);
decoded = ModelHelper.decode(encoded);
assertEquals(compatibility, decoded);

}

private <T> T convert(T t, Class<T> tClass) throws IOException {
String str = OBJECT_MAPPER.writeValueAsString(t);
return OBJECT_MAPPER.readValue(str, tClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ public void testEndToEnd() {
assertEquals(version2.getId(), 1);
assertEquals(version2.getType(), myTest);

assertTrue(client.updateCompatibility(group, Compatibility.backwardTillAndForwardOne(version1), null));

assertFalse(client.updateCompatibility(group, Compatibility.fullTransitive(), Compatibility.forward()));

assertTrue(client.updateCompatibility(group, Compatibility.fullTransitive(), null));
Expand Down

0 comments on commit eb61c9e

Please sign in to comment.