Windows Azure SDK for Java - Lab 1 Windows Azure Storage using Blob Service を試し中。 - お だ のスペース の続きです。
testContainer_wMetadata というテストメソッドが失敗する原因が判りました、単純なミスの様です。
BlobStorageJUnit.java Line 213 - 244
NameValueCollection objMetadataContainerPost = new NameValueCollection(); assertTrue(objMetadataContainerPost.isEmpty()); BlobContainer objBlobContainerPost = BlobSample.getBlobContainer_wMetadata( m_objBlobStorage, strContainerName, objMetadataContainerPost ); assertNotNull(objBlobContainerPost); assertTrue(objBlobContainerPost.doesContainerExist()); assertNotNull(objMetadataContainerPost); assertFalse(objMetadataContainerPost.isEmpty()); int countMetadata = objMetadataContainerPost.size(); assertEquals(1, countMetadata); for ( Iterator iter = objMetadataContainerPost.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = (Map.Entry)iter.next(); String strKey = (String) entry.getKey(); Collection<Object> vals = (Collection) entry.getValue(); for (Iterator<Object> valIter = vals.iterator(); valIter.hasNext(); ) { String strValue = (String) valIter.next(); System.out.printf( "key '%s'\tvalue '%s'\n", strKey, strValue ); } } String strCreatedBy = (String) objMetadataContainerPost.get(METADATA_CREATED_BY_KEY);
最後の行で objMetadataContainerPost から取り出したものを String にキャストしていますが、ここで ClassCastException が発生していました。
この直前の二重の for 文を見てみると objMetadataContainerPost ってのは、Map で Key は String で値は、Collection
// String strCreatedBy = (String) objMetadataContainerPost.get(METADATA_CREATED_BY_KEY); String strCreatedBy = (String) ((Collection<Object>)objMetadataContainerPost.get(METADATA_CREATED_BY_KEY)).toArray()[0];