Ignore:
Timestamp:
2022-06-06T19:07:05+02:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #21813: Improve marker handling in sessions and #21923: Improve session workflow/Add "save session" (patch by Bjoeni)

  • Allow saving a previously saved session
  • Add "File" -> "Save Session"
  • Add shortcuts for saving sessions
  • Add warning if a layer in a session is being removed when saving over the session
  • Improve GPX marker handling
Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/SessionSaveAsActionTest.java

    r17275 r18466  
    44import static org.junit.jupiter.api.Assertions.assertFalse;
    55
     6import org.junit.jupiter.api.Test;
    67import org.junit.jupiter.api.extension.RegisterExtension;
    7 import org.junit.jupiter.api.Test;
    88import org.openstreetmap.josm.testutils.JOSMTestRules;
    99
     
    2020    @RegisterExtension
    2121    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    22     public JOSMTestRules test = new JOSMTestRules();
     22    public JOSMTestRules test = new JOSMTestRules().main();
    2323
    2424    /**
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r18287 r18466  
    5151 * Unit tests for Session writing.
    5252 */
    53 class SessionWriterTest {
     53public class SessionWriterTest {
    5454
    5555    protected static final class OsmHeadlessJosExporter extends OsmDataSessionExporter {
     
    123123        for (final Layer l : layers) {
    124124            SessionLayerExporter s = SessionWriter.getSessionLayerExporter(l);
     125            s.getExportPanel();
    125126            exporters.put(l, s);
    126127            if (s instanceof GpxTracksSessionExporter) {
     
    154155    }
    155156
    156     private OsmDataLayer createOsmLayer() {
     157    /**
     158     * Creates an OSM layer
     159     * @return OSM layer
     160     * @since 18466
     161     */
     162    public static OsmDataLayer createOsmLayer() {
    157163        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "OSM layer name", null);
    158164        layer.setAssociatedFile(new File("data.osm"));
     
    160166    }
    161167
    162     private GpxLayer createGpxLayer() {
     168    /**
     169     * Creates a GPX layer
     170     * @return GPX layer
     171     * @since 18466
     172     */
     173    public static GpxLayer createGpxLayer() {
    163174        GpxData data = new GpxData();
    164175        WayPoint wp = new WayPoint(new LatLon(42.72665, -0.00747));
     
    171182    }
    172183
    173     private MarkerLayer createMarkerLayer(GpxLayer gpx) {
     184    /**
     185     * Creates a MarkerLayer
     186     * @param gpx linked GPX layer
     187     * @return MarkerLayer
     188     * @since 18466
     189     */
     190    public static MarkerLayer createMarkerLayer(GpxLayer gpx) {
    174191        MarkerLayer layer = new MarkerLayer(gpx.data, "Marker layer name", gpx.getAssociatedFile(), gpx);
    175192        layer.setOpacity(0.5);
    176193        layer.setColor(new Color(0x12345678, true));
     194        gpx.setLinkedMarkerLayer(layer);
    177195        return layer;
    178196    }
    179197
    180     private ImageryLayer createImageryLayer() {
     198    /**
     199     * Creates an ImageryLayer
     200     * @return ImageryLayer
     201     * @since 18466
     202     */
     203    public static ImageryLayer createImageryLayer() {
    181204        TMSLayer layer = new TMSLayer(new ImageryInfo("the name", "http://www.url.com/"));
    182205        layer.getDisplaySettings().setOffsetBookmark(
     
    185208    }
    186209
    187     private NoteLayer createNoteLayer() {
     210    /**
     211     * Creates a NoteLayer
     212     * @return NoteLayer
     213     * @since 18466
     214     */
     215    public static NoteLayer createNoteLayer() {
    188216        return new NoteLayer(Arrays.asList(new Note(LatLon.ZERO)), "layer name");
    189217    }
     
    250278    void testWriteGpxAndMarkerJoz() throws IOException {
    251279        GpxLayer gpx = createGpxLayer();
    252         Map<String, byte[]> bytes = testWrite(Arrays.asList(gpx, createMarkerLayer(gpx)), true);
    253 
    254         Path path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers.jos");
     280        MarkerLayer markers = createMarkerLayer(gpx);
     281        Map<String, byte[]> bytes = testWrite(Arrays.asList(gpx, markers), true);
     282
     283        Path path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers_combined.jos");
    255284        String expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
    256285        String actual = new String(bytes.get("session.jos"), StandardCharsets.UTF_8).replace("\r", "");
     
    262291        assertEquals(expected, actual);
    263292
     293        //Test writing when the marker layer has no corresponding GPX layer:
     294        gpx.setLinkedMarkerLayer(null);
     295        markers.fromLayer = null;
     296        markers.data.transferLayerPrefs(gpx.data.getLayerPrefs());
     297        bytes = testWrite(Arrays.asList(gpx, markers), true);
     298
     299        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers.jos");
     300        expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     301        actual = new String(bytes.get("session.jos"), StandardCharsets.UTF_8).replace("\r", "");
     302        assertEquals(expected, actual);
     303
     304        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/data_export.gpx");
     305        expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     306        actual = new String(bytes.get("layers/01/data.gpx"), StandardCharsets.UTF_8).replace("\r", "");
     307        assertEquals(expected, actual);
     308
    264309        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/markers.gpx");
    265310        expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
    266311        actual = new String(bytes.get("layers/02/data.gpx"), StandardCharsets.UTF_8).replace("\r", "");
    267312        assertEquals(expected, actual);
     313
    268314    }
    269315
Note: See TracChangeset for help on using the changeset viewer.