gpt4 book ai didi

org.mozilla.zest.core.v1.ZestJSON类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 09:36:40 25 4
gpt4 key购买 nike

本文整理了Java中org.mozilla.zest.core.v1.ZestJSON类的一些代码示例,展示了ZestJSON类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestJSON类的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestJSON
类名称:ZestJSON

ZestJSON介绍

[英]The Class ZestJSON.
[中]类ZestJSON。

代码示例

代码示例来源:origin: mozilla/zest

@Test
public void testSerializationLoopInteger() {
  ZestLoopInteger loop = new ZestLoopInteger(0, 1235);
  for (ZestStatement stmt : statements) {
    loop.addStatement(stmt);
  }
  String loopString = ZestJSON.toString(loop);
  ZestLoopInteger copy = (ZestLoopInteger) ZestJSON.fromString(loopString);
  String copyString = ZestJSON.toString(copy);
  // System.out.println("===============================");
  // System.out.println("          LOOP INTEGER");
  // System.out.println("===============================");
  // System.out.println(copyString);
  assertTrue(copyString.equals(loopString));
}

代码示例来源:origin: mozilla/zest

/**
 * Gets the gson.
 *
 * @return the gson
 */
private static Gson getGson() {
  if (gson == null) {
    // Need to add all of the abstract classes
    gson =
        new GsonBuilder()
            .registerTypeAdapter(ZestAction.class, new ZestJSON())
            .registerTypeAdapter(ZestAssignment.class, new ZestJSON())
            .registerTypeAdapter(ZestAuthentication.class, new ZestJSON())
            .registerTypeAdapter(ZestElement.class, new ZestJSON())
            .registerTypeAdapter(ZestStatement.class, new ZestJSON())
            .registerTypeAdapter(ZestExpressionElement.class, new ZestJSON())
            .registerTypeAdapter(ZestLoop.class, new ZestJSON())
            .registerTypeAdapter(ZestLoopState.class, new ZestJSON())
            .registerTypeAdapter(ZestLoopTokenSet.class, new ZestJSON())
            .setPrettyPrinting()
            .create();
  }
  return gson;
}

代码示例来源:origin: mozilla/zest

/**
 * To string.
 *
 * @param element the element
 * @return the string
 */
public static String toString(ZestElement element) {
  return getGson().toJson(element);
}

代码示例来源:origin: mozilla/zest

@Override
public String runScript(String script, Map<String, String> params)
    throws ZestAssertFailException, ZestActionFailException, IOException,
        ZestInvalidCommonTestException, ZestAssignFailException,
        ZestClientFailException {
  return run((ZestScript) ZestJSON.fromString(script), params);
}

代码示例来源:origin: mozilla/zest

System.out.println("        SCRIPT");
System.out.println("========================");
System.out.println(ZestJSON.toString(script));
System.out.println("========================");
System.out.println("         LOOP");
System.out.println("========================");
System.out.println(ZestJSON.toString(loop));
System.out.println("========================");
System.out.println("    LOOP FROM SCRIPT");
System.out.println("========================");
System.out.println(ZestJSON.toString(script.getStatement(1)));
ZestScript copy = script.deepCopy();
System.out.println("========================");
System.out.println("   DEEP COPIED SCRIPT");
System.out.println("========================");
System.out.println(ZestJSON.toString(copy));

代码示例来源:origin: mozilla/zest

@Override
public String runScript(Reader reader, Map<String, String> params)
    throws ZestAssertFailException, ZestActionFailException, IOException,
        ZestInvalidCommonTestException, ZestAssignFailException,
        ZestClientFailException {
  StringBuilder sb = new StringBuilder();
  try (BufferedReader fr = new BufferedReader(reader)) {
    String line;
    while ((line = fr.readLine()) != null) {
      sb.append(line);
    }
  }
  return run((ZestScript) ZestJSON.fromString(sb.toString()), params);
}

代码示例来源:origin: mozilla/zest

@Test
  public void testSerializationLoopFile() throws FileNotFoundException {
    ZestLoopFile loop = new ZestLoopFile(ZestLoopFileUnitTest.file.getAbsolutePath());
    for (ZestStatement stmt : statements) {
      loop.addStatement(stmt);
    }
    String loopString = ZestJSON.toString(loop);
    ZestLoopFile copy = (ZestLoopFile) ZestJSON.fromString(loopString);
    String copyString = ZestJSON.toString(copy);
    // System.out.println("===============================");
    // System.out.println("           LOOP FILE");
    // System.out.println("===============================");
    // System.out.println(copyString);
    assertTrue(loopString.equals(copyString));
  }
}

代码示例来源:origin: mozilla/zest

private static void assertZestScript(String name) throws Exception {
  ZestElement zestElement = ZestJSON.fromString(readScript(name));
  assertTrue(name, zestElement instanceof ZestScript);
}

代码示例来源:origin: mozilla/zest

/**
 * From string.
 *
 * @param str the str
 * @return the zest element
 */
public static ZestElement fromString(String str) {
  ZestElement ze = getGson().fromJson(str, ZestElement.class);
  if (ze != null && ze instanceof ZestStatement) {
    ((ZestStatement) ze).init();
  }
  return ze;
}

代码示例来源:origin: mozilla/zest

@Test
public void testSerializationLoopString() {
  ZestLoopString loop = new ZestLoopString(values);
  for (ZestStatement stmt : statements) {
    loop.addStatement(stmt);
  }
  String loopString = ZestJSON.toString(loop);
  // System.out.println(loopString);
  ZestLoopString copy = (ZestLoopString) ZestJSON.fromString(loopString);
  String copyString = ZestJSON.toString(copy);
  // System.out.println("===============================");
  // System.out.println("          LOOP STRING");
  // System.out.println("===============================");
  // System.out.println(copyString);
  assertTrue(copyString.equals(loopString));
}

代码示例来源:origin: mozilla/zest

zs = (ZestScript) ZestJSON.fromString(sb.toString());

代码示例来源:origin: mozilla/zest

@Override
public ZestElement deserialize(
    JsonElement element, Type rawType, JsonDeserializationContext arg2)
    throws JsonParseException {
  if (element instanceof JsonObject) {
    String elementType = ((JsonObject) element).get("elementType").getAsString();
    if (elementType.startsWith("Zest")) {
      try {
        // Class<?> c =
        // Class.forName(this.getClass().getPackage().getName()"org.mozilla.zest.core.v1." + elementType);
        Class<?> c =
            Class.forName(
                this.getClass().getPackage().getName() + "." + elementType);
        return (ZestElement) getGson().fromJson(element, c);
      } catch (ClassNotFoundException e) {
        throw new JsonParseException(e);
      }
    }
  }
  return null;
}

代码示例来源:origin: mozilla/zest

@Test
public void testSerialization() {
  ZestLoopString loop = new ZestLoopString(values);
  String str = ZestJSON.toString(loop);
  System.out.println(str);
  ZestLoopString loop2 = (ZestLoopString) ZestJSON.fromString(str);
  if (loop2.getValues().length != values.length) {
    fail("The two arrays do not have same length!");
  }
  for (int i = 0; i < values.length; i++) {
    assertTrue(
        i + " expected " + values[i] + " instead of " + loop2.getValues()[i],
        loop2.getValues()[i].equals(values[i]));
  }
}

代码示例来源:origin: mozilla/zest

getClass().getResource("/data/assignRegexDelimiters-script.zest"),
        StandardCharsets.UTF_8);
ZestScript zestScript = (ZestScript) ZestJSON.fromString(zestString);

代码示例来源:origin: mozilla/zest

request.setTimestamp(timestamp);
String serialisation = ZestJSON.toString(request);
ZestRequest deserialisedRequest = (ZestRequest) ZestJSON.fromString(serialisation);

代码示例来源:origin: mozilla/zest

@Test
  public void testSerialization() {
    ZestActionSleep inv = new ZestActionSleep();
    inv.setMilliseconds(1000);

    String str = ZestJSON.toString(inv);

    ZestActionSleep inv2 = (ZestActionSleep) ZestJSON.fromString(str);

    assertEquals(inv.getElementType(), inv2.getElementType());
    assertEquals(inv.getMilliseconds(), inv2.getMilliseconds());
  }
}

代码示例来源:origin: mozilla/zest

@Test
public void shouldSerialiseAndDeserialise() {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(401);
  // When
  String serialisation = ZestJSON.toString(statusCodeExpression);
  ZestExpressionStatusCode deserialisedStatusCodeExpression =
      (ZestExpressionStatusCode) ZestJSON.fromString(serialisation);
  // Then
  assertTrue(deserialisedStatusCodeExpression != statusCodeExpression);
  assertEquals(deserialisedStatusCodeExpression.getCode(), statusCodeExpression.getCode());
  assertEquals(
      deserialisedStatusCodeExpression.isInverse(), statusCodeExpression.isInverse());
}

代码示例来源:origin: mozilla/zest

@Test
public void shouldSerialiseAndDeserialise() {
  // Given
  ZestExpressionProtocol protocolExpression = new ZestExpressionProtocol("http");
  // When
  String serialisation = ZestJSON.toString(protocolExpression);
  ZestExpressionProtocol deserialisedProtocolExpression =
      (ZestExpressionProtocol) ZestJSON.fromString(serialisation);
  // Then
  assertTrue(deserialisedProtocolExpression != protocolExpression);
  assertEquals(
      deserialisedProtocolExpression.getProtocol(), protocolExpression.getProtocol());
  assertEquals(deserialisedProtocolExpression.isInverse(), protocolExpression.isInverse());
}

代码示例来源:origin: mozilla/zest

@Test
  public void testSerialization() {
    ZestAssignString assign = new ZestAssignString("var", "io;hjvd9740[w9u;sdz");

    String str = ZestJSON.toString(assign);

    ZestAssignString assign2 = (ZestAssignString) ZestJSON.fromString(str);

    assertEquals(assign.getElementType(), assign2.getElementType());
    assertEquals(assign.getVariableName(), assign2.getVariableName());
    assertEquals(assign.getString(), assign2.getString());
  }
}

代码示例来源:origin: mozilla/zest

@Test
public void testSerialization() {
  ZestActionInvoke inv = new ZestActionInvoke();
  inv.setVariableName("test");
  inv.setCharset(StandardCharsets.UTF_8.name());
  inv.setParameters(params(param("first", "AAA"), param("second", "BBB")));
  inv.setScript(
      ZestActionInvokeUnitTest.class.getResource("/data/simple-script.js").getPath());
  String str = ZestJSON.toString(inv);
  ZestActionInvoke inv2 = (ZestActionInvoke) ZestJSON.fromString(str);
  assertEquals(inv.getElementType(), inv2.getElementType());
  assertEquals(inv.getVariableName(), inv2.getVariableName());
  assertEquals(inv.getScript(), inv2.getScript());
  assertEquals(inv.getCharset(), inv2.getCharset());
  assertEquals(inv.getParameters().size(), inv2.getParameters().size());
  for (int i = 0; i < inv.getParameters().size(); i++) {
    assertEquals(inv.getParameters().get(i).length, inv2.getParameters().get(i).length);
    for (int j = 0; j < inv.getParameters().get(i).length; j++) {
      assertEquals(inv.getParameters().get(i)[j], inv2.getParameters().get(i)[j]);
    }
  }
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com