@Test
  public void shouldThrowExceptionOnvInDifferentPartition() {
    final Vertex vA = g.addVertex("any", "a");
    assertEquals(vA.id(), g.v(vA.id()).id());

    final PartitionGraphStrategy strategy =
        (PartitionGraphStrategy) ((StrategyWrappedGraph) g).strategy().getGraphStrategy().get();
    strategy.clearReadPartitions();

    try {
      g.v(vA.id());
    } catch (Exception ex) {
      final Exception expected = Graph.Exceptions.elementNotFound(Vertex.class, vA.id());
      assertEquals(expected.getClass(), ex.getClass());
      assertEquals(expected.getMessage(), ex.getMessage());
    }
  }
Example #2
0
  private static final void checkIterable(Iterable<Namespace> abl, Namespace... values) {
    int cnt = 0;
    for (Namespace ns : abl) {
      if (cnt >= values.length) {
        fail("Unexpected extra Namespace: " + ns);
      }
      if (ns != values[cnt]) {
        fail("We expected Namespace " + values[cnt] + " but instead we got " + ns);
      }
      cnt++;
    }
    if (cnt < values.length) {
      fail(
          "We expected an additional "
              + (values.length - cnt)
              + " Namespaces, starting with "
              + values[cnt]);
    }
    Iterator<Namespace> it = abl.iterator();
    while (--cnt >= 0) {
      it.next();
    }

    assertFalse(it.hasNext());

    try {
      it.remove();
      fail("Should not be able to remove content from this iterator.");
    } catch (UnsupportedOperationException uoe) {
      // good.
    } catch (Exception e) {
      e.printStackTrace();
      fail("expected UnsupportedOperationException but got :" + e.getClass());
    }

    try {
      it.next();
      fail("Should not be able to iterate beyond the iterator.");
    } catch (NoSuchElementException nsee) {
      // good.
    } catch (Exception e) {
      e.printStackTrace();
      fail("expected NoSuchElementException but got :" + e.getClass());
    }
  }
 @Test
 public void testHandlerDispatching_ThrowingException() throws Throwable {
   try {
     testSubject.handle(GenericCommandMessage.asCommandMessage(new HashSet()), mockUnitOfWork);
     fail("Expected exception");
   } catch (Exception ex) {
     assertEquals(Exception.class, ex.getClass());
   }
 }
  @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
  private void checkException(
      final ArgumentCaptor<Exception> exceptionCaptor,
      final Class<? extends Exception> expectedException,
      final String expectedMessage) {
    final Exception exception = exceptionCaptor.getValue();

    assertEquals(expectedException, exception.getClass());
    assertEquals(expectedMessage, exception.getMessage());
  }
 /**
  * Create a PostfixEvaluator on the given sequence of operations, and return the results of
  * eval(), or catches an exception thrown by eval().
  *
  * @param operationExpression the sequence of operations to perform, written in RPN or postfix
  *     notation.
  * @return the results of running PostfixEvaluator.eval() on the operationExpression.
  */
 private double evalTest(String operationExpression) {
   PostfixEvaluator testPostfix = new PostfixEvaluator(operationExpression);
   double evalResult = 0;
   try {
     evalResult = testPostfix.eval();
   } catch (Exception e) {
     System.out.println("Unexpected exception occurred. Details:");
     System.out.println("\t" + e.getClass());
     System.out.println("\t" + e.getMessage());
   }
   return evalResult;
 }
  @Test
  public void testParseMissingUserElement() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    try {
      UserStoreConfigParser.parse(configEl);
      fail("An exception should have been thrown.");
    } catch (Exception ex) {
      assertEquals(InvalidUserStoreConfigException.class.getName(), ex.getClass().getName());
    }
  }
  @Test
  public void testParseIllegalUserFieldAttributeValue_Required() throws IOException, JDOMException {
    final StringBuffer configXml = new StringBuffer();
    configXml.append("<config>");
    configXml.append("  <user-fields>");
    configXml.append("    <prefix required=\"fisk\"/>");
    configXml.append("  </user-fields>");
    configXml.append("</config>");
    final Element configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();

    try {
      UserStoreConfigParser.parse(configEl);
      fail("An exception should have been thrown.");
    } catch (Exception ex) {
      assertEquals(InvalidUserStoreConfigException.class.getName(), ex.getClass().getName());
    }
  }
 private void assertInvalidParameter(long windowSize, long windowSlide) {
   try {
     new AccumulatingProcessingTimeWindowOperator<String, String, String>(
         mockFunction,
         mockKeySelector,
         StringSerializer.INSTANCE,
         StringSerializer.INSTANCE,
         windowSize,
         windowSlide);
     fail("This should fail with an IllegalArgumentException");
   } catch (IllegalArgumentException e) {
     // expected
   } catch (Exception e) {
     fail(
         "Wrong exception. Expected IllegalArgumentException but found "
             + e.getClass().getSimpleName());
   }
 }
Example #9
0
  @Test
  public void testEmptyStack() {
    Namespace[] scopea = new Namespace[] {Namespace.NO_NAMESPACE, Namespace.XML_NAMESPACE};
    List<Namespace> scopel = Arrays.asList(scopea);

    NamespaceStack stack = new NamespaceStack();

    checkIterators(stack, scopel, scopel);

    try {
      stack.pop();
      fail("Should not be able to over-pop the stack.");
    } catch (IllegalStateException ise) {
      // good.
    } catch (Exception e) {
      e.printStackTrace();
      fail("Expected IllegalStateException but got " + e.getClass());
    }
  }