org.mozilla.zest.core.v1.ZestExpressionStatusCode.<init>()方法的使用及代码示例

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

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

ZestExpressionStatusCode.<init>介绍

[英]Instantiates a new zest expression status code.
[中]实例化一个新的zest表达式状态代码。

代码示例

代码示例来源: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 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 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

@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 shouldSetStatusCode() {
  // Given
  int statusCode = 201;
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode();
  // When
  statusCodeExpression.setCode(statusCode);
  // Then
  assertEquals(statusCode, statusCodeExpression.getCode());
}

代码示例来源: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 shouldSetInverse() {
  // Given
  ZestExpressionStatusCode statusCodeExpression = new ZestExpressionStatusCode();
  // When
  statusCodeExpression.setInverse(true);
  // Then
  assertTrue(statusCodeExpression.isInverse());
}

代码示例来源: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 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

@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

@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));
    }
  }
}

代码示例来源: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 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 testRemoveMiddleChild() {
  int half = 5;
  ZestExpressionAnd and = new ZestExpressionAnd();
  for (int i = 0; i < half; i++) {
    and.addChildCondition(new ZestExpressionLength());
  }
  and.addChildCondition(new ZestExpressionStatusCode());
  for (int i = 0; i < half; i++) {
    and.addChildCondition(new ZestExpressionLength());
  }
  boolean middleElementIsCode =
      and.getChild(half).getClass().equals(ZestExpressionStatusCode.class);
  if (!middleElementIsCode) fail();
  and.removeChildCondition(half);
  assertTrue(and.getChild(half) instanceof ZestExpressionLength);
}

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

@Test
public void testRemoveLastChild() {
  int childrenSize = 10; // initial size
  ZestExpressionAnd and = new ZestExpressionAnd();
  for (int i = 0; i < childrenSize - 1; i++) {
    and.addChildCondition(new ZestExpressionLength());
  }
  and.addChildCondition(new ZestExpressionStatusCode());
  and.removeChildCondition(childrenSize - 1); // removes last child
  if (and.getChildrenCondition().size() == childrenSize) fail();
  else assertTrue(and.getChild(childrenSize - 2) instanceof ZestExpressionLength); // last
  // of
  // the
  // remaining
}

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

@Test
public void testRemoveFirstChild() {
  ZestExpressionAnd and = new ZestExpressionAnd();
  and.addChildCondition(new ZestExpressionLength());
  and.addChildCondition(new ZestExpressionStatusCode());
  and.removeChildCondition(0);
  assertTrue(and.getChild(0) instanceof 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 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());
}

相关文章