/** * CcBase64 can encode and decode. * * @throws IOException If some problem inside */ @Test public void encodesAndDecodes() throws IOException { final String urn = "urn:test:Hello World!"; final Map<String, String> properties = ImmutableMap.of("userName", "user"); final Codec codec = new CcBase64(new CcPlain()); final Identity expected = codec.decode(codec.encode(new Identity.Simple(urn, properties))); MatcherAssert.assertThat(expected.urn(), Matchers.equalTo(urn)); MatcherAssert.assertThat(expected.properties(), Matchers.equalTo(properties)); }
/** * Apply validation rules to identity. * * @param identity Identity * @return Identity */ private static Identity applyRules(final Identity identity) { if (!identity.equals(Identity.ANONYMOUS)) { final String urn = identity.urn(); if (urn.isEmpty()) { throw new DecodingException("urn is empty"); } if (!CcStrict.PTN.matcher(urn).matches()) { throw new DecodingException(String.format("urn isn't valid: \"%s\"", urn)); } } return identity; }