예제 #1
0
 TestCaseDef getTestCase(TestSuiteDef testSuite, String testName) throws QuickFixException {
   for (TestCaseDef currentTestDef : testSuite.getTestCaseDefs()) {
     if (testName.equals(currentTestDef.getName())) {
       currentTestDef.validateDefinition();
       return currentTestDef;
     }
   }
   throw new DefinitionNotFoundException(
       definitionService.getDefDescriptor(testName, TestCaseDef.class));
 }
 private ComponentTestCase(ComponentTestSuite suite, TestCaseDef caseDef) {
   super("testRun");
   this.name =
       String.format(
           "%s$%s",
           suite.descriptor.getQualifiedName().replaceAll("://", "_"), caseDef.getName());
   this.suite = suite;
   this.caseDef = caseDef;
   for (String browser : caseDef.getBrowsers()) {
     String token = browser.trim().toUpperCase();
     Set<BrowserType> set;
     if (token.charAt(0) == '-') {
       token = token.substring(1);
       set = excludedBrowsers;
     } else {
       set = targetBrowsers;
     }
     try {
       set.add(BrowserType.valueOf(token));
     } catch (IllegalArgumentException e) {
       fail("Unknown BrowserType: " + browser);
     }
   }
 }
예제 #3
0
  private String buildJsTestTargetUri(DefDescriptor<?> targetDescriptor, TestCaseDef testDef)
      throws QuickFixException {

    Map<String, Object> targetAttributes = testDef.getAttributeValues();

    // Force "legacy" style tests until ready
    if (!ENABLE_FREEFORM_TESTS && targetAttributes == null) {
      targetAttributes = ImmutableMap.of();
    }

    if (targetAttributes != null) {
      // The test has attributes specified, so request for the target component with the test's
      // attributes.
      String hash = "";
      List<NameValuePair> newParams = Lists.newArrayList();
      for (Entry<String, Object> entry : targetAttributes.entrySet()) {
        String key = entry.getKey();
        String value;
        if (entry.getValue() instanceof Map<?, ?> || entry.getValue() instanceof List<?>) {
          value = JsonEncoder.serialize(entry.getValue());
        } else {
          value = entry.getValue().toString();
        }
        if (key.equals("__layout")) {
          hash = value;
        } else {
          newParams.add(new BasicNameValuePair(key, value));
        }
      }
      String qs = URLEncodedUtils.format(newParams, "UTF-8") + hash;
      return createURI(
          targetDescriptor.getNamespace(),
          targetDescriptor.getName(),
          targetDescriptor.getDefType(),
          null,
          Authentication.AUTHENTICATED.name(),
          qs);
    } else {
      // Free-form tests will load only the target component's template.
      // TODO: Allow specifying the template on the test.
      // TODO: Load proxy app for cmps, apps must loadApplication.
      final BaseComponentDef originalDef = (BaseComponentDef) targetDescriptor.getDef();
      final ComponentDef targetTemplate = originalDef.getTemplateDef();
      String newDescriptorString =
          String.format("%s$%s", targetDescriptor.getDescriptorName(), testDef.getName());
      final DefDescriptor<ApplicationDef> newDescriptor =
          Aura.getDefinitionService().getDefDescriptor(newDescriptorString, ApplicationDef.class);
      final ApplicationDef dummyDef =
          Aura.getDefinitionService().getDefinition("aurajstest:blank", ApplicationDef.class);
      BaseComponentDef targetDef =
          (BaseComponentDef)
              Proxy.newProxyInstance(
                  originalDef.getClass().getClassLoader(),
                  new Class<?>[] {ApplicationDef.class},
                  new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args)
                        throws Throwable {
                      switch (method.getName()) {
                        case "getDescriptor":
                          return newDescriptor;
                        case "getTemplateDef":
                          return targetTemplate;
                        case "isLocallyRenderable":
                          return method.invoke(originalDef, args);
                        default:
                          return method.invoke(dummyDef, args);
                      }
                    }
                  });
      TestContext testContext =
          Aura.get(TestContextAdapter.class).getTestContext(testDef.getQualifiedName());
      testContext.getLocalDefs().add(targetDef);
      return createURI(
          newDescriptor.getNamespace(),
          newDescriptor.getName(),
          newDescriptor.getDefType(),
          null,
          Authentication.AUTHENTICATED.name(),
          null);
    }
  }