1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.student.svn.model;
16
17 import java.io.File;
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.apache.commons.io.FileUtils;
24 import org.eclipse.jgit.lib.FileMode;
25 import org.eclipse.jgit.lib.ObjectId;
26 import org.eclipse.jgit.lib.ObjectInserter;
27 import org.eclipse.jgit.revwalk.RevCommit;
28 import org.eclipse.jgit.treewalk.TreeWalk;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.kuali.student.git.model.DummyGitTreeNodeInitializer;
32 import org.kuali.student.git.model.tree.GitTreeData;
33 import org.kuali.student.git.model.tree.utils.GitTreeProcessor;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41
42
43
44 public class TestGitTreeData extends AbstractGitRespositoryTestCase {
45
46 private static final Logger log = LoggerFactory.getLogger(TestGitTreeData.class);
47
48
49
50
51 public TestGitTreeData() {
52 super("git-tree-data");
53 }
54
55
56
57
58
59 @Override
60 protected void onAfter() throws Exception {
61 }
62
63
64
65
66
67 @Override
68 protected void onBefore() throws Exception {
69
70 }
71
72 @Test
73 public void testDirtyChecks() throws IOException {
74
75
76
77
78
79
80
81 ObjectInserter inserter = repo.newObjectInserter();
82
83 GitTreeData branch = new GitTreeData(new DummyGitTreeNodeInitializer());
84
85 List<String> lines = FileUtils.readLines(new File ("src/test/resources/ks-r21-expected-files.txt"));
86
87 for (String line : lines) {
88
89 String parts[] = line.split ("\t");
90
91 String path = parts[1];
92
93 storeFile(inserter, branch, path, Double.valueOf(Math.random()).toString());
94 }
95
96 ObjectId commitId = super.commit(inserter, branch, "commit");
97
98 createBranch(commitId, "branch");
99
100 inserter.flush();
101
102
103 GitTreeProcessor treeProcessor = new GitTreeProcessor(repo);
104
105 GitTreeData nextCommitBase = treeProcessor.extractExistingTreeDataFromCommit(commitId);
106
107 nextCommitBase.resetDirtyFlag();
108
109 storeFile(inserter, nextCommitBase, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/AttributeDefinition.java", Double.valueOf(Math.random()).toString());
110
111 ObjectId blobId = nextCommitBase.find(repo, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/AttributeDefinition.java");
112
113 Assert.assertNotNull(blobId);
114
115 ObjectId treeId = nextCommitBase.find(repo, "src/main/java/org/kuali/student/poc/xsd/personidentity/person");
116
117 Assert.assertNotNull(treeId);
118
119 TreeWalk tw = new TreeWalk(repo);
120
121 tw.addTree(treeId);
122
123 boolean expectDto = true;
124
125 List<String>expectedBlobNames = Arrays.asList(new String [] {"AttributeDataTypeDTO.java", "AttributeDefinitionDTO.java", "AttributeSetDTO.java", "PersonCreateInfo.java",
126 "PersonDTO.java", "PersonDisplayInfo.java", "PersonIdDTO.java", "PersonInfo.java", "PersonInfoDTO.java", "PersonTypeDTO.java", "PersonTypeInfoDTO.java", "PersonUpdateInfo.java"});
127
128 List<String>actualBlobNames = new ArrayList<>();
129
130 while (tw.next()) {
131
132 if (expectDto) {
133
134 Assert.assertEquals(FileMode.TREE, tw.getFileMode(0));
135
136 Assert.assertEquals("dto", tw.getNameString());
137
138 tw.enterSubtree();
139
140 expectDto = false;
141 }
142 else {
143
144 Assert.assertEquals(FileMode.REGULAR_FILE, tw.getFileMode(0));
145
146 actualBlobNames.add(tw.getNameString());
147
148 }
149 }
150
151 tw.release();
152
153 Assert.assertArrayEquals(expectedBlobNames.toArray(), actualBlobNames.toArray());
154
155 storeFile(inserter, nextCommitBase, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/AttributeSetDefinition.java", Double.valueOf(Math.random()).toString());
156
157 storeFile(inserter, nextCommitBase, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/PersonCitizenship.java", Double.valueOf(Math.random()).toString());
158
159 storeFile(inserter, nextCommitBase, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/PersonInfo.java", Double.valueOf(Math.random()).toString());
160
161 storeFile(inserter, nextCommitBase, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/PersonName.java", Double.valueOf(Math.random()).toString());
162
163 storeFile(inserter, nextCommitBase, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/PersonReferenceIdName.java", Double.valueOf(Math.random()).toString());
164
165 storeFile(inserter, nextCommitBase, "src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/PersonType.java", Double.valueOf(Math.random()).toString());
166
167 nextCommitBase.deletePath("src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/AttributeDataTypeDTO.java");
168
169 nextCommitBase.deletePath("src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/AttributeDefinitionDTO.java");
170
171 nextCommitBase.deletePath("src/main/java/org/kuali/student/poc/xsd/personidentity/person/dto/PersonTypeDTO.java");
172
173
174 ObjectId nextCommitId = super.commit(inserter, nextCommitBase, "commit");
175
176 RevCommit originalCommit = rw.parseCommit(commitId);
177
178 RevCommit currentCommit = rw.parseCommit(nextCommitId);
179
180 String result = super.diffTrees(originalCommit.getTree().getId(), currentCommit.getTree().getId());
181
182 log.info(result);
183
184 Assert.assertEquals(true, result.trim().length() > 0);
185
186
187
188 }
189
190
191 }