@Test public void testToDomain() throws Exception { final ZonedDateTime now = ZonedDateTime.parse("2015-08-14T17:52:43Z"); final Notification n1 = Notification.builder("test-category", "this is a test") .withId("1") .withCreatedAt(now) .build(); final NotificationListObject expected = new NotificationListObject(); expected.addNotification(n1); final NotificationPB pb = NotificationPB.newBuilder() .setId("1") .setCategory("test-category") .setMessage("this is a test") .setCreatedAt(now.toInstant().toEpochMilli()) .build(); final NotificationListPB list = NotificationListPB.newBuilder().addNotification(pb).build(); final NotificationListObject actual = converter.toDomain(BinaryValue.create(list.toByteArray()), "application/x-protobuf"); assertThat(actual).isEqualTo(expected); }
@Override public NotificationListObject toDomain(final BinaryValue value, final String contentType) { if (!ProtocolBufferMediaType.APPLICATION_PROTOBUF.equals(contentType)) { LOGGER.error("Invalid Content-Type: {}", contentType); throw new ConversionException("Invalid Content-Type: " + contentType); } final NotificationListPB list; try { list = NotificationListPB.parseFrom(value.unsafeGetValue()); } catch (InvalidProtocolBufferException e) { LOGGER.error("Unable to convert value from Riak", e); throw new ConversionException(e); } final NotificationListObject obj = new NotificationListObject(); list.getNotificationList().stream() .map(NotificationListConverter::convert) .forEach(obj::addNotification); obj.deleteNotifications(list.getDeletedIdList()); return obj; }
NotificationListConverter extends Converter<NotificationListObject> { @Override public NotificationListObject toDomain(final BinaryValue value, final String contentType) { if (!ProtocolBufferMediaType.APPLICATION_PROTOBUF.equals(contentType)) { LOGGER.error("Invalid Content-Type: {}", contentType); throw new ConversionException("Invalid Content-Type: " + contentType); } final NotificationListPB list; try { list = NotificationListPB.parseFrom(value.unsafeGetValue()); } catch (InvalidProtocolBufferException e) { LOGGER.error("Unable to convert value from Riak", e); throw new ConversionException(e); } final NotificationListObject obj = new NotificationListObject(); list.getNotificationList().stream() .map(NotificationListConverter::convert) .forEach(obj::addNotification); obj.deleteNotifications(list.getDeletedIdList()); return obj; } }
NotificationListConverter extends Converter<NotificationListObject> { @Override public NotificationListObject toDomain(final BinaryValue value, final String contentType) { if (!ProtocolBufferMediaType.APPLICATION_PROTOBUF.equals(contentType)) { LOGGER.error("Invalid Content-Type: {}", contentType); throw new ConversionException("Invalid Content-Type: " + contentType); } final NotificationListPB list; try { list = NotificationListPB.parseFrom(value.unsafeGetValue()); } catch (InvalidProtocolBufferException e) { LOGGER.error("Unable to convert value from Riak", e); throw new ConversionException(e); } final NotificationListObject obj = new NotificationListObject(); list.getNotificationList().stream() .map(NotificationListConverter::convert) .forEach(obj::addNotification); obj.deleteNotifications(list.getDeletedIdList()); return obj; } NotificationListConverter(); }
NotificationListConverter extends Converter<NotificationListObject> { @Override public NotificationListObject toDomain(final BinaryValue value, final String contentType) { if (!ProtocolBufferMediaType.APPLICATION_PROTOBUF.equals(contentType)) { LOGGER.error("Invalid Content-Type: {}", contentType); throw new ConversionException("Invalid Content-Type: " + contentType); } final NotificationListPB list; try { list = NotificationListPB.parseFrom(value.unsafeGetValue()); } catch (InvalidProtocolBufferException e) { LOGGER.error("Unable to convert value from Riak", e); throw new ConversionException(e); } final NotificationListObject obj = new NotificationListObject(); list.getNotificationList().stream() .map(NotificationListConverter::convert) .forEach(obj::addNotification); obj.deleteNotifications(list.getDeletedIdList()); return obj; } NotificationListConverter(); @Override NotificationListObject toDomain(final BinaryValue value, final String contentType); @Override ContentAndType fromDomain(final NotificationListObject domainObject); }
NotificationListConverter extends Converter<NotificationListObject> { @Override public NotificationListObject toDomain(final BinaryValue value, final String contentType) { if (!ProtocolBufferMediaType.APPLICATION_PROTOBUF.equals(contentType)) { LOGGER.error("Invalid Content-Type: {}", contentType); throw new ConversionException("Invalid Content-Type: " + contentType); } final NotificationListPB list; try { list = NotificationListPB.parseFrom(value.unsafeGetValue()); } catch (InvalidProtocolBufferException e) { LOGGER.error("Unable to convert value from Riak", e); throw new ConversionException(e); } final NotificationListObject obj = new NotificationListObject(); list.getNotificationList().stream() .map(NotificationListConverter::convert) .forEach(obj::addNotification); obj.deleteNotifications(list.getDeletedIdList()); return obj; } NotificationListConverter(); @Override NotificationListObject toDomain(final BinaryValue value, final String contentType); @Override ContentAndType fromDomain(final NotificationListObject domainObject);  }