Enforce serialization API for Java. (#2014)

This commit is contained in:
Andrzej Cichocki 2017-11-08 11:49:52 +00:00 committed by GitHub
parent 117261caa4
commit a036a6300c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,37 @@
package net.corda.core.flows;
import net.corda.core.serialization.SerializationDefaults;
import net.corda.core.serialization.SerializationFactory;
import net.corda.testing.SerializationEnvironmentRule;
import org.junit.Rule;
import org.junit.Test;
import static net.corda.core.serialization.SerializationAPIKt.serialize;
import static org.junit.Assert.assertNull;
/**
* Enforce parts of the serialization API that aren't obvious from looking at the {@link net.corda.core.serialization.SerializationAPIKt} code.
*/
public class SerializationApiInJavaTest {
@Rule
public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
@Test
public void enforceSerializationFactoryApi() {
assertNull(SerializationFactory.Companion.getCurrentFactory());
SerializationFactory factory = SerializationFactory.Companion.getDefaultFactory();
assertNull(factory.getCurrentContext());
serialize("hello", factory, factory.getDefaultContext());
}
@Test
public void enforceSerializationDefaultsApi() {
SerializationDefaults defaults = SerializationDefaults.INSTANCE;
SerializationFactory factory = defaults.getSERIALIZATION_FACTORY();
serialize("hello", factory, defaults.getP2P_CONTEXT());
serialize("hello", factory, defaults.getRPC_SERVER_CONTEXT());
serialize("hello", factory, defaults.getRPC_CLIENT_CONTEXT());
serialize("hello", factory, defaults.getSTORAGE_CONTEXT());
serialize("hello", factory, defaults.getCHECKPOINT_CONTEXT());
}
}

View File

@ -20,7 +20,7 @@ import static org.assertj.core.api.ThrowableAssert.catchThrowable;
public final class ForbiddenLambdaSerializationTests {
@Rule
public SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
private SerializationFactory factory;
@Before

View File

@ -19,7 +19,7 @@ import static org.assertj.core.api.ThrowableAssert.catchThrowable;
public final class LambdaCheckpointSerializationTest {
@Rule
public SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
private SerializationFactory factory;
private SerializationContext context;

View File

@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.*;
public class VaultQueryJavaTests {
@Rule
public SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule();
private MockServices services;
private MockServices issuerServices;
private VaultService vaultService;