mladjan-gadzic commented on code in PR #4186:
URL: https://github.com/apache/ozone/pull/4186#discussion_r1097279126
##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectPut.java:
##########
@@ -288,4 +298,82 @@ public void testEmptyStorageType() throws IOException,
OS3Exception {
//default type is set
Assert.assertEquals(ReplicationType.RATIS, key.getReplicationType());
}
+
+ @Test
+ public void testDirectoryCreation() throws IOException,
+ OS3Exception {
+ // GIVEN
+ final String bucketname = "bucketName";
+ final String path = "dir";
+ final long length = 0L;
+ final int partNumber = 0;
+ final String uploadId = "";
+ final InputStream body = null;
+ final HttpHeaders headers = Mockito.mock(HttpHeaders.class);
+ final ObjectEndpoint objEndpoint = new ObjectEndpoint();
+ objEndpoint.setOzoneConfiguration(new OzoneConfiguration());
+ objEndpoint.setHeaders(headers);
+ final OzoneClient client = Mockito.mock(OzoneClient.class);
+ objEndpoint.setClient(client);
+ final ObjectStore objectStore = Mockito.mock(ObjectStore.class);
+ final OzoneVolume volume = Mockito.mock(OzoneVolume.class);
+ final OzoneBucket bucket = Mockito.mock(OzoneBucket.class);
+ final ClientProtocol protocol = Mockito.mock(ClientProtocol.class);
+
+ // WHEN
+ when(headers.getHeaderString(any())).thenReturn("");
+ when(client.getObjectStore()).thenReturn(objectStore);
+ when(client.getObjectStore().getS3Volume()).thenReturn(volume);
+ when(volume.getBucket(bucketname)).thenReturn(bucket);
+ when(bucket.getBucketLayout())
+ .thenReturn(BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ when(client.getProxy()).thenReturn(protocol);
+ final Response response = objEndpoint.put(bucketname, path, length,
+ partNumber, uploadId, body);
+
+ // THEN
+ Assertions.assertEquals(HttpStatus.SC_OK, response.getStatus());
+ Mockito.verify(protocol).createDirectory(any(), any(), any());
+ }
+
+ @Test
+ public void testDirectoryCreationOverFile() throws IOException {
+ // GIVEN
+ final String bucketname = "bucketName";
+ final String path = "key";
+ final long length = 0L;
+ final int partNumber = 0;
+ final String uploadId = "";
+ final ByteArrayInputStream body =
+ new ByteArrayInputStream("content".getBytes(UTF_8));
+ final HttpHeaders headers = Mockito.mock(HttpHeaders.class);
+ final ObjectEndpoint objEndpoint = new ObjectEndpoint();
+ objEndpoint.setOzoneConfiguration(new OzoneConfiguration());
+ objEndpoint.setHeaders(headers);
+ final OzoneClient client = Mockito.mock(OzoneClient.class);
+ objEndpoint.setClient(client);
+ final ObjectStore objectStore = Mockito.mock(ObjectStore.class);
+ final OzoneVolume volume = Mockito.mock(OzoneVolume.class);
+ final OzoneBucket bucket = Mockito.mock(OzoneBucket.class);
+ final ClientProtocol protocol = Mockito.mock(ClientProtocol.class);
+
+ // WHEN
+ when(client.getObjectStore()).thenReturn(objectStore);
+ when(client.getObjectStore().getS3Volume()).thenReturn(volume);
+ when(volume.getBucket(bucketname)).thenReturn(bucket);
+ when(bucket.getBucketLayout())
+ .thenReturn(BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ when(client.getProxy()).thenReturn(protocol);
+ doThrow(new OMException(OMException.ResultCodes.FILE_ALREADY_EXISTS))
+ .when(protocol)
+ .createDirectory(any(), any(), any());
+
+ // THEN
+ final OS3Exception exception = Assertions.assertThrows(OS3Exception.class,
+ () -> objEndpoint
+ .put(bucketname, path, length, partNumber, uploadId, body));
+ Assertions.assertEquals("Conflict", exception.getCode());
+ Assertions.assertEquals(409, exception.getHttpCode());
+ Mockito.verify(protocol, times(1)).createDirectory(any(), any(), any());
Review Comment:
I agree, that is doable, but then we would be testing multiple test cases in
a single test. I am of opinion that unit test needs to be self configured and
test only single use case for clarity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]