Search in sources :

Example 1 with RefUpdateAttribute

use of com.google.gerrit.server.data.RefUpdateAttribute in project gerrit by GerritCodeReview.

the class EventFactory method asRefUpdateAttribute.

/**
   * Create a RefUpdateAttribute for the given old ObjectId, new ObjectId, and branch that is
   * suitable for serialization to JSON.
   *
   * @param oldId
   * @param newId
   * @param refName
   * @return object suitable for serialization to JSON
   */
public RefUpdateAttribute asRefUpdateAttribute(ObjectId oldId, ObjectId newId, Branch.NameKey refName) {
    RefUpdateAttribute ru = new RefUpdateAttribute();
    ru.newRev = newId != null ? newId.getName() : ObjectId.zeroId().getName();
    ru.oldRev = oldId != null ? oldId.getName() : ObjectId.zeroId().getName();
    ru.project = refName.getParentKey().get();
    ru.refName = refName.get();
    return ru;
}
Also used : RefUpdateAttribute(com.google.gerrit.server.data.RefUpdateAttribute)

Example 2 with RefUpdateAttribute

use of com.google.gerrit.server.data.RefUpdateAttribute in project gerrit by GerritCodeReview.

the class EventRecorder method assertRefUpdatedEvents.

public void assertRefUpdatedEvents(String project, String branch, String... expected) throws Exception {
    ImmutableList<RefUpdatedEvent> events = getRefUpdatedEvents(project, branch, expected.length / 2);
    int i = 0;
    for (RefUpdatedEvent event : events) {
        RefUpdateAttribute actual = event.refUpdate.get();
        String oldRev = expected[i] == null ? ObjectId.zeroId().name() : expected[i];
        String newRev = expected[i + 1] == null ? ObjectId.zeroId().name() : expected[i + 1];
        assertThat(actual.oldRev).isEqualTo(oldRev);
        assertThat(actual.newRev).isEqualTo(newRev);
        i += 2;
    }
}
Also used : RefUpdateAttribute(com.google.gerrit.server.data.RefUpdateAttribute) RefUpdatedEvent(com.google.gerrit.server.events.RefUpdatedEvent)

Example 3 with RefUpdateAttribute

use of com.google.gerrit.server.data.RefUpdateAttribute in project gerrit by GerritCodeReview.

the class EventJsonTest method refUpdatedEvent.

@Test
public void refUpdatedEvent() {
    RefUpdatedEvent event = new RefUpdatedEvent();
    RefUpdateAttribute refUpdatedAttribute = new RefUpdateAttribute();
    refUpdatedAttribute.refName = REF;
    event.refUpdate = createSupplier(refUpdatedAttribute);
    event.submitter = newAccount("submitter");
    assertThatJsonMap(event).isEqualTo(ImmutableMap.builder().put("submitter", ImmutableMap.builder().put("name", event.submitter.get().name).put("email", event.submitter.get().email).put("username", event.submitter.get().username).build()).put("refUpdate", ImmutableMap.of("refName", REF)).put("type", "ref-updated").put("eventCreatedOn", TS1).build());
}
Also used : RefUpdateAttribute(com.google.gerrit.server.data.RefUpdateAttribute) Test(org.junit.Test)

Example 4 with RefUpdateAttribute

use of com.google.gerrit.server.data.RefUpdateAttribute in project gerrit by GerritCodeReview.

the class EventDeserializerTest method refUpdatedEvent.

@Test
public void refUpdatedEvent() {
    RefUpdatedEvent orig = new RefUpdatedEvent();
    RefUpdateAttribute refUpdatedAttribute = new RefUpdateAttribute();
    refUpdatedAttribute.refName = "refs/heads/master";
    orig.refUpdate = createSupplier(refUpdatedAttribute);
    AccountAttribute accountAttribute = new AccountAttribute();
    accountAttribute.email = "some.user@domain.com";
    orig.submitter = createSupplier(accountAttribute);
    RefUpdatedEvent e = roundTrip(orig);
    assertThat(e).isNotNull();
    assertThat(e.refUpdate).isInstanceOf(Supplier.class);
    assertThat(e.refUpdate.get().refName).isEqualTo(refUpdatedAttribute.refName);
    assertThat(e.submitter).isInstanceOf(Supplier.class);
    assertThat(e.submitter.get().email).isEqualTo(accountAttribute.email);
}
Also used : AccountAttribute(com.google.gerrit.server.data.AccountAttribute) RefUpdateAttribute(com.google.gerrit.server.data.RefUpdateAttribute) Test(org.junit.Test)

Example 5 with RefUpdateAttribute

use of com.google.gerrit.server.data.RefUpdateAttribute in project gerrit by GerritCodeReview.

the class EventRecorder method assertRefUpdatedEvents.

public void assertRefUpdatedEvents(String project, String branch, RevCommit... expected) throws Exception {
    ImmutableList<RefUpdatedEvent> events = getRefUpdatedEvents(project, branch, expected.length / 2);
    int i = 0;
    for (RefUpdatedEvent event : events) {
        RefUpdateAttribute actual = event.refUpdate.get();
        String oldRev = expected[i] == null ? ObjectId.zeroId().name() : expected[i].name();
        String newRev = expected[i + 1] == null ? ObjectId.zeroId().name() : expected[i + 1].name();
        assertThat(actual.oldRev).isEqualTo(oldRev);
        assertThat(actual.newRev).isEqualTo(newRev);
        i += 2;
    }
}
Also used : RefUpdateAttribute(com.google.gerrit.server.data.RefUpdateAttribute) RefUpdatedEvent(com.google.gerrit.server.events.RefUpdatedEvent)

Aggregations

RefUpdateAttribute (com.google.gerrit.server.data.RefUpdateAttribute)6 RefUpdatedEvent (com.google.gerrit.server.events.RefUpdatedEvent)2 Test (org.junit.Test)2 AccountAttribute (com.google.gerrit.server.data.AccountAttribute)1