Changeset 7081 in josm for trunk/test/functional


Ignore:
Timestamp:
2014-05-09T04:49:54+02:00 (6 years ago)
Author:
Don-vip
Message:

fixes for unit tests

Location:
trunk/test/functional/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/gui/history/HistoryBrowserTest.java

    r7030 r7081  
    22package org.openstreetmap.josm.gui.history;
    33
    4 import static org.junit.Assert.fail;
    5 
    64import java.awt.BorderLayout;
    7 import java.io.File;
    8 import java.io.IOException;
    9 import java.io.InputStream;
    10 import java.text.MessageFormat;
    11 import java.util.Properties;
    12 import java.util.logging.Level;
    135import java.util.logging.Logger;
    146
     
    168
    179import org.junit.BeforeClass;
     10import org.openstreetmap.josm.JOSMFixture;
    1811import org.openstreetmap.josm.Main;
    1912import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    2114import org.openstreetmap.josm.data.osm.history.History;
    2215import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    23 import org.openstreetmap.josm.data.projection.Projections;
    2416import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2517import org.openstreetmap.josm.io.OsmServerHistoryReader;
     
    3022    static private Logger logger = Logger.getLogger(HistoryBrowserTest.class.getName());
    3123
    32     static Properties testProperties;
    33 
    3424    @BeforeClass
    3525    static public void init() {
    36         testProperties = new Properties();
    37 
    38         // load properties
    39         //
    40         try (InputStream is = HistoryBrowserTest.class.getResourceAsStream("/test-functional-env.properties");) {
    41             testProperties.load(is);
    42         } catch(IOException e){
    43             logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
    44             fail(MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
    45         }
    46 
    47         // check josm.home
    48         //
    49         String josmHome = testProperties.getProperty("josm.home");
    50         if (josmHome == null) {
    51             fail(MessageFormat.format("property ''{0}'' not set in test environment", "josm.home"));
    52         } else {
    53             File f = new File(josmHome);
    54             if (! f.exists() || ! f.canRead()) {
    55                 fail(MessageFormat.format("property ''{0}'' points to ''{1}'' which is either not existing or not readable", "josm.home", josmHome));
    56             }
    57         }
    58         System.setProperty("josm.home", josmHome);
    59         Main.pref.init(false);
    60 
    61         // init projection
    62         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
     26        JOSMFixture.createFunctionalTestFixture().init();
    6327    }
    6428
  • trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java

    r7040 r7081  
    1212import java.io.FileOutputStream;
    1313import java.io.IOException;
    14 import java.io.InputStream;
    1514import java.io.OutputStreamWriter;
    1615import java.io.PrintWriter;
     
    1817import java.util.ArrayList;
    1918import java.util.Properties;
    20 import java.util.logging.Level;
    2119import java.util.logging.Logger;
    2220
     
    2422import org.junit.BeforeClass;
    2523import org.junit.Test;
     24import org.openstreetmap.josm.JOSMFixture;
    2625import org.openstreetmap.josm.Main;
    2726import org.openstreetmap.josm.data.coor.LatLon;
     
    3332import org.openstreetmap.josm.data.osm.RelationMember;
    3433import org.openstreetmap.josm.data.osm.Way;
    35 import org.openstreetmap.josm.data.projection.Projections;
    3634import org.openstreetmap.josm.gui.io.UploadStrategy;
    3735import org.openstreetmap.josm.gui.io.UploadStrategySpecification;
     
    136134    public static void init() throws OsmTransferException {
    137135        logger.info("initializing ...");
    138         testProperties = new Properties();
    139 
    140         // load properties
    141         //
    142         try (InputStream is = MultiFetchServerObjectReaderTest.class.getResourceAsStream("/test-functional-env.properties")) {
    143             if (is == null) {
    144                 throw new IOException();
    145             }
    146             testProperties.load(is);
    147         } catch(IOException e){
    148             logger.log(Level.SEVERE, MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
    149             fail(MessageFormat.format("failed to load property file ''{0}''", "test-functional-env.properties"));
    150         }
    151 
    152         // check josm.home
    153         //
    154         String josmHome = testProperties.getProperty("josm.home");
    155         if (josmHome == null) {
    156             fail(MessageFormat.format("property ''{0}'' not set in test environment", "josm.home"));
    157         } else {
    158             File f = new File(josmHome);
    159             if (! f.exists() || ! f.canRead()) {
    160                 fail(MessageFormat.format("property ''{0}'' points to ''{1}'' which is either not existing or not readable", "josm.home", josmHome));
    161             }
    162         }
    163 
    164         // check temp output dir
    165         //
    166         String tempOutputDir = testProperties.getProperty("test.functional.tempdir");
    167         if (tempOutputDir == null) {
    168             fail(MessageFormat.format("property ''{0}'' not set in test environment", "test.functional.tempdir"));
    169         } else {
    170             File f = new File(tempOutputDir);
    171             if (! f.exists() || ! f.isDirectory() || ! f.canWrite()) {
    172                 fail(MessageFormat.format("property ''{0}'' points to ''{1}'' which is either not existing, not a directory, or not writeable", "test.functional.tempdir", tempOutputDir));
    173             }
    174         }
    175 
    176 
    177         // init preferences
    178         //
    179         System.setProperty("josm.home", josmHome);
    180         Main.pref.init(false);
     136        JOSMFixture.createFunctionalTestFixture().init();
     137
    181138        // don't use atomic upload, the test API server can't cope with large diff uploads
    182139        //
    183140        Main.pref.put("osm-server.atomic-upload", false);
    184         Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    185 
    186         File dataSetCacheOutputFile = new File(tempOutputDir, MultiFetchServerObjectReaderTest.class.getName() + ".dataset");
     141
     142        File dataSetCacheOutputFile = new File(System.getProperty("java.io.tmpdir"), MultiFetchServerObjectReaderTest.class.getName() + ".dataset");
    187143
    188144        // make sure we don't upload to production
Note: See TracChangeset for help on using the changeset viewer.