コード例 #1
0
  @Test
  public void run() throws UnsupportedEncodingException {

    Person user = new Person();
    user.setUsername("Bob");
    user.setPassword("password");
    user.setGender(Gender.M);
    user.setPicture("picture".getBytes());
    user.setInfo("some info");

    user = repository.save(user);
    assertNotNull(user);
    assertEquals("picture", new String(user.getPicture(), "UTF-8"));

    user = repository.findOne(user.getId());
    assertNotNull(user);

    user.setInfo("other info");
    user = repository.save(user);
    assertNotNull(user);
    assertEquals("other info", user.getInfo());

    Iterable<Person> iter = repository.findAll();
    assertTrue(iter.iterator().hasNext());

    for (Person person : iter) {
      assertNotNull(person);
    }

    repository.delete(user);

    Person found = repository.findOne(user.getId());
    assertNull(found);
  }
コード例 #2
0
ファイル: ModelAssert.java プロジェクト: CloudMetal/MPS
  private static void assertDeepChildrenEquals(SNode expectedNode, SNode actualNode) {
    Set<String> roles = new HashSet<String>();
    for (SNode child : expectedNode.getChildren()) {
      roles.add(child.getRoleInParent());
    }
    for (SNode child : actualNode.getChildren()) {
      roles.add(child.getRoleInParent());
    }

    for (String role : roles) {
      Iterable<? extends SNode> expectedChildren = expectedNode.getChildren(role);
      Iterable<? extends SNode> actualChildren = actualNode.getChildren(role);

      int esize = IterableUtil.asCollection(expectedChildren).size();
      int asize = IterableUtil.asCollection(actualChildren).size();
      assertEquals(
          getErrorString("child count in role " + role, expectedNode, actualNode), esize, asize);

      Iterator<? extends SNode> actualIterator = actualChildren.iterator();
      for (SNode expectedChild : expectedChildren) {
        SNode actualChild = actualIterator.next();
        assertEquals(
            getErrorString("children in role " + role, expectedNode, actualNode),
            expectedChild.getNodeId(),
            actualChild.getNodeId());
        assertDeepNodeEquals(expectedChild, actualChild);
      }
    }
  }
コード例 #3
0
  /**
   * @param xmlSample
   * @return
   * @throws MalformedURLException
   * @throws IOException
   */
  protected HtmlElement createHtmlElement(String xmlSample)
      throws MalformedURLException, IOException {
    String xmlSampleWithTags =
        "<table><tr><div id=\"maxtest2\"" + xmlSample + "</div></tr></table>";

    URL url = new URL("http://www.example.com");
    StringWebResponse response = new StringWebResponse(xmlSampleWithTags, url);
    WebClient client = new WebClient();
    HtmlPage page = HTMLParser.parseHtml(response, client.getCurrentWindow());

    // HtmlElement element = page.getHtmlElementById("maxtest");

    HtmlElement element = page.getHtmlElementById("maxtest2");
    Iterable<HtmlElement> children = element.getChildElements();
    Iterator<HtmlElement> iter = children.iterator();

    return iter.next();
  }
コード例 #4
0
  private void assertContentsInOrder(Iterable<String> s, String... expecteds) {
    Iterator<String> sIter = s.iterator();
    boolean match = true;
    for (String expected : expecteds) {
      match &= sIter.hasNext() && sIter.next().equals(expected);
    }

    assertTrue(
        "Expected " + Arrays.toString(expecteds) + " but was " + s, !sIter.hasNext() && match);
  }
コード例 #5
0
  @Test
  public void testObjectKeyIterable() {

    Iterable<Integer> objectKeys = SQLiteIndex.objectKeyIterable(data, Car.CAR_ID, null);
    Assert.assertNotNull(objectKeys);

    Iterator<Integer> objectKeysIterator = objectKeys.iterator();
    Assert.assertNotNull(objectKeysIterator);
    assertTrue(objectKeysIterator.hasNext());
    assertEquals(new Integer(1), objectKeysIterator.next());
    assertTrue(objectKeysIterator.hasNext());
    assertEquals(new Integer(2), objectKeysIterator.next());
    assertTrue(objectKeysIterator.hasNext());
    assertEquals(new Integer(3), objectKeysIterator.next());
    assertTrue(objectKeysIterator.hasNext());
    assertEquals(new Integer(4), objectKeysIterator.next());
    assertTrue(objectKeysIterator.hasNext());
    assertEquals(new Integer(5), objectKeysIterator.next());
    assertFalse(objectKeysIterator.hasNext());
  }
コード例 #6
0
  @Test
  public void backups() {
    Balancer<Void, MockDatabase> balancer =
        this.factory.createBalancer(Collections.<MockDatabase>emptySet());

    Iterable<MockDatabase> result = balancer.backups();
    assertNotNull(result);
    Iterator<MockDatabase> backups = result.iterator();
    assertFalse(backups.hasNext());

    balancer = this.factory.createBalancer(Collections.singleton(this.databases[0]));

    result = balancer.backups();
    assertNotNull(result);
    backups = result.iterator();
    assertFalse(backups.hasNext());

    balancer =
        this.factory.createBalancer(
            new HashSet<MockDatabase>(Arrays.asList(this.databases[0], this.databases[1])));

    result = balancer.backups();
    assertNotNull(result);
    backups = result.iterator();
    assertTrue(backups.hasNext());
    assertSame(this.databases[1], backups.next());
    assertFalse(backups.hasNext());

    balancer =
        this.factory.createBalancer(new HashSet<MockDatabase>(Arrays.asList(this.databases)));

    result = balancer.backups();
    assertNotNull(result);
    backups = result.iterator();
    assertTrue(backups.hasNext());
    assertSame(this.databases[1], backups.next());
    assertTrue(backups.hasNext());
    assertSame(this.databases[2], backups.next());
    assertFalse(backups.hasNext());
  }
  @Test
  public void testGetTransitiveDependencies() {
    DependencyDescription transitiveDependencies =
        dataObjQueries.getTransitiveDependencies(attr2Bos1, false, true, null, null);
    Iterator<DependencyDescription> transDepIt = transitiveDependencies.iterator();
    assertTrue(transDepIt.hasNext());

    final IEObjectDescription bo2Desc = descriptionBuilder.buildDescription(bo2);
    Iterable<DependencyDescription> filtered =
        Iterables.filter(
            transitiveDependencies,
            new Predicate<DependencyDescription>() {

              public boolean apply(DependencyDescription input) {
                assertNotNull(input.getTarget());
                assertNotNull(input.getSource());
                return BaseDslEqualityHelper.isEqual(bo2Desc, input.getTarget());
              }
            });
    Iterator<DependencyDescription> depIt = filtered.iterator();
    assertTrue(depIt.hasNext());
    List<DependencyDescription> filteredDeps = Lists.newArrayList(filtered);
    assertEquals(1, filteredDeps.size());
  }
コード例 #8
0
    @Override
    public UnmodIterator<T> iterator() {
      Iterator<T> iter = inner.iterator();
      return new UnmodIterator<T>() {
        @Override
        public boolean hasNext() {
          return iter.hasNext();
        }

        @Override
        public T next() {
          return iter.next();
        }
      };
    }
コード例 #9
0
ファイル: TestNamespaceStack.java プロジェクト: rongbo-j/jdom
  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());
    }
  }
コード例 #10
0
  /** Testa la correttezza del costruttore e dei metodi "getter" della classe. */
  @Test
  public void testConstructor() {
    Date first_event = new Date(1124242);
    Date second_event = new Date(95843);
    Date[] events = {first_event, second_event};
    Iterable<Date> i_events = Arrays.asList(events);
    Telemetry t1 = new Telemetry(events, "track");
    Telemetry t2 = new Telemetry(i_events, "track");
    Iterable<Date> t1_events = t1.getEvents();
    Iterable<Date> t2_events = t2.getEvents();
    Iterator<Date> t1_iterator = t1_events.iterator();
    Iterator<Date> t2_iterator = t2_events.iterator();
    Iterator<Date> input_iterator = i_events.iterator();
    while (t1_iterator.hasNext() && t2_iterator.hasNext() && input_iterator.hasNext()) {
      Date te1 = t1_iterator.next();
      Date te2 = t2_iterator.next();
      Date ie = input_iterator.next();

      assertTrue(te1.getTime() == ie.getTime());
      assertTrue(te2.getTime() == ie.getTime());
    }
  }
コード例 #11
0
 private <T> void assertSingleResult(T expected, Iterable<T> iterable) {
   Iterator<T> result = iterable.iterator();
   assertEquals(expected, result.next());
   assertEquals(false, result.hasNext());
 }
  @Test
  public void testGetIssue() throws Exception {
    final Issue issue = client.getIssueClient().getIssue("TST-1").claim();
    assertEquals("TST-1", issue.getKey());
    assertEquals(Long.valueOf(10000), issue.getId());
    assertTrue(issue.getSelf().toString().startsWith(jiraUri.toString()));
    assertEqualsNoUri(IntegrationTestUtil.USER_ADMIN, issue.getReporter());
    assertEqualsNoUri(IntegrationTestUtil.USER_ADMIN, issue.getAssignee());

    assertThat(issue.getLabels(), containsInAnyOrder("a", "bcds"));

    assertEquals(3, Iterables.size(issue.getComments()));
    final Iterable<String> expectedExpandos = getExpectedExpands();
    assertThat(
        ImmutableList.copyOf(issue.getExpandos()),
        containsInAnyOrder(toArray(expectedExpandos, String.class)));
    assertEquals(new TimeTracking(null, 0, 190), issue.getTimeTracking());
    assertTrue(Iterables.size(issue.getFields()) > 0);

    assertEquals(
        IntegrationTestUtil.START_PROGRESS_TRANSITION_ID, Iterables.size(issue.getAttachments()));
    final Iterable<Attachment> items = issue.getAttachments();
    assertNotNull(items);
    Attachment attachment1 =
        new Attachment(
            IntegrationTestUtil.concat(
                IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER
                    ? UriBuilder.fromUri(jiraUri).path("/rest/api/2/").build()
                    : jiraRestRootUri,
                "/attachment/10040"),
            "dla Paw\u0142a.txt",
            IntegrationTestUtil.USER_ADMIN,
            dateTime,
            643,
            "text/plain",
            IntegrationTestUtil.concat(jiraUri, "/secure/attachment/10040/dla+Paw%C5%82a.txt"),
            null);

    assertEquals(attachment1, items.iterator().next());

    // test for changelog
    assertNull(issue.getChangelog());

    final Issue issueWithChangelogAndOperations =
        client.getIssueClient().getIssue("TST-2", EnumSet.of(CHANGELOG, OPERATIONS)).claim();
    final Iterable<ChangelogGroup> changelog = issueWithChangelogAndOperations.getChangelog();
    if (isJira5xOrNewer()) {
      assertNotNull(changelog);
      final ChangelogGroup chg1 = Iterables.get(changelog, 18);
      assertEquals("admin", chg1.getAuthor().getName());
      assertEquals("Administrator", chg1.getAuthor().getDisplayName());
      assertEquals(
          new DateTime(2010, 8, 17, 16, 40, 34, 924).toInstant(), chg1.getCreated().toInstant());

      assertEquals(
          Collections.singletonList(
              new ChangelogItem(FieldType.JIRA, "status", "1", "Open", "3", "In Progress")),
          chg1.getItems());

      final ChangelogGroup chg2 = Iterables.get(changelog, 20);
      assertEquals("admin", chg2.getAuthor().getName());
      assertEquals("Administrator", chg2.getAuthor().getDisplayName());
      assertEquals(
          new DateTime(2010, 8, 24, 16, 10, 23, 468).toInstant(), chg2.getCreated().toInstant());

      final List<ChangelogItem> expected =
          ImmutableList.of(
              new ChangelogItem(FieldType.JIRA, "timeoriginalestimate", null, null, "0", "0"),
              new ChangelogItem(FieldType.CUSTOM, "My Radio buttons", null, null, null, "Another"),
              new ChangelogItem(FieldType.CUSTOM, "project3", null, null, "10000", "Test Project"),
              new ChangelogItem(FieldType.CUSTOM, "My Number Field New", null, null, null, "1.45"));
      assertEquals(expected, chg2.getItems());
    }
    final Operations operations = issueWithChangelogAndOperations.getOperations();
    if (isJira5xOrNewer()) {
      assertThat(operations, notNullValue());
      assertThat(
          operations.getOperationById("log-work"),
          allOf(instanceOf(OperationLink.class), hasProperty("id", is("log-work"))));
    }
  }
コード例 #13
0
ファイル: DollarTest.java プロジェクト: roblally/dollar
 @Test
 public void dollarCanBeBackedWithIterator() {
   assertEquals(stringInput, $(stringInput.iterator()).asList());
 }
コード例 #14
0
  private void validateNodeRel2(
      long node,
      DefinedProperty prop1,
      DefinedProperty prop2,
      DefinedProperty prop3,
      long rel1,
      long rel2,
      int relType1,
      int relType2)
      throws IOException {
    NodeRecord nodeRecord = xaCon.getTransaction().nodeLoadLight(node);
    assertTrue(nodeRecord != null);
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    xaCon.getTransaction().nodeLoadProperties(node, false, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
      long id = props.get(keyId).other();
      PropertyRecord record = pStore.getRecord(id);
      PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
      DefinedProperty data = block.newPropertyData(pStore);
      if (data.propertyKeyId() == prop1.propertyKeyId()) {
        assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
        assertEquals("string2", data.value());
        xaCon.getTransaction().nodeChangeProperty(node, prop1.propertyKeyId(), "-string2");
      } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
        assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
        assertEquals(2, data.value());
        xaCon.getTransaction().nodeChangeProperty(node, prop2.propertyKeyId(), new Integer(-2));
      } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
        assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
        assertEquals(false, data.value());
        xaCon.getTransaction().nodeChangeProperty(node, prop3.propertyKeyId(), true);
      } else {
        throw new IOException();
      }
      count++;
    }
    assertEquals(3, count);
    count = 0;

    MutableRelationshipLoadingPosition pos = getPosition(xaCon, node);
    while (true) {
      Iterable<RelationshipRecord> relData = getMore(xaCon, node, pos);
      if (!relData.iterator().hasNext()) {
        break;
      }
      for (RelationshipRecord rel : relData) {
        if (rel.getId() == rel1) {
          assertEquals(node, rel.getSecondNode());
          assertEquals(relType1, rel.getType());
        } else if (rel.getId() == rel2) {
          assertEquals(node, rel.getFirstNode());
          assertEquals(relType2, rel.getType());
        } else {
          throw new IOException();
        }
        count++;
      }
    }
    assertEquals(2, count);
  }