OpenLRDecoder implements openlr.OpenLRDecoder { @Override public List<Location> decodeRaw(final OpenLRDecoderParameter parameter, final List<RawLocationReference> locRefs) throws OpenLRProcessingException { List<Location> locations = new ArrayList<Location>(); OpenLRDecoderProperties properties = new OpenLRDecoderProperties(parameter.getConfiguration()); for (RawLocationReference locRef : locRefs) { locations.add(decodeRaw(parameter, properties, locRef)); } return locations; }  static List<PhysicalDecoder> resolvePhysicalDecoder(); @Override Location decode(final OpenLRDecoderParameter parameter,
                           final LocationReference locRef); @Override List<Location> decode(final OpenLRDecoderParameter parameter,
                                 final List<LocationReference> locRefs); @Override List<Location> decodeRaw(final OpenLRDecoderParameter parameter,
                                    final List<RawLocationReference> locRefs); @Override Location decodeRaw(final OpenLRDecoderParameter parameter,
                              final RawLocationReference rawLocRef); @Override String getMajorVersion(); @Override String getMinorVersion(); @Override String getPatchVersion(); @Override String getVersion();  }
@Test public final void testLineLocationExceedingOffsets() { Location decLocRef; InputStream properties = null; try { properties = new FileInputStream(DECODER_PROPERTIES); } catch (IOException e) { fail("Error creating properties stream.", e); } try { OpenLRDecoder decoder = new OpenLRDecoder(); OpenLRDecoderParameter parameter = new OpenLRDecoderParameter.Builder() .with(mockedMapDB) .with(OpenLRPropertiesReader.loadPropertiesFromStream( properties, true)).buildParameter(); decLocRef = decoder.decodeRaw(parameter, td.getLineLocationExceedingOffsets()); assertTrue(decLocRef.isValid()); assertNotNull(decLocRef.toString()); } catch (OpenLRProcessingException e) { fail("Decoding location failed with exception: " + e.getErrorCode(), e); } }
@Test public final void testPOIWithAccesNoOffsets() { Location decLocRef = null; RawLocationReference inputLocation = null; try { inputLocation = td.getPWANoOffsets(); mockedLocRefPoiWithAccess = inputLocation; OpenLRDecoder decoder = new OpenLRDecoder(); OpenLRDecoderParameter parameter = new OpenLRDecoderParameter.Builder() .with(mockedMapDB) .with(td.getProperties()).buildParameter(); decLocRef = decoder.decodeRaw(parameter, inputLocation); } catch (OpenLRProcessingException e) { fail("Decoding location failed with exception: " + e.getErrorCode(), e); } catch (InvalidMapDataException e) { fail("Decoding location failed with exception", e); } assertTrue(decLocRef.isValid()); GeoCoordinates inputPoi = inputLocation.getGeoCoordinates(); GeoCoordinates coords = decLocRef.getPointLocation(); assertEquals(coords.getLatitudeDeg(), inputPoi.getLatitudeDeg()); assertEquals(coords.getLongitudeDeg(), inputPoi.getLongitudeDeg()); GeoCoordinates accessP = decLocRef.getAccessPoint(); Node node5 = mockedMapDB.getNode(EXPECTED_NODE_NO_OFFSETS); assertEquals(accessP.getLongitudeDeg(), node5.getLongitudeDeg()); assertEquals(accessP.getLatitudeDeg(), node5.getLatitudeDeg()); assertNotNull(accessP.toString()); }
@Test public final void testInvalidLocationType() { final RawLocationReference mockedLocRef = new RawInvalidLocRef("id", null, LocationType.UNKNOWN); try { OpenLRDecoder decoder = new OpenLRDecoder(); OpenLRDecoderParameter parameter = new OpenLRDecoderParameter.Builder() .with(mockedMapDB) .with(td.getProperties()).buildParameter(); Location result = decoder.decodeRaw(parameter, mockedLocRef); assertFalse(result.isValid()); assertEquals(result.getReturnCode(), DecoderReturnCode.INVALID_LOCATION_TYPE); assertNull(result.getAccessPoint()); assertNull(result.getPointLocation()); assertNull(result.getPoiLine()); assertNull(result.getOrientation()); assertNull(result.getSideOfRoad()); assertTrue(result.getLocationLines().isEmpty()); assertFalse(result.hasNegativeOffset()); assertFalse(result.hasPositiveOffset()); CommonObjectTestUtils.testToString(result); } catch (OpenLRProcessingException e) { fail("Unexpected exception!", e); } }
@Test public final void testDecodingWithLRDB() { OpenLRDecoder decoder = new OpenLRDecoder(); LocationDatabase db = LocationDatabaseFactory .createLocationDatabase(2); OpenLRDecoderParameter parameter = new OpenLRDecoderParameter.Builder() .with(mockedMapDB) .with(td.getProperties()).with(db).buildParameter(); try { Location result = decoder.decodeRaw(parameter, td.getWhitepaperGeoCoordinateLocation()); assertTrue(result.isValid()); } catch (Exception e) { fail("Unexpected exception!", e); } }
@Test public final void testPOIWithAccesNotConnected() { Location decLocRef; String id = "notConnectedPAL"; InputStream properties = null; try { properties = new FileInputStream(DECODER_PROPERTIES); } catch (IOException e) { fail("Error creating properties stream.", e); } try { OpenLRDecoder decoder = new OpenLRDecoder(); OpenLRDecoderParameter parameter = new OpenLRDecoderParameter.Builder() .with(mockedMapDB) .with(OpenLRPropertiesReader.loadPropertiesFromStream( properties, true)).buildParameter(); decLocRef = decoder.decodeRaw(parameter, td.getNotConnectedPWA()); assertFalse(decLocRef.isValid()); assertEquals(decLocRef.getReturnCode().getID(), DecoderReturnCode.NO_ROUTE_FOUND.getID()); assertNotNull(decLocRef.toString()); assertEquals(decLocRef.getID(), id); } catch (OpenLRProcessingException e) { fail("Decoding location failed with exception: " + e.getErrorCode(), e); } }