public void testConnectToRoot() throws Exception { // Set up blob names. final String blobPrefix = String.format("wasbtests-%s-%tQ-blob", System.getProperty("user.name"), new Date()); final String inblobName = blobPrefix + "_In" + ".txt"; final String outblobName = blobPrefix + "_Out" + ".txt"; // Create test account with default root access. testAccount = AzureBlobStorageTestAccount.createRoot(inblobName, FILE_SIZE); assumeNotNull(testAccount); // Read the file from the default container. assertEquals(FILE_SIZE, readInputStream(new Path(PATH_DELIMITER + inblobName))); try { // Capture file system. FileSystem fs = testAccount.getFileSystem(); // Create output path and open an output stream to the root folder. Path outputPath = new Path(PATH_DELIMITER + outblobName); OutputStream outputStream = fs.create(outputPath); fail("Expected an AzureException when writing to root folder."); outputStream.write(new byte[FILE_SIZE]); outputStream.close(); } catch (AzureException e) { assertTrue(true); } catch (Exception e) { String errMsg = String.format( "Expected AzureException but got %s instead.", e); assertTrue(errMsg, false); } }
public void testConnectToRoot() throws Exception { // Set up blob names. final String blobPrefix = String.format("wasbtests-%s-%tQ-blob", System.getProperty("user.name"), new Date()); final String inblobName = blobPrefix + "_In" + ".txt"; final String outblobName = blobPrefix + "_Out" + ".txt"; // Create test account with default root access. testAccount = AzureBlobStorageTestAccount.createRoot(inblobName, FILE_SIZE); assumeNotNull(testAccount); // Read the file from the default container. assertEquals(FILE_SIZE, readInputStream(new Path(PATH_DELIMITER + inblobName))); try { // Capture file system. FileSystem fs = testAccount.getFileSystem(); // Create output path and open an output stream to the root folder. Path outputPath = new Path(PATH_DELIMITER + outblobName); OutputStream outputStream = fs.create(outputPath); fail("Expected an AzureException when writing to root folder."); outputStream.write(new byte[FILE_SIZE]); outputStream.close(); } catch (AzureException e) { assertTrue(true); } catch (Exception e) { String errMsg = String.format( "Expected AzureException but got %s instead.", e); assertTrue(errMsg, false); } }