[9666] | 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 |
|
---|
[10113] | 9 | import javax.swing.JPanel;
|
---|
| 10 |
|
---|
[10962] | 11 | import org.junit.Rule;
|
---|
[9666] | 12 | import org.junit.Test;
|
---|
[10113] | 13 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[9666] | 14 | import org.openstreetmap.josm.data.osm.Node;
|
---|
| 15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 16 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
| 17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
[10113] | 18 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.LeftButtonToolbar;
|
---|
| 19 | import org.openstreetmap.josm.gui.dialogs.relation.actions.ApplyAction;
|
---|
| 20 | import org.openstreetmap.josm.gui.dialogs.relation.actions.CancelAction;
|
---|
| 21 | import org.openstreetmap.josm.gui.dialogs.relation.actions.DeleteCurrentRelationAction;
|
---|
| 22 | import org.openstreetmap.josm.gui.dialogs.relation.actions.DuplicateRelationAction;
|
---|
| 23 | import org.openstreetmap.josm.gui.dialogs.relation.actions.OKAction;
|
---|
| 24 | import org.openstreetmap.josm.gui.dialogs.relation.actions.RefreshAction;
|
---|
[12933] | 25 | import org.openstreetmap.josm.gui.dialogs.relation.actions.SelectAction;
|
---|
[10113] | 26 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
| 27 | import org.openstreetmap.josm.gui.tagging.TagEditorModel;
|
---|
| 28 | import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
|
---|
| 29 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
[10962] | 30 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
[9666] | 31 |
|
---|
[10962] | 32 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
| 33 |
|
---|
[9666] | 34 | /**
|
---|
| 35 | * Unit tests of {@link GenericRelationEditor} class.
|
---|
| 36 | */
|
---|
| 37 | public class GenericRelationEditorTest {
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * Setup test.
|
---|
| 41 | */
|
---|
[10962] | 42 | @Rule
|
---|
| 43 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
[12564] | 44 | public JOSMTestRules test = new JOSMTestRules().preferences().platform().main();
|
---|
[9666] | 45 |
|
---|
| 46 | /**
|
---|
[10113] | 47 | * Returns a new relation editor for unit tests.
|
---|
| 48 | * @param orig relation
|
---|
| 49 | * @param layer data layer
|
---|
| 50 | * @return new relation editor for unit tests
|
---|
| 51 | */
|
---|
| 52 | public static IRelationEditor newRelationEditor(final Relation orig, final OsmDataLayer layer) {
|
---|
| 53 | return new IRelationEditor() {
|
---|
| 54 | private Relation r = orig;
|
---|
| 55 |
|
---|
| 56 | @Override
|
---|
| 57 | public void setRelation(Relation relation) {
|
---|
| 58 | r = relation;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | @Override
|
---|
| 62 | public boolean isDirtyRelation() {
|
---|
| 63 | return false;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | @Override
|
---|
| 67 | public Relation getRelationSnapshot() {
|
---|
| 68 | return r;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | @Override
|
---|
| 72 | public Relation getRelation() {
|
---|
| 73 | return r;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | @Override
|
---|
| 77 | public void reloadDataFromRelation() {
|
---|
| 78 | // Do nothing
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | @Override
|
---|
| 82 | public OsmDataLayer getLayer() {
|
---|
| 83 | return layer;
|
---|
| 84 | }
|
---|
| 85 | };
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /**
|
---|
[9666] | 89 | * Unit test of {@link GenericRelationEditor#addPrimitivesToRelation}.
|
---|
| 90 | */
|
---|
| 91 | @Test
|
---|
| 92 | public void testAddPrimitivesToRelation() {
|
---|
[12728] | 93 | Relation r = new Relation(1);
|
---|
| 94 | new DataSet(r);
|
---|
| 95 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.<OsmPrimitive>emptyList()));
|
---|
| 96 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(1))));
|
---|
[9666] | 97 |
|
---|
[12728] | 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))));
|
---|
[9666] | 101 | }
|
---|
| 102 |
|
---|
[10113] | 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 | LeftButtonToolbar leftButtonToolbar = new LeftButtonToolbar(memberTable, memberTableModel, re);
|
---|
| 121 | assertNotNull(leftButtonToolbar.sortBelowButton);
|
---|
| 122 |
|
---|
| 123 | AutoCompletingTextField tfRole = GenericRelationEditor.buildRoleTextField(re);
|
---|
| 124 | assertNotNull(tfRole);
|
---|
| 125 |
|
---|
| 126 | TagEditorPanel tagEditorPanel = new TagEditorPanel(relation, null);
|
---|
| 127 |
|
---|
| 128 | JPanel top = GenericRelationEditor.buildTagEditorPanel(tagEditorPanel);
|
---|
| 129 | JPanel bottom = GenericRelationEditor.buildMemberEditorPanel(
|
---|
| 130 | memberTable, memberTableModel, selectionTable, selectionTableModel, re, leftButtonToolbar, tfRole);
|
---|
| 131 | assertNotNull(top);
|
---|
| 132 | assertNotNull(bottom);
|
---|
| 133 | assertNotNull(GenericRelationEditor.buildSplitPane(top, bottom, re));
|
---|
| 134 |
|
---|
| 135 | TagEditorModel tagModel = tagEditorPanel.getModel();
|
---|
| 136 |
|
---|
| 137 | assertNotNull(GenericRelationEditor.buildOkCancelButtonPanel(
|
---|
| 138 | new OKAction(memberTable, memberTableModel, tagModel, layer, re, tfRole),
|
---|
| 139 | new CancelAction(memberTable, memberTableModel, tagModel, layer, re, tfRole)));
|
---|
| 140 | assertNotNull(GenericRelationEditor.buildSelectionControlButtonToolbar(memberTable, memberTableModel, selectionTableModel, re));
|
---|
| 141 | assertNotNull(GenericRelationEditor.buildSelectionTablePanel(selectionTable));
|
---|
| 142 |
|
---|
| 143 | assertNotNull(GenericRelationEditor.buildToolBar(
|
---|
| 144 | new RefreshAction(memberTable, memberTableModel, tagModel, layer, re),
|
---|
| 145 | new ApplyAction(memberTable, memberTableModel, tagModel, layer, re),
|
---|
[12933] | 146 | new SelectAction(layer, re),
|
---|
[10113] | 147 | new DuplicateRelationAction(memberTableModel, tagModel, layer),
|
---|
| 148 | new DeleteCurrentRelationAction(layer, re)));
|
---|
| 149 | }
|
---|
[9666] | 150 | }
|
---|