Пример #1
0
 /**
  * Prints out the markers attached to a file
  *
  * @param tpl Path to the file
  */
 protected void dumpMarkers(final IPath tpl) {
   final IMarker[] markers = env.getMarkersFor(tpl);
   for (int i = 0; i < markers.length; i++) {
     final IMarker marker = markers[i];
     System.out.println(getDescription(marker));
   }
 }
Пример #2
0
  /** setup with spedified user */
  @Override
  protected void before() throws Throwable {
    if (AppEngineUtil.isProduction()) {
      // not loaded TestEnvironment on production
      return;
    }

    TestEnvironment environment = (TestEnvironment) ApiProxy.getCurrentEnvironment();
    if (environment == null) {
      throw new NullPointerException("Not initialized TestEnvironment. please use RuleChain");
    }
    environment.setEmail(email);
    environment.setAdmin(admin);
    if (authDomain != null) {
      environment.setAuthDomain(authDomain);
    }
  }
Пример #3
0
 public T withTestEnvironment(TestEnvironment testEnvironment) {
   if (_testEnvironment.isRemoteExecutionEnvironment()) {
     throw new IllegalStateException(
         "For now, withTestEnvironment must be called BEFORE withRemoteServer is called");
   }
   _testEnvironment = testEnvironment;
   _executionManager.setEnvironment(_testEnvironment);
   return thisAsT();
 }
Пример #4
0
  private void maybeCreateTestClassWrappers() {

    maybeInitSuite();

    if (!_testClassWrappersCreated) {
      long start = System.currentTimeMillis();

      if (_testSpecs.isEmpty()) {
        TestClassFinder finder =
            new TestClassFinder(_iFileFilters, _packageFilters, _withPackages, _typeFilters);
        _testSpecs.addAll(finder.findTests(_gosuClassSearchPath, _javaClassSearchPath));
      }

      restrictTestSpecsToSpecifiedNames();

      for (TestSpec spec : _testSpecs) {
        if (_testEnvironment.isRemoteExecutionEnvironment()) {
          String[] methods = spec.runAllMethods() ? null : spec.getMethods();
          RemoteTestClassWrapper remoteWrapper =
              new RemoteTestClassWrapper(_executionManager, spec.getTestTypeName(), methods);
          addTest(remoteWrapper);
        } else {
          IType type = spec.getTestType();
          addTest(new TestClassWrapper(_executionManager, type, spec.getMethods()));
        }
      }
      _testClassWrappersCreated = true;
      long end = System.currentTimeMillis();
      System.out.println("Test wrappers created in " + (end - start) + "ms");

      if (_testEnvironment.isDynamicallyDeterminedEnvironment()) {
        _testEnvironment = determineTestEnvironmentBasedOnTestDefaults();
        System.out.println(
            "Dynamically determined the test environment to be " + _testEnvironment.getClass());
        // This is pretty hacky, but RemoteTestEnvironments need a chance to tell the remote server
        // what sort of environment to set up, and that actually needs to be done prior to beginning
        // the suite
        if (_testEnvironment instanceof ForwardingTestEnvironment) {
          _testEnvironment.initializeTypeSystem();
        }
        _executionManager.setEnvironment(_testEnvironment);
      }
    }
  }
Пример #5
0
 /**
  * Asserts that no markers with severity ERROR are attached to a file
  *
  * @param tpl Path to the file
  */
 public void assertNoErrorMarkers(final IPath tpl) {
   final IMarker[] markers = env.getMarkersFor(tpl);
   for (IMarker marker : markers) {
     try {
       if (marker.isSubtypeOf(IMarker.PROBLEM)) {
         fail(getDescription(marker));
       }
     } catch (CoreException e) {
       throw new RuntimeException(e);
     }
   }
 }
Пример #6
0
  public void waitUntilWindowExists(TestEnvironment te, String window) {
    int time = 0;
    boolean found = false;
    while (!found)
      for (String winHandle : te.getDriver().getWindowHandles()) {
        try {
          /*
           * switch focus of WebDriver to the next found window handle
           * (that's your newly opened window)
           */
          te.getDriver().switchTo().window(winHandle);
          if (te.getDriver().getTitle().toUpperCase().contains(window.toUpperCase())) {
            found = true;
            break;
          }
        } catch (NoSuchWindowException | NullPointerException e) {

        }
      }
    time++;

    if (time == TestEnvironment.getDefaultTestTimeout()) found = true;
  }
Пример #7
0
  @Override
  protected boolean isActive(AnnotatedElement e) {
    TestEnvironment env = TestEnvironment.get();

    String testName = e.getAnnotation(TestExtension.class).value();
    if (testName.length() > 0 && !env.testCase.getName().equals(testName))
      return false; // doesn't apply to this test

    if (e instanceof Class) {
      return isActive(env, (Class) e);
    }
    if (e instanceof Field) {
      Field f = (Field) e;
      return f.getDeclaringClass().isInstance(env.testCase);
    }
    if (e instanceof Method) {
      Method m = (Method) e;
      return m.getDeclaringClass().isInstance(env.testCase);
    }
    return false;
  }
Пример #8
0
  private TestEnvironment determineTestEnvironmentBasedOnTestDefaults() {
    TestEnvironment defaultEnv = null;
    TestClass defaultEnvTest = null;

    for (Test t : testsAsList()) {
      if (t instanceof TestClassWrapper) {
        if (((TestClassWrapper) t).testCount() > 0) {
          Test firstTest = ((TestClassWrapper) t).tests().nextElement();
          if (firstTest instanceof TestClass) {
            TestEnvironment env = ((TestClass) firstTest).createDefaultEnvironment();
            if (defaultEnv == null) {
              defaultEnv = env;
              defaultEnvTest = (TestClass) firstTest;
            } else {
              if (!defaultEnv.getClass().equals(env.getClass())) {
                throw new IllegalStateException(
                    "The test "
                        + defaultEnvTest.getClassName()
                        + " requires the "
                        + defaultEnv.getClass()
                        + " environment, while the "
                        + ((TestClass) firstTest).getClassName()
                        + " test requires the "
                        + env.getClass()
                        + " environment.  Automatic resolution of the appropriate "
                        + "test environment will only work if all tests in the suite use the exact same default test environment.");
              }
            }
          } else {
            throw new IllegalStateException(
                "Found a test that was a " + firstTest.getClass() + " instead of a TestClass");
          }
        } else {
          throw new IllegalStateException(
              "Found a test class "
                  + ((TestClassWrapper) t).getBackingType().getName()
                  + " that has no tests.");
        }
      } else {
        throw new IllegalStateException(
            "Found a test that was a " + t.getClass() + " instead of a TestClassWrapper");
      }
    }

    return defaultEnv;
  }
Пример #9
0
 public void restoreTest(TestEnvironment env, Object val) {
   env.removeModifier(this);
 }
Пример #10
0
 public void modifyTest(TestEnvironment env, Object val) {
   env.setModifier(this, val);
 }
Пример #11
0
 public void setCurrentWindow(TestEnvironment te) {
   currentWindow = te.getDriver().getWindowHandle(); // get the current
   // window handle
 }
Пример #12
0
 public WebDriver swapToParentWindow(TestEnvironment te) {
   te.getDriver().switchTo().window(currentWindow); // switch back to the
   // original window
   return te.getDriver();
 }
 /**
  * Disposes the current test environment, which was corrupted by the test.
  *
  * @see #disposeEnvironment(TestEnvironment)
  */
 public void disposeEnvironment() {
   tEnv.dispose();
   TestCase tCase = tEnv.getTestCase();
   tCase.disposeTestEnvironment(tEnv, tParam);
 }
  /**
   * Runs the interface test: its method tests. First, it initializes some of MultiMethodTest
   * fields, like tRes, log, tEnv, etc. Then, it queries the tested interface and initializes 'oObj'
   * field (defined in a subclass). Before calling method tests, before() method calles to allow
   * initialization of s stuff before testing. Then, the method tests are called. After them,
   * after() method is called, to allow cleaning up the stuff initialized in before() and test
   * methods.
   *
   * @param entry the interface test state
   * @param tEnv the environment to test
   * @param tParam the parameters of the test
   * @see #before
   * @see #after
   */
  public TestResult run(DescEntry entry, TestEnvironment tEnv, TestParameters tParam) {

    log = (PrintWriter) entry.Logger;

    this.tEnv = tEnv;
    this.tParam = tParam;
    // this.log = log;
    this.entry = entry;
    this.tRes = new TestResult();
    Class<?> testedClass;

    // Some fake code for a self test.
    // For normal test we must not be a "ifc.qadevooo._SelfTest"
    if (!("ifc.qadevooo._SelfTest").equals(entry.entryName)) {
      getInterfaceName();
      // System.out.println("checking : " + ifcName);
      System.out.print("checking: [" + entry.longName + "]");

      // defining a name of the class corresponding to the tested interface
      // or service
      String testedClassName;

      testedClassName = getTestedClassName();

      if (entry.EntryType.equals("service")) {
        testedClassName = "com.sun.star.beans.XPropertySet";
      }

      try {
        testedClass = Class.forName(testedClassName);
      } catch (ClassNotFoundException cnfE) {
        System.out.println();
        cnfE.printStackTrace(log);
        log.println("could not find a class : " + getTestedClassName());
        return null;
      }
      System.out.println(
          " is iface: [" + testedClassName + "] testcode: [" + entry.entryName + "]");

      Object oObj = UnoRuntime.queryInterface(testedClass, tEnv.getTestObject());

      if (oObj == null) {
        if (entry.isOptional) {
          Summarizer.summarizeDown(entry, "Not supported but optional.OK");
        } else {
          Summarizer.summarizeDown(entry, "queryInterface returned null.FAILED");
          entry.ErrorMsg = "queryInterface returned null";
          entry.hasErrorMsg = true;
        }

        return null;
      }

      // setting the field oObj
      try {
        setField("oObj", oObj);
      } catch (Exception e) {
        e.printStackTrace();
        setSubStates(e.toString());
        return tRes;
      }
    }

    // to perform some stuff before all method tests
    try {
      before();
    } catch (Exception e) {
      e.printStackTrace();
      setSubStates(e.toString());
      return tRes;
    }

    // executing methods tests
    for (int i = 0; i < entry.SubEntryCount; i++) {
      DescEntry aSubEntry = entry.SubEntries[i];
      try {
        final String sEntryName = aSubEntry.entryName;
        executeMethod(sEntryName);
      } catch (Exception e) {
        log.println("Exception while checking: " + aSubEntry.entryName + " : " + e.getMessage());
      }
    }

    // to perform some stuff after all method tests
    try {
      after();
    } catch (Exception e) {
    }

    return tRes;
  }
Пример #15
0
 @Override
 public void tearDown() throws Exception {
   env.resetWorkspace();
 }