コード例 #1
0
  @Test
  public void testListRemote() throws IOException {
    Repository dst = createBareRepository();

    assertEquals("http", remoteURI.getScheme());

    Map<String, Ref> map;
    Transport t = Transport.open(dst, remoteURI);
    ((TransportHttp) t).setUseSmartHttp(false);
    try {
      // I didn't make up these public interface names, I just
      // approved them for inclusion into the code base. Sorry.
      // --spearce
      //
      assertTrue("isa TransportHttp", t instanceof TransportHttp);
      assertTrue("isa HttpTransport", t instanceof HttpTransport);

      FetchConnection c = t.openFetch();
      try {
        map = c.getRefsMap();
      } finally {
        c.close();
      }
    } finally {
      t.close();
    }

    assertNotNull("have map of refs", map);
    assertEquals(2, map.size());

    assertNotNull("has " + master, map.get(master));
    assertEquals(B, map.get(master).getObjectId());

    assertNotNull("has " + Constants.HEAD, map.get(Constants.HEAD));
    assertEquals(B, map.get(Constants.HEAD).getObjectId());

    List<AccessEvent> requests = getRequests();
    assertEquals(2, requests.size());
    assertEquals(0, getRequests(remoteURI, "git-upload-pack").size());

    AccessEvent info = requests.get(0);
    assertEquals("GET", info.getMethod());
    assertEquals(join(remoteURI, "info/refs"), info.getPath());
    assertEquals(0, info.getParameters().size());
    assertNull("no service parameter", info.getParameter("service"));
    assertEquals("no-cache", info.getRequestHeader(HDR_PRAGMA));
    assertNotNull("has user-agent", info.getRequestHeader(HDR_USER_AGENT));
    assertTrue("is jgit agent", info.getRequestHeader(HDR_USER_AGENT).startsWith("JGit/"));
    assertEquals("*/*", info.getRequestHeader(HDR_ACCEPT));
    assertEquals(200, info.getStatus());
    assertEquals("text/plain;charset=UTF-8", info.getResponseHeader(HDR_CONTENT_TYPE));

    AccessEvent head = requests.get(1);
    assertEquals("GET", head.getMethod());
    assertEquals(join(remoteURI, "HEAD"), head.getPath());
    assertEquals(0, head.getParameters().size());
    assertEquals(200, head.getStatus());
    assertEquals("text/plain", head.getResponseHeader(HDR_CONTENT_TYPE));
  }
コード例 #2
0
  @Test
  public void testListRemote_Smart_WithQueryParameters() throws Exception {
    URIish myURI = toURIish("/snone/do?r=1&p=test.git");
    Repository dst = createBareRepository();
    Transport t = Transport.open(dst, myURI);
    try {
      try {
        t.openFetch();
        fail("test did not fail to find repository as expected");
      } catch (NoRemoteRepositoryException err) {
        // expected
      }
    } finally {
      t.close();
    }

    List<AccessEvent> requests = getRequests();
    assertEquals(1, requests.size());

    AccessEvent info = requests.get(0);
    assertEquals("GET", info.getMethod());
    assertEquals("/snone/do", info.getPath());
    assertEquals(3, info.getParameters().size());
    assertEquals("1", info.getParameter("r"));
    assertEquals("test.git/info/refs", info.getParameter("p"));
    assertEquals("git-upload-pack", info.getParameter("service"));
    assertEquals(404, info.getStatus());
  }