HadoopClusterEndpoints { @VisibleForTesting List<CachedFileItemStream> copyAndUnzip( FileItemStream fileItemStream, FileType fileType ) throws IOException { List<CachedFileItemStream> unzippedFileItemStreams = new ArrayList<>(); if ( fileItemStream.getFieldName().endsWith( ".zip" ) ) { try ( ZipInputStream zis = new ZipInputStream( fileItemStream.openStream() ) ) { for ( ZipEntry zipEntry = zis.getNextEntry(); zipEntry != null; zipEntry = zis.getNextEntry() ) { if ( !zipEntry.isDirectory() ) { String[] split = zipEntry.getName().split( "/" ); String unzippedFileName = split[ split.length - 1 ]; if ( isValidUpload( unzippedFileName, fileType ) ) { CachedFileItemStream unzippedFileItemStream = new CachedFileItemStream( zis, fileItemStream.getName(), unzippedFileName ); unzippedFileItemStreams.add( unzippedFileItemStream ); } } } } } else { if ( isValidUpload( fileItemStream.getFieldName(), fileType ) ) { unzippedFileItemStreams.add( new CachedFileItemStream( fileItemStream ) ); } } return unzippedFileItemStreams; } HadoopClusterEndpoints( MetastoreLocator metastoreLocator, NamedClusterService namedClusterService,
                                 RuntimeTester runtimeTester, String internalShim, boolean secureEnabled ); @POST @Consumes( { MediaType.MULTIPART_FORM_DATA } ) @Path( "/importNamedCluster" ) @Produces( { MediaType.APPLICATION_JSON } ) Response importNamedCluster( @Context HttpServletRequest request ); @POST @Path( "/createNamedCluster" ) @Consumes( { MediaType.MULTIPART_FORM_DATA } ) @Produces( { MediaType.APPLICATION_JSON } ) Response createNamedCluster( @Context HttpServletRequest request ); @POST @Path( "/editNamedCluster" ) @Consumes( { MediaType.MULTIPART_FORM_DATA } ) @Produces( { MediaType.APPLICATION_JSON } ) Response editNamedCluster( @Context HttpServletRequest request ); @POST @Path( "/duplicateNamedCluster" ) @Consumes( { MediaType.MULTIPART_FORM_DATA } ) @Produces( { MediaType.APPLICATION_JSON } ) Response duplicateNamedCluster( @Context HttpServletRequest request ); @GET @Path( "/getNamedCluster" ) @Produces( { MediaType.APPLICATION_JSON } ) Response getNamedCluster( @QueryParam( "namedCluster" ) String namedCluster ); @GET @Path( "/getShimIdentifiers" ) @Produces( { MediaType.APPLICATION_JSON } ) Response getShimIdentifiers(); @GET @Path( "/runTests" ) @Produces( { MediaType.APPLICATION_JSON } ) Response runTests( @QueryParam( "namedCluster" ) String namedCluster ); @POST @Path( "/installDriver" ) @Consumes( { MediaType.MULTIPART_FORM_DATA } ) @Produces( { MediaType.APPLICATION_JSON } ) Response installDriver( @Context HttpServletRequest request ); @GET @Path( "/getSecure" ) @Produces( { MediaType.APPLICATION_JSON } ) Response getSecure();  }
@Test public void testCopyAndUnzip() throws IOException { File zippedSiteFiles = new File( "src/test/resources/zippedSiteFiles/site.zip" ); InputStream zippedInputStream = new FileInputStream( zippedSiteFiles ); String name = zippedSiteFiles.getName(); when( fileItemStream.openStream() ).thenReturn( zippedInputStream ); when( fileItemStream.getName() ).thenReturn( name ); when( fileItemStream.getFieldName() ).thenReturn( name ); HadoopClusterEndpoints hce = new HadoopClusterEndpoints( metaStoreLocator, namedClusterService, runtimeTester, internalShim, secureEnabled ); List<CachedFileItemStream> cachedFileItemStreams = hce.copyAndUnzip( fileItemStream, HadoopClusterEndpoints.FileType.CONFIGURATION ); assertEquals( 6, cachedFileItemStreams.size() ); Map<String, Integer> zipFileSizeByName = new HashMap<>(); zipFileSizeByName.put( "core-site.xml", 3875 ); zipFileSizeByName.put( "hbase-site.xml", 3121 ); zipFileSizeByName.put( "hdfs-site.xml", 1778 ); zipFileSizeByName.put( "hive-site.xml", 5918 ); zipFileSizeByName.put( "mapred-site.xml", 5178 ); zipFileSizeByName.put( "yarn-site.xml", 3689 ); for ( CachedFileItemStream cachedFileItemStream : cachedFileItemStreams ) { int unzippedSize = zipFileSizeByName.get( cachedFileItemStream.getFieldName() ); assertEquals( unzippedSize, cachedFileItemStream.getCachedOutputStream().size() ); assertEquals( name, cachedFileItemStream.getName() ); } }