View Javadoc
1   /*
2    * Copyright (C) 2008-2009, Google Inc.
3    * Copyright (C) 2008, Imran M Yousuf <imyousuf@smartitengineering.com>
4    * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
5    * Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> and others
6    *
7    * This program and the accompanying materials are made available under the
8    * terms of the Eclipse Distribution License v. 1.0 which is available at
9    * https://www.eclipse.org/org/documents/edl-v10.php.
10   *
11   * SPDX-License-Identifier: BSD-3-Clause
12   */
13  
14  package org.eclipse.jgit.internal.storage.file;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertNotNull;
18  
19  import java.io.IOException;
20  
21  import org.eclipse.jgit.lib.Constants;
22  import org.eclipse.jgit.lib.ObjectId;
23  import org.eclipse.jgit.lib.ObjectLoader;
24  import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
25  import org.junit.Test;
26  
27  public class T0004_PackReaderTest extends SampleDataRepositoryTestCase {
28  	private static final String PACK_NAME = "34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
29  
30  	@Test
31  	public void test003_lookupCompressedObject() throws IOException {
32  		final ObjectId id;
33  		final ObjectLoader or;
34  
35  		Pack pr = null;
36  		for (Pack p : db.getObjectDatabase().getPacks()) {
37  			if (PACK_NAME.equals(p.getPackName())) {
38  				pr = p;
39  				break;
40  			}
41  		}
42  		assertNotNull("have pack-" + PACK_NAME, pr);
43  
44  		id = ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327");
45  		or = pr.get(new WindowCursor(null), id);
46  		assertNotNull(or);
47  		assertEquals(Constants.OBJ_TREE, or.getType());
48  		assertEquals(35, or.getSize());
49  		pr.close();
50  	}
51  
52  	@Test
53  	public void test004_lookupDeltifiedObject() throws IOException {
54  		final ObjectId id;
55  		final ObjectLoader or;
56  
57  		id = ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259");
58  		or = db.open(id);
59  		assertNotNull(or);
60  		assertEquals(Constants.OBJ_BLOB, or.getType());
61  		assertEquals(18009, or.getSize());
62  	}
63  }