PayloadTypeExtractor implements Function<JAXBElement<? extends IdentifiableType>, Optional<String>> { @Override public Optional<String> apply(JAXBElement<? extends IdentifiableType> jaxbElement) { Optional<String> payloadType = Optional.absent(); IdentifiableType value = jaxbElement.getValue(); if (value instanceof ExtrinsicObjectType) { ExtrinsicObjectType extrinsicObjectType = (ExtrinsicObjectType) value; Optional<ClassificationType> classificationType = findClassificationType(extrinsicObjectType, DocumentConstants.EBXML_RESPONSE_NODE_REPRESENTATION_FORMAT_CODE); if (classificationType.isPresent()) { payloadType = JaxbDocumentUtils.findSlotType(classificationType.get().getSlot(), DocumentConstants.EBXML_RESPONSE_CODE_CODESCHEME_SLOTNAME); } } else { LOG.warn("Passed in element has an unexpected type. Expecting ExtrinsicObjectType. Returning as absent."); } return payloadType; }  @Override Optional<String> apply(JAXBElement<? extends IdentifiableType> jaxbElement);  }
@Test public void extract() { ExtrinsicObjectType extrinsicObject = createExtrinsicObject("formatCode", "codingScheme", "value"); JAXBElement<ExtrinsicObjectType> jaxbWrapper = wrapExtrinsicObject(extrinsicObject); PayloadTypeExtractor extractor = new PayloadTypeExtractor(); Optional<String> payloadType = extractor.apply(jaxbWrapper); assertEquals("value", payloadType.get()); }
@Test public void missingClassfication() { ExtrinsicObjectType extrinsicObject = createExtrinsicObject("test", "codingScheme", "value"); JAXBElement<ExtrinsicObjectType> jaxbWrapper = wrapExtrinsicObject(extrinsicObject); PayloadTypeExtractor extractor = new PayloadTypeExtractor(); Optional<String> payloadType = extractor.apply(jaxbWrapper); assertFalse(payloadType.isPresent()); }
@Test public void missingSlot() { ExtrinsicObjectType extrinsicObject = createExtrinsicObject("formatCode", "test", "value"); JAXBElement<ExtrinsicObjectType> jaxbWrapper = wrapExtrinsicObject(extrinsicObject); PayloadTypeExtractor extractor = new PayloadTypeExtractor(); Optional<String> payloadType = extractor.apply(jaxbWrapper); assertFalse(payloadType.isPresent()); }