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

x33g5p2x  于2022-02-05 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(77)

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

ZestExpressionStatusCode介绍

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

代码示例

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

@Test
public void shouldDeepCopy() {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(404);
  statusCodeExpression.setInverse(true);
  // When
  ZestExpressionStatusCode copyStatusCodeExpression = statusCodeExpression.deepCopy();
  // Then
  assertTrue(copyStatusCodeExpression != statusCodeExpression);
  assertEquals(copyStatusCodeExpression.getCode(), statusCodeExpression.getCode());
  assertEquals(copyStatusCodeExpression.isInverse(), statusCodeExpression.isInverse());
}

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

@Test
public void shouldSetStatusCode() {
  // Given
  int statusCode = 201;
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode();
  // When
  statusCodeExpression.setCode(statusCode);
  // Then
  assertEquals(statusCode, statusCodeExpression.getCode());
}

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

@Override
public ZestExpressionStatusCode deepCopy() {
  ZestExpressionStatusCode copy = new ZestExpressionStatusCode();
  copy.code = code;
  copy.setInverse(isInverse());
  return copy;
}

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

@Test
public void shouldEvaluateToFalseIfInverseAndSameStatusCode() throws Exception {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(200);
  statusCodeExpression.setInverse(true);
  ZestResponse response = createResponse(200);
  // When
  boolean result = statusCodeExpression.evaluate(new TestRuntime(response));
  // Then
  assertFalse(result);
}

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

@Test
public void testSetChildrenCondition() {
  List<ZestExpressionElement> children = new LinkedList<>();
  children.add(new ZestExpressionAnd());
  children.add(new ZestExpressionLength("response.body", 1, 2));
  children.add(new ZestExpressionStatusCode(200));
  ZestExpressionAnd root = new ZestExpressionAnd();
  root.setChildrenCondition(children);
  for (int i = 0; i < children.size(); i++) {
    String expected = children.get(i).getClass().getName();
    String obtained = root.getChild(i).getClass().getName();
    String msg = "[" + i + "] - Obtained " + obtained + " instead of " + expected;
    assertTrue(msg, children.get(i).getClass().equals(root.getChild(i).getClass()));
  }
}

代码示例来源: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 shouldEvaluateToFalseIfNoResponse() throws Exception {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(204);
  // When
  boolean result = statusCodeExpression.evaluate(new TestRuntime());
  // Then
  assertFalse(result);
}

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

@Test
public void shouldNotBeInversedByDefault() {
  // Given / When
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode();
  // Then
  assertFalse(statusCodeExpression.isInverse());
}

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

@Test
public void shouldHaveZeroStatusCodeByDefault() {
  // Given / When
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode();
  // Then
  assertEquals(statusCodeExpression.getCode(), 0);
}

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

@Override
  public String toString() {
    String expression = (isInverse() ? "NOT " : "") + "Status Code: " + code;
    return expression;
  }
}

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

} else if (element instanceof ZestExpressionStatusCode) {
  ZestExpressionStatusCode codeExpr = (ZestExpressionStatusCode) element;
  System.out.print("Status Code: " + codeExpr.getCode());
} else if (element instanceof ZestExpressionIsInteger) {
  ZestExpressionIsInteger codeExpr = (ZestExpressionIsInteger) element;

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

@Test
public void shouldSetInverse() {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode();
  // When
  statusCodeExpression.setInverse(true);
  // Then
  assertTrue(statusCodeExpression.isInverse());
}

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

@Test
public void shouldEvaluateToTrueIfInverseAndNotSameStatusCode() throws Exception {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(200);
  statusCodeExpression.setInverse(true);
  ZestResponse response = createResponse(500);
  // When
  boolean result = statusCodeExpression.evaluate(new TestRuntime(response));
  // Then
  assertTrue(result);
}

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

@Test
public void testDeepCopyNoPointer() {
  LinkedList<ZestExpressionElement> children = new LinkedList<>();
  for (int i = 0; i < 10; i++) {
    children.add(new ZestExpressionStatusCode(i));
  }
  ZestExpressionAnd and = new ZestExpressionAnd(children);
  ZestExpressionAnd copy = and.deepCopy();
  and.removeChildCondition(0);
  assertTrue(
      and.getChildrenCondition().size() + 1
          == copy.getChildrenCondition().size()); // different size <=> no
  // pointers
}

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

@Test
public void shouldEvaluateToFalseIfNotSameStatusCode() throws Exception {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(500);
  ZestResponse response = createResponse(200);
  // When
  boolean result = statusCodeExpression.evaluate(new TestRuntime(response));
  // Then
  assertFalse(result);
}

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

Random random = new Random();
int pos = random.nextInt(10);
and.addChildCondition(new ZestExpressionStatusCode(), pos);
if (and.getChildrenCondition().size() != 11) fail();
for (int i = 0; i < 11; i++) {

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

@Test
public void shouldEvaluateToTrueIfSameStatusCode() throws Exception {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode(200);
  ZestResponse response = createResponse(200);
  // When
  boolean result = statusCodeExpression.evaluate(new TestRuntime(response));
  // Then
  assertTrue(result);
}

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

public void testOrDeepCopySingleAndSameChildrenSize() {
  ZestExpressionOr or = new ZestExpressionOr();
  or.addChildCondition(new ZestExpressionStatusCode(100));
  or.addChildCondition(new ZestExpressionLength("response.body", 1, 1));
  ZestExpressionOr copy = or.deepCopy();
  assertTrue(or.getChildrenCondition().size() == copy.getChildrenCondition().size());
}

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

@Test
public void testDeepCopySingleAndSameChildrenSize() {
  ZestExpressionAnd and = new ZestExpressionAnd();
  and.addChildCondition(new ZestExpressionStatusCode(100));
  and.addChildCondition(new ZestExpressionLength("response.body", 1, 1));
  ZestExpressionAnd copy = and.deepCopy();
  assertTrue(and.getChildrenCondition().size() == copy.getChildrenCondition().size());
}

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

@Test
public void testRemoveAllChildren() {
  ZestExpressionAnd and = new ZestExpressionAnd();
  for (int i = 0; i < 10; i++) {
    if (i % 2 == 0) and.addChildCondition(new ZestExpressionLength());
    else and.addChildCondition(new ZestExpressionStatusCode());
  }
  LinkedList<ZestExpressionElement> toRemove = new LinkedList<>();
  for (int i = 0; i < 10; i += 2) {
    toRemove.add(and.getChild(i));
  }
  if (!and.removeAllChildren(toRemove)) fail();
  else {
    for (int i = 0; i < and.getChildrenCondition().size(); i++) {
      assertTrue(
          "Element n°" + i,
          and.getChild(i).getClass().equals(ZestExpressionStatusCode.class));
    }
  }
}

相关文章