Esempio n. 1
0
 @Before
 public void initTestObjects() throws Exception {
   given(brjs).hasCommandPlugins(new CreateBladeCommand()).and(brjs).hasBeenCreated();
   app = brjs.app("app");
   bladeset = app.bladeset("bladeset");
   blade = bladeset.blade("blade");
   badBlade = bladeset.blade("!$%$^");
   blade1InDefaultBladeset = app.defaultBladeset().blade("blade1");
   blade2InDefaultBladeset = app.defaultBladeset().blade("blade2");
   angularTemplates = brjs.sdkTemplateGroup("angular");
   defaultTemplates = brjs.sdkTemplateGroup("default");
   myTemplateTemplates = brjs.sdkTemplateGroup("myTemplate");
 }
 @Before
 public void initTestObjects() throws Exception {
   given(brjs)
       .automaticallyFindsBundlerPlugins()
       .and(brjs)
       .automaticallyFindsMinifierPlugins()
       .and(brjs)
       .hasBeenCreated();
   app = brjs.app("app1");
   aspect = app.aspect("default");
   thirdpartyLib = app.jsLib("thirdparty-lib");
   thirdpartyLib2 = app.jsLib("thirdparty-lib2");
   bladerunnerConf = brjs.bladerunnerConf();
   sdkLib = brjs.sdkLib("lib");
 }
Esempio n. 3
0
 @Test
 public void exceptionIsThrownIfTheAppDoesntExist() throws Exception {
   when(brjs).runCommand("create-blade", "app", "bladeset", "blade");
   then(exceptions)
       .verifyException(
           NodeDoesNotExistException.class, "app", unquoted(app.getClass().getSimpleName()))
       .whereTopLevelExceptionIs(CommandArgumentsException.class);
 }
Esempio n. 4
0
 @Test
 public void debugMessageIsLoggedWhenImplicitRequirePrefixesAreUsed() throws Exception {
   App myApp = brjs.app("myApp");
   Blade blade = myApp.defaultBladeset().blade("b1");
   Aspect aspect = myApp.defaultAspect();
   given(blade)
       .containsFile("src/pkg/Class.js")
       .and(aspect)
       .indexPageRequires("appns/b1/pkg/Class")
       .and(logging)
       .enabled();
   when(aspect).bundleSetGenerated();
   then(logging)
       .debugMessageReceived(
           BRJSConformantAssetPlugin.IMPLICIT_PACKAGE_USED,
           "apps/myApp/blades/b1/src",
           "appns/b1",
           "appns/b1")
       .and(logging)
       .otherMessagesIgnored();
 }
  @Test
  public void testLibraryResourceRequestCanNotHaveAQueryString() throws Exception {
    JsLib appLib = app.jsLib("myLib");

    given(appLib)
        .hasBeenCreated()
        .and(appLib)
        .containsFileWithContents("thirdparty-lib.manifest", "js: myFile.js")
        .and(appLib)
        .containsFile("myFile.js");
    when(aspect).requestReceivedInDev("thirdparty/myLib/myFile.js?q=1234", pageResponse);
    then(exceptions).verifyException(MalformedRequestException.class);
  }
  @Override
  public ResponseContent handleRequest(
      String contentPath, BundleSet bundleSet, UrlContentAccessor contentAccessor, String version)
      throws MalformedRequestException, ContentProcessingException {
    ParsedContentPath parsedContentPath = contentPathParser.parse(contentPath);

    if (parsedContentPath.formName.equals(APP_META_REQUEST)) {
      try {
        App app = bundleSet.bundlableNode().app();
        // NOTE: this metadata is used by the BRAppMetaService
        // This can't be modeled as a SourceModule since it needs access to the version which is
        // only available to ContentPlugins
        return new CharResponseContent(
            brjs,
            "define('app-meta!$data', function(require, exports, module) {\n"
                + "// these variables should not be used directly but accessed via the 'br.app-meta-service' instead\n"
                + "module.exports.APP_VERSION = '"
                + version
                + "';\n"
                + "module.exports.VERSIONED_BUNDLE_PATH = '"
                + AppMetadataUtility.getRelativeVersionedBundlePath(app, version, "")
                + "';\n"
                + "module.exports.LOCALE_COOKIE_NAME = '"
                + app.appConf().getLocaleCookieName()
                + "';\n"
                + "module.exports.APP_LOCALES = {'"
                + Joiner.on("':true, '").join(app.appConf().getLocales())
                + "':true};\n"
                + "});\n");
      } catch (ConfigException ex) {
        throw new ContentProcessingException(ex);
      }
    } else {
      throw new ContentProcessingException(
          "unknown request form '" + parsedContentPath.formName + "'.");
    }
  }
Esempio n. 7
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String requestPath =
        request
            .getRequestURI()
            .replaceFirst("^" + request.getContextPath() + request.getServletPath() + "/", "");

    if (!requestPath.endsWith("/")) {
      String fileName =
          (requestPath.contains("/"))
              ? StringUtils.substringAfterLast(requestPath, "/")
              : requestPath;
      String mimeType = servletContext.getMimeType(fileName);
      if (mimeType != null) {
        response.setHeader(CONTENT_TYPE, mimeType);
      }
    }

    ThreadSafeStaticBRJSAccessor.aquireModel();
    UrlContentAccessor contentAccessor =
        new ServletContentAccessor(app, servletContext, request, response);
    try (ResponseContent content =
        app.requestHandler()
            .handleLogicalRequest(requestPath, contentAccessor, RequestMode.Dev); ) {
      if (!response
          .isCommitted()) { // check the ServletContentAccessor hasnt been used to handle a request
                            // and sent headers
        content.write(response.getOutputStream());
      }
    } catch (MalformedRequestException e) {
      response.sendError(400, e.getMessage());
    } catch (ResourceNotFoundException e) {
      response.sendError(404, e.getMessage());
    } catch (ContentProcessingException e) {
      response.sendError(500, e.getMessage());
    } catch (ModelOperationException e) {
      throw new ServletException(e);
    } finally {
      ThreadSafeStaticBRJSAccessor.releaseModel();
    }
  }
Esempio n. 8
0
 @Test
 public void infoMessageIsLoggedWhenAppsDirectoryIsDiscovered() throws Exception {
   given(testRootDirectory)
       .containsFolder("apps")
       .and(logging)
       .enabled()
       .and(app1)
       .hasBeenCreated()
       .and(app1)
       .containsFiles(AppConf.FILE_NAME, "index.html");
   when(brjs).hasBeenCreated().and(brjs).discoverUserApps();
   then(logging)
       .infoMessageReceived(BRJS_LOCATION, brjs.dir().getAbsolutePath())
       .and(logging)
       .infoMessageReceived(
           APPS_FOLDER_FOUND, testRootDirectory.getAbsolutePath() + File.separator + "apps")
       .and(logging)
       .infoMessageReceived(PERFORMING_NODE_DISCOVERY_LOG_MSG)
       .and(logging)
       .infoMessageReceived(APPS_DISCOVERED, "User", app1.getName());
 }