basedir = temp.newFolder();
}
+ @Test
+ public void testPersistUpdateWhenSrcHashIsMissing() throws Exception {
+ setupData("file_sources_missing_src_hash");
+ Date now = DateUtils.parseDateTime("2014-10-29T16:44:02+0100");
+ when(system2.newDate()).thenReturn(now);
+
+ String relativePathSame = "src/same.java";
+ java.io.File sameFile = new java.io.File(basedir, relativePathSame);
+ FileUtils.write(sameFile, "unchanged\ncontent");
+ DefaultInputFile inputFileNew = new DefaultInputFile(PROJECT_KEY, relativePathSame)
+ .setLines(2)
+ .setAbsolutePath(sameFile.getAbsolutePath())
+ .setHash("123456")
+ .setLineHashes(new byte[][] {md5("unchanged"), md5("content")});
+ when(inputPathCache.all()).thenReturn(Arrays.<InputPath>asList(inputFileNew));
+
+ mockResourceCache(relativePathSame, PROJECT_KEY, "uuidsame");
+
+ sourcePersister.persist();
+ FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidsame");
+ assertThat(fileSourceDto.getCreatedAt()).isEqualTo(DateUtils.parseDateTime("2014-10-10T16:44:02+0200").getTime());
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now.getTime());
+ assertThat(fileSourceDto.getSrcHash()).isEqualTo("123456");
+ }
+
@Test
public void testPersistDontTouchUnchanged() throws Exception {
setupData("file_sources");
String relativePathSame = "src/same.java";
java.io.File sameFile = new java.io.File(basedir, relativePathSame);
FileUtils.write(sameFile, "unchanged\ncontent");
- DefaultInputFile inputFileNew = new DefaultInputFile(PROJECT_KEY, relativePathSame).setLines(2).setAbsolutePath(sameFile.getAbsolutePath())
+ DefaultInputFile inputFileNew = new DefaultInputFile(PROJECT_KEY, relativePathSame).setLines(2)
+ .setAbsolutePath(sameFile.getAbsolutePath())
+ .setHash("123456")
.setLineHashes(new byte[][] {md5("unchanged"), md5("ncontent")});
when(inputPathCache.all()).thenReturn(Arrays.<InputPath>asList(inputFileNew));
--- /dev/null
+<dataset>
+ <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame"
+ data=",,,,,,,,,,,,,,,unchanged ,,,,,,,,,,,,,,,content "
+ line_hashes="8d7b3d6b83c0a517eac07e1aac94b773 9a0364b9e99bb480dd25e1f0284c8555"
+ data_hash="0263047cd758c68c27683625f072f010"
+ src_hash="[null]"
+ created_at="1412952242000" updated_at="1412952242000" />
+
+</dataset>