static public Reference fromDslBinder(Binder ref, Contract contract) { String name = ref.getString("name"); String comment = ref.getString("comment", null); Binder where = null; try { where = ref.getBinderOrThrow("where"); } catch (Exception e) { // Insert simple condition to binder with key all_of List<String> simpleConditions = ref.getList("where", null); if (simpleConditions != null) where = new Binder(all_of.name(), simpleConditions); } Reference reference = new Reference(contract); if (name == null) throw new IllegalArgumentException("Expected reference name"); reference.setName(name); reference.setComment(comment); if (where != null) reference.setConditions(where); return reference; }
/** * Check serialization and deserialization contract with references * @throws Exception */ @Test public void checkReferenceSerialization() throws Exception { Contract contract = Contract.fromDslFile(rootPath + "simple_root_contract_with_references.yml"); assertEquals(contract.findReferenceByName("ref_cont").getComment(), "ref_comment"); contract.findReferenceByName("ref_cont3").setComment("ref_comment3"); contract.seal(); Binder b = BossBiMapper.serialize(contract); Contract desContract = DefaultBiMapper.deserialize(b); assertEquals(desContract.findReferenceByName("ref_cont").getComment(), "ref_comment"); assertEquals(desContract.findReferenceByName("ref_cont3").getComment(), "ref_comment3"); assertNull(desContract.findReferenceByName("ref_cont2").getComment()); for (Reference ref: contract.getReferences().values()) { Reference desRef = desContract.findReferenceByName(ref.getName()); assertTrue(desRef != null); assertEquals(ref.getConditions(), desRef.getConditions()); } }