File rootDir = getTempDir();
File changeSetsDir = new File(rootDir, "changesets");
deleteDirectory(changeSetsDir);
changeSetsDir.mkdirs();
Headers headers = new Headers();
headers.setResourceId(newResource.getId());
headers.setDriftDefinitionId(1);
headers.setDriftDefinitionName("test-1");
headers.setBasedir(rootDir.getAbsolutePath());
headers.setType(COVERAGE);
headers.setVersion(0);
String file1Hash = sha256("test-1-file-1");
File changeSet1 = new File(changeSetsDir, "changeset-1.txt");
ChangeSetWriter writer = new ChangeSetWriterImpl(changeSet1, headers);
writer.write(addedFileEntry("test/file-1", file1Hash, 56789L, 1024L));
writer.close();
File changeSet1Zip = new File(changeSetsDir, "changeset-1.zip");
ZipUtil.zipFileOrDirectory(changeSet1, changeSet1Zip);
assertTrue("Expected to find change set zip file: " + changeSet1Zip.getPath(), changeSet1Zip.exists());
jpaDriftServer.storeChangeSet(overlord, newResource.getId(), changeSet1Zip);
JPADriftChangeSetCriteria c = new JPADriftChangeSetCriteria();
c.addFilterResourceId(newResource.getId());
c.fetchDrifts(true);
List<? extends DriftChangeSet<?>> changeSets = jpaDriftServer.findDriftChangeSetsByCriteria(overlord, c);
assertEquals(1, changeSets.size());
DriftChangeSet<?> changeSet = changeSets.get(0);
assertEquals(0, changeSet.getVersion());
assertEquals("Expected to find one entry in change set", 1, changeSet.getDrifts().size());
DriftFile driftFile = jpaDriftServer.getDriftFile(overlord, file1Hash);
assertNotNull(driftFile);
assertEquals(DriftFileStatus.REQUESTED, driftFile.getStatus());
// the second change set should report drift
String modifiedFile1Hash = sha256("test-2-file-1-modified");
headers.setType(DRIFT);
headers.setVersion(1);
File changeSet2 = new File(changeSetsDir, "changeset-2.txt");
writer = new ChangeSetWriterImpl(changeSet2, headers);
writer.write(changedFileEntry("test/file-1", file1Hash, modifiedFile1Hash, 56789L, 1024L));
writer.close();