1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.io;
|
---|
3 |
|
---|
4 | import java.util.Collections;
|
---|
5 | import java.util.Optional;
|
---|
6 |
|
---|
7 | import javax.swing.JOptionPane;
|
---|
8 |
|
---|
9 | import org.junit.Assert;
|
---|
10 | import org.junit.jupiter.api.AfterEach;
|
---|
11 | import org.junit.jupiter.api.BeforeEach;
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
14 | import org.openstreetmap.josm.TestUtils;
|
---|
15 | import org.openstreetmap.josm.data.APIDataSet;
|
---|
16 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
17 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
18 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
19 | import org.openstreetmap.josm.data.osm.Node;
|
---|
20 | import org.openstreetmap.josm.data.osm.Way;
|
---|
21 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
22 | import org.openstreetmap.josm.io.UploadStrategySpecification;
|
---|
23 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
24 | import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
|
---|
25 |
|
---|
26 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Unit tests of {@link AsynchronousUploadPrimitivesTask}.
|
---|
30 | */
|
---|
31 | class AsynchronousUploadPrimitivesTaskTest {
|
---|
32 |
|
---|
33 | private UploadStrategySpecification strategy;
|
---|
34 | private OsmDataLayer layer;
|
---|
35 | private APIDataSet toUpload;
|
---|
36 | private Changeset changeset;
|
---|
37 | private AsynchronousUploadPrimitivesTask uploadPrimitivesTask;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Setup tests
|
---|
41 | */
|
---|
42 | @RegisterExtension
|
---|
43 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
44 | public JOSMTestRules test = new JOSMTestRules().assertionsInEDT();
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Bootstrap.
|
---|
48 | */
|
---|
49 | @BeforeEach
|
---|
50 | public void bootStrap() {
|
---|
51 | DataSet dataSet = new DataSet();
|
---|
52 | Node node1 = new Node();
|
---|
53 | Node node2 = new Node();
|
---|
54 | node1.setCoor(new LatLon(0, 0));
|
---|
55 | node2.setCoor(new LatLon(30, 30));
|
---|
56 | Way way = new Way();
|
---|
57 | way.addNode(node1);
|
---|
58 | way.addNode(node2);
|
---|
59 | dataSet.addPrimitive(node1);
|
---|
60 | dataSet.addPrimitive(node2);
|
---|
61 | dataSet.addPrimitive(way);
|
---|
62 |
|
---|
63 | toUpload = new APIDataSet(dataSet);
|
---|
64 | layer = new OsmDataLayer(dataSet, "uploadTest", null);
|
---|
65 | strategy = new UploadStrategySpecification();
|
---|
66 | changeset = new Changeset();
|
---|
67 | uploadPrimitivesTask = AsynchronousUploadPrimitivesTask.createAsynchronousUploadTask(strategy, layer, toUpload, changeset).get();
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Tear down.
|
---|
72 | */
|
---|
73 | @AfterEach
|
---|
74 | public void tearDown() {
|
---|
75 | toUpload = null;
|
---|
76 | layer = null;
|
---|
77 | strategy = null;
|
---|
78 | changeset = null;
|
---|
79 | if (uploadPrimitivesTask != null) {
|
---|
80 | uploadPrimitivesTask.cancel();
|
---|
81 | }
|
---|
82 | uploadPrimitivesTask = null;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Test single upload instance.
|
---|
87 | */
|
---|
88 | @Test
|
---|
89 | void testSingleUploadInstance() {
|
---|
90 | TestUtils.assumeWorkingJMockit();
|
---|
91 | new JOptionPaneSimpleMocker(Collections.singletonMap(
|
---|
92 | "A background upload is already in progress. Kindly wait for it to finish before uploading new changes", JOptionPane.OK_OPTION
|
---|
93 | ));
|
---|
94 | Optional<AsynchronousUploadPrimitivesTask> task = AsynchronousUploadPrimitivesTask.
|
---|
95 | createAsynchronousUploadTask(strategy, layer, toUpload, changeset);
|
---|
96 | Assert.assertNotNull(uploadPrimitivesTask);
|
---|
97 | Assert.assertFalse(task.isPresent());
|
---|
98 | }
|
---|
99 | }
|
---|