OpenLRBinaryDecoder implements PhysicalDecoder { @Override public RawLocationReference decodeData(final LocationReference lr) throws PhysicalFormatException { Object data = lr.getLocationReferenceData(); if (data == null || !(data instanceof ByteArray)) { throw new OpenLRBinaryException( PhysicalFormatError.INVALID_BINARY_DATA); } ByteArray dataList = (ByteArray) data; return parseBinaryData(lr.getID(), dataList.getData(), null); }  static int[] getVersions(); @Override RawLocationReference decodeData(final LocationReference lr); @Override Class<?> getDataClass(); @Override String getDataFormatIdentifier(); RawBinaryData resolveBinaryData(final String id, final ByteArray ba);  }
@Test public final void testValidData() { ByteArray validBinLoc = new ByteArray(VALID_BIN_DATA_POS_OFFSET_V2); try { validDecodeLocation = decodeData(validBinLoc); Lrp[] expectedLrps = new Lrp[]{Lrp.LINE_DEC_LRP1, Lrp.LINE_DEC_LRP2, Lrp.LINE_DEC_LRP3}; Utils.checkDecodedLrps(validDecodeLocation, expectedLrps); checkOffsetsV2(validDecodeLocation.getOffsets(), EXPECTED_POS_OFFSET_V2, EXPECTED_NEG_OFFSET_V2); } catch (PhysicalFormatException e) { fail("failed on valid input", e); } }
@Test public final void testValidDataNoOffsets() { ByteArray validBinLoc = new ByteArray(VALID_BIN_DATA_NO_OFFSET_V3); try { RawLocationReference decodeData = decodeData(validBinLoc); Lrp[] expectedLrps = new Lrp[]{Lrp.LINE_DEC_LRP1, Lrp.LINE_DEC_LRP2, Lrp.LINE_DEC_LRP3}; Utils.checkDecodedLrps(decodeData, expectedLrps); checkOffsetsV3(decodeData.getOffsets(), null, null); } catch (PhysicalFormatException e) { fail("failed on valid input", e); } }
@Test public final void testValidDataBothOffsets() { ByteArray validBinLoc = new ByteArray(VALID_BIN_DATA_OFFSETS_V3); try { RawLocationReference decodeData = decodeData(validBinLoc); Lrp[] expectedLrps = new Lrp[]{Lrp.LINE_DEC_LRP1, Lrp.LINE_DEC_LRP2, Lrp.LINE_DEC_LRP3}; Utils.checkDecodedLrps(decodeData, expectedLrps); checkOffsetsV3(decodeData.getOffsets(), EXPECTED_POS_OFFSET_V3, EXPECTED_NEG_OFFSET_V3); assertNotNull(decodeData.getOffsets().toString()); } catch (PhysicalFormatException e) { fail("failed on valid input", e); } }
@Test public final void testWhitepaperExample() { ByteArray validBinLoc = new ByteArray( OpenLRBinaryEncoderTest.DATA_WP_EXAMPLE); try { RawLocationReference decodeData = decodeData(validBinLoc); Lrp[] expectedLrps = new Lrp[]{Lrp.LINE_DEC_LRP1, Lrp.LINE_DEC_LRP2_WP, Lrp.LINE_DEC_LRP3_WP}; Utils.checkDecodedLrps(decodeData, expectedLrps); checkOffsetsV3(decodeData.getOffsets(), EXPECTED_POS_OFFSET_WP_EXAMPLE, null); } catch (PhysicalFormatException e) { fail("failed on valid input", e); } }
@Test(dependsOnMethods = {"testValidData"}) public final void testValidDataBase64() { ByteArray validBinLoc = new ByteArray(Base64 .encodeBase64String(VALID_BIN_DATA_POS_OFFSET_V2)); RawLocationReference decodeData = null; try { decodeData = decodeData(validBinLoc); } catch (PhysicalFormatException e) { fail("failed on valid input", e); } List<? extends LocationReferencePoint> b64Points = decodeData .getLocationReferencePoints(); List<? extends LocationReferencePoint> templateLRPs = validDecodeLocation .getLocationReferencePoints(); LocationReferencePoint currentPoint; LocationReferencePoint currentB64Point; for (int i = 0; i < templateLRPs.size(); i++) { currentPoint = templateLRPs.get(i); currentB64Point = b64Points.get(i); assertEquals(currentPoint.getBearing(), currentB64Point .getBearing()); assertEquals(currentPoint.getDistanceToNext(), currentB64Point .getDistanceToNext()); assertEquals(currentPoint.getFOW(), currentB64Point.getFOW()); assertEquals(currentPoint.getFRC(), currentB64Point.getFRC()); assertEquals(currentPoint.getLatitudeDeg(), currentB64Point .getLatitudeDeg()); assertEquals(currentPoint.getLongitudeDeg(), currentB64Point .getLongitudeDeg()); assertEquals(currentPoint.getLfrc(), currentB64Point.getLfrc()); } Offsets b64Offset = decodeData.getOffsets(); Offsets templateOffsets = validDecodeLocation.getOffsets(); assertEquals(templateOffsets.hasPositiveOffset(), b64Offset .hasPositiveOffset()); assertEquals(templateOffsets.hasNegativeOffset(), b64Offset .hasNegativeOffset()); assertEquals(templateOffsets.getPositiveOffset(0), b64Offset .getPositiveOffset(0)); assertEquals(templateOffsets.getNegativeOffset(0), b64Offset .getNegativeOffset(0)); }
@Test public final void testValidDataStream() { ByteArray validBinLoc = null; try { validBinLoc = new ByteArray(new ByteArrayInputStream( VALID_BIN_DATA_POS_OFFSET_V2)); } catch (IOException obe) { fail("Unexpected Exception during creation of ByteArray from " + "stream", obe); } try { RawLocationReference locRef = decodeData(validBinLoc); Lrp[] expectedLrps = new Lrp[]{Lrp.LINE_DEC_LRP1, Lrp.LINE_DEC_LRP2, Lrp.LINE_DEC_LRP3}; Utils.checkDecodedLrps(locRef, expectedLrps); checkOffsetsV3(locRef.getOffsets(), EXPECTED_POS_OFFSET_V2, EXPECTED_NEG_OFFSET_V2); } catch (PhysicalFormatException e) { fail("failed on valid input", e); } }
@Test public final void testInvalidData() { ByteArray invalidBinLoc = new ByteArray(INVALID_BIN_LOC_DATA); try { decodeData(invalidBinLoc); } catch (PhysicalFormatException e) { fail("failed on invalid input"); } }