/** Verify .cmp/.app and .css files are created through QuickFix screen. */
 public void testCreationQuickFix() throws Exception {
   String namespace = "auratest";
   String cmpName = String.format("nonExistent%s%s", defType.name(), System.currentTimeMillis());
   DefDescriptor<?> defDescriptor = createComponentDefDescriptor(namespace, cmpName);
   DefDescriptor<?> defDescriptorCss =
       Aura.getDefinitionService().getDefDescriptor(namespace + "." + cmpName, StyleDef.class);
   BaseComponentQuickFixWidget quickFixUIWidget;
   quickFixUIWidget = new BaseComponentQuickFixWidget(defType, this);
   try {
     open(String.format("/%s/%s%s", namespace, cmpName, typeSuffix), Mode.DEV);
     quickFixUIWidget.verifyToolbarAndClickCreate(defDescriptor.getQualifiedName());
     quickFixUIWidget.verifyCustomizationMenu();
     quickFixUIWidget.selectCssCheckbox(true);
     quickFixUIWidget.clickFix(true, String.format("TODO: %s:%s", namespace, cmpName));
     //
     // Serverside verification
     // This needs to be very careful, as static registries can stay constant.
     //
     getAuraTestingUtil().restartContext();
     assertTrue("Failed to locate the definition", defDescriptor.exists());
     assertTrue("Failed to locate the css definition", defDescriptorCss.exists());
   } finally {
     quickFixUIWidget.deleteFiles(defDescriptor);
   }
 }
Пример #2
0
  public DefOverviewModel() throws QuickFixException {

    AuraContext context = Aura.getContextService().getCurrentContext();
    BaseComponent<?, ?> component = context.getCurrentComponent();

    String desc = (String) component.getAttributes().getValue("descriptor");

    DefType defType =
        DefType.valueOf(((String) component.getAttributes().getValue("defType")).toUpperCase());
    DefinitionService definitionService = Aura.getDefinitionService();
    DefDescriptor<?> descriptor =
        definitionService.getDefDescriptor(desc, defType.getPrimaryInterface());

    Definition def = descriptor.getDef();
    ReferenceTreeModel.assertAccess(def);

    Map<DefType, List<DefModel>> depsMap = Maps.newEnumMap(DefType.class);

    Set<DefDescriptor<?>> deps = Sets.newHashSet();

    def.appendDependencies(deps);

    for (DefDescriptor<?> dep : deps) {
      DefType type = dep.getDefType();

      List<DefModel> depsList = depsMap.get(type);
      if (depsList == null) {
        depsList = Lists.newArrayList();
        depsMap.put(type, depsList);
      }
      depsList.add(new DefModel(dep));
    }

    for (Entry<DefType, List<DefModel>> entry : depsMap.entrySet()) {
      List<DefModel> list = entry.getValue();
      Collections.sort(list);

      Map<String, Object> group = Maps.newHashMap();
      group.put("type", AuraTextUtil.initCap(entry.getKey().toString().toLowerCase()));
      group.put("list", list);
      dependencies.add(group);
    }
  }
Пример #3
0
  private String createURI(
      String namespace, String name, DefType defType, Mode mode, String access, String qs) {
    if (mode == null) {
      try {
        mode = Aura.getContextService().getCurrentContext().getMode();
      } catch (Throwable t) {
        mode = Mode.AUTOJSTEST; // TODO: default to PROD
      }
    }

    String ret = String.format(GET_URI, namespace, name, defType.name(), mode.toString(), access);
    if (qs != null) {
      ret = String.format("%s&%s", ret, qs);
    }
    return ret;
  }
 /**
  * Verify error message that is displayed when attempting to create a cmp bundle with a
  * non-existing namespace.
  */
 public void testCreationQuickFixNonexistentNamespace() throws Exception {
   String namespace = String.format("nonExistentNamespace%s", System.currentTimeMillis());
   String cmpName = String.format("nonExistent%s%s", defType.name(), System.currentTimeMillis());
   DefDescriptor<?> defDescriptor = createComponentDefDescriptor(namespace, cmpName);
   BaseComponentQuickFixWidget quickFixUIWidget;
   quickFixUIWidget = new BaseComponentQuickFixWidget(defType, this);
   try {
     open(String.format("/%s/%s%s", namespace, cmpName, typeSuffix), Mode.DEV);
     quickFixUIWidget.verifyToolbarAndClickCreate(defDescriptor.getQualifiedName());
     quickFixUIWidget.verifyCustomizationMenu();
     quickFixUIWidget.clickFix(false, "Cannot find location to save definition");
     assertFalse("Should not have created component bundle", defDescriptor.exists());
   } finally {
     quickFixUIWidget.deleteFiles(defDescriptor);
   }
 }
 /**
  * Verify that multiple component bundles can be created by entering the DefDescriptors in, comma
  * separated.
  */
 public void testMultipleDescriptors() throws Exception {
   String namespace = String.format("auratest", System.currentTimeMillis());
   String cmpName1 = String.format("nonExistent1%s%s", defType.name(), System.currentTimeMillis());
   String cmpName2 = String.format("nonExistent2%s%s", defType.name(), System.currentTimeMillis());
   DefDescriptor<?> defDescriptor1 = createComponentDefDescriptor(namespace, cmpName1);
   DefDescriptor<?> defDescriptor2 = createComponentDefDescriptor(namespace, cmpName2);
   BaseComponentQuickFixWidget quickFixUIWidget;
   quickFixUIWidget = new BaseComponentQuickFixWidget(defType, this);
   try {
     open(String.format("/%s/%s%s", namespace, cmpName1, typeSuffix), Mode.DEV);
     quickFixUIWidget.verifyToolbarAndClickCreate(defDescriptor1.getQualifiedName());
     quickFixUIWidget.verifyCustomizationMenu();
     quickFixUIWidget.setDescriptorNames(
         namespace + ":" + cmpName1 + ", " + namespace + ":" + cmpName2);
     quickFixUIWidget.clickFix(true, String.format("TODO: %s:%s", namespace, cmpName1));
     assertTrue("Should not have created component bundle", defDescriptor1.exists());
     assertTrue("Should not have created component bundle", defDescriptor2.exists());
   } finally {
     quickFixUIWidget.deleteFiles(defDescriptor1);
     quickFixUIWidget.deleteFiles(defDescriptor2);
   }
 }
Пример #6
0
  @Override
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
      throws ServletException, IOException {

    if (!Aura.getConfigAdapter().isTestAllowed()) {
      chain.doFilter(req, res);
      return;
    }

    TestContextAdapter testContextAdapter = Aura.get(TestContextAdapter.class);
    if (testContextAdapter == null) {
      chain.doFilter(req, res);
      return;
    }

    // Check for requests to execute a JSTest, i.e. initial component GETs with particular
    // parameters.
    HttpServletRequest request = (HttpServletRequest) req;
    if ("GET".equals(request.getMethod())) {
      String contextPath = request.getContextPath();
      String uri = request.getRequestURI();
      String browserType = request.getParameter("aura.browserType");
      if (browserType == null) {
        // read it from request header
        String ua = request.getHeader(HttpHeaders.USER_AGENT);
        if (ua != null) {
          ua = ua.toLowerCase();
          if (ua.contains("chrome")) {
            browserType = "GOOGLECHROME";
          } else if (ua.contains("safari")) {
            browserType = "SAFARI";
          } else if (ua.contains("firefox")) {
            browserType = "FIREFOX";
          } else if (ua.contains("ipad")) {
            browserType = "IPAD";
          } else if (ua.contains("iphone")) {
            browserType = "IPHONE";
          } else if (ua.contains("msie 10")) {
            browserType = "IE10";
          } else if (ua.contains("msie 9")) {
            browserType = "IE9";
          } else if (ua.contains("msie 8")) {
            browserType = "IE8";
          } else if (ua.contains("msie 7")) {
            browserType = "IE7";
          } else if (ua.contains("msie 6")) {
            browserType = "IE6";
          } else if (ua.contains("trident/7.0")) {
            browserType = "IE11";
          } else if (ua.contains("edge/12")) {
            browserType = "IE12";
          } else {
            browserType = "OTHER";
          }
        }
      }
      String path;
      if (uri.startsWith(contextPath)) {
        path = uri.substring(contextPath.length());
      } else {
        path = uri;
      }
      Matcher matcher = AuraRewriteFilter.DESCRIPTOR_PATTERN.matcher(path);
      if (matcher.matches()) {
        // Extract the target component since AuraContext usually does not have the app descriptor
        // set yet.
        DefType type = "app".equals(matcher.group(3)) ? DefType.APPLICATION : DefType.COMPONENT;
        String namespace = matcher.group(1);
        String name = matcher.group(2);
        DefDescriptor<?> targetDescriptor =
            Aura.getDefinitionService()
                .getDefDescriptor(
                    String.format("%s:%s", namespace, name), type.getPrimaryInterface());

        // Check if a single jstest is being requested.
        String testToRun = jstestToRun.get(request);
        if (testToRun != null && !testToRun.isEmpty()) {
          AuraContext context = Aura.getContextService().getCurrentContext();
          Format format = context.getFormat();
          switch (format) {
            case HTML:
              TestCaseDef testDef;
              TestContext testContext;
              String targetUri;
              try {
                TestSuiteDef suiteDef = getTestSuite(targetDescriptor);
                testDef = getTestCase(suiteDef, testToRun);
                testDef.validateDefinition();
                testDef.setCurrentBrowser(browserType);
                testContextAdapter.getTestContext(testDef.getQualifiedName());
                testContextAdapter.release();
                testContext = testContextAdapter.getTestContext(testDef.getQualifiedName());
                targetUri = buildJsTestTargetUri(targetDescriptor, testDef);
              } catch (QuickFixException e) {
                ((HttpServletResponse) res).setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                res.setCharacterEncoding(AuraBaseServlet.UTF_ENCODING);
                res.getWriter().append(e.getMessage());
                Aura.getExceptionAdapter().handleException(e);
                return;
              }

              // Load any test mocks.
              Collection<Definition> mocks = testDef.getLocalDefs();
              testContext.getLocalDefs().addAll(mocks);
              loadTestMocks(context, true, testContext.getLocalDefs());

              // Capture the response and inject tags to load jstest.
              String capturedResponse = captureResponse(req, res, targetUri);
              if (capturedResponse != null) {
                res.setCharacterEncoding(AuraBaseServlet.UTF_ENCODING);
                if (!Aura.getContextService().isEstablished()) {
                  // There was an error in the original response, so just write the response out.
                  res.getWriter().write(capturedResponse);
                } else {
                  String testTag =
                      buildJsTestScriptTag(targetDescriptor, testToRun, capturedResponse);
                  injectScriptTags(res.getWriter(), capturedResponse, testTag);
                }
                return;
              }
            case JS:
              res.setCharacterEncoding(AuraBaseServlet.UTF_ENCODING);
              writeJsTestScript(res.getWriter(), targetDescriptor, testToRun);
              return;
            default:
              // Pass it on.
          }
        }

        // aurajstest:jstest app is invokable in the following ways:
        // ?aura.mode=JSTEST - run all tests
        // ?aura.mode JSTEST&test=XXX - run single test
        // ?aura.jstest - run all tests
        // ?aura.jstest=XXX - run single test
        // ?aura.jstestrun - run all tests
        // TODO: delete JSTEST mode
        String jstestAppRequest = jstestAppFlag.get(request);
        Mode mode = AuraContextFilter.mode.get(request, Mode.PROD);
        if (mode == Mode.JSTEST
            || mode == Mode.JSTESTDEBUG
            || jstestAppRequest != null
            || testToRun != null) {

          mode = mode.toString().endsWith("DEBUG") ? Mode.AUTOJSTESTDEBUG : Mode.AUTOJSTEST;

          String qs = String.format("descriptor=%s:%s&defType=%s", namespace, name, type.name());
          String testName = null;
          if (jstestAppRequest != null && !jstestAppRequest.isEmpty()) {
            testName = jstestAppRequest;
          } else if (testToRun != null && !testToRun.isEmpty()) {
            testName = testToRun;
          }
          if (testName != null) {
            qs = qs + "&test=" + testName;
          }

          String newUri =
              createURI(
                  "aurajstest",
                  "jstest",
                  DefType.APPLICATION,
                  mode,
                  Authentication.AUTHENTICATED.name(),
                  qs);
          RequestDispatcher dispatcher =
              servletContext.getContext(newUri).getRequestDispatcher(newUri);
          if (dispatcher != null) {
            dispatcher.forward(req, res);
            return;
          }
        }
      }
    }

    // Handle mock definitions specified in the tests.
    TestContext testContext = getTestContext(request);
    if (testContext == null) {
      // During manual testing, the test context adapter may not always get cleared.
      testContextAdapter.clear();
    } else {
      ContextService contextService = Aura.getContextService();
      if (!contextService.isEstablished()) {
        LOG.error("Aura context is not established! New context will NOT be created.");
        chain.doFilter(req, res);
        return;
      }
      AuraContext context = contextService.getCurrentContext();

      // Reset mocks if requested, or for the initial GET.
      boolean doResetMocks = testReset.get(request, Format.HTML.equals(context.getFormat()));
      loadTestMocks(context, doResetMocks, testContext.getLocalDefs());
    }
    chain.doFilter(req, res);
  }
Пример #7
0
 /**
  * Create a new bundle in a current namespace with a given name and type.
  *
  * <p>This should be used for the bundle-defining name, and subsequent calls should use the
  * descriptor form since this will create a new name.
  */
 public <T extends Definition> DefDescriptor<T> getNewObject(
     String ns, Class<T> clazz, String contents) throws IOException {
   String name = getNewName(ns);
   String qualified = null;
   // FIXME: W-2368202
   DefType defType = DefType.getDefType(clazz);
   switch (defType) {
     case CONTROLLER:
     case TESTSUITE:
     case MODEL:
     case RENDERER:
     case HELPER:
     case STYLE:
     case FLAVORED_STYLE:
     case RESOURCE:
     case TYPE:
     case PROVIDER:
     case TOKEN_DESCRIPTOR_PROVIDER:
     case TOKEN_MAP_PROVIDER:
     case INCLUDE:
     case REQUIRED_VERSION:
       qualified = String.format("%s.%s", ns, name);
       break;
       // subtypes
     case ACTION:
     case DESCRIPTION:
     case INCLUDE_REF:
       return null;
     case ATTRIBUTE:
     case LAYOUT:
     case LAYOUT_ITEM:
     case TESTCASE:
     case TOKEN:
     case TOKENS_IMPORT:
     case ATTRIBUTE_DESIGN:
     case DESIGN_TEMPLATE:
     case DESIGN_TEMPLATE_REGION:
     case FLAVOR_INCLUDE:
     case FLAVOR_DEFAULT:
       qualified = name;
       break;
     case APPLICATION:
     case COMPONENT:
     case INTERFACE:
     case EVENT:
     case LIBRARY:
     case DOCUMENTATION:
     case EXAMPLE:
     case LAYOUTS:
     case NAMESPACE:
     case TOKENS:
     case DESIGN:
     case SVG:
     case FLAVORS:
     case FLAVOR_ASSORTMENT:
       qualified = String.format("%s:%s", ns, name);
       break;
     default:
       break;
   }
   DefDescriptor<T> desc = Aura.getDefinitionService().getDefDescriptor(qualified, clazz);
   createFile(desc, contents);
   return desc;
 }
Пример #8
0
  public ComponentDefModel() throws QuickFixException {
    AuraContext context = Aura.getContextService().getCurrentContext();
    BaseComponent<?, ?> component = context.getCurrentComponent();

    String desc = (String) component.getAttributes().getValue("descriptor");

    DefType defType =
        DefType.valueOf(((String) component.getAttributes().getValue("defType")).toUpperCase());
    DefinitionService definitionService = Aura.getDefinitionService();
    descriptor = definitionService.getDefDescriptor(desc, defType.getPrimaryInterface());
    definition = descriptor.getDef();

    ReferenceTreeModel.assertAccess(definition);

    String type = null;
    if (definition instanceof RootDefinition) {
      RootDefinition rootDef = (RootDefinition) definition;
      for (AttributeDef attribute : rootDef.getAttributeDefs().values()) {
        if (ReferenceTreeModel.hasAccess(attribute)) {
          attributes.add(new AttributeModel(attribute));
        }
      }

      DocumentationDef docDef = rootDef.getDocumentationDef();
      doc = docDef != null ? new DocumentationDefModel(docDef) : null;

      if (definition instanceof BaseComponentDef) {
        BaseComponentDef cmpDef = (BaseComponentDef) definition;
        for (RegisterEventDef reg : cmpDef.getRegisterEventDefs().values()) {
          if (ReferenceTreeModel.hasAccess(reg)) {
            events.add(new AttributeModel(reg));
          }
        }

        for (EventHandlerDef handler : cmpDef.getHandlerDefs()) {
          handledEvents.add(new AttributeModel(handler));
        }

        for (DefDescriptor<InterfaceDef> intf : cmpDef.getInterfaces()) {
          if (ReferenceTreeModel.hasAccess(intf.getDef())) {
            interfaces.add(intf.getNamespace() + ":" + intf.getName());
          }
        }

        DefDescriptor<?> superDesc = cmpDef.getExtendsDescriptor();
        if (superDesc != null) {
          theSuper = superDesc.getNamespace() + ":" + superDesc.getName();
        } else {
          theSuper = null;
        }

        isAbstract = cmpDef.isAbstract();
        isExtensible = cmpDef.isExtensible();

      } else if (definition instanceof EventDef) {
        EventDef eventDef = (EventDef) definition;
        DefDescriptor<?> superDesc = eventDef.getExtendsDescriptor();
        if (superDesc != null) {
          theSuper = superDesc.getNamespace() + ":" + superDesc.getName();
        } else {
          theSuper = null;
        }

        type = eventDef.getEventType().name();
        isExtensible = true;
        isAbstract = false;
      } else {
        theSuper = null;
        isExtensible = true;
        isAbstract = false;
      }

      support = rootDef.getSupport().name();

      if (definition instanceof RootDefinition) {
        List<DefDescriptor<?>> deps = ((RootDefinition) definition).getBundle();

        for (DefDescriptor<?> dep : deps) {
          // we already surface the documentation--users don't need to see the source for it.
          if (dep.getDefType() != DefType.DOCUMENTATION) {
            Definition def = dep.getDef();
            if (ReferenceTreeModel.hasAccess(def)) {
              defs.add(new DefModel(dep));
            }
          }
        }
      }
    } else {
      support = null;
      theSuper = null;
      isExtensible = false;
      isAbstract = false;
      doc = null;
    }
    this.type = type;
  }