-
Notifications
You must be signed in to change notification settings - Fork 4
/
PutFileRequestIT.java
187 lines (171 loc) · 11 KB
/
PutFileRequestIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* #%L
* Bitrepository Reference Pillar
* %%
* Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package org.bitrepository.pillar.integration.func.putfile;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import java.lang.reflect.Method;
import org.bitrepository.bitrepositoryelements.ResponseCode;
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForPutFileRequest;
import org.bitrepository.bitrepositorymessages.IdentifyPillarsForPutFileResponse;
import org.bitrepository.bitrepositorymessages.MessageRequest;
import org.bitrepository.bitrepositorymessages.MessageResponse;
import org.bitrepository.bitrepositorymessages.PutFileFinalResponse;
import org.bitrepository.bitrepositorymessages.PutFileProgressResponse;
import org.bitrepository.bitrepositorymessages.PutFileRequest;
import org.bitrepository.common.utils.ChecksumUtils;
import org.bitrepository.common.utils.TestFileHelper;
import org.bitrepository.pillar.PillarTestGroups;
import org.bitrepository.pillar.integration.func.DefaultPillarOperationTest;
import org.bitrepository.pillar.messagefactories.PutFileMessageFactory;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class PutFileRequestIT extends DefaultPillarOperationTest {
protected PutFileMessageFactory msgFactory;
private String pillarDestination;
@BeforeMethod(alwaysRun=true)
public void initialiseReferenceTest(Method method) throws Exception {
pillarDestination = lookupPutFileDestination();
msgFactory = new PutFileMessageFactory(collectionID, settingsForTestClient, getPillarID(), pillarDestination);
}
@Test( groups = {PillarTestGroups.FULL_PILLAR_TEST, PillarTestGroups.CHECKSUM_PILLAR_TEST})
public void normalPutFileTest() {
addDescription("Tests a normal PutFile sequence");
addStep("Send a putFile request to " + testConfiguration.getPillarUnderTestID(),
"The pillar should send a final response with the following elements: <ol>" +
"<li>'CollectionID' element corresponding to the supplied value</li>" +
"<li>'CorrelationID' element corresponding to the supplied value</li>" +
"<li>'From' element corresponding to the pillars component ID</li>" +
"<li>'To' element should be set to the value of the 'From' elements in the request</li>" +
"<li>'Destination' element should be set to the value of 'ReplyTo' from the request</li>" +
"<li>'ChecksumDataForExistingFile' element should be null</li>" +
"<li>'ChecksumDataForNewFile' element should be null</li>" +
"<li>'PillarID' element corresponding to the pillars component ID</li>" +
"<li>'FileID' element corresponding to the supplied fileID</li>" +
"<li>'FileAddress' element corresponding to the supplied FileAddress</li>" +
"<li>'ResponseInfo.ResponseCode' element should be OPERATION_COMPLETED</li>" +
"</ol>");
PutFileRequest putRequest = msgFactory.createPutFileRequest(
TestFileHelper.getDefaultFileChecksum(), null, DEFAULT_DOWNLOAD_FILE_ADDRESS, testSpecificFileID,
DEFAULT_FILE_SIZE);
messageBus.sendMessage(putRequest);
PutFileFinalResponse finalResponse = clientReceiver.waitForMessage(PutFileFinalResponse.class);
assertNotNull(finalResponse);
assertEquals(finalResponse.getCorrelationID(), putRequest.getCorrelationID(),
"Received unexpected 'CorrelationID' element.");
assertEquals(finalResponse.getCollectionID(), putRequest.getCollectionID(),
"Received unexpected 'CollectionID' element.");
assertEquals(finalResponse.getFrom(), getPillarID(),
"Received unexpected 'From' element.");
assertEquals(finalResponse.getTo(), putRequest.getFrom(),
"Received unexpected 'To' element.");
assertEquals(finalResponse.getDestination(), putRequest.getReplyTo(),
"Received unexpected 'Destination' element.");
assertNull(finalResponse.getChecksumDataForExistingFile(),
"Received unexpected 'ChecksumDataForExistingFile' element.");
assertNull(finalResponse.getChecksumDataForNewFile(),
"Received unexpected 'ChecksumDataForNewFile' element.");
assertEquals(finalResponse.getFileID(), putRequest.getFileID(),
"Received unexpected 'To' element.");
assertEquals(finalResponse.getFileAddress(), putRequest.getFileAddress(),
"Received unexpected 'FileAddress' element.");
assertEquals(finalResponse.getPillarID(), getPillarID(),
"Received unexpected 'PillarID' element.");
assertEquals(finalResponse.getResponseInfo().getResponseCode(), ResponseCode.OPERATION_COMPLETED,
"Received unexpected 'ResponseCode' element.");
}
@Test( groups = {PillarTestGroups.FULL_PILLAR_TEST})
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 elements containing the MD5 " +
"checksum for the supplied file.");
PutFileRequest putRequest = msgFactory.createPutFileRequest(
TestFileHelper.getDefaultFileChecksum(), null, DEFAULT_DOWNLOAD_FILE_ADDRESS, testSpecificFileID,
DEFAULT_FILE_SIZE);
putRequest.setChecksumRequestForNewFile(ChecksumUtils.getDefault(settingsForTestClient));
messageBus.sendMessage(putRequest);
PutFileFinalResponse finalResponse = clientReceiver.waitForMessage(PutFileFinalResponse.class);
assertEquals(TestFileHelper.getDefaultFileChecksum().getChecksumValue(),
finalResponse.getChecksumDataForNewFile().getChecksumValue(),
"Return MD5 checksum was not equals to checksum for default file.");
}
@Test( groups = {PillarTestGroups.FULL_PILLAR_TEST, PillarTestGroups.CHECKSUM_PILLAR_TEST,
PillarTestGroups.OPERATION_ACCEPTED_PROGRESS})
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>" +
"<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>" +
"<li>'To' element should be set to the value of the 'From' elements in the request</li>" +
"<li>'Destination' element should be set to the value of 'ReplyTo' from the request</li>" +
"<li>'PillarID' element corresponding to the pillars component ID</li>" +
"<li>'FileID' element corresponding to the supplied fileID</li>" +
"<li>'FileAddress' element corresponding to the supplied FileAddress</li>" +
"<li>'ResponseInfo.ResponseCode' element should be OPERATION_ACCEPTED_PROGRESS</li>" +
"</ol>");
PutFileRequest putRequest = (PutFileRequest)createRequest();
messageBus.sendMessage(putRequest);
PutFileProgressResponse progressResponse = clientReceiver.waitForMessage(PutFileProgressResponse.class);
assertNotNull(progressResponse);
assertEquals(progressResponse.getCorrelationID(), putRequest.getCorrelationID(),
"Received unexpected 'CorrelationID' element.");
assertEquals(progressResponse.getCollectionID(), putRequest.getCollectionID(),
"Received unexpected 'CollectionID' element.");
assertEquals(progressResponse.getFrom(), getPillarID(),
"Received unexpected 'From' element.");
assertEquals(progressResponse.getTo(), putRequest.getFrom(),
"Received unexpected 'To' element.");
assertEquals(progressResponse.getDestination(), putRequest.getReplyTo(),
"Received unexpected 'Destination' element.");
assertEquals(progressResponse.getPillarID(), getPillarID(),
"Received unexpected 'PillarID' element.");
assertEquals(progressResponse.getFileID(), putRequest.getFileID(),
"Received unexpected 'FileID' element.");
assertEquals(progressResponse.getFileAddress(), putRequest.getFileAddress(),
"Received unexpected 'FileAddress' element.");
assertEquals(progressResponse.getResponseInfo().getResponseCode(),
ResponseCode.OPERATION_ACCEPTED_PROGRESS,
"Received unexpected 'ResponseCode' element.");
}
@Override
protected MessageRequest createRequest() {
return msgFactory.createPutFileRequest(TestFileHelper.getDefaultFileChecksum(), null,
DEFAULT_DOWNLOAD_FILE_ADDRESS, NON_DEFAULT_FILE_ID, DEFAULT_FILE_SIZE);
}
@Override
protected MessageResponse receiveResponse() {
return clientReceiver.waitForMessage(PutFileFinalResponse.class);
}
protected void assertNoResponseIsReceived() {
clientReceiver.checkNoMessageIsReceived(PutFileFinalResponse.class);
}
public String lookupPutFileDestination() {
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();
}
}