ChaincodeEndorsementPolicy { public void fromYamlFile(File yamlPolicyFile) throws IOException, ChaincodeEndorsementPolicyParseException { final Yaml yaml = new Yaml(); final Map<?, ?> load = (Map<?, ?>) yaml.load(new FileInputStream(yamlPolicyFile)); Map<?, ?> mp = (Map<?, ?>) load.get("policy"); if (null == mp) { throw new ChaincodeEndorsementPolicyParseException("The policy file has no policy section"); } IndexedHashMap<String, MSPPrincipal> identities = parseIdentities((Map<?, ?>) load.get("identities")); SignaturePolicy sp = parsePolicy(identities, mp); policyBytes = Policies.SignaturePolicyEnvelope.newBuilder() .setVersion(0) .addAllIdentities(identities.values()) .setRule(sp) .build().toByteArray(); } ChaincodeEndorsementPolicy(); void fromFile(File policyFile); void fromYamlFile(File yamlPolicyFile); void fromStream(InputStream inputStream); void fromBytes(byte[] policyAsBytes); byte[] getChaincodeEndorsementPolicyAsBytes();  }
@Test public void testBadYaml() throws IOException, ChaincodeEndorsementPolicyParseException { try { ChaincodeEndorsementPolicy itTestPolicy = new ChaincodeEndorsementPolicy(); itTestPolicy.fromYamlFile(new File("src/test/fixture/sample_chaincode_endorsement_policies/badusertestCCEPPolicy.yaml")); fail("Expected ChaincodeEndorsementPolicyParseException"); } catch (ChaincodeEndorsementPolicyParseException e) { } catch (Exception e) { fail("Expected ChaincodeEndorsementPolicyParseException"); } }