Ignore:
Timestamp:
2024-03-14T16:34:12+01:00 (10 months ago)
Author:
taylor.smock
Message:

StreetSide: Update to official API

This also moves the plugin to Java 21 (mostly for virtual threads), reformats the
code to match the JOSM standard (4 spaces), and fixes a bunch of lint issues.

Additionally, a lot of cruft from when this plugin was copied from Mapillary was
removed. That was largely related to image import, uploading, and login.

Location:
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside
Files:
1 added
4 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideAbstractImageTest.java

    r36194 r36228  
    22package org.openstreetmap.josm.plugins.streetside;
    33
    4 import static org.junit.jupiter.api.Assertions.assertFalse;
    5 import static org.junit.jupiter.api.Assertions.assertTrue;
     4import static org.junit.jupiter.api.Assertions.assertAll;
     5import static org.junit.jupiter.api.Assertions.assertEquals;
    66
     7import java.text.MessageFormat;
     8import java.util.stream.Collectors;
     9import java.util.stream.Stream;
     10
     11import org.junit.jupiter.api.BeforeEach;
    712import org.junit.jupiter.api.Test;
    8 import org.openstreetmap.josm.data.coor.LatLon;
     13import org.junit.jupiter.params.ParameterizedTest;
     14import org.junit.jupiter.params.provider.Arguments;
     15import org.junit.jupiter.params.provider.MethodSource;
     16import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapUtils;
     17import org.openstreetmap.josm.plugins.streetside.utils.TestUtil;
    918
    1019class StreetsideAbstractImageTest {
     20    private StreetsideImage image;
     21    private String imageUrlBase;
     22
     23    @BeforeEach
     24    void setup() {
     25        this.image = TestUtil.generateImage("1013203010232123", 39.065321, -108.553035);
     26        this.imageUrlBase = "https://ecn.t0.tiles.virtualearth.net/tiles/hs1013203010232123{0}?"
     27                + "g=14336&key=Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU";
     28    }
     29
    1130    @Test
    12     void testIsModified() {
    13         StreetsideImage img = new StreetsideImage("key___________________", new LatLon(0, 0), 0);
    14         assertFalse(img.isModified());
    15         img.turn(1e-4);
    16         img.stopMoving();
    17         assertTrue(img.isModified());
    18         img.turn(-1e-4);
    19         img.stopMoving();
    20         assertFalse(img.isModified());
    21         img.move(1e-4, 1e-4);
    22         img.stopMoving();
    23         assertTrue(img.isModified());
    24         img.move(-1e-4, -1e-4);
    25         img.stopMoving();
    26         assertFalse(img.isModified());
     31    void testThumbnail() {
     32        assertEquals(MessageFormat.format(this.imageUrlBase, "01"), this.image.getThumbnail());
     33    }
     34
     35    private static CubeMapTileXY frontCube(int x, int y) {
     36        return new CubeMapTileXY(CubemapUtils.CubemapFaces.FRONT, x, y);
     37    }
     38
     39    @Test
     40    void testTilesZoom1() {
     41        // 2x2 (4 total tiles)
     42        final var z1 = image.getFaceTiles(CubemapUtils.CubemapFaces.FRONT, 1)
     43                .collect(Collectors.toMap(p -> p.a, p -> p.b));
     44        assertEquals(MessageFormat.format(this.imageUrlBase, "010"), z1.get(frontCube(0, 0)));
     45        assertEquals(MessageFormat.format(this.imageUrlBase, "011"), z1.get(frontCube(1, 0)));
     46        assertEquals(MessageFormat.format(this.imageUrlBase, "012"), z1.get(frontCube(0, 1)));
     47        assertEquals(MessageFormat.format(this.imageUrlBase, "013"), z1.get(frontCube(1, 1)));
     48        assertEquals(4, z1.size());
     49    }
     50
     51    @Test
     52    void testTilesZoom2() {
     53        // 4x4 (16 total tiles)
     54        final var z2 = image.getFaceTiles(CubemapUtils.CubemapFaces.FRONT, 2)
     55                .collect(Collectors.toMap(p -> p.a, p -> p.b));
     56        assertEquals(MessageFormat.format(this.imageUrlBase, "0100"), z2.get(frontCube(0, 0)));
     57        assertEquals(MessageFormat.format(this.imageUrlBase, "0101"), z2.get(frontCube(1, 0)));
     58        assertEquals(MessageFormat.format(this.imageUrlBase, "0102"), z2.get(frontCube(0, 1)));
     59        assertEquals(MessageFormat.format(this.imageUrlBase, "0103"), z2.get(frontCube(1, 1)));
     60        assertEquals(MessageFormat.format(this.imageUrlBase, "0110"), z2.get(frontCube(2, 0)));
     61        assertEquals(MessageFormat.format(this.imageUrlBase, "0111"), z2.get(frontCube(3, 0)));
     62        assertEquals(MessageFormat.format(this.imageUrlBase, "0112"), z2.get(frontCube(2, 1)));
     63        assertEquals(MessageFormat.format(this.imageUrlBase, "0113"), z2.get(frontCube(3, 1)));
     64        assertEquals(MessageFormat.format(this.imageUrlBase, "0120"), z2.get(frontCube(0, 2)));
     65        assertEquals(MessageFormat.format(this.imageUrlBase, "0121"), z2.get(frontCube(1, 2)));
     66        assertEquals(MessageFormat.format(this.imageUrlBase, "0122"), z2.get(frontCube(0, 3)));
     67        assertEquals(MessageFormat.format(this.imageUrlBase, "0123"), z2.get(frontCube(1, 3)));
     68        assertEquals(MessageFormat.format(this.imageUrlBase, "0130"), z2.get(frontCube(2, 2)));
     69        assertEquals(MessageFormat.format(this.imageUrlBase, "0131"), z2.get(frontCube(3, 2)));
     70        assertEquals(MessageFormat.format(this.imageUrlBase, "0132"), z2.get(frontCube(2, 3)));
     71        assertEquals(MessageFormat.format(this.imageUrlBase, "0133"), z2.get(frontCube(3, 3)));
     72        assertEquals(16, z2.size());
     73    }
     74
     75    @Test
     76    void testTilesZoom3() {
     77        // 8x8 (64 total tiles)
     78        final var z3 = image.getFaceTiles(CubemapUtils.CubemapFaces.FRONT, 3)
     79                .collect(Collectors.toMap(p -> p.a, p -> p.b));
     80        // Just check the first row to keep test size smallish
     81        assertEquals(MessageFormat.format(this.imageUrlBase, "01000"), z3.get(frontCube(0, 0)));
     82        assertEquals(MessageFormat.format(this.imageUrlBase, "01001"), z3.get(frontCube(1, 0)));
     83        assertEquals(MessageFormat.format(this.imageUrlBase, "01010"), z3.get(frontCube(2, 0)));
     84        assertEquals(MessageFormat.format(this.imageUrlBase, "01011"), z3.get(frontCube(3, 0)));
     85        assertEquals(MessageFormat.format(this.imageUrlBase, "01100"), z3.get(frontCube(4, 0)));
     86        assertEquals(MessageFormat.format(this.imageUrlBase, "01101"), z3.get(frontCube(5, 0)));
     87        assertEquals(MessageFormat.format(this.imageUrlBase, "01110"), z3.get(frontCube(6, 0)));
     88        assertEquals(MessageFormat.format(this.imageUrlBase, "01111"), z3.get(frontCube(7, 0)));
     89        assertEquals(64, z3.size());
     90    }
     91
     92    static Stream<Arguments> testQuadKeyToXY() {
     93        final Stream.Builder<Arguments> builder = Stream.builder();
     94        // 2x2
     95        builder.add(Arguments.of("0", 0, 0));
     96        builder.add(Arguments.of("1", 1, 0));
     97        builder.add(Arguments.of("2", 0, 1));
     98        builder.add(Arguments.of("3", 1, 1));
     99        // 4x4
     100        builder.add(Arguments.of("00", 0, 0));
     101        builder.add(Arguments.of("01", 1, 0));
     102        builder.add(Arguments.of("02", 0, 1));
     103        builder.add(Arguments.of("03", 1, 1));
     104        builder.add(Arguments.of("10", 2, 0));
     105        builder.add(Arguments.of("11", 3, 0));
     106        builder.add(Arguments.of("12", 2, 1));
     107        builder.add(Arguments.of("13", 3, 1));
     108        builder.add(Arguments.of("20", 0, 2));
     109        builder.add(Arguments.of("21", 1, 2));
     110        builder.add(Arguments.of("22", 0, 3));
     111        builder.add(Arguments.of("23", 1, 3));
     112        builder.add(Arguments.of("30", 2, 2));
     113        builder.add(Arguments.of("31", 3, 2));
     114        builder.add(Arguments.of("32", 2, 3));
     115        builder.add(Arguments.of("33", 3, 3));
     116        return builder.build();
     117    }
     118
     119    @ParameterizedTest
     120    @MethodSource
     121    void testQuadKeyToXY(String quadKey, int x, int y) {
     122        final var xy = StreetsideAbstractImage.quadKeyToTile(quadKey);
     123        assertAll(() -> assertEquals(x, xy.getXIndex(), "x"), () -> assertEquals(y, xy.getYIndex(), "y"));
    27124    }
    28125}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideDataTest.java

    r36194 r36228  
    1212import org.junit.jupiter.api.Disabled;
    1313import org.junit.jupiter.api.Test;
    14 import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.plugins.streetside.utils.TestUtil;
    1515import org.openstreetmap.josm.testutils.annotations.Main;
    1616
     
    3131
    3232    /**
    33      * Creates a sample {@link StreetsideData} objects, 4 {@link StreetsideImage}
    34      * objects and a {@link StreetsideSequence} object.
     33     * Creates a sample {@link StreetsideData} object and 4 {@link StreetsideImage}
     34     * objects.
    3535     */
    3636    @BeforeEach
    3737    public void setUp() {
    38         img1 = new StreetsideImage("id1__________________", new LatLon(0.1, 0.1), 90);
    39         img2 = new StreetsideImage("id2__________________", new LatLon(0.2, 0.2), 90);
    40         img3 = new StreetsideImage("id3__________________", new LatLon(0.3, 0.3), 90);
    41         img4 = new StreetsideImage("id4__________________", new LatLon(0.4, 0.4), 90);
    42         final StreetsideSequence seq = new StreetsideSequence();
    43 
    44         seq.add(Arrays.asList(img1, img2, img3, img4));
     38        img1 = TestUtil.generateImage("1", 0.1, 0.1);
     39        img2 = TestUtil.generateImage("2", 0.2, 0.2);
     40        img3 = TestUtil.generateImage("3", 0.3, 0.3);
     41        img4 = TestUtil.generateImage("4", 0.4, 0.4);
    4542
    4643        data = new StreetsideData();
    47         data.addAll(new ConcurrentSkipListSet<>(seq.getImages()));
     44        data.addAll(Arrays.asList(img1, img2, img3, img4));
    4845    }
    4946
     
    7269    void testSize() {
    7370        assertEquals(4, data.getImages().size());
    74         data.add(new StreetsideImage("id5__________________", new LatLon(0.1, 0.1), 90));
     71        data.add(TestUtil.generateImage("5", 0.1, 0.1));
    7572        assertEquals(5, data.getImages().size());
    7673    }
    7774
    7875    /**
    79      * Test the {@link StreetsideData#setHighlightedImage(StreetsideAbstractImage)}
     76     * Test the {@link StreetsideData#setHighlightedImage(StreetsideImage)}
    8077     * and {@link StreetsideData#getHighlightedImage()} methods.
    8178     */
     
    137134        assertThrows(IllegalStateException.class, data::selectPrevious);
    138135    }
    139 
    140     /**
    141      * Test the multiselection of images. When a new image is selected, the
    142      * multiselected List should reset.
    143      */
    144     @Disabled("The imgs have non-int identifiers while the code expects the identifiers to be int in string form")
    145     @Test
    146     void testMultiSelect() {
    147         assertEquals(0, data.getMultiSelectedImages().size());
    148         data.setSelectedImage(img1);
    149         assertEquals(1, data.getMultiSelectedImages().size());
    150         data.addMultiSelectedImage(img2);
    151         assertEquals(2, data.getMultiSelectedImages().size());
    152         data.setSelectedImage(img1);
    153         assertEquals(1, data.getMultiSelectedImages().size());
    154     }
    155136}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideLayerTest.java

    r36194 r36228  
    1010import org.junit.jupiter.api.Test;
    1111import org.junit.jupiter.api.condition.DisabledIf;
    12 import org.openstreetmap.josm.data.coor.LatLon;
    1312import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1413import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1514import org.openstreetmap.josm.gui.layer.Layer;
    16 import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapUtils;
    1715import org.openstreetmap.josm.testutils.JOSMTestRules;
    1816import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     
    4644
    4745    @Test
    48     void testSetVisible() {
    49         StreetsideLayer.getInstance().getData()
    50                 .add(new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0));
    51         StreetsideLayer.getInstance().getData()
    52                 .add(new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0));
    53         StreetsideImage invisibleImage = new StreetsideImage(CubemapUtils.TEST_IMAGE_ID, new LatLon(0.0, 0.0), 0.0);
    54         invisibleImage.setVisible(false);
    55         StreetsideLayer.getInstance().getData().add(invisibleImage);
    56 
    57         StreetsideLayer.getInstance().setVisible(false);
    58         for (StreetsideAbstractImage img : StreetsideLayer.getInstance().getData().getImages()) {
    59             assertFalse(img.isVisible());
    60         }
    61 
    62         StreetsideLayer.getInstance().setVisible(true);
    63         for (StreetsideAbstractImage img : StreetsideLayer.getInstance().getData().getImages()) {
    64             assertTrue(img.isVisible());
    65         }
    66     }
    67 
    68     @Test
    6946    void testGetInfoComponent() {
    7047        Object comp = StreetsideLayer.getInstance().getInfoComponent();
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cache/StreetsideCacheTest.java

    r36194 r36228  
    44import static org.junit.jupiter.api.Assertions.assertFalse;
    55import static org.junit.jupiter.api.Assertions.assertNotNull;
    6 import static org.junit.jupiter.api.Assertions.assertNull;
    76
    87import org.junit.jupiter.api.Test;
    9 import org.openstreetmap.josm.plugins.streetside.cache.StreetsideCache.Type;
    108import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    119
     
    1513    @Test
    1614    void testCache() {
    17         StreetsideCache cache = new StreetsideCache("00000", Type.FULL_IMAGE);
     15        StreetsideCache cache = new StreetsideCache("https://ecn.t0.tiles.virtualearth.net/tiles/hs101320223333223201");
    1816        assertNotNull(cache.getUrl());
    1917        assertNotNull(cache.getCacheKey());
     
    2119        assertFalse(cache.isObjectLoadable());
    2220
    23         cache = new StreetsideCache("00000", Type.THUMBNAIL);
     21        cache = new StreetsideCache("https://ecn.t0.tiles.virtualearth.net/tiles/hs101320223333223201");
    2422        assertNotNull(cache.getCacheKey());
    2523        assertNotNull(cache.getUrl());
    26 
    27         cache = new StreetsideCache(null, null);
    28         assertNull(cache.getCacheKey());
    29         assertNull(cache.getUrl());
    3024    }
    3125}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cubemap/CubemapUtilsTest.java

    r36194 r36228  
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    55
    6 import org.junit.jupiter.api.Disabled;
    76import org.junit.jupiter.api.Test;
    87
     
    2827        assertEquals("680931568", res);
    2928    }
    30 
    31     @Disabled
    32     @Test
    33     void testGetFaceNumberForCount() {
    34         String faceNrFront = CubemapUtils.getFaceNumberForCount(0);
    35         String faceNrRight = CubemapUtils.getFaceNumberForCount(1);
    36         String faceNrBack = CubemapUtils.getFaceNumberForCount(2);
    37         String faceNrLeft = CubemapUtils.getFaceNumberForCount(3);
    38         String faceNrUp = CubemapUtils.getFaceNumberForCount(4);
    39         String faceNrDown = CubemapUtils.getFaceNumberForCount(5);
    40         assertEquals(faceNrFront, "01");
    41         assertEquals(faceNrRight, "02");
    42         assertEquals(faceNrBack, "03");
    43         assertEquals(faceNrLeft, "10");
    44         assertEquals(faceNrUp, "11");
    45         assertEquals(faceNrDown, "12");
    46     }
    47 
    48     @Disabled
    49     @Test
    50     void testGetCount4FaceNumber() {
    51         int count4Front = CubemapUtils.getCount4FaceNumber("01");
    52         int count4Right = CubemapUtils.getCount4FaceNumber("02");
    53         int count4Back = CubemapUtils.getCount4FaceNumber("03");
    54         int count4Left = CubemapUtils.getCount4FaceNumber("10");
    55         int count4Up = CubemapUtils.getCount4FaceNumber("11");
    56         int count4Down = CubemapUtils.getCount4FaceNumber("12");
    57         assertEquals(count4Front, 0);
    58         assertEquals(count4Right, 1);
    59         assertEquals(count4Back, 2);
    60         assertEquals(count4Left, 3);
    61         assertEquals(count4Up, 4);
    62         assertEquals(count4Down, 5);
    63     }
    64 
    65     @Test
    66     void testConvertDoubleCountNrto16TileNr() {
    67         String x0y0 = CubemapUtils.convertDoubleCountNrto16TileNr("00");
    68         String x0y1 = CubemapUtils.convertDoubleCountNrto16TileNr("01");
    69         String x0y2 = CubemapUtils.convertDoubleCountNrto16TileNr("02");
    70         String x0y3 = CubemapUtils.convertDoubleCountNrto16TileNr("03");
    71         String x1y0 = CubemapUtils.convertDoubleCountNrto16TileNr("10");
    72         String x1y1 = CubemapUtils.convertDoubleCountNrto16TileNr("11");
    73         String x1y2 = CubemapUtils.convertDoubleCountNrto16TileNr("12");
    74         String x1y3 = CubemapUtils.convertDoubleCountNrto16TileNr("13");
    75         String x2y0 = CubemapUtils.convertDoubleCountNrto16TileNr("20");
    76         String x2y1 = CubemapUtils.convertDoubleCountNrto16TileNr("21");
    77         String x2y2 = CubemapUtils.convertDoubleCountNrto16TileNr("22");
    78         String x2y3 = CubemapUtils.convertDoubleCountNrto16TileNr("23");
    79         String x3y0 = CubemapUtils.convertDoubleCountNrto16TileNr("30");
    80         String x3y1 = CubemapUtils.convertDoubleCountNrto16TileNr("31");
    81         String x3y2 = CubemapUtils.convertDoubleCountNrto16TileNr("32");
    82         String x3y3 = CubemapUtils.convertDoubleCountNrto16TileNr("33");
    83 
    84         assertEquals(x0y0, "00");
    85         assertEquals(x0y1, "01");
    86         assertEquals(x0y2, "10");
    87         assertEquals(x0y3, "11");
    88         assertEquals(x1y0, "02");
    89         assertEquals(x1y1, "03");
    90         assertEquals(x1y2, "12");
    91         assertEquals(x1y3, "13");
    92         assertEquals(x2y0, "20");
    93         assertEquals(x2y1, "21");
    94         assertEquals(x2y2, "30");
    95         assertEquals(x2y3, "31");
    96         assertEquals(x3y0, "22");
    97         assertEquals(x3y1, "23");
    98         assertEquals(x3y2, "32");
    99         assertEquals(x3y3, "33");
    100     }
    10129}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cubemap/TileDownloadingTaskTest.java

    r36194 r36228  
    77import java.util.List;
    88import java.util.concurrent.Callable;
     9import java.util.concurrent.ExecutionException;
    910import java.util.concurrent.ExecutorService;
    1011import java.util.concurrent.Executors;
     
    1314import org.junit.jupiter.api.Disabled;
    1415import org.junit.jupiter.api.Test;
     16import org.openstreetmap.josm.plugins.streetside.CubeMapTileXY;
     17import org.openstreetmap.josm.plugins.streetside.utils.TestUtil;
    1518
    1619@Disabled
     
    1821
    1922    @Test
    20     final void testCall() throws InterruptedException {
    21         ExecutorService pool = Executors.newFixedThreadPool(1);
    22         List<Callable<List<String>>> tasks = new ArrayList<>(1);
    23         tasks.add(new TileDownloadingTask("2202112030033001233"));
    24         List<Future<List<String>>> results = pool.invokeAll(tasks);
    25         assertEquals(results.get(0), "2202112030033001233");
     23    final void testCall() throws InterruptedException, ExecutionException {
     24        try (ExecutorService pool = Executors.newFixedThreadPool(1)) {
     25            List<Callable<List<String>>> tasks = new ArrayList<>(1);
     26            tasks.add(new TileDownloadingTask(TestUtil.generateImage("2202112030033001233", 0, 0),
     27                    CubemapUtils.CubemapFaces.FRONT, new CubeMapTileXY(CubemapUtils.CubemapFaces.FRONT, 0, 0)));
     28            List<Future<List<String>>> results = pool.invokeAll(tasks);
     29            assertEquals("2202112030033001233", results.get(0).get().get(0));
     30        }
    2631    }
    2732}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/gui/ImageDisplayTest.java

    r36194 r36228  
    2525    void testImagePersistence() {
    2626        StreetsideImageDisplay display = new StreetsideImageDisplay();
    27         display.setImage(DUMMY_IMAGE, null);
     27        display.setImage(DUMMY_IMAGE);
    2828        assertEquals(DUMMY_IMAGE, display.getImage());
    2929    }
     
    4444        display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll);
    4545
    46         display.setImage(DUMMY_IMAGE, null);
     46        display.setImage(DUMMY_IMAGE);
    4747
    4848        display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll);
     
    7272            display.getMouseListeners()[0].mouseClicked(dummyClick);
    7373
    74             display.setImage(DUMMY_IMAGE, null);
     74            display.setImage(DUMMY_IMAGE);
    7575
    7676            display.getMouseListeners()[0].mouseClicked(dummyClick);
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/gui/StreetsidePreferenceSettingTest.java

    r36194 r36228  
    66
    77import java.awt.GraphicsEnvironment;
     8import java.util.Objects;
    89
    910import javax.swing.JCheckBox;
     
    99100            settings.ok();
    100101            assertEquals(new StringProperty("streetside.download-mode", "default").get(),
    101                     DOWNLOAD_MODE.fromLabel(((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox"))
    102                             .getSelectedItem().toString()).getPrefId());
     102                    DOWNLOAD_MODE.fromLabel(Objects.requireNonNull(((JComboBox<String>) getPrivateFieldValue(settings, "downloadModeComboBox"))
     103                            .getSelectedItem()).toString()).getPrefId());
    103104        }
    104105    }
    105106
    106107    /**
    107      * Checks, if a certain {@link BooleanProperty} (identified by the {@code propName} attribute) matches the selected-state of the given {@link JCheckBox}
     108     * Checks, if a certain {@link BooleanProperty} (identified by the {@code propName} attribute)
     109     * matches the selected-state of the given {@link JCheckBox}
    108110     * @param cb the {@link JCheckBox}, which should be checked against the {@link BooleanProperty}
    109111     * @param propName the name of the property against which the selected-state of the given {@link JCheckBox} should be checked
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/io/download/SequenceDownloadRunnableTest.java

    r36194 r36228  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    5 
    6 import java.lang.reflect.Field;
    7 import java.net.MalformedURLException;
    8 import java.net.URL;
    9 import java.util.function.Function;
    105
    116import org.junit.jupiter.api.Disabled;
     
    2015class SequenceDownloadRunnableTest {
    2116
    22     private static final Function<Bounds, URL> SEARCH_SEQUENCES_URL_GEN = b -> {
    23         return SequenceDownloadRunnableTest.class.getResource("/api/v3/responses/searchSequences.json");
    24     };
    25     private Field urlGenField;
    26 
    2717    @Test
    28     void testRun1() throws IllegalArgumentException, IllegalAccessException {
    29         testNumberOfDecodedImages(4, SEARCH_SEQUENCES_URL_GEN, new Bounds(7.246497, 16.432955, 7.249027, 16.432976));
     18    void testRun1() throws IllegalArgumentException {
     19        testNumberOfDecodedImages(4, new Bounds(7.246497, 16.432955, 7.249027, 16.432976));
    3020    }
    3121
    3222    @Test
    33     void testRun2() throws IllegalArgumentException, IllegalAccessException {
    34         testNumberOfDecodedImages(0, SEARCH_SEQUENCES_URL_GEN, new Bounds(0, 0, 0, 0));
     23    void testRun2() throws IllegalArgumentException {
     24        testNumberOfDecodedImages(0, new Bounds(0, 0, 0, 0));
    3525    }
    3626
    3727    @Test
    38     void testRun3() throws IllegalArgumentException, IllegalAccessException {
    39         testNumberOfDecodedImages(0, b -> {
    40             try {
    41                 return new URL("https://streetside/nonexistentURL");
    42             } catch (MalformedURLException e) {
    43                 return null;
    44             }
    45         }, new Bounds(0, 0, 0, 0));
     28    void testRun3() throws IllegalArgumentException {
     29        testNumberOfDecodedImages(0, new Bounds(0, 0, 0, 0));
    4630    }
    4731
    4832    @Test
    49     void testRun4() throws IllegalArgumentException, IllegalAccessException {
     33    void testRun4() throws IllegalArgumentException {
    5034        StreetsideProperties.CUT_OFF_SEQUENCES_AT_BOUNDS.put(true);
    51         testNumberOfDecodedImages(4, SEARCH_SEQUENCES_URL_GEN, new Bounds(7.246497, 16.432955, 7.249027, 16.432976));
     35        testNumberOfDecodedImages(4, new Bounds(7.246497, 16.432955, 7.249027, 16.432976));
    5236    }
    5337
    5438    @Test
    55     void testRun5() throws IllegalArgumentException, IllegalAccessException {
     39    void testRun5() throws IllegalArgumentException {
    5640        StreetsideProperties.CUT_OFF_SEQUENCES_AT_BOUNDS.put(true);
    57         testNumberOfDecodedImages(0, SEARCH_SEQUENCES_URL_GEN, new Bounds(0, 0, 0, 0));
     41        testNumberOfDecodedImages(0, new Bounds(0, 0, 0, 0));
    5842    }
    5943
    60     private void testNumberOfDecodedImages(int expectedNumImgs, Function<Bounds, URL> urlGen, Bounds bounds)
    61             throws IllegalArgumentException, IllegalAccessException {
     44    private void testNumberOfDecodedImages(int expectedNumImgs, Bounds bounds)
     45            throws IllegalArgumentException {
    6246        SequenceDownloadRunnable r = new SequenceDownloadRunnable(StreetsideLayer.getInstance().getData(), bounds);
    63         urlGenField.set(null, urlGen);
    6447        r.run();
    6548        assertEquals(expectedNumImgs, StreetsideLayer.getInstance().getData().getImages().size());
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/PluginStateTest.java

    r36194 r36228  
    22package org.openstreetmap.josm.plugins.streetside.utils;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    54import static org.junit.jupiter.api.Assertions.assertFalse;
    65import static org.junit.jupiter.api.Assertions.assertTrue;
    76
    8 import javax.swing.JOptionPane;
    9 
    107import org.junit.jupiter.api.Test;
    11 import org.openstreetmap.josm.TestUtils;
    12 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    138
    149/**
     
    3530        assertFalse(PluginState.isDownloading());
    3631    }
    37 
    38     /**
    39      * Tests the methods related to the upload.
    40      */
    41     @Test
    42     void testUpload() {
    43         TestUtils.assumeWorkingJMockit();
    44         JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker();
    45         jopsMocker.getMockResultMap().put("You have successfully uploaded 2 images to Bing.com", JOptionPane.OK_OPTION);
    46         assertFalse(PluginState.isUploading());
    47         PluginState.addImagesToUpload(2);
    48         assertEquals(2, PluginState.getImagesToUpload());
    49         assertEquals(0, PluginState.getImagesUploaded());
    50         assertTrue(PluginState.isUploading());
    51         PluginState.imageUploaded();
    52         assertEquals(1, PluginState.getImagesUploaded());
    53         assertTrue(PluginState.isUploading());
    54         PluginState.imageUploaded();
    55         assertFalse(PluginState.isUploading());
    56         assertEquals(2, PluginState.getImagesToUpload());
    57         assertEquals(2, PluginState.getImagesUploaded());
    58     }
    5932}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsideURLTest.java

    r36194 r36228  
    55import static org.junit.jupiter.api.Assertions.assertNull;
    66import static org.junit.jupiter.api.Assertions.assertThrows;
     7import static org.junit.jupiter.api.Assertions.fail;
    78
    89import java.lang.reflect.InvocationTargetException;
    910import java.lang.reflect.Method;
    1011import java.net.MalformedURLException;
    11 import java.net.URL;
     12import java.net.URI;
     13import java.net.URISyntaxException;
    1214
    1315import org.junit.jupiter.api.Assertions;
     
    1618
    1719class StreetsideURLTest {
    18     // TODO: replace with Streetside URL @rrh
    19     private static final String CLIENT_ID_QUERY_PART = "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";
    20 
    21     public static class APIv3 {
    22 
    23         /*@Ignore
    24         @Test
    25         public void testSearchDetections() {
    26           assertUrlEquals(StreetsideURL.APIv3.searchDetections(null), "https://a.streetside.com/v3/detections", CLIENT_ID_QUERY_PART);
    27         }
    28 
    29         @Ignore
    30         @Test
    31         public void testSearchImages() {
    32           assertUrlEquals(StreetsideURL.APIv3.searchImages(null), "https://a.streetside.com/v3/images", CLIENT_ID_QUERY_PART);
    33         }
    34 
    35         @Ignore
    36         @Test
    37         public void testSubmitChangeset() throws MalformedURLException {
    38           assertEquals(
    39         new URL("https://a.streetside.com/v3/changesets?" + CLIENT_ID_QUERY_PART),
    40         StreetsideURL.APIv3.submitChangeset()
    41           );
    42         }*/
     20    @Test
     21    void testParseNextFromHeaderValue() throws MalformedURLException {
     22        String headerVal = "<https://a.streetside.com/v3/sequences?page=1&per_page=200"
     23                + "&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"first\", "
     24                + "<https://a.streetside.com/v3/sequences?page=2&per_page=200"
     25                + "&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"prev\", "
     26                + "<https://a.streetside.com/v3/sequences?page=4&per_page=200"
     27                + "&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"next\"";
     28        assertEquals(URI.create(
     29                "https://a.streetside.com/v3/sequences?page=4&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2")
     30                .toURL(), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal));
    4331    }
    4432
    4533    @Test
    46     void testParseNextFromHeaderValue() throws MalformedURLException {
    47         String headerVal = "<https://a.streetside.com/v3/sequences?page=1&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"first\", "
    48                 + "<https://a.streetside.com/v3/sequences?page=2&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"prev\", "
    49                 + "<https://a.streetside.com/v3/sequences?page=4&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2>; rel=\"next\"";
    50         assertEquals(new URL(
    51                 "https://a.streetside.com/v3/sequences?page=4&per_page=200&client_id=TG1sUUxGQlBiYWx2V05NM0pQNUVMQTo2NTU3NTBiNTk1NzM1Y2U2"),
    52                 StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal));
    53     }
    54 
    55     @Test
    56     void testParseNextFromHeaderValue2() throws MalformedURLException {
     34    void testParseNextFromHeaderValue2() throws MalformedURLException, URISyntaxException {
    5735        String headerVal = "<https://urlFirst>; rel=\"first\", " + "rel = \"next\" ; < ; , "
    5836                + "rel = \"next\" ; <https://urlNext> , " + "<https://urlPrev>; rel=\"prev\"";
    59         assertEquals(new URL("https://urlNext"), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal));
     37        assertEquals(new URI("https://urlNext").toURL(), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal));
    6038    }
    6139
     
    7048    }
    7149
    72     /*public static class Cloudfront {
    73     @Ignore
    74     @Test
    75     public void testThumbnail() {
    76       assertUrlEquals(StreetsideURL.VirtualEarth.streetsideTile("arbitrary_key", true), "https://d1cuyjsrcm0gby.cloudfront.net/arbitrary_key/thumb-2048.jpg");
    77       assertUrlEquals(StreetsideURL.VirtualEarth.streetsideTile("arbitrary_key2", false), "https://d1cuyjsrcm0gby.cloudfront.net/arbitrary_key2/thumb-320.jpg");
    78     }
    79     }*/
    80 
    8150    @Disabled
    8251    @Test
    8352    void testBrowseImageURL() throws MalformedURLException {
    84         assertEquals(new URL("https://www.streetside.com/map/im/1234567890123456789012"),
    85                 StreetsideURL.MainWebsite.browseImage("1234567890123456789012"));
     53        fail("Needs editing for MS Streetside");
     54        // assertEquals(new URL("https://www.streetside.com/map/im/1234567890123456789012"),
     55        // StreetsideURL.MainWebsite.browseImage("1234567890123456789012"));
    8656    }
    8757
     
    9161    }
    9262
    93     @Disabled
    94     @Test
    95     void testConnectURL() {
    96         /*assertUrlEquals(
    97         StreetsideURL.MainWebsite.connect("http://redirect-host/ä"),
    98         "https://www.streetside.com/connect",
    99         CLIENT_ID_QUERY_PART,
    100         "scope=user%3Aread+public%3Aupload+public%3Awrite",
    101         "response_type=token",
    102         "redirect_uri=http%3A%2F%2Fredirect-host%2F%C3%A4"
    103         );
    104 
    105         assertUrlEquals(
    106         StreetsideURL.MainWebsite.connect(null),
    107         "https://www.streetside.com/connect",
    108         CLIENT_ID_QUERY_PART,
    109         "scope=user%3Aread+public%3Aupload+public%3Awrite",
    110         "response_type=token"
    111         );
    112 
    113         assertUrlEquals(
    114         StreetsideURL.MainWebsite.connect(""),
    115         "https://www.streetside.com/connect",
    116         CLIENT_ID_QUERY_PART,
    117         "scope=user%3Aread+public%3Aupload+public%3Awrite",
    118         "response_type=token"
    119         );*/
    120     }
    121 
    122     @Disabled
    123     @Test
    124     void testUploadSecretsURL() throws MalformedURLException {
    125         /*assertEquals(
    126         new URL("https://a.streetside.com/v2/me/uploads/secrets?"+CLIENT_ID_QUERY_PART),
    127         StreetsideURL.uploadSecretsURL()
    128         );*/
    129     }
    130 
    131     @Disabled
    132     @Test
    133     void testUserURL() throws MalformedURLException {
    134         /*assertEquals(
    135         new URL("https://a.streetside.com/v3/me?"+CLIENT_ID_QUERY_PART),
    136         StreetsideURL.APIv3.userURL()
    137         );*/
    138     }
    139 
    14063    @Test
    14164    void testString2MalformedURL() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException,
     
    14366        Method method = StreetsideURL.class.getDeclaredMethod("string2URL", String[].class);
    14467        method.setAccessible(true);
    145         Assertions.assertNull(method.invoke(null, new Object[] { new String[] { "malformed URL" } })); // this simply invokes string2URL("malformed URL")
    146         Assertions.assertNull(method.invoke(null, new Object[] { null })); // invokes string2URL(null)
     68        // this simply invokes string2URL("malformed URL")
     69        Assertions.assertNull(method.invoke(null, (Object) new String[] { "malformed URL" }));
     70        // invokes string2URL(null)
     71        Assertions.assertNull(method.invoke(null, (Object) null));
    14772    }
    14873
     
    15176        TestUtil.testUtilityClass(StreetsideURL.class);
    15277        TestUtil.testUtilityClass(StreetsideURL.APIv3.class);
    153         TestUtil.testUtilityClass(StreetsideURL.VirtualEarth.class);
    15478        TestUtil.testUtilityClass(StreetsideURL.MainWebsite.class);
    15579    }
    156 
    157     private static void assertUrlEquals(URL actualUrl, String expectedBaseUrl, String... expectedParams) {
    158         final String actualUrlString = actualUrl.toString();
    159         assertEquals(expectedBaseUrl,
    160                 actualUrlString.contains("?") ? actualUrlString.substring(0, actualUrlString.indexOf('?'))
    161                         : actualUrlString);
    162         String[] actualParams = actualUrl.getQuery() == null ? new String[0] : actualUrl.getQuery().split("&");
    163         assertEquals(expectedParams.length, actualParams.length);
    164         for (int exIndex = 0; exIndex < expectedParams.length; exIndex++) {
    165             boolean parameterIsPresent = false;
    166             for (int acIndex = 0; !parameterIsPresent && acIndex < actualParams.length; acIndex++) {
    167                 parameterIsPresent |= actualParams[acIndex].equals(expectedParams[exIndex]);
    168             }
    169             Assertions.assertTrue(parameterIsPresent, expectedParams[exIndex] + " was expected in the query string of "
    170                     + actualUrl + " but wasn't there.");
    171         }
    172     }
    17380}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsideUtilsTest.java

    r36194 r36228  
    22package org.openstreetmap.josm.plugins.streetside.utils;
    33
    4 import static org.junit.jupiter.api.Assertions.assertEquals;
    5 
    6 import org.apache.commons.imaging.common.RationalNumber;
    7 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
    84import org.junit.jupiter.api.Test;
    95
     
    2117    }
    2218
    23     /**
    24      * Test {@link StreetsideUtils#degMinSecToDouble(RationalNumber[], String)}
    25      * method.
    26      */
    27     @Test
    28     void testDegMinSecToDouble() {
    29         RationalNumber[] num = new RationalNumber[3];
    30         num[0] = new RationalNumber(1, 1);
    31         num[1] = new RationalNumber(0, 1);
    32         num[2] = new RationalNumber(0, 1);
    33         String ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH;
    34         assertEquals(1, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);
    35         ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH;
    36         assertEquals(-1, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);
    37         num[0] = new RationalNumber(180, 1);
    38         assertEquals(-180, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);
    39         num[0] = new RationalNumber(190, 1);
    40         assertEquals(170, StreetsideUtils.degMinSecToDouble(num, ref), 0.01);
    41     }
    4219}
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/TestUtil.java

    r36194 r36228  
    1010import java.lang.reflect.Method;
    1111import java.lang.reflect.Modifier;
     12import java.time.Instant;
     13import java.util.Arrays;
    1214
     15import org.openstreetmap.josm.plugins.streetside.StreetsideImage;
    1316import org.openstreetmap.josm.tools.JosmRuntimeException;
    1417
     
    7679        }
    7780    }
     81
     82    /**
     83     * Generate a valid image
     84     * @param id The id of the image
     85     * @param lat The latitude of the image
     86     * @param lon The longitude of the image
     87     * @return The new image
     88     */
     89    public static StreetsideImage generateImage(String id, double lat, double lon) {
     90        return new StreetsideImage("https://ecn.{subdomain}.tiles.virtualearth.net/tiles/hs" + id
     91                + "{faceId}{tileId}?g=14336&key=Arzdiw4nlOJzRwOz__qailc8NiR31Tt51dN2D7cm57NrnceZnCpgOkmJhNpGoppU", lat,
     92                lon, 268.811, 1.395, -4.875, Instant.ofEpochMilli(1614556800000L), Instant.ofEpochMilli(1614643199999L),
     93                "https://dev.virtualearth.net/Branding/logo_powered_by.png",
     94                "Copyright © 2024 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
     95                1, 3, 256, 256, Arrays.asList("t0", "t1", "t2", "t3"));
     96    }
    7897}
Note: See TracChangeset for help on using the changeset viewer.