Ignore:
Timestamp:
2017-11-04T17:11:15+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #15508 - add TileSourceRule, use in MinimapDialogTest (patch by ris, modified) + update WireMock to 2.10.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r13021 r13078  
    22package org.openstreetmap.josm.testutils;
    33
     4import java.awt.Color;
    45import java.io.File;
    56import java.io.IOException;
     
    5758    private APIType useAPI = APIType.NONE;
    5859    private String i18n = null;
     60    private TileSourceRule tileSourceRule;
    5961    private boolean platform;
    6062    private boolean useProjection;
     
    243245
    244246    /**
     247     * Replace imagery sources with a default set of mock tile sources
     248     *
     249     * @return this instance, for easy chaining
     250     */
     251    public JOSMTestRules fakeImagery() {
     252        return this.fakeImagery(
     253            new TileSourceRule(
     254                true,
     255                true,
     256                true,
     257                new TileSourceRule.ColorSource(Color.WHITE, "White Tiles", 256),
     258                new TileSourceRule.ColorSource(Color.BLACK, "Black Tiles", 256),
     259                new TileSourceRule.ColorSource(Color.MAGENTA, "Magenta Tiles", 256),
     260                new TileSourceRule.ColorSource(Color.GREEN, "Green Tiles", 256)
     261            )
     262        );
     263    }
     264
     265    /**
     266     * Replace imagery sources with those from specific mock tile server setup
     267     * @param tileSourceRule Tile source rule
     268     *
     269     * @return this instance, for easy chaining
     270     */
     271    public JOSMTestRules fakeImagery(TileSourceRule tileSourceRule) {
     272        this.preferences();
     273        this.tileSourceRule = tileSourceRule;
     274        return this;
     275    }
     276
     277    /**
    245278     * Use the {@link Main#main}, {@code Main.contentPanePrivate}, {@code Main.mainPanel},
    246279     *         {@link Main#menu}, {@link Main#toolbar} global variables in this test.
     
    257290    public Statement apply(Statement base, Description description) {
    258291        Statement statement = base;
     292        // counter-intuitively, Statements which need to have their setup routines performed *after* another one need to
     293        // be added into the chain *before* that one, so that it ends up on the "inside".
    259294        if (timeout > 0) {
    260295            // TODO: new DisableOnDebug(timeout)
    261296            statement = new FailOnTimeoutStatement(statement, timeout);
    262297        }
     298
     299        // this half of TileSourceRule's initialization must happen after josm is set up
     300        if (this.tileSourceRule != null) {
     301            statement = this.tileSourceRule.applyRegisterLayers(statement, description);
     302        }
     303
    263304        statement = new CreateJosmEnvironment(statement);
    264305        if (josmHome != null) {
    265306            statement = josmHome.apply(statement, description);
     307        }
     308
     309        // run mock tile server as the outermost Statement (started first) so it can hopefully be initializing in
     310        // parallel with other setup
     311        if (this.tileSourceRule != null) {
     312            statement = this.tileSourceRule.applyRunServer(statement, description);
    266313        }
    267314        return statement;
     
    407454        MainApplication.getLayerManager().resetState();
    408455        eventManager.resetState();
     456    }
     457
     458    /**
     459     * @return TileSourceRule which is automatically started by this rule
     460     */
     461    public TileSourceRule getTileSourceRule() {
     462        return this.tileSourceRule;
    409463    }
    410464
Note: See TracChangeset for help on using the changeset viewer.