Skip to content

Commit

Permalink
Tests in GetFileRequest now working and changes for timestamp tests i…
Browse files Browse the repository at this point in the history
…n GetFileIDsQueryTest
  • Loading branch information
Bohlski committed Jul 2, 2020
1 parent 06a7551 commit 9ba23d3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 45 deletions.
Expand Up @@ -60,7 +60,7 @@ public interface GetChecksumsClient extends BitrepositoryClient {
* connection with the pillar communication.
* @param auditTrailInformation Audittrail information for the contributors
*/
public void getChecksums(String collectionID, ContributorQuery[] contributorQueries, String fileID,
ChecksumSpecTYPE checksumSpec, URL addressForResult, EventHandler eventHandler,
String auditTrailInformation);
void getChecksums(String collectionID, ContributorQuery[] contributorQueries, String fileID,
ChecksumSpecTYPE checksumSpec, URL addressForResult, EventHandler eventHandler,
String auditTrailInformation);
}
Expand Up @@ -25,5 +25,5 @@
* Defines the interface for classes implementing functionality for constructing receiverDestinationIDs.
*/
public interface ReceiverDestinationIDFactory {
public String getReceiverDestinationID(String componentID, String collectionDestinationID);
String getReceiverDestinationID(String componentID, String collectionDestinationID);
}
Expand Up @@ -77,7 +77,10 @@ public void maxNumberOfResultTest() {
@Test ( groups = {PillarTestGroups.FULL_PILLAR_TEST, PillarTestGroups.CHECKSUM_PILLAR_TEST} )
public void minTimeStampTest() {
addDescription("Test the pillar support for only retrieving checksums newer that a given time. " +
"Note that this test assumes there is at least 2 checksums with different timestamps.");
"Note that this test assumes there is at least 2 checksums with different timestamps." +
"(Checksum lists are not compared directly as long lists might have checksums with shared " +
"timestamps which possibly leads to ambiguous results when sorting by time only. " +
"Instead, list size and outer points are compared)");
pillarFileManager.ensureNumberOfFilesOnPillar(2, testMethodName);

addStep("Request default checksums for all files on the pillar",
Expand All @@ -94,14 +97,19 @@ public void minTimeStampTest() {
ContributorQuery query = new ContributorQuery(getPillarID(),
oldestTimestamp.toGregorianCalendar().getTime(), null, null);
List<ChecksumDataForChecksumSpecTYPE> limitedChecksumList = pillarFileManager.getChecksums(null, query, null);
Assert.assertEquals(limitedChecksumList, originalChecksumList, "Different list return ");
Assert.assertEquals(limitedChecksumList.size(), originalChecksumList.size(),
"Differing size of checksum lists");
Assert.assertEquals(limitedChecksumList.get(0), originalChecksumList.get(0),
"Different first list element when setting oldest minTimestamp");
Assert.assertEquals(limitedChecksumList.get(limitedChecksumList.size()-1), originalChecksumList.get(originalChecksumList.size()-1),
"Different last list element when setting oldest minTimestamp");

addStep("Request checksums with MinTimeStamp set to the timestamp of the newest checksum",
"Only checksum with the timestamp equal to MinTimeStamp are returned.");
XMLGregorianCalendar newestTimestamp = originalChecksumList.get(originalChecksumList.size()-1).getCalculationTimestamp();
query = new ContributorQuery(getPillarID(), newestTimestamp.toGregorianCalendar().getTime(), null, null);
limitedChecksumList = pillarFileManager.getChecksums(null, query, null);
Assert.assertTrue(!limitedChecksumList.isEmpty(),
Assert.assertFalse(limitedChecksumList.isEmpty(),
"Empty list returned when when minTimestamp is set to newest calculated checksum timestamp");
Assert.assertTrue(limitedChecksumList.get(0).getCalculationTimestamp().compare(newestTimestamp) == 0,
"Different timestamps in the set of newest checksums." + limitedChecksumList);
Expand All @@ -119,8 +127,11 @@ public void minTimeStampTest() {

@Test ( groups = {PillarTestGroups.FULL_PILLAR_TEST, PillarTestGroups.CHECKSUM_PILLAR_TEST} )
public void maxTimeStampTest() {
addDescription("Test the pillar support for only retrieving checksums older that a given time. " +
"Note that this test assumes there is at least 2 checksums with different timestamps.");
addDescription("Test the pillar support for only retrieving checksums older than a given time. " +
"Note that this test assumes there is at least 2 checksums with different timestamps. " +
"(Checksum lists are not compared directly as long lists might have checksums with shared " +
"timestamps which possibly leads to ambiguous results when sorting by time only. " +
"Instead, list size and outer points are compared)");

pillarFileManager.ensureNumberOfFilesOnPillar(2, testMethodName);

Expand All @@ -138,8 +149,12 @@ public void maxTimeStampTest() {
ContributorQuery query = new ContributorQuery(getPillarID(),
null, newestTimestamp.toGregorianCalendar().getTime(), null);
List<ChecksumDataForChecksumSpecTYPE> limitedChecksumList = pillarFileManager.getChecksums(null, query, null);
Assert.assertEquals(limitedChecksumList, originalChecksumList,
"Different list return when setting newest maxTimestamp");
Assert.assertEquals(limitedChecksumList.size(), originalChecksumList.size(),
"Differing size of checksum lists");
Assert.assertEquals(limitedChecksumList.get(0), originalChecksumList.get(0),
"Different first list element when setting newest maxTimestamp");
Assert.assertEquals(limitedChecksumList.get(limitedChecksumList.size()-1), originalChecksumList.get(originalChecksumList.size()-1),
"Different last list element when setting newest maxTimestamp");

addStep("Request checksums with MaxTimeStamp set to the timestamp of the oldest checksum",
"Only checksum with the timestamp equal to MaxTimeStamp are returned.");
Expand Down
Expand Up @@ -15,18 +15,16 @@
import org.bitrepository.pillar.messagefactories.GetFileMessageFactory;
import org.bitrepository.protocol.FileExchange;
import org.bitrepository.protocol.ProtocolComponentFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;

Expand All @@ -35,27 +33,29 @@
import static org.testng.Assert.assertNull;

public class GetFileRequestIT extends DefaultPillarOperationTest {
private final Logger log = LoggerFactory.getLogger(this.getClass());
protected GetFileMessageFactory msgFactory;
protected String testFileURL = null;
protected FileExchange fe = ProtocolComponentFactory.getInstance().getFileExchange(settingsForCUT);
protected URL testFileURL = null;
protected FileExchange fe = null;

@BeforeMethod(alwaysRun=true)
public void initialiseReferenceTest(Method method) throws Exception {
String pillarDestination = lookupGetFileDestination();
msgFactory = new GetFileMessageFactory(collectionID, settingsForTestClient, getPillarID(), pillarDestination);
testFileURL = DEFAULT_FILE_URL.toExternalForm() + System.currentTimeMillis();
testFileURL = new URL(DEFAULT_FILE_URL.toExternalForm() + System.currentTimeMillis());
fe = ProtocolComponentFactory.getInstance().getFileExchange(settingsForCUT);
}

@AfterMethod
public void cleanUp() {
@AfterMethod(alwaysRun=true)
public void cleanUp(Method method) {
try {
fe.deleteFile(new URL(testFileURL));
} catch (IOException | URISyntaxException e) {
throw new AssertionError("Could not delete file at '" + testFileURL + "'");
fe.deleteFile(testFileURL);
} catch (Exception e) {
log.warn("Could not clean up file '{}' after method '{}'", testFileURL, method.getName());
}
}

@Test(groups = {PillarTestGroups.FULL_PILLAR_TEST, PillarTestGroups.CHECKSUM_PILLAR_TEST})
@Test(groups = {PillarTestGroups.FULL_PILLAR_TEST})
public void normalGetFileTest() throws IOException {
addDescription("Tests a normal GetFile sequence");
addStep("Send a getFile request to " + testConfiguration.getPillarUnderTestID(),
Expand All @@ -77,7 +77,7 @@ public void normalGetFileTest() throws IOException {

GetFileFinalResponse finalResponse = clientReceiver.waitForMessage(GetFileFinalResponse.class);
assertNotNull(finalResponse);
assertEquals(finalResponse.getCorrelationID(), getRequest.getCollectionID(),
assertEquals(finalResponse.getCorrelationID(), getRequest.getCorrelationID(),
"Received unexpected 'CorrelationID' element.");
assertEquals(finalResponse.getCollectionID(), getRequest.getCollectionID(),
"Received unexpected 'CollectionID' element.");
Expand All @@ -98,35 +98,46 @@ public void normalGetFileTest() throws IOException {
assertEquals(finalResponse.getResponseInfo().getResponseCode(), ResponseCode.OPERATION_COMPLETED,
"Received unexpected 'ResponseCode' element.");

File file = new File(DEFAULT_FILE_URL.toExternalForm());
FileInputStream fis = new FileInputStream(file);
String putFileContent = IOUtils.toString(fis, StandardCharsets.UTF_8);
InputStream is = fe.getFile(new URL(testFileURL));
String fileContent = IOUtils.toString(is, StandardCharsets.UTF_8);

assertEquals(fileContent, putFileContent);
try (InputStream localFileIS = TestFileHelper.getDefaultFile();
InputStream getFileIS = fe.getFile(testFileURL)) {
String localFileContent = IOUtils.toString(localFileIS, StandardCharsets.UTF_8);
String getFileContent = IOUtils.toString(getFileIS, StandardCharsets.UTF_8);
assertEquals(getFileContent, localFileContent,
"Differing content between original file and file from GetFileRequest");
}
}

/*@Test(groups = {PillarTestGroups.FULL_PILLAR_TEST, PillarTestGroups.CHECKSUM_PILLAR_TEST})
public void getFileWithFilePartTest() {
@Test(groups = {PillarTestGroups.FULL_PILLAR_TEST})
public void getFileWithFilePartTest() throws IOException {
addDescription("Tests that a pillar is able to return a specified FilePart in the final response");
addStep("Send a getFile request to " + testConfiguration.getPillarUnderTestID() + " with a specified " +
"FilePart", "The pillar should send a final response with the FilePart element for the " +
"supplied file");
GetFileRequest getRequest = (GetFileRequest) createRequest();

final int offsetAndLength = 5;
FilePart filePart = new FilePart();
filePart.setPartOffSet(BigInteger.valueOf(9));
filePart.setPartLength(BigInteger.valueOf(7));
filePart.setPartOffSet(BigInteger.valueOf(offsetAndLength));
filePart.setPartLength(BigInteger.valueOf(offsetAndLength));
getRequest.setFilePart(filePart);
messageBus.sendMessage(getRequest);

GetFileFinalResponse finalResponse = clientReceiver.waitForMessage(GetFileFinalResponse.class);
assertEquals(finalResponse.getFilePart(), getRequest.getFilePart(),
"Received unexpected 'FilePart' element.");

try (InputStream localFileIS = TestFileHelper.getDefaultFile();
InputStream getFileIS = fe.getFile(testFileURL)) {
byte[] localFilePartContent = new byte[offsetAndLength];
localFileIS.skip(offsetAndLength);
localFileIS.read(localFilePartContent, 0, offsetAndLength);
String getFileContent = IOUtils.toString(getFileIS, StandardCharsets.UTF_8);
assertEquals(getFileContent, new String(localFilePartContent),
"Differing content between original file and file from GetFileRequest");
}
}

@Test(groups = {PillarTestGroups.FULL_PILLAR_TEST, PillarTestGroups.CHECKSUM_PILLAR_TEST})
@Test(groups = {PillarTestGroups.FULL_PILLAR_TEST})
public void getMissingFileTest() {
addDescription("Tests that a pillar gives an error when trying to get a non-existing file");
addStep("Send a getFile request to " + testConfiguration.getPillarUnderTestID() + " with a " +
Expand All @@ -137,13 +148,13 @@ public void getMissingFileTest() {
messageBus.sendMessage(getRequest);

GetFileFinalResponse finalResponse = clientReceiver.waitForMessage(GetFileFinalResponse.class);
assertEquals(finalResponse.getResponseInfo().getResponseCode(), ResponseCode.FAILURE,
assertEquals(finalResponse.getResponseInfo().getResponseCode(), ResponseCode.FILE_NOT_FOUND_FAILURE,
"Received unexpected 'ResponseCode' element.");
}*/
}

@Override
protected MessageRequest createRequest() {
return msgFactory.createGetFileRequest(testFileURL, DEFAULT_FILE_ID);
return msgFactory.createGetFileRequest(testFileURL.toExternalForm(), DEFAULT_FILE_ID);
}

@Override
Expand Down
Expand Up @@ -24,6 +24,7 @@
import static org.bitrepository.pillar.integration.func.Assert.assertEmpty;
import static org.bitrepository.pillar.integration.func.Assert.assertEquals;
import static org.bitrepository.pillar.integration.func.Assert.assertTrue;
import static org.testng.Assert.assertFalse;

import java.util.GregorianCalendar;
import java.util.List;
Expand Down Expand Up @@ -158,7 +159,7 @@ public void maxTimeStampTest() {
query = new ContributorQuery(getPillarID(),
null, oldestTimestamp.toGregorianCalendar().getTime(), null);
limitedFileIDsList = pillarFileManager.getFileIDs(query);
assertTrue(!limitedFileIDsList.isEmpty(), "At least one file id with the oldest timestamp should be " +
assertFalse(limitedFileIDsList.isEmpty(), "At least one file id with the oldest timestamp should be " +
"returned. The folliwing fileIDs where received: ");
assertTrue(limitedFileIDsList.get(0).getLastModificationTime().compare(oldestTimestamp) == 0,
"Different timestamps in the set of oldest file ids." + limitedFileIDsList);
Expand Down
Expand Up @@ -105,7 +105,7 @@ public void normalPutFileTest() {
public void putFileWithMD5ReturnChecksumTest() {
addDescription("Tests that the pillar is able to return the default type checksum in the final response");
addStep("Send a putFile request to " + testConfiguration.getPillarUnderTestID() + " with the ",
"The pillar should send a final response with the ChecksumRequestForNewFile elemets containing the MD5 " +
"The pillar should send a final response with the ChecksumRequestForNewFile elements containing the MD5 " +
"checksum for the supplied file.");
PutFileRequest putRequest = msgFactory.createPutFileRequest(
TestFileHelper.getDefaultFileChecksum(), null, DEFAULT_DOWNLOAD_FILE_ADDRESS, testSpecificFileID,
Expand All @@ -125,7 +125,7 @@ public void putFileOperationAcceptedProgressTest() {
addDescription("Tests a that a pillar sends progress response after receiving a putFile request.");

addStep("Send a putFile request to " + testConfiguration.getPillarUnderTestID(),
"The pillar should generate a progress response with the following elements: <ol>" +
"The pillar should generate a progress response with the following elements: <ol>" +
"<li>'CollectionID' element corresponding to the value in the request.</li>" +
"<li>'CorrelationID' element corresponding to the value in the request.</li>" +
"<li>'From' element corresponding to the pillars component ID</li>" +
Expand Down Expand Up @@ -178,8 +178,8 @@ protected void assertNoResponseIsReceived() {
}

public String lookupPutFileDestination() {
PutFileMessageFactory pillarLookupmMsgFactory = new PutFileMessageFactory(collectionID, settingsForTestClient, getPillarID(), null);
IdentifyPillarsForPutFileRequest identifyRequest = pillarLookupmMsgFactory.createIdentifyPillarsForPutFileRequest(
PutFileMessageFactory pillarLookupMsgFactory = new PutFileMessageFactory(collectionID, settingsForTestClient, getPillarID(), null);
IdentifyPillarsForPutFileRequest identifyRequest = pillarLookupMsgFactory.createIdentifyPillarsForPutFileRequest(
TestFileHelper.DEFAULT_FILE_ID, 0L);
messageBus.sendMessage(identifyRequest);
return clientReceiver.waitForMessage(IdentifyPillarsForPutFileResponse.class).getReplyTo();
Expand Down

0 comments on commit 9ba23d3

Please sign in to comment.