Exemplo n.º 1
0
 private static String getACountryName() throws SQLException, CorpusDatabaseException {
   Country country = new Country(SiteTest.db);
   List<String> countriesAll = null;
   countriesAll = country.getAllEntries("name_de", false);
   countriesAll.addAll(country.getAllEntries("name_en", false));
   return countriesAll.get(Testing.randomInt(countriesAll.size()));
 }
Exemplo n.º 2
0
  private static void testCountryCode() {
    Testing.so("Getting country-codes..", Format.STEP);

    // get test data
    List<String> ccodesAll = null;
    List<String> ccodesUsed = null;
    try {
      Country country = new Country(SiteTest.db);
      ccodesAll = country.getAllEntries("name_de", false);
      ccodesAll.addAll(country.getAllEntries("name_en", false));
      ccodesUsed = country.getAllEntries("country_code", true);
      Testing.so(
          String.format("%d of %d currently used", ccodesUsed.size(), ccodesAll.size()),
          Format.STEPSUB);
    } catch (Exception e) {
      Testing.err(e);
    }

    // test assignment
    Testing.so("Assigning country-codes", Format.STEP);
    Testing.so("This test only assigning the value. Site won't be saved.", Format.STEPINFO);
    for (int i = 0; i < ccodesAll.size(); i++) {
      Testing.so("Try assigning country-code '" + ccodesAll.get(i) + "'", Format.STEPSUB);
      try {
        SiteTest.site.setCountryCodeByName(ccodesAll.get(i));
      } catch (Exception e) {
        Testing.err(e);
      }
    }

    // test setting
    try {
      String cCode = ccodesAll.get(Testing.randomInt(ccodesAll.size()));
      Testing.so("Setting country-code for this site to (random): '" + cCode + "'", Format.STEP);
      SiteTest.site.setCountryCodeByName(cCode);
      SiteTest.properties.put("countrycode", cCode);
    } catch (Exception e) {
      Testing.err(e);
    }
  }
Exemplo n.º 3
0
  private static final boolean checkTest(Number siteId) {
    final Map<String, Object> dbData = new HashMap<String, Object>();
    System.out.println("Site id is " + siteId);

    try {
      gimmi.content.Site newSite = new gimmi.content.Site(SiteTest.db);
      ResultSet newSiteRS = newSite.getTable().find("site_id", siteId.toString());
      if (newSiteRS.next()) {
        // simple types
        dbData.put("timestamp", newSiteRS.getString("crawl_time"));
        dbData.put("time", newSiteRS.getString("crawl_time"));
        dbData.put("url", newSiteRS.getString("url_path"));
        dbData.put("rootfile", newSiteRS.getString("root_file"));
        dbData.put("title", newSiteRS.getString("title"));
        dbData.put("storage", newSiteRS.getString("storage_path"));
        // referenced types
        Language language = new Language(SiteTest.db);
        dbData.put(
            "languagecode", language.getNameById("language_id", newSiteRS.getInt("language_id")));
        Country country = new Country(SiteTest.db);
        dbData.put(
            "countrycode", country.getNameById("country_id", newSiteRS.getInt("country_id")));
        // relation types
        SiteHasCategory siteCategory = new SiteHasCategory(SiteTest.db);
        ResultSet siteCategoryRS =
            siteCategory
                .getTable()
                .joinWithCondition(
                    "category_id",
                    new Category(SiteTest.db).getTable(),
                    "category_id",
                    siteCategory.getTable().getName() + ".site_id='" + siteId + "'");
        if (siteCategoryRS.next()) {
          dbData.put("category", newSite.getCategoryNameById(siteId).toString());
        }
      }
    } catch (Exception e) {
      Testing.err(e);
    }

    for (String setting : SiteTest.properties.keySet()) {
      String test = null;
      if (setting == "url") {
        try {
          test =
              (new URL(SiteTest.properties.get(setting).toString()).getPath())
                      .equals(dbData.get(setting))
                  ? "ok"
                  : "fail?";
        } catch (MalformedURLException e) {
          Testing.err(e);
        }
      } else if (setting == "timestamp") {
        // cut the hundreds - they aren't stored in the db
        String ts1 = SiteTest.properties.get(setting).toString();
        ts1 = ts1.substring(0, ts1.lastIndexOf("."));
        String ts2 = SiteTest.properties.get(setting).toString();
        ts2 = ts2.substring(0, ts2.lastIndexOf("."));
        test = ts1.equals(ts2) ? "ok" : "fail?";
      } else if (setting == "storage") {
        String ts = SiteTest.properties.get(setting).toString();
        // fix slashes like on add to db
        if (!ts.startsWith("/")) {
          ts = "/" + ts;
        }
        if (!ts.endsWith("/")) {
          ts = ts + "/";
        }
        test = ts.equals(dbData.get(setting)) ? "ok" : "fail?";
      } else {
        test = SiteTest.properties.get(setting).equals(dbData.get(setting)) ? "ok" : "fail?";
      }
      System.out.printf(
          "%-15s: set['%-45s'] get['%-45s'] = %s\n",
          setting, SiteTest.properties.get(setting), dbData.get(setting), test);
    }
    return true;
  }