Beispiel #1
0
  protected void check(LayoutDefinition layoutDef, String lang) throws Exception {
    LayoutConversionContext ctx = new LayoutConversionContext(lang, null);
    List<LayoutDefinitionConverter> layoutConverters = service.getLayoutConverters(TEST_CATEGORY);
    for (LayoutDefinitionConverter conv : layoutConverters) {
      layoutDef = conv.getLayoutDefinition(layoutDef, ctx);
    }
    List<WidgetDefinitionConverter> widgetConverters = service.getWidgetConverters(TEST_CATEGORY);

    String langFilePath = lang;
    if (langFilePath == null) {
      langFilePath = "nolang";
    }
    File file = Framework.createTempFile("layout-export-" + langFilePath, ".json");
    FileOutputStream out = new FileOutputStream(file);
    JSONLayoutExporter.export(WebLayoutManager.JSF_CATEGORY, layoutDef, ctx, widgetConverters, out);
    out.close();

    InputStream written = new FileInputStream(file);
    InputStream expected =
        new FileInputStream(
            FileUtils.getResourcePathFromContext("layout-export-" + langFilePath + ".json"));

    String expectedString = IOUtils.toString(expected, Charsets.UTF_8);
    String writtenString = IOUtils.toString(written, Charsets.UTF_8);
    // order of select options may depend on directory database => do not
    // check order of element by using the NON_EXTENSIBLE mode
    JSONAssert.assertEquals(expectedString, writtenString, JSONCompareMode.NON_EXTENSIBLE);
  }
Beispiel #2
0
  protected void check(String layoutName, String lang) throws Exception {
    LayoutConversionContext ctx = new LayoutConversionContext(lang, null);
    LayoutDefinition layoutDef =
        service.getLayoutDefinition(WebLayoutManager.JSF_CATEGORY, layoutName);
    Layout layout =
        jsfService.getLayout(
            null, ctx, TEST_CATEGORY, layoutDef, BuiltinModes.VIEW, "currentDocument", null, false);
    String langFilePath = lang;
    if (langFilePath == null) {
      langFilePath = "nolang";
    }
    File file = Framework.createTempFile("layout-instance-export-" + langFilePath, ".json");
    FileOutputStream out = new FileOutputStream(file);
    JSONObject res = JSONLayoutExporter.exportToJson(layout);
    out.write(res.toString(2).getBytes(JSONLayoutExporter.ENCODED_VALUES_ENCODING));
    out.close();

    InputStream written = new FileInputStream(file);
    InputStream expected =
        new FileInputStream(
            FileUtils.getResourcePathFromContext(
                "layout-instance-export-" + langFilePath + ".json"));

    String expectedString = IOUtils.toString(expected, Charsets.UTF_8);
    String writtenString = IOUtils.toString(written, Charsets.UTF_8);
    // order of select options may depend on directory database => do not
    // check order of element by using the NON_EXTENSIBLE mode
    JSONAssert.assertEquals(expectedString, writtenString, JSONCompareMode.NON_EXTENSIBLE);
  }