source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java @ 14027

Last change on this file since 14027 was 14027, checked in by michael2402, 5 months ago

See #16388: New mechanism for plugins to register relation editor actions.

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation;
3
4import static org.junit.Assert.assertNotNull;
5import static org.junit.Assert.assertNull;
6
7import java.util.Collections;
8
9import javax.swing.JPanel;
10
11import org.junit.Rule;
12import org.junit.Test;
13import org.openstreetmap.josm.TestUtils;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Relation;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.LeftButtonToolbar;
20import org.openstreetmap.josm.gui.dialogs.relation.actions.ApplyAction;
21import org.openstreetmap.josm.gui.dialogs.relation.actions.CancelAction;
22import org.openstreetmap.josm.gui.dialogs.relation.actions.DeleteCurrentRelationAction;
23import org.openstreetmap.josm.gui.dialogs.relation.actions.DuplicateRelationAction;
24import org.openstreetmap.josm.gui.dialogs.relation.actions.OKAction;
25import org.openstreetmap.josm.gui.dialogs.relation.actions.RefreshAction;
26import org.openstreetmap.josm.gui.dialogs.relation.actions.SelectAction;
27import org.openstreetmap.josm.gui.layer.OsmDataLayer;
28import org.openstreetmap.josm.gui.tagging.TagEditorModel;
29import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
30import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
31import org.openstreetmap.josm.testutils.JOSMTestRules;
32
33import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
34
35/**
36 * Unit tests of {@link GenericRelationEditor} class.
37 */
38public 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}
Note: See TracBrowser for help on using the repository browser.