XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Done
    • Icon: Medium Medium
    • None
    • None
    • None
    • None
    • Integration R5 Test1(08/19)

      One way of doing it is using gerrit REST API. You can use the API directly (https://gerrit-review.googlesource.com/Documentation/rest-api.html), or use some opensource implementation of the API, such asĀ https://github.com/uwolfer/gerrit-rest-java-client

      Here is some code example on how to retrieve change list:

      import com.google.common.truth.Truth;
      import com.google.gerrit.extensions.common.AccountInfo;
      import com.google.gerrit.extensions.common.ChangeInfo;
      import com.google.gerrit.extensions.common.RevisionInfo;
      import com.google.gson.Gson;
      import com.urswolfer.gerrit.client.rest.http.HttpStatusException;
      import org.testng.SkipException;
      import org.testng.annotations.DataProvider;
      import org.testng.annotations.Test;
      
      import java.io.File;
      import java.io.FileReader;
      import java.net.URL;
      import java.util.List;
      
      public class OnapServerTest {
      
       public void run(String url, String user, String password) throws Exception {
       System.out.println(String.format("Testing against '%s'", url));
       GerritRestApiFactory gerritRestApiFactory = new GerritRestApiFactory();
       GerritAuthData.Basic authData;
       if (user != null) {
       authData = new GerritAuthData.Basic(url, user, password);
       } else {
       authData = new GerritAuthData.Basic(url);
       }
       GerritRestApi gerritApi = gerritRestApiFactory.create(authData);
      
       System.out.println(String.format("Gerrit version: %s", gerritApi.config().server().getVersion()));
      
       List<ChangeInfo> changeInfoList = gerritApi.changes().query("project:so+status:open").withLimit(1).get();
       
       //by Yang
       ChangeInfo change = changeInfoList.get(0);
       System.out.println("change set:");
       System.out.println(String.format(" id: %s", change.id)); 
       System.out.println(String.format(" project: %s", change.project)); 
       System.out.println(String.format(" branch: %s", change.branch)); 
       System.out.println(String.format(" topic: %s", change.topic)); 
       System.out.println(String.format(" changeId: %s", change.changeId)); 
       System.out.println(String.format(" subject: %s", change.subject)); 
       System.out.println(" created: " + change.created);
       System.out.println(" updated: " + change.updated);
       System.out.println(" submitted: " + change.submitted);
       System.out.println(" submitter: " + change.submitter);
       System.out.println(" revisions: " + change.revisions);
       Truth.assertThat(changeInfoList.size()).isLessThan(2);
      
       if (authData.isLoginAndPasswordAvailable()) {
       if (!changeInfoList.isEmpty()) {
       String id = changeInfoList.get(0).id;
       try {
       gerritApi.accounts().self().starChange(id);
       gerritApi.accounts().self().unstarChange(id);
       } catch (HttpStatusException exception) {
       System.out.println("Failed starring changes. Probably too old Gerrit version (<2.8)?");
       exception.printStackTrace();
       }
       }
      
       AccountInfo accountInfo = gerritApi.accounts().self().get();
       System.out.println(String.format("Username: '%s', name: '%s'", accountInfo.username, accountInfo.name));
       }
       }
      
       @Test
       public void test1() {
       OnapServerTest test = new OnapServerTest();
       try {
       test.run("https://gerrit.onap.org/r/", "username", "password");
       }
       catch(Throwable t) {
       t.printStackTrace();
       }
       }
      }

            xuyang11 xuyang11
            xuyang11 xuyang11
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: