IdentityContextMessageJSONObjectMapper implements JSONObjectMapper<IdentityContextMessage> { @Override public String map(IdentityContextMessage identityContextMessage) throws IOException { return ObjectMapperHolder._objectMapper.writeValueAsString( identityContextMessage); }  @Override String map(IdentityContextMessage identityContextMessage); @Override IdentityContextMessage map(String jsonString);  }
@Test public void testJSONDeserialization() throws Exception { String jsonString = read("identity_context_message.json"); IdentityContextMessage identityContextMessage = _jsonObjectMapper.map( jsonString); Map<String, String> identityFields = identityContextMessage.getIdentityFields(); Assert.assertEquals( "julio.camarero@liferay.com", identityFields.get("email")); Assert.assertEquals("Julio Camarero", identityFields.get("name")); Assert.assertEquals("liferay.com", identityContextMessage.getDomain()); Assert.assertEquals("en-US", identityContextMessage.getLanguage()); Assert.assertEquals("MacIntel", identityContextMessage.getPlatform()); Assert.assertEquals("1.0", identityContextMessage.getProtocolVersion()); Assert.assertEquals("CET", identityContextMessage.getTimezone()); }
@Test public void testJSONSerialization() throws Exception { IdentityContextMessage.Builder identityContextMessageBuilder = IdentityContextMessage.builder("DataSourceId"); identityContextMessageBuilder.domain("liferay.com"); identityContextMessageBuilder.language("en-US"); identityContextMessageBuilder.platform("MacIntel"); identityContextMessageBuilder.protocolVersion("1.0"); identityContextMessageBuilder.timezone("CET"); identityContextMessageBuilder.identityFieldsProperty( "email", "julio.camarero@liferay.com"); identityContextMessageBuilder.identityFieldsProperty( "name", "Julio Camarero"); String actualJSON = _jsonObjectMapper.map( identityContextMessageBuilder.build()); String expectedJSON = read("identity_context_message.json"); JSONAssert.assertEquals(expectedJSON, actualJSON, false); }