Ejemplo n.º 1
0
  /**
   * utility method to read the contents of a file, and return it as a string
   *
   * @param fileName
   * @return
   */
  public static String readWeaponFromThisFile(final String fileName) {
    final StringBuffer res = new StringBuffer();
    // we've received the weapon description as a filename, load it
    try {

      final java.io.FileReader fi = new java.io.FileReader(fileName);
      final java.io.BufferedReader bg = new java.io.BufferedReader(fi);
      String next = bg.readLine();
      while (next != null) {
        res.append(next);
        res.append("\n");
        next = bg.readLine();
      }
      bg.close();

    } catch (java.io.IOException ee) {
      ee.printStackTrace();
    }
    return res.toString();
  }
Ejemplo n.º 2
0
    /** test case for importing a Launch command from XML (because it's fiddly) */
    public void NOTtestImportXML() {

      /** create the scenario */
      final CoreScenario scenario = new CoreScenario();
      scenario.setScenarioStepTime(10000);
      scenario.setTime(0);
      scenario.setName("Testing importing Launch");

      final Waterfall theWaterfall = new Waterfall();

      /** read in the file */
      String root = System.getProperty("TEST_ROOT");
      if (root == null) {
        System.err.println("Don't know test root, using hard-coded.");
        root = "src";
      }

      final String fName = root + "TEST_LAUNCH.XML";

      // check it exists
      assertTrue("Couldn't find tests data file", new java.io.File(fName).exists());

      try {
        //        ASSET.Util.XML.ASSETReaderWriter.importThis(scenario, fName, new
        // java.io.FileInputStream(fName));
        ASSET.Util.XML.ASSETReaderWriter.importThis(
            theWaterfall, fName, new java.io.FileInputStream(fName));
      } catch (java.io.IOException ee) {
        ee.printStackTrace();
      }

      final Waterfall newWaterfall = (Waterfall) theWaterfall.getModels().firstElement();
      assertEquals(
          "Read in launch behaviour",
          newWaterfall.getModels().firstElement().toString(),
          "Destroy Red");
      final LaunchWeapon theLaunch = (LaunchWeapon) newWaterfall.getModels().firstElement();
      //      final String launchType = theLaunch.getLaunchType();
      assertEquals("Behaviour is correct length", 1719, theLaunch.getLaunchType().length());
    }