Changeset 10113 in josm for trunk/test


Ignore:
Timestamp:
2016-04-06T23:06:38+02:00 (9 years ago)
Author:
Don-vip
Message:

refactor relation editor to allow unit tests in headless mode

Location:
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java

    r9669 r10113  
    77import java.util.Collections;
    88
     9import javax.swing.JPanel;
     10
    911import org.junit.BeforeClass;
    1012import org.junit.Test;
    1113import org.openstreetmap.josm.JOSMFixture;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1215import org.openstreetmap.josm.data.osm.Node;
    1316import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1417import org.openstreetmap.josm.data.osm.Relation;
    1518import 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.layer.OsmDataLayer;
     27import org.openstreetmap.josm.gui.tagging.TagEditorModel;
     28import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
     29import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    1630
    1731/**
     
    2539    @BeforeClass
    2640    public static void setUpBeforeClass() {
    27         JOSMFixture.createUnitTestFixture().init();
     41        JOSMFixture.createUnitTestFixture().init(true);
     42    }
     43
     44    /**
     45     * Returns a new relation editor for unit tests.
     46     * @param orig relation
     47     * @param layer data layer
     48     * @return new relation editor for unit tests
     49     */
     50    public static IRelationEditor newRelationEditor(final Relation orig, final OsmDataLayer layer) {
     51        return new IRelationEditor() {
     52            private Relation r = orig;
     53
     54            @Override
     55            public void setRelation(Relation relation) {
     56                r = relation;
     57            }
     58
     59            @Override
     60            public boolean isDirtyRelation() {
     61                return false;
     62            }
     63
     64            @Override
     65            public Relation getRelationSnapshot() {
     66                return r;
     67            }
     68
     69            @Override
     70            public Relation getRelation() {
     71                return r;
     72            }
     73
     74            @Override
     75            public void reloadDataFromRelation() {
     76                // Do nothing
     77            }
     78
     79            @Override
     80            public OsmDataLayer getLayer() {
     81                return layer;
     82            }
     83        };
    2884    }
    2985
     
    4197    }
    4298
     99    /**
     100     * Unit test of {@code GenericRelationEditor#build*} methods.
     101     */
     102    @Test
     103    public void testBuild() {
     104        DataSet ds = new DataSet();
     105        Relation relation = new Relation(1);
     106        ds.addPrimitive(relation);
     107        OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
     108        IRelationEditor re = newRelationEditor(relation, layer);
     109
     110        MemberTableModel memberTableModel = new MemberTableModel(relation, layer, null);
     111        MemberTable memberTable = new MemberTable(layer, relation, memberTableModel);
     112
     113        SelectionTableModel selectionTableModel = new SelectionTableModel(layer);
     114        SelectionTable selectionTable = new SelectionTable(selectionTableModel, memberTableModel);
     115
     116        LeftButtonToolbar leftButtonToolbar = new LeftButtonToolbar(memberTable, memberTableModel, re);
     117        assertNotNull(leftButtonToolbar.sortBelowButton);
     118
     119        AutoCompletingTextField tfRole = GenericRelationEditor.buildRoleTextField(re);
     120        assertNotNull(tfRole);
     121
     122        TagEditorPanel tagEditorPanel = new TagEditorPanel(relation, null);
     123
     124        JPanel top = GenericRelationEditor.buildTagEditorPanel(tagEditorPanel);
     125        JPanel bottom = GenericRelationEditor.buildMemberEditorPanel(
     126                memberTable, memberTableModel, selectionTable, selectionTableModel, re, leftButtonToolbar, tfRole);
     127        assertNotNull(top);
     128        assertNotNull(bottom);
     129        assertNotNull(GenericRelationEditor.buildSplitPane(top, bottom, re));
     130
     131        TagEditorModel tagModel = tagEditorPanel.getModel();
     132
     133        assertNotNull(GenericRelationEditor.buildOkCancelButtonPanel(
     134                new OKAction(memberTable, memberTableModel, tagModel, layer, re, tfRole),
     135                new CancelAction(memberTable, memberTableModel, tagModel, layer, re, tfRole)));
     136        assertNotNull(GenericRelationEditor.buildSelectionControlButtonToolbar(memberTable, memberTableModel, selectionTableModel, re));
     137        assertNotNull(GenericRelationEditor.buildSelectionTablePanel(selectionTable));
     138
     139        assertNotNull(GenericRelationEditor.buildToolBar(
     140                new RefreshAction(memberTable, memberTableModel, tagModel, layer, re),
     141                new ApplyAction(memberTable, memberTableModel, tagModel, layer, re),
     142                new DuplicateRelationAction(memberTableModel, tagModel, layer),
     143                new DeleteCurrentRelationAction(layer, re)));
     144    }
    43145}
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/actions/RelationEditorActionsTest.java

    r9669 r10113  
    77import org.openstreetmap.josm.data.osm.DataSet;
    88import org.openstreetmap.josm.data.osm.Relation;
     9import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditorTest;
    910import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    1011import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
     
    3637        final Relation orig = new Relation(1);
    3738        ds.addPrimitive(orig);
    38         OsmDataLayer layer = new OsmDataLayer(new DataSet(), "test", null);
     39        final OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
    3940        MemberTableModel memberTableModel = new MemberTableModel(orig, layer, null);
    4041        SelectionTableModel selectionTableModel = new SelectionTableModel(layer);
    4142
    42         IRelationEditor editor = new IRelationEditor() {
    43             private Relation r = orig;
    44 
    45             @Override
    46             public void setRelation(Relation relation) {
    47                 r = relation;
    48             }
    49 
    50             @Override
    51             public boolean isDirtyRelation() {
    52                 return false;
    53             }
    54 
    55             @Override
    56             public Relation getRelationSnapshot() {
    57                 return r;
    58             }
    59 
    60             @Override
    61             public Relation getRelation() {
    62                 return r;
    63             }
    64 
    65             @Override
    66             public void reloadDataFromRelation() {
    67                 // Do nothing
    68             }
    69         };
     43        IRelationEditor editor = GenericRelationEditorTest.newRelationEditor(orig, layer);
    7044
    7145        MemberTable memberTable = new MemberTable(layer, editor.getRelation(), memberTableModel);
Note: See TracChangeset for help on using the changeset viewer.