use of org.drools.serialization.protobuf.marshalling.IdentityPlaceholderResolverStrategy in project drools by kiegroup.
the class ObjectMarshallingStrategyStoreTest method testThrowErrorWhenExistMultipleMarshallingStrategiesWithSameName.
@Test
public void testThrowErrorWhenExistMultipleMarshallingStrategiesWithSameName() throws IOException, ClassNotFoundException {
Environment env = EnvironmentFactory.newEnvironment();
final Thing entityOne = new Thing(1, "Object 1");
final Thing entityTwo = new Thing(2, "Object 2");
Collection srcItems = new ArrayList();
srcItems.add(entityOne);
srcItems.add(entityTwo);
ObjectMarshallingStrategy[] strats = new ObjectMarshallingStrategy[] { new IdentityPlaceholderResolverStrategy(new ObjectMarshallingStrategyAcceptor() {
@Override
public boolean accept(Object object) {
return entityOne.equals(object);
}
}, Collections.singletonMap(entityOne.id, (Object) entityOne)), new IdentityPlaceholderResolverStrategy(new ObjectMarshallingStrategyAcceptor() {
@Override
public boolean accept(Object object) {
return entityTwo.equals(object);
}
}, Collections.singletonMap(entityTwo.id, (Object) entityTwo)) };
env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, strats);
KieSessionConfiguration ksc = SessionConfiguration.newInstance();
final KieBaseConfiguration kbconf = RuleBaseFactory.newKnowledgeBaseConfiguration();
kbconf.setOption(EventProcessingOption.STREAM);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(RuleBaseFactory.newRuleBase(kbconf));
KieSession ks = kbase.newKieSession(ksc, env);
ks.insert(entityOne);
ks.insert(entityTwo);
try {
ProtobufMarshaller marshaller = (ProtobufMarshaller) MarshallerFactory.newMarshaller(kbase, strats);
// Here ocurrs the bug that shows that NamedObjectMarshallingStrategies are required.
Assert.fail("A runtime error must be thrown while found strategies with same name");
} catch (RuntimeException re) {
Assert.assertTrue(re.getMessage().contains("Multiple"));
}
}
Aggregations