Ejemplo n.º 1
0
 private static File createDefaultSUT() throws Exception {
   File sutDirectory = new File(JSystemProperties.getCurrentTestsPath(), "sut");
   JSystemProperties.getInstance().setPreference(FrameworkOptions.USED_SUT_FILE, "default.xml");
   File defaultSut = new File(sutDirectory, "default.xml");
   if (!defaultSut.exists()) {
     FileUtils.write(defaultSut, "<sut/>", false);
   }
   return defaultSut;
 }
Ejemplo n.º 2
0
  /**
   * get the current sut file<br>
   *
   * @param needToOpenSUTCombo if True and sut is not found, opens a comboBox of suts NOTE: if the
   *     runner was closed, do not use true!
   * @return
   */
  public File getSutFile(boolean needToOpenSUTCombo) {
    String sutFileName =
        JSystemProperties.getInstance().getPreference(FrameworkOptions.USED_SUT_FILE);
    File sutDirectory = getSutDirectory();
    File sutFile;
    if (StringUtils.isEmpty(
        sutFileName)) { // patch in case the entry was deleted only in the current
                        // jsystem.properties file
      JSystemProperties.getInstance().restoreFromBackup();
      sutFileName = JSystemProperties.getInstance().getPreference(FrameworkOptions.USED_SUT_FILE);
    }
    if (!StringUtils.isEmpty(sutFileName)) {
      File _sutFileName = new File(sutFileName);
      if (_sutFileName.exists()) {
        return _sutFileName;
      }
      sutFile = new File(sutDirectory, sutFileName);
      if (sutFile.exists() && sutFile.isFile()) {
        return sutFile;
      }
      log.warning("Can't find sut file: " + sutFile.getPath());
    }

    Vector<String> v = getOptionalSuts();
    if (v.size() == 0 || (v.size() == 1 && CREATE_A_NEW_SUT_FILE.equals(v.get(0)))) {
      try {
        return createDefaultSUT();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    sutFileName = null;
    if (needToOpenSUTCombo && !getSuppressGUI()) {
      sutFileName =
          (String)
              JOptionPane.showInputDialog(
                  TestRunnerFrame.guiMainFrame,
                  "Select SUT File from list",
                  "Select SUT",
                  JOptionPane.INFORMATION_MESSAGE,
                  null,
                  v.toArray(),
                  v.elementAt(0));
    }

    if (sutFileName == null) {
      try {
        return createDefaultSUT();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    return new File(sutDirectory, sutFileName);
  }
Ejemplo n.º 3
0
 public Sut getNewSutInstance() throws Exception {
   String defaultSutClassName = null;
   defaultSutClassName =
       JSystemProperties.getInstance().getPreference(FrameworkOptions.SUT_CLASS_NAME);
   if (defaultSutClassName == null) {
     defaultSutClassName = "jsystem.framework.sut.SutImpl";
     JSystemProperties.getInstance()
         .setPreference(FrameworkOptions.SUT_CLASS_NAME, defaultSutClassName);
   }
   Class<?> c = Class.forName(defaultSutClassName);
   return (Sut) c.getConstructor(new Class[0]).newInstance(new Object[0]);
 }
Ejemplo n.º 4
0
 /** Resets static factory instance. */
 public static void resetSutFactory(String sutFile) {
   factory = null;
   if (sutFile == null) {
     sutFile = JSystemProperties.getInstance().getPreference(FrameworkOptions.USED_SUT_FILE);
   }
   // if no sut is set in jsystem.properties, don't set the sutInstance to null, simply run without
   // sut
   if (sutFile != null) {
     JSystemProperties.getInstance().setPreference(FrameworkOptions.USED_SUT_FILE, sutFile);
     getInstance().getSutInstance();
   }
 }
Ejemplo n.º 5
0
 public Vector<String> getOptionalSuts() {
   File path = getSutDirectory();
   File[] list = path.listFiles();
   if (list != null && list.length > 0) {
     Arrays.sort(list);
   }
   Vector<String> sutsVector = new Vector<String>();
   try {
     if (list == null) {
       return sutsVector;
     }
     for (int i = 0; i < list.length; i++) {
       if (list[i].getName().toLowerCase().endsWith(".xml")) {
         sutsVector.removeElement(list[i].getName());
         sutsVector.addElement(list[i].getName());
       }
     }
     return sutsVector;
   } finally {
     // add create new sut file menu item in the end of the list.
     if (!"false"
         .equals(JSystemProperties.getInstance().getPreference(FrameworkOptions.SUT_PLANNER))) {
       sutsVector.addElement(CREATE_A_NEW_SUT_FILE);
     }
   }
 }
Ejemplo n.º 6
0
 public void toFile(NameGenerator generator) throws IOException {
   if ("false"
       .equals(
           JSystemProperties.getInstance()
               .getPreferenceOrDefault(FrameworkOptions.SAVE_REPORTERS_ON_RUN_END))) {
     doToFile(generator);
   }
 }
Ejemplo n.º 7
0
 public File getSutDirectory() {
   String sutDir = JSystemProperties.getInstance().getPreference(FrameworkOptions.SUT_DIR);
   if (sutDir != null && !(sutDir = sutDir.trim()).isEmpty()) {
     File sd = new File(sutDir);
     sd = new File(System.getProperty("user.dir") + File.separator + sutDir);
     if (sd.exists() && sd.isDirectory()) {
       return sd;
     } else {
       log.log(Level.WARNING, "SUT directory: " + sutDir + " couldn't be found");
     }
   }
   final File testsPath = new File(JSystemProperties.getCurrentTestsPath());
   if (testsPath.getName().equals("test-classes")) {
     // ITAI: We are running from Eclipse project with Maven structure.
     return new File(testsPath.getParentFile() + File.separator + "classes", "sut");
   }
   return new File(testsPath, "sut");
 }
Ejemplo n.º 8
0
 public void testCopyFileFromServerToRemoteClientWithJsystemProperties() throws Exception {
   URL url = getClass().getResource("FTPRemoteClientTest.class");
   FileUtils.copyURLToFile(
       url, new File(ftpServer.getDefaultUserHomeDirectory(), "FTPRemoteClientTest.class"));
   String ftpServer = ftpRemoteClient.getFtpServerHostName();
   try {
     JSystemProperties.getInstance()
         .setPreference(FTPRemoteClient.LOCAL_HOST_ADDRESS_PROPERTY, "128.0.0.1");
     ftpRemoteClient.copyFileFromLocalMachineToRemoteClient(
         "FTPRemoteClientTest.class", "./FTPRemoteClientTest2.class");
     assertTrue(false);
   } catch (Exception e) {
     // good
   } finally {
     ftpRemoteClient.setFtpServerHostName(ftpServer);
     JSystemProperties.getInstance()
         .setPreference(FTPRemoteClient.LOCAL_HOST_ADDRESS_PROPERTY, "");
   }
 }
Ejemplo n.º 9
0
 public int getCurrentSutIndex() {
   Vector<String> v = getOptionalSuts();
   String currentSut =
       JSystemProperties.getInstance().getPreference(FrameworkOptions.USED_SUT_FILE);
   for (int i = 0; i < v.size(); i++) {
     if (v.elementAt(i).toString().equals(currentSut)) {
       return i;
     }
   }
   return -1;
 }
  /**
   * Assert current running test html file with an expected html file name.
   *
   * @param expectedfileName expected report html file
   */
  private void assertCurrentTestFileName(String expectedfileName) {
    String baseLogFolder =
        JSystemProperties.getInstance().getPreference(FrameworkOptions.LOG_FOLDER)
            + File.separator
            + "current";
    String expectedCurrentTestFileName = baseLogFolder + File.separator + expectedfileName;
    String actualCurrentTestFileName = HtmlReporterUtils.getCurrentTestFileName();

    report.report("Expected Current Test File Name: " + expectedCurrentTestFileName);
    report.report("Actual Current Test File Name: " + actualCurrentTestFileName);

    Assert.assertEquals(expectedCurrentTestFileName, actualCurrentTestFileName);
  }
Ejemplo n.º 11
0
 /**
  * Get an instance of the used SUT.
  *
  * @return The SUT instance.
  */
 public Sut getSutInstance() {
   if (usedSut == null) {
     try {
       usedSut = getNewSutInstance();
       init();
     } catch (Exception e) {
       log.log(
           Level.SEVERE,
           "Unable to load sut class: "
               + JSystemProperties.getInstance().getPreference(FrameworkOptions.SUT_CLASS_NAME),
           e);
     }
   }
   return usedSut;
 }
Ejemplo n.º 12
0
  /** Init the SUT. */
  private void init() {
    File sutFile = getSutFile();
    if (sutFile == null) {
      log.fine("Fail to load SUT file");
      return;
    }
    JSystemProperties.getInstance()
        .setPreference(FrameworkOptions.USED_SUT_FILE, sutFile.getName());

    try {
      File file = new File(getSutDirectory(), sutFile.getName());
      usedSut.setSutXml(file);
      log.log(Level.FINE, "Use sut file: " + sutFile.getName());
    } catch (Exception e) {
      String message = "Unable to init sut with file: " + sutFile.getName() + " " + e.getMessage();
      log.log(Level.WARNING, message);
      log.log(Level.FINE, message, e);
    }
  }
Ejemplo n.º 13
0
  public JythonTestInterpreter() {
    super();

    // do common interpreter initialization

    // set up the __main__ module
    PyModule mod = imp.addModule("__main__");
    setLocals(mod.__dict__);

    // load the jyrunner module that contains helper methods for reflecting and
    // running jython tests
    exec("import sys");
    exec(String.format("sys.path.append(r'%s\\lib\\jython')", System.getenv("RUNNER_ROOT")));
    exec(
        String.format(
            "sys.path.append(r'%s')",
            JSystemProperties.getInstance().getPreference(FrameworkOptions.TESTS_CLASS_FOLDER)));
    execfile(String.format("%s\\lib\\jython\\jyrunner.py", System.getenv("RUNNER_ROOT")));
  }
Ejemplo n.º 14
0
 public void doToFile(NameGenerator generator) throws IOException {
   if (isTreeRoot) {
     StringBuffer buffer = new StringBuffer();
     buffer.append(
         "<HEAD>\n"
             + "<LINK REL=\"stylesheet\" HREF=\""
             + FileUtils.getFileNameWithoutFullPath(
                 JSystemProperties.getInstance()
                     .getPreferenceOrDefault(FrameworkOptions.HTML_CSS_PATH))
             + "\">\n");
     if (isTreeRoot) {
       buffer.append(
           "<SCRIPT SRC=\"mktree.js\" LANGUAGE=\"JavaScript\"></SCRIPT>\n"
               + "<LINK REL=\"stylesheet\" HREF=\"mktree.css\">\n");
     }
     buffer.append("</HEAD>\n");
     buffer.append("<BODY class=\"" + getCssClassCanonicalValue() + "\">");
     buffer.append(getTreeSons(null));
     buffer.append("</BODY>");
     writeBufferToFile(buffer);
   }
   updateParents(generator);
 }
Ejemplo n.º 15
0
  /**
   * Updates the JSystem properties file with all the data required for the execution
   *
   * @param sutFile - The SUT file to use
   * @param scenarioFile - The scenario to use
   */
  private void updateJSystemProperties(
      final File sutFile,
      final String sutName,
      final File scenarioFile,
      final String scenarioName) {
    JSystemProperties.getInstance()
        .setPreference(
            FrameworkOptions.LOG_FOLDER,
            mavenProject.getBasedir().getAbsolutePath() + File.separator + "log");
    String reporters =
        JSystemProperties.getInstance().getPreference(FrameworkOptions.REPORTERS_CLASSES);

    // Making sure that there are reporters configured in the properties
    // file.
    if (null == reporters) {
      JSystemProperties.getInstance()
          .setPreference(FrameworkOptions.REPORTERS_CLASSES, DEFAULT_REPORTERS);
    }

    // Configure all other required parameters:

    // Scenario
    JSystemProperties.getInstance().setPreference(FrameworkOptions.CURRENT_SCENARIO, scenarioName);

    // SUT
    JSystemProperties.getInstance().setPreference(FrameworkOptions.USED_SUT_FILE, sutName);

    // Class Folder
    JSystemProperties.getInstance()
        .setPreference(
            FrameworkOptions.TESTS_CLASS_FOLDER,
            mavenProject.getBasedir().getAbsolutePath()
                + File.separator
                + "target"
                + File.separator
                + "classes");

    // Test Source
    JSystemProperties.getInstance()
        .setPreference(
            FrameworkOptions.TESTS_SOURCE_FOLDER,
            mavenProject.getBasedir().getAbsolutePath()
                + File.separator
                + "src"
                + File.separator
                + "main"
                + File.separator
                + "java");

    // resources folder.
    JSystemProperties.getInstance()
        .setPreference(
            FrameworkOptions.RESOURCES_SOURCE_FOLDER,
            mavenProject.getBasedir().getAbsolutePath()
                + File.separator
                + "src"
                + File.separator
                + "main"
                + File.separator
                + "resources");
  }
Ejemplo n.º 16
0
  /** @param parent JFrame parent */
  public About(JFrame parent) {

    super(parent);

    // Set window frame - label and icon
    setTitle("About JSystem");
    setIconImage(ImageCenter.getInstance().getAwtImage(ImageCenter.ICON_JSYSTEM));

    // Set window location in the middle of the physical screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    setLocation(screenWidth / 3, screenHeight / 3);
    setModal(true);
    setResizable(false);

    // Get dialog panel
    JPanel panel = (JPanel) getContentPane();

    // Add JPanel with background
    ImageIcon leftImage = ImageCenter.getInstance().getImage(ImageCenter.ABOUT_DIALOG_LEFT_IMAGE);
    JPanel bgPanel = jsystem.utils.SwingUtils.getJPannelWithLeftBgImage(leftImage);
    bgPanel.setLayout(new BorderLayout());
    bgPanel.setBackground(new Color(0xf6, 0xf6, 0xf6));
    panel.add(bgPanel);

    // Add JSystem logo
    ImageIcon logoImage = ImageCenter.getInstance().getImage(ImageCenter.ABOUT_DIALOG_LOGO);
    JLabel logoImageLable = new JLabel(logoImage);
    logoImageLable.setOpaque(false);
    logoImageLable.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0));
    bgPanel.add(logoImageLable, BorderLayout.PAGE_START);

    /*
     * Add label panel for version, contribution note and customer product
     */
    JPanel labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
    labelPanel.setOpaque(false);
    labelPanel.setBorder(BorderFactory.createEmptyBorder(4, 32, 4, 8));

    // Add version
    try {
      version =
          ClassSearchUtil.getPropertyFromClassPath(
              "META-INF/maven/org.jsystemtest/jsystemApp/pom.properties", "version");
    } catch (Exception e) {
      log.log(Level.WARNING, "Failed getting client version: " + e.getMessage());
    }
    JLabel versionLabel = new JLabel("Version: " + version);
    versionLabel.setOpaque(false);
    versionLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 2, 4));
    versionLabel.setFont(new Font("sansserif", Font.BOLD, 16));
    labelPanel.add(versionLabel);

    // Add copyright
    final JLabel copyrightLabel =
        new JLabel("<html> Copyright 2005-2014 <a href=\"www.top-q.co.il\">Top-Q</a>.</html>");
    copyrightLabel.setOpaque(false);
    copyrightLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 8, 4));
    copyrightLabel.setFont(new Font("sansserif", Font.PLAIN, 12));
    labelPanel.add(copyrightLabel);

    // Add link to Top-Q URL
    copyrightLabel.addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent me) {
            copyrightLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
          }

          public void mouseExited(MouseEvent me) {
            copyrightLabel.setCursor(Cursor.getDefaultCursor());
          }

          public void mouseClicked(MouseEvent me) {
            if (Desktop.isDesktopSupported()) {
              Desktop desktop = Desktop.getDesktop();
              try {
                desktop.browse(new URI("http://www.top-q.co.il"));
              } catch (Exception e) {
                log.log(
                    Level.WARNING, "Failed opening browser to Top-Q website: " + e.getMessage());
              }
            }
          }
        });

    JLabel contributionLable2 = new JLabel("For version release notes go to:");
    contributionLable2.setOpaque(false);
    contributionLable2.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
    contributionLable2.setFont(new Font("sansserif", Font.PLAIN, 12));
    labelPanel.add(contributionLable2);
    final JLabel contributionLable3 =
        new JLabel(
            "<html><a href=\"https://github.com/Top-Q/jsystem/wiki/Release-Notes\">https://github.com/Top-Q/jsystem/wiki/Release-Notes</a></html>");
    contributionLable3.setOpaque(false);
    contributionLable3.setBorder(BorderFactory.createEmptyBorder(2, 4, 16, 4));
    contributionLable3.setFont(new Font("sansserif", Font.PLAIN, 12));
    labelPanel.add(contributionLable3);

    // Add link to release notes URL
    contributionLable3.addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent me) {
            contributionLable3.setCursor(new Cursor(Cursor.HAND_CURSOR));
          }

          public void mouseExited(MouseEvent me) {
            contributionLable3.setCursor(Cursor.getDefaultCursor());
          }

          public void mouseClicked(MouseEvent me) {
            if (Desktop.isDesktopSupported()) {
              Desktop desktop = Desktop.getDesktop();
              try {
                desktop.browse(new URI("https://github.com/Top-Q/jsystem/wiki/Release-Notes"));
              } catch (Exception e) {
                log.log(
                    Level.WARNING, "Failed openning browser to JSystem wiki: " + e.getMessage());
              }
            }
          }
        });

    // Add customer version if required
    String customerProduct =
        JSystemProperties.getInstance().getPreference(FrameworkOptions.CUSTOMER_PRODUCT);
    if (customerProduct != null) {
      String customerProductList[] = customerProduct.split(CommonResources.DELIMITER);
      labelPanel.add(new JSeparator());
      JLabel customerLabel = new JLabel("Customer information:");
      customerLabel.setOpaque(false);
      customerLabel.setBorder(BorderFactory.createEmptyBorder(8, 4, 8, 4));
      customerLabel.setFont(new Font("sansserif", Font.PLAIN, 12));
      labelPanel.add(customerLabel);
      JLabel customerLabels[] = new JLabel[customerProductList.length];
      for (int i = 0; i < customerProductList.length; i++) {
        customerLabels[i] = new JLabel(customerProductList[i]);
        customerLabels[i].setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
        customerLabels[i].setFont(new Font("sansserif", Font.PLAIN, 12));
        labelPanel.add(customerLabels[i]);
      }
    }

    // Add label panel to the dialog
    bgPanel.add(labelPanel, BorderLayout.CENTER);

    // Add Close button
    JButton closeButton = new JButton("Close");
    closeButton.setOpaque(false);
    closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    closeButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    JPanel closeButtonPanel = new JPanel();
    closeButtonPanel.setOpaque(false);
    closeButtonPanel.add(closeButton);
    closeButtonPanel.setBorder(BorderFactory.createEmptyBorder(8, 4, 8, 4));
    bgPanel.add(closeButtonPanel, BorderLayout.PAGE_END);

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            dispose();
          }
        });

    pack();
  }
Ejemplo n.º 17
0
 public void setSut(String sutName) {
   JSystemProperties.getInstance().setPreference(FrameworkOptions.USED_SUT_FILE, sutName);
   init();
 }