View Javadoc
1   /*
2    * Copyright 2014 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 1.0 (the
5    * "License"); you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl1.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.kuali.student.git.model;
17  
18  import java.io.File;
19  import java.io.IOException;
20  import java.util.List;
21  
22  import org.apache.commons.io.FileUtils;
23  import org.apache.commons.io.IOUtils;
24  import org.eclipse.jgit.lib.Constants;
25  import org.eclipse.jgit.lib.FileMode;
26  import org.eclipse.jgit.lib.ObjectId;
27  import org.eclipse.jgit.lib.ObjectLoader;
28  import org.eclipse.jgit.lib.Ref;
29  import org.eclipse.jgit.lib.Repository;
30  import org.eclipse.jgit.revwalk.RevCommit;
31  import org.eclipse.jgit.revwalk.RevWalk;
32  import org.eclipse.jgit.treewalk.TreeWalk;
33  import org.junit.Assert;
34  import org.junit.Test;
35  import org.junit.runner.RunWith;
36  import org.junit.runners.BlockJUnit4ClassRunner;
37  import org.kuali.student.git.importer.GitImporterMain;
38  
39  /**
40   * 
41   * Test the importer on KS Revision 27975 to make sure the blob add is working properly
42   * 
43   * @author Kuali Student Team
44   *
45   */
46  @RunWith(BlockJUnit4ClassRunner.class)
47  public class TestKSRevision27975 {
48  
49  	/**
50  	 * @param name
51  	 */
52  	public TestKSRevision27975() {
53  	}
54  
55  	@Test
56  	public void testRevision27975 () throws IOException {
57  		File gitRepository = new File ("target/ks-r27975");
58  		
59  		FileUtils.deleteDirectory(gitRepository);
60  		
61  		Repository repository = GitRepositoryUtils
62  				.buildFileRepository(gitRepository, true);
63  		
64  		GitImporterMain.main(new String [] {"src/test/resources/ks-r27975.dump.bz2", gitRepository.getAbsolutePath(), "target/ks-r27975-ks-veto.log", "target/ks-r27975-ks-copyFrom-skipped.log", "target/ks-r27975-blob.log", "0", "https://svn.kuali.org/repos/student", "uuid"});
65  		
66  		RevWalk rw = new RevWalk(repository);
67  		
68  		Ref branch = repository.getRef("sandbox_ks-1.3-core-slice-demo_modules_ks-pom_trunk");
69  		
70  		Assert.assertNotNull(branch);
71  
72  		RevCommit headCommit = rw.parseCommit(branch.getObjectId());
73  		
74  		TreeWalk tw = new TreeWalk(repository);
75  		
76  		tw.addTree(headCommit.getTree().getId());
77  		
78  		tw.setRecursive(true);
79  		
80  		int blobCount = 0;
81  		
82  		ObjectId blobId = null;
83  		
84  		while (tw.next()) {
85  			
86  			if (tw.getFileMode(0) == FileMode.REGULAR_FILE) {
87  				blobCount++;
88  				
89  				blobId = tw.getObjectId(0);
90  			}
91  		}
92  		
93  		Assert.assertEquals(1, blobCount);
94  		
95  		ObjectLoader blobLoader = repository.getObjectDatabase().newReader().open(blobId);
96  		
97  		List<String> lines = IOUtils.readLines(blobLoader.openStream());
98  		
99  		Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", lines.get(0));
100 		
101 		tw.release();
102 		
103 		rw.release();
104 		repository.close();
105 		
106 		
107 	}
108 	
109 	
110 	
111 }