Changeset 36228 in osm for applications/editors/josm/plugins/MicrosoftStreetside/test
- Timestamp:
- 2024-03-14T16:34:12+01:00 (10 months ago)
- 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 2 2 package org.openstreetmap.josm.plugins.streetside; 3 3 4 import static org.junit.jupiter.api.Assertions.assert False;5 import static org.junit.jupiter.api.Assertions.assert True;4 import static org.junit.jupiter.api.Assertions.assertAll; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 6 7 import java.text.MessageFormat; 8 import java.util.stream.Collectors; 9 import java.util.stream.Stream; 10 11 import org.junit.jupiter.api.BeforeEach; 7 12 import org.junit.jupiter.api.Test; 8 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.junit.jupiter.params.ParameterizedTest; 14 import org.junit.jupiter.params.provider.Arguments; 15 import org.junit.jupiter.params.provider.MethodSource; 16 import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapUtils; 17 import org.openstreetmap.josm.plugins.streetside.utils.TestUtil; 9 18 10 19 class 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 11 30 @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")); 27 124 } 28 125 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideDataTest.java
r36194 r36228 12 12 import org.junit.jupiter.api.Disabled; 13 13 import org.junit.jupiter.api.Test; 14 import org.openstreetmap.josm. data.coor.LatLon;14 import org.openstreetmap.josm.plugins.streetside.utils.TestUtil; 15 15 import org.openstreetmap.josm.testutils.annotations.Main; 16 16 … … 31 31 32 32 /** 33 * Creates a sample {@link StreetsideData} object s,4 {@link StreetsideImage}34 * objects and a {@link StreetsideSequence} object.33 * Creates a sample {@link StreetsideData} object and 4 {@link StreetsideImage} 34 * objects. 35 35 */ 36 36 @BeforeEach 37 37 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); 45 42 46 43 data = new StreetsideData(); 47 data.addAll( new ConcurrentSkipListSet<>(seq.getImages()));44 data.addAll(Arrays.asList(img1, img2, img3, img4)); 48 45 } 49 46 … … 72 69 void testSize() { 73 70 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)); 75 72 assertEquals(5, data.getImages().size()); 76 73 } 77 74 78 75 /** 79 * Test the {@link StreetsideData#setHighlightedImage(Streetside AbstractImage)}76 * Test the {@link StreetsideData#setHighlightedImage(StreetsideImage)} 80 77 * and {@link StreetsideData#getHighlightedImage()} methods. 81 78 */ … … 137 134 assertThrows(IllegalStateException.class, data::selectPrevious); 138 135 } 139 140 /**141 * Test the multiselection of images. When a new image is selected, the142 * 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 @Test146 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 }155 136 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/StreetsideLayerTest.java
r36194 r36228 10 10 import org.junit.jupiter.api.Test; 11 11 import org.junit.jupiter.api.condition.DisabledIf; 12 import org.openstreetmap.josm.data.coor.LatLon;13 12 import org.openstreetmap.josm.data.imagery.ImageryInfo; 14 13 import org.openstreetmap.josm.gui.layer.ImageryLayer; 15 14 import org.openstreetmap.josm.gui.layer.Layer; 16 import org.openstreetmap.josm.plugins.streetside.cubemap.CubemapUtils;17 15 import org.openstreetmap.josm.testutils.JOSMTestRules; 18 16 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; … … 46 44 47 45 @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 @Test69 46 void testGetInfoComponent() { 70 47 Object comp = StreetsideLayer.getInstance().getInfoComponent(); -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cache/StreetsideCacheTest.java
r36194 r36228 4 4 import static org.junit.jupiter.api.Assertions.assertFalse; 5 5 import static org.junit.jupiter.api.Assertions.assertNotNull; 6 import static org.junit.jupiter.api.Assertions.assertNull;7 6 8 7 import org.junit.jupiter.api.Test; 9 import org.openstreetmap.josm.plugins.streetside.cache.StreetsideCache.Type;10 8 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 11 9 … … 15 13 @Test 16 14 void testCache() { 17 StreetsideCache cache = new StreetsideCache(" 00000", Type.FULL_IMAGE);15 StreetsideCache cache = new StreetsideCache("https://ecn.t0.tiles.virtualearth.net/tiles/hs101320223333223201"); 18 16 assertNotNull(cache.getUrl()); 19 17 assertNotNull(cache.getCacheKey()); … … 21 19 assertFalse(cache.isObjectLoadable()); 22 20 23 cache = new StreetsideCache(" 00000", Type.THUMBNAIL);21 cache = new StreetsideCache("https://ecn.t0.tiles.virtualearth.net/tiles/hs101320223333223201"); 24 22 assertNotNull(cache.getCacheKey()); 25 23 assertNotNull(cache.getUrl()); 26 27 cache = new StreetsideCache(null, null);28 assertNull(cache.getCacheKey());29 assertNull(cache.getUrl());30 24 } 31 25 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cubemap/CubemapUtilsTest.java
r36194 r36228 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 5 6 import org.junit.jupiter.api.Disabled;7 6 import org.junit.jupiter.api.Test; 8 7 … … 28 27 assertEquals("680931568", res); 29 28 } 30 31 @Disabled32 @Test33 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 @Disabled49 @Test50 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 @Test66 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 }101 29 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/cubemap/TileDownloadingTaskTest.java
r36194 r36228 7 7 import java.util.List; 8 8 import java.util.concurrent.Callable; 9 import java.util.concurrent.ExecutionException; 9 10 import java.util.concurrent.ExecutorService; 10 11 import java.util.concurrent.Executors; … … 13 14 import org.junit.jupiter.api.Disabled; 14 15 import org.junit.jupiter.api.Test; 16 import org.openstreetmap.josm.plugins.streetside.CubeMapTileXY; 17 import org.openstreetmap.josm.plugins.streetside.utils.TestUtil; 15 18 16 19 @Disabled … … 18 21 19 22 @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 } 26 31 } 27 32 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/gui/ImageDisplayTest.java
r36194 r36228 25 25 void testImagePersistence() { 26 26 StreetsideImageDisplay display = new StreetsideImageDisplay(); 27 display.setImage(DUMMY_IMAGE , null);27 display.setImage(DUMMY_IMAGE); 28 28 assertEquals(DUMMY_IMAGE, display.getImage()); 29 29 } … … 44 44 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll); 45 45 46 display.setImage(DUMMY_IMAGE , null);46 display.setImage(DUMMY_IMAGE); 47 47 48 48 display.getMouseWheelListeners()[0].mouseWheelMoved(dummyScroll); … … 72 72 display.getMouseListeners()[0].mouseClicked(dummyClick); 73 73 74 display.setImage(DUMMY_IMAGE , null);74 display.setImage(DUMMY_IMAGE); 75 75 76 76 display.getMouseListeners()[0].mouseClicked(dummyClick); -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/gui/StreetsidePreferenceSettingTest.java
r36194 r36228 6 6 7 7 import java.awt.GraphicsEnvironment; 8 import java.util.Objects; 8 9 9 10 import javax.swing.JCheckBox; … … 99 100 settings.ok(); 100 101 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()); 103 104 } 104 105 } 105 106 106 107 /** 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} 108 110 * @param cb the {@link JCheckBox}, which should be checked against the {@link BooleanProperty} 109 111 * @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 3 3 4 4 import 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;10 5 11 6 import org.junit.jupiter.api.Disabled; … … 20 15 class SequenceDownloadRunnableTest { 21 16 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 27 17 @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)); 30 20 } 31 21 32 22 @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)); 35 25 } 36 26 37 27 @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)); 46 30 } 47 31 48 32 @Test 49 void testRun4() throws IllegalArgumentException , IllegalAccessException{33 void testRun4() throws IllegalArgumentException { 50 34 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)); 52 36 } 53 37 54 38 @Test 55 void testRun5() throws IllegalArgumentException , IllegalAccessException{39 void testRun5() throws IllegalArgumentException { 56 40 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)); 58 42 } 59 43 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 { 62 46 SequenceDownloadRunnable r = new SequenceDownloadRunnable(StreetsideLayer.getInstance().getData(), bounds); 63 urlGenField.set(null, urlGen);64 47 r.run(); 65 48 assertEquals(expectedNumImgs, StreetsideLayer.getInstance().getData().getImages().size()); -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/PluginStateTest.java
r36194 r36228 2 2 package org.openstreetmap.josm.plugins.streetside.utils; 3 3 4 import static org.junit.jupiter.api.Assertions.assertEquals;5 4 import static org.junit.jupiter.api.Assertions.assertFalse; 6 5 import static org.junit.jupiter.api.Assertions.assertTrue; 7 6 8 import javax.swing.JOptionPane;9 10 7 import org.junit.jupiter.api.Test; 11 import org.openstreetmap.josm.TestUtils;12 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;13 8 14 9 /** … … 35 30 assertFalse(PluginState.isDownloading()); 36 31 } 37 38 /**39 * Tests the methods related to the upload.40 */41 @Test42 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 }59 32 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsideURLTest.java
r36194 r36228 5 5 import static org.junit.jupiter.api.Assertions.assertNull; 6 6 import static org.junit.jupiter.api.Assertions.assertThrows; 7 import static org.junit.jupiter.api.Assertions.fail; 7 8 8 9 import java.lang.reflect.InvocationTargetException; 9 10 import java.lang.reflect.Method; 10 11 import java.net.MalformedURLException; 11 import java.net.URL; 12 import java.net.URI; 13 import java.net.URISyntaxException; 12 14 13 15 import org.junit.jupiter.api.Assertions; … … 16 18 17 19 class 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)); 43 31 } 44 32 45 33 @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 { 57 35 String headerVal = "<https://urlFirst>; rel=\"first\", " + "rel = \"next\" ; < ; , " 58 36 + "rel = \"next\" ; <https://urlNext> , " + "<https://urlPrev>; rel=\"prev\""; 59 assertEquals(new UR L("https://urlNext"), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal));37 assertEquals(new URI("https://urlNext").toURL(), StreetsideURL.APIv3.parseNextFromLinkHeaderValue(headerVal)); 60 38 } 61 39 … … 70 48 } 71 49 72 /*public static class Cloudfront {73 @Ignore74 @Test75 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 81 50 @Disabled 82 51 @Test 83 52 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")); 86 56 } 87 57 … … 91 61 } 92 62 93 @Disabled94 @Test95 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 @Disabled123 @Test124 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 @Disabled132 @Test133 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 140 63 @Test 141 64 void testString2MalformedURL() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, … … 143 66 Method method = StreetsideURL.class.getDeclaredMethod("string2URL", String[].class); 144 67 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)); 147 72 } 148 73 … … 151 76 TestUtil.testUtilityClass(StreetsideURL.class); 152 77 TestUtil.testUtilityClass(StreetsideURL.APIv3.class); 153 TestUtil.testUtilityClass(StreetsideURL.VirtualEarth.class);154 78 TestUtil.testUtilityClass(StreetsideURL.MainWebsite.class); 155 79 } 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 }173 80 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/StreetsideUtilsTest.java
r36194 r36228 2 2 package org.openstreetmap.josm.plugins.streetside.utils; 3 3 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;8 4 import org.junit.jupiter.api.Test; 9 5 … … 21 17 } 22 18 23 /**24 * Test {@link StreetsideUtils#degMinSecToDouble(RationalNumber[], String)}25 * method.26 */27 @Test28 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 }42 19 } -
applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/TestUtil.java
r36194 r36228 10 10 import java.lang.reflect.Method; 11 11 import java.lang.reflect.Modifier; 12 import java.time.Instant; 13 import java.util.Arrays; 12 14 15 import org.openstreetmap.josm.plugins.streetside.StreetsideImage; 13 16 import org.openstreetmap.josm.tools.JosmRuntimeException; 14 17 … … 76 79 } 77 80 } 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 } 78 97 }
Note:
See TracChangeset
for help on using the changeset viewer.