@Test public void testDoesNotProvideNullValue() throws SerializerException, ODataJPASerializerException { final EntityCollection results = new EntityCollection(); final Entity result = new Entity(); final Property value = new Property(); final ODataRequest request = new ODataRequest(); final EdmPrimitiveType valueODataType = mock(EdmPrimitiveType.class); final EdmProperty valueODataProperty = mock(EdmProperty.class); final EdmProperty addrODataProperty = mock(EdmProperty.class); final UriResourceEntitySet orgOData = mock(UriResourceEntitySet.class); final UriResourceComplexProperty addrOData = mock(UriResourceComplexProperty.class); final UriResourcePrimitiveProperty streetOData = mock(UriResourcePrimitiveProperty.class); final UriResourceValue valueOData = mock(UriResourceValue.class); final List<UriResource> uriResourceParts = Arrays.asList(orgOData, addrOData, streetOData, valueOData); when(streetOData.getType()).thenReturn(valueODataType); when(valueODataProperty.getType()).thenReturn(valueODataType); when(valueODataProperty.getName()).thenReturn("StreetName"); when(addrODataProperty.getName()).thenReturn("Address"); when(streetOData.getProperty()).thenReturn(valueODataProperty); when(addrOData.getProperty()).thenReturn(addrODataProperty); when(uriInfo.getUriResourceParts()).thenReturn(uriResourceParts); value.setValue(ValueType.PRIMITIVE, null); value.setName("StreetName"); result.getProperties().add(value); results.getEntities().add(result); final SerializerResult act = cut.serialize(request, results); assertNotNull(act); verify(serializer, times(0)).primitiveValue(eq(valueODataType), isNull(), any()); }
@Override public SerializerResult serialize(final ODataRequest request, final EntityCollection result) throws SerializerException, ODataJPASerializerException { if (result.getEntities().get(0) == null || result.getEntities().get(0).getProperties() == null || result.getEntities().get(0).getProperties().isEmpty()) { throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); } InputStream serializerResult = null; if (isStream()) { final Entity et = result.getEntities().get(0); final EdmEntityType edmEt = serviceMetadata.getEdm().getEntityType(new FullQualifiedName(et.getType())); final List<EdmKeyPropertyRef> p = edmEt.getKeyPropertyRefs(); Property property = null; for (final Property item : result.getEntities().get(0).getProperties()) { if (!isKey(p, item)) { property = item; break; } } if (property == null) throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); serializerResult = serializer.binary((byte[]) property.getValue()); } else { final UriResourceProperty uriProperty = (UriResourceProperty) uriInfo.getUriResourceParts().get(uriInfo .getUriResourceParts().size() - 2); final EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) uriProperty.getType(); final JPAPrimitivePropertyInfo info = determinePrimitiveProperty(result, uriInfo.getUriResourceParts()); final PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with().build(); if (!info.getProperty().isNull()) serializerResult = serializer.primitiveValue(edmPropertyType, info.getProperty().getValue(), options); } return new JPAValueSerializerResult(serializerResult); }
JPASerializeValue extends JPASerializePrimitiveAbstract { @Override public SerializerResult serialize(final ODataRequest request, final EntityCollection result) throws SerializerException, ODataJPASerializerException { if (result.getEntities().get(0) == null || result.getEntities().get(0).getProperties() == null || result.getEntities().get(0).getProperties().isEmpty()) { throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); } InputStream serializerResult = null; if (isStream()) { final Entity et = result.getEntities().get(0); final EdmEntityType edmEt = serviceMetadata.getEdm().getEntityType(new FullQualifiedName(et.getType())); final List<EdmKeyPropertyRef> p = edmEt.getKeyPropertyRefs(); Property property = null; for (final Property item : result.getEntities().get(0).getProperties()) { if (!isKey(p, item)) { property = item; break; } } if (property == null) throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); serializerResult = serializer.binary((byte[]) property.getValue()); } else { final UriResourceProperty uriProperty = (UriResourceProperty) uriInfo.getUriResourceParts().get(uriInfo .getUriResourceParts().size() - 2); final EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) uriProperty.getType(); final JPAPrimitivePropertyInfo info = determinePrimitiveProperty(result, uriInfo.getUriResourceParts()); final PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with().build(); if (!info.getProperty().isNull()) serializerResult = serializer.primitiveValue(edmPropertyType, info.getProperty().getValue(), options); } return new JPAValueSerializerResult(serializerResult); } }
JPASerializeValue extends JPASerializePrimitiveAbstract { @Override public SerializerResult serialize(final ODataRequest request, final EntityCollection result) throws SerializerException, ODataJPASerializerException { if (result.getEntities().get(0) == null || result.getEntities().get(0).getProperties() == null || result.getEntities().get(0).getProperties().isEmpty()) { throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); } InputStream serializerResult = null; if (isStream()) { final Entity et = result.getEntities().get(0); final EdmEntityType edmEt = serviceMetadata.getEdm().getEntityType(new FullQualifiedName(et.getType())); final List<EdmKeyPropertyRef> p = edmEt.getKeyPropertyRefs(); Property property = null; for (final Property item : result.getEntities().get(0).getProperties()) { if (!isKey(p, item)) { property = item; break; } } if (property == null) throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); serializerResult = serializer.binary((byte[]) property.getValue()); } else { final UriResourceProperty uriProperty = (UriResourceProperty) uriInfo.getUriResourceParts().get(uriInfo .getUriResourceParts().size() - 2); final EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) uriProperty.getType(); final JPAPrimitivePropertyInfo info = determinePrimitiveProperty(result, uriInfo.getUriResourceParts()); final PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with().build(); if (!info.getProperty().isNull()) serializerResult = serializer.primitiveValue(edmPropertyType, info.getProperty().getValue(), options); } return new JPAValueSerializerResult(serializerResult); } JPASerializeValue(final ServiceMetadata serviceMetadata, final FixedFormatSerializer serializer,
      final UriInfo uriInfo); }
JPASerializeValue extends JPASerializePrimitiveAbstract { @Override public SerializerResult serialize(final ODataRequest request, final EntityCollection result) throws SerializerException, ODataJPASerializerException { if (result.getEntities().get(0) == null || result.getEntities().get(0).getProperties() == null || result.getEntities().get(0).getProperties().isEmpty()) { throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); } InputStream serializerResult = null; if (isStream()) { final Entity et = result.getEntities().get(0); final EdmEntityType edmEt = serviceMetadata.getEdm().getEntityType(new FullQualifiedName(et.getType())); final List<EdmKeyPropertyRef> p = edmEt.getKeyPropertyRefs(); Property property = null; for (final Property item : result.getEntities().get(0).getProperties()) { if (!isKey(p, item)) { property = item; break; } } if (property == null) throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); serializerResult = serializer.binary((byte[]) property.getValue()); } else { final UriResourceProperty uriProperty = (UriResourceProperty) uriInfo.getUriResourceParts().get(uriInfo .getUriResourceParts().size() - 2); final EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) uriProperty.getType(); final JPAPrimitivePropertyInfo info = determinePrimitiveProperty(result, uriInfo.getUriResourceParts()); final PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with().build(); if (!info.getProperty().isNull()) serializerResult = serializer.primitiveValue(edmPropertyType, info.getProperty().getValue(), options); } return new JPAValueSerializerResult(serializerResult); } JPASerializeValue(final ServiceMetadata serviceMetadata, final FixedFormatSerializer serializer,
      final UriInfo uriInfo); @Override SerializerResult serialize(final ODataRequest request, final EntityCollection result); @Override SerializerResult serialize(final Annotatable result, final EdmType entityType, final ODataRequest request); @Override ContentType getContentType(); }
JPASerializeValue extends JPASerializePrimitiveAbstract { @Override public SerializerResult serialize(final ODataRequest request, final EntityCollection result) throws SerializerException, ODataJPASerializerException { if (result.getEntities().get(0) == null || result.getEntities().get(0).getProperties() == null || result.getEntities().get(0).getProperties().isEmpty()) { throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); } InputStream serializerResult = null; if (isStream()) { final Entity et = result.getEntities().get(0); final EdmEntityType edmEt = serviceMetadata.getEdm().getEntityType(new FullQualifiedName(et.getType())); final List<EdmKeyPropertyRef> p = edmEt.getKeyPropertyRefs(); Property property = null; for (final Property item : result.getEntities().get(0).getProperties()) { if (!isKey(p, item)) { property = item; break; } } if (property == null) throw new ODataJPASerializerException(ODataJPASerializerException.MessageKeys.RESULT_NOT_FOUND, HttpStatusCode.INTERNAL_SERVER_ERROR); serializerResult = serializer.binary((byte[]) property.getValue()); } else { final UriResourceProperty uriProperty = (UriResourceProperty) uriInfo.getUriResourceParts().get(uriInfo .getUriResourceParts().size() - 2); final EdmPrimitiveType edmPropertyType = (EdmPrimitiveType) uriProperty.getType(); final JPAPrimitivePropertyInfo info = determinePrimitiveProperty(result, uriInfo.getUriResourceParts()); final PrimitiveValueSerializerOptions options = PrimitiveValueSerializerOptions.with().build(); if (!info.getProperty().isNull()) serializerResult = serializer.primitiveValue(edmPropertyType, info.getProperty().getValue(), options); } return new JPAValueSerializerResult(serializerResult); } JPASerializeValue(final ServiceMetadata serviceMetadata, final FixedFormatSerializer serializer,
      final UriInfo uriInfo); @Override SerializerResult serialize(final ODataRequest request, final EntityCollection result); @Override SerializerResult serialize(final Annotatable result, final EdmType entityType, final ODataRequest request); @Override ContentType getContentType();  }