1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertNotNull;
|
---|
5 | import static org.junit.Assert.assertNull;
|
---|
6 |
|
---|
7 | import java.util.Collections;
|
---|
8 |
|
---|
9 | import javax.swing.JPanel;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.TestUtils;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
17 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
18 | import org.openstreetmap.josm.data.osm.Way;
|
---|
19 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.LeftButtonToolbar;
|
---|
20 | import org.openstreetmap.josm.gui.dialogs.relation.actions.ApplyAction;
|
---|
21 | import org.openstreetmap.josm.gui.dialogs.relation.actions.CancelAction;
|
---|
22 | import org.openstreetmap.josm.gui.dialogs.relation.actions.DeleteCurrentRelationAction;
|
---|
23 | import org.openstreetmap.josm.gui.dialogs.relation.actions.DuplicateRelationAction;
|
---|
24 | import org.openstreetmap.josm.gui.dialogs.relation.actions.OKAction;
|
---|
25 | import org.openstreetmap.josm.gui.dialogs.relation.actions.RefreshAction;
|
---|
26 | import org.openstreetmap.josm.gui.dialogs.relation.actions.SelectAction;
|
---|
27 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
28 | import org.openstreetmap.josm.gui.tagging.TagEditorModel;
|
---|
29 | import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
|
---|
30 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
31 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
32 |
|
---|
33 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Unit tests of {@link GenericRelationEditor} class.
|
---|
37 | */
|
---|
38 | public class GenericRelationEditorTest {
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Setup test.
|
---|
42 | */
|
---|
43 | @Rule
|
---|
44 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
45 | public JOSMTestRules test = new JOSMTestRules().preferences().platform().main();
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Returns a new relation editor for unit tests.
|
---|
49 | * @param orig relation
|
---|
50 | * @param layer data layer
|
---|
51 | * @return new relation editor for unit tests
|
---|
52 | */
|
---|
53 | public static IRelationEditor newRelationEditor(final Relation orig, final OsmDataLayer layer) {
|
---|
54 | return new IRelationEditor() {
|
---|
55 | private Relation r = orig;
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void setRelation(Relation relation) {
|
---|
59 | r = relation;
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public boolean isDirtyRelation() {
|
---|
64 | return false;
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | public Relation getRelationSnapshot() {
|
---|
69 | return r;
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | public Relation getRelation() {
|
---|
74 | return r;
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public void reloadDataFromRelation() {
|
---|
79 | // Do nothing
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public OsmDataLayer getLayer() {
|
---|
84 | return layer;
|
---|
85 | }
|
---|
86 | };
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Unit test of {@link GenericRelationEditor#addPrimitivesToRelation}.
|
---|
91 | */
|
---|
92 | @Test
|
---|
93 | public void testAddPrimitivesToRelation() {
|
---|
94 | Relation r = TestUtils.addFakeDataSet(new Relation(1));
|
---|
95 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.<OsmPrimitive>emptyList()));
|
---|
96 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(1))));
|
---|
97 |
|
---|
98 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Node(1))));
|
---|
99 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Way(1))));
|
---|
100 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(2))));
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Unit test of {@code GenericRelationEditor#build*} methods.
|
---|
105 | */
|
---|
106 | @Test
|
---|
107 | public void testBuild() {
|
---|
108 | DataSet ds = new DataSet();
|
---|
109 | Relation relation = new Relation(1);
|
---|
110 | ds.addPrimitive(relation);
|
---|
111 | OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
|
---|
112 | IRelationEditor re = newRelationEditor(relation, layer);
|
---|
113 |
|
---|
114 | MemberTableModel memberTableModel = new MemberTableModel(relation, layer, null);
|
---|
115 | MemberTable memberTable = new MemberTable(layer, relation, memberTableModel);
|
---|
116 |
|
---|
117 | SelectionTableModel selectionTableModel = new SelectionTableModel(layer);
|
---|
118 | SelectionTable selectionTable = new SelectionTable(selectionTableModel, memberTableModel);
|
---|
119 |
|
---|
120 | AutoCompletingTextField tfRole = GenericRelationEditor.buildRoleTextField(re);
|
---|
121 | assertNotNull(tfRole);
|
---|
122 |
|
---|
123 | TagEditorPanel tagEditorPanel = new TagEditorPanel(relation, null);
|
---|
124 |
|
---|
125 | JPanel top = GenericRelationEditor.buildTagEditorPanel(tagEditorPanel);
|
---|
126 | assertNotNull(top);
|
---|
127 | TagEditorModel tagModel = tagEditorPanel.getModel();
|
---|
128 |
|
---|
129 | }
|
---|
130 | }
|
---|