FileResource extends AbstractJaxRSResource { @GET @Path ( "{pathId : .+}/parameterizable" ) @Produces ( MediaType.TEXT_PLAIN ) @Facet ( name = "Unsupported" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully get the file or directory." ), @ResponseCode ( code = 404, condition = "Failed to find the file or resource." ) } ) public String doIsParameterizable( @PathParam ( "pathId" ) String pathId ) throws FileNotFoundException { boolean hasParameterUi = false; RepositoryFile repositoryFile = getRepository().getFile( fileService.idToPath( pathId ) ); if ( repositoryFile != null ) { try { hasParameterUi = hasParameterUi( repositoryFile ); } catch ( NoSuchBeanDefinitionException e ) { } } boolean hasParameters = false; if ( hasParameterUi ) { try { IContentGenerator parameterContentGenerator = getContentGenerator( repositoryFile ); if ( parameterContentGenerator != null ) { ByteArrayOutputStream outputStream = getByteArrayOutputStream(); parameterContentGenerator.setOutputHandler( new SimpleOutputHandler( outputStream, false ) ); parameterContentGenerator.setMessagesList( new ArrayList<String>() ); Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>(); SimpleParameterProvider parameterProvider = getSimpleParameterProvider(); parameterProvider.setParameter( "path", encode( repositoryFile.getPath() ) ); parameterProvider.setParameter( "renderMode", "PARAMETER" ); parameterProviders.put( IParameterProvider.SCOPE_REQUEST, parameterProvider ); parameterContentGenerator.setParameterProviders( parameterProviders ); parameterContentGenerator.setSession( getSession() ); parameterContentGenerator.createContent(); if ( outputStream.size() > 0 ) { Document document = parseText( outputStream.toString() ); @SuppressWarnings ( "rawtypes" ) List nodes = document.selectNodes( "parameters/parameter" ); for ( int i = 0; i < nodes.size() && !hasParameters; i++ ) { Element elem = (Element) nodes.get( i ); if ( elem.attributeValue( "name" ).equalsIgnoreCase( "output-target" ) && elem.attributeValue( "is-mandatory" ).equalsIgnoreCase( "true" ) ) { hasParameters = true; continue; } Element attrib = (Element) elem.selectSingleNode( "attribute[@namespace='http: + ".org/namespaces/engine/parameter-attributes/core' and @name='role']" ); if ( attrib == null || !"system".equals( attrib.attributeValue( "value" ) ) ) { hasParameters = true; } } } } } catch ( Exception e ) { logger.error( getMessagesInstance().getString( "FileResource.PARAM_FAILURE", e.getMessage() ), e ); } } return Boolean.toString( hasParameters ); } FileResource();  FileResource( HttpServletResponse httpServletResponse ); static String idToPath( String pathId ); @GET @Path( "/backup" ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully exported the existing Pentaho System" ), @ResponseCode( code = 403, condition = "User does not have administrative permissions" ), @ResponseCode( code = 500, condition = "Failure to complete the export." ) } ) Response systemBackup( @HeaderParam ( "user-agent" ) String userAgent ); @POST @Path( "/systemRestore" ) @Consumes( MediaType.MULTIPART_FORM_DATA ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully imported the Pentaho System" ), @ResponseCode( code = 403, condition = "User does not have administrative permissions" ), @ResponseCode( code = 500, condition = "Failure to complete the import." ) } ) Response systemRestore( @FormDataParam( "fileUpload" ) InputStream fileUpload, @FormDataParam ( "overwriteFile" ) String overwriteFile,
                                 @FormDataParam ( "applyAclSettings" ) String applyAclSettings, @FormDataParam ( "overwriteAclSettings" ) String overwriteAclSettings ); @PUT @Path( "/delete" ) @Consumes( { MediaType.WILDCARD } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully moved file to trash." ), @ResponseCode( code = 500, condition = "Failure move the file to the trash." ) } ) Response doDeleteFiles( String params ); @PUT @Path ( "/deletepermanent" ) @Consumes ( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully deleted the comma seperated list of fileIds from the system." ), @ResponseCode ( code = 403, condition = "Failure to delete the file due to path not found." ) } ) Response doDeleteFilesPermanent( String params ); @PUT @Path ( "{pathId : .+}/move" ) @Consumes ( { MediaType.WILDCARD } ) @Facet ( name = "Unsupported" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully moved the file." ), @ResponseCode ( code = 403, condition = "Failure to move the file due to path not found." ), @ResponseCode ( code = 500, condition = "Failure to move the file." ) } ) Response doMove( @PathParam ( "pathId" ) String destPathId, String params ); @PUT @Path( "/restore" ) @Consumes( { MediaType.WILDCARD } ) @Facet( name = "Unsupported" ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully restored the file." ), @ResponseCode( code = 307, condition = "Cannot restore in origin folder, can restore in home folder without " + "conflicts" ), @ResponseCode( code = 403, condition = "Failure to Restore the file." ), @ResponseCode( code = 409, condition = "Cannot restore in origin folder, cannot restore in home folder without " + "conflicts" ), } ) Response doRestore( String params,
                             @QueryParam( value = "overwriteMode" ) Integer mode ); @PUT @Path ( "{pathId : .+}" ) @Consumes ( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully created the file." ), @ResponseCode ( code = 403, condition = "Failure to create the file due to permissions, file already exists, or invalid path id." ) } ) Response createFile( @PathParam ( "pathId" ) String pathId, InputStream fileContents ); @PUT @Path ( "{pathId : .+}/children" ) @Consumes ( { MediaType.TEXT_PLAIN } ) @Facet ( name = "Unsupported" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully copied the file." ), @ResponseCode ( code = 500, condition = "Failure to Copy file due to exception while getting file with id fileid..." ), } ) Response doCopyFiles( @PathParam ( "pathId" ) String pathId, @QueryParam ( "mode" ) Integer mode,
                               String params ); @GET @Path ( "{pathId : .+}" ) @Produces ( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully get the file or directory." ), @ResponseCode ( code = 404, condition = "Failed to find the file or resource." ), @ResponseCode ( code = 500, condition = "Failed to open content." ) } ) Response doGetFileOrDir( @PathParam ( "pathId" ) String pathId ); Response doGetDirAsZip( @PathParam ( "pathId" ) String pathId ); Response doGetDirAsZip( RepositoryFile repositoryFile ); @GET @Path ( "{pathId : .+}/parameterizable" ) @Produces ( MediaType.TEXT_PLAIN ) @Facet ( name = "Unsupported" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully get the file or directory." ), @ResponseCode ( code = 404, condition = "Failed to find the file or resource." ) } ) // have to accept anything for browsers to work String doIsParameterizable( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/download" ) @Produces ( MediaType.WILDCARD ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successful download." ), @ResponseCode ( code = 400, condition = "Usually a bad pathId." ), @ResponseCode ( code = 403, condition = "pathId points at a file the user doesn't have access to." ), @ResponseCode ( code = 404, condition = "File not found." ), @ResponseCode ( code = 500, condition = "Failed to download file for another reason." ) } ) // have to accept anything for browsers to work Response doGetFileOrDirAsDownload( @HeaderParam ( "user-agent" ) String userAgent,
                                            @PathParam ( "pathId" ) String pathId, @QueryParam ( "withManifest" ) String strWithManifest ); @GET @Path ( "{pathId : .+}/inline" ) @Produces ( MediaType.WILDCARD ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved file." ), @ResponseCode ( code = 403, condition = "Failed to retrieve file due to permission problem." ), @ResponseCode ( code = 404, condition = "Failed to retrieve file due because file was not found." ), @ResponseCode ( code = 500, condition = "Failed to download file because of some other error." ) } ) Response doGetFileAsInline( @PathParam ( "pathId" ) String pathId ); @PUT @Path ( "{pathId : .+}/acl" ) @Consumes ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully saved file." ), @ResponseCode ( code = 403, condition = "Failed to save acls due to missing or incorrect properties." ), @ResponseCode ( code = 400, condition = "Failed to save acls due to malformed xml." ), @ResponseCode ( code = 500, condition = "Failed to save acls due to another error." ) } ) Response setFileAcls( @PathParam ( "pathId" ) String pathId, RepositoryFileAclDto acl ); @PUT @Path ( "{pathId : .+}/creator" ) @Consumes ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved file." ), @ResponseCode ( code = 500, condition = "Failed to download file because of some other error." ) } ) @Facet ( name = "Unsupported" ) Response doSetContentCreator( @PathParam ( "pathId" ) String pathId, RepositoryFileDto contentCreator ); @GET @Path ( "{pathId : .+}/locales" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved locale information." ), @ResponseCode ( code = 404, condition = "Failed to retrieve locales because the file was not found." ), @ResponseCode ( code = 500, condition = "Unable to retrieve locales due to some other error." ) } ) List<LocaleMapDto> doGetFileLocales( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/localeProperties" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved locale properties." ), @ResponseCode ( code = 500, condition = "Unable to retrieve locale properties due to some other error." ) } ) List<StringKeyStringValueDto> doGetLocaleProperties( @PathParam ( "pathId" ) String pathId,
                                                              @QueryParam ( "locale" ) String locale ); @PUT @Path ( "{pathId : .+}/localeProperties" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully updated locale properties." ), @ResponseCode ( code = 500, condition = "Unable to update locale properties due to some other error." ) } ) Response doSetLocaleProperties( @PathParam ( "pathId" ) String pathId, @QueryParam ( "locale" ) String locale,
                                         List<StringKeyStringValueDto> properties ); @PUT @Path ( "{pathId : .+}/deleteLocale" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully deleted the locale." ), @ResponseCode ( code = 500, condition = "Unable to delete the locale properties due to some other error." ) } ) Response doDeleteLocale( @PathParam ( "pathId" ) String pathId, @QueryParam ( "locale" ) String locale ); @GET @Path ( "/properties" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the properties of the root directory." ), @ResponseCode ( code = 404, condition = "Unable to retrieve the properties of the root directory due to file not found error." ), @ResponseCode ( code = 500, condition = "Unable to retrieve the properties of the root directory due to some other error." ) } ) RepositoryFileDto doGetRootProperties(); @GET @Path ( "{pathId : .+}/canAccessMap" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the permissions of the file." ), @ResponseCode ( code = 500, condition = "Unable to retrieve the permissions of the file due to some other error." ) } ) List<Setting> doGetCanAccessList( @PathParam ( "pathId" ) String pathId,
                                           @QueryParam ( "permissions" ) String permissions ); @POST @Path ( "/pathsAccessList" ) @Consumes ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the permissions of the given paths." ), @ResponseCode ( code = 500, condition = "Unable to retrieve the permissions of the given paths due to some other error." ) } ) List<Setting> doGetPathsAccessList( StringListWrapper pathsWrapper ); @GET @Path ( "{pathId : .+}/canAccess" ) @Produces ( MediaType.TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the permissions of the given paths." ), @ResponseCode ( code = 500, condition = "Unable to retrieve the permissions of the given paths due to some other error." ) } ) String doGetCanAccess( @PathParam ( "pathId" ) String pathId,
                                @QueryParam ( "permissions" ) String permissions ); @GET @Path ( "/canAdminister" ) @Produces ( MediaType.TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully returns a boolean value, either true or false" ) } ) String doGetCanAdminister(); @GET @Path ( "/reservedCharacters" ) @Produces ( { MediaType.TEXT_PLAIN } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully returns a list of repositroy reserved characters" ) } ) Response doGetReservedChars(); @GET @Path ( "/reservedCharactersDisplay" ) @Produces ( { MediaType.TEXT_PLAIN } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully returns a list of repositroy reserved characters" ) } ) Response doGetReservedCharactersDisplay(); @GET @Path ( "/canCreate" ) @Produces ( MediaType.TEXT_PLAIN ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully returns true or false depending on the users permissions" ) } ) String doGetCanCreate(); @GET @Path ( "{pathId : .+}/acl" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Returns the requested file permissions in xml or json format" ), @ResponseCode ( code = 500, condition = "File failed to be retrieved. This could be caused by an invalid path, or the file does not exist." ) } ) RepositoryFileAclDto doGetFileAcl( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/properties" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the properties for a file." ), @ResponseCode ( code = 204, condition = "Invalid file path." ) } ) RepositoryFileDto doGetProperties( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/creator" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @Facet ( name = "Unsupported" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the content creator for a file." ), @ResponseCode ( code = 403, condition = "Failure to move the file due to path not found." ) } ) RepositoryFileDto doGetContentCreator( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/generatedContent" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of RepositoryFileDto objects." ), @ResponseCode ( code = 200, condition = "Empty list of RepositoryFileDto objects." ) } ) List<RepositoryFileDto> doGetGeneratedContent( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/generatedContentForUser" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of RepositoryFileDto objects." ), @ResponseCode ( code = 200, condition = "Empty list of RepositoryFileDto objects." ), @ResponseCode ( code = 500, condition = "Server Error." ) } ) List<RepositoryFileDto> doGetGeneratedContentForUser( @PathParam ( "pathId" ) String pathId,
                                                               @QueryParam ( "user" ) String user ); @GET @Path ( "/tree" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of files from root of the repository." ), @ResponseCode ( code = 404, condition = "Invalid parameters." ), @ResponseCode ( code = 500, condition = "Server Error." ) } ) RepositoryFileTreeDto doGetRootTree( @QueryParam ( "depth" ) Integer depth,
                                              @QueryParam ( "filter" ) String filter, @QueryParam ( "showHidden" ) Boolean showHidden,
                                              @DefaultValue ( "false" ) @QueryParam ( "includeAcls" ) Boolean includeAcls ); @GET @Path ( "/children" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of child files from root of the repository." ), @ResponseCode ( code = 500, condition = "Server Error." ) } ) List<RepositoryFileDto> doGetRootChildren( @QueryParam ( "filter" ) String filter,
                                                    @QueryParam ( "showHidden" ) Boolean showHidden,
                                                    @DefaultValue ( "false" ) @QueryParam ( "includeAcls" ) Boolean includeAcls ); @GET @Path ( "{pathId : .+}/tree" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of files from root of the repository." ), @ResponseCode ( code = 404, condition = "Invalid parameters." ), @ResponseCode ( code = 500, condition = "Server Error." ) } ) RepositoryFileTreeDto doGetTree( @PathParam ( "pathId" ) String pathId, @QueryParam ( "depth" ) Integer depth,
                                          @QueryParam ( "filter" ) String filter, @QueryParam ( "showHidden" ) Boolean showHidden,
                                          @DefaultValue ( "false" ) @QueryParam ( "includeAcls" ) Boolean includeAcls,
                                          @DefaultValue ( "false" ) @QueryParam ( "includeSysDirs" ) Boolean includeSystemFolders ); @GET @Path ( "{pathId : .+}/children" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode( code = 200, condition = "Successfully retrieved the list of child files from selected repository path of the repository." ), @ResponseCode( code = 500, condition = "Server Error." ) } ) List<RepositoryFileDto> doGetChildren( @PathParam ( "pathId" ) String pathId,
                                                @QueryParam ( "filter" ) String filter, @QueryParam ( "showHidden" ) Boolean showHidden,
                                                @DefaultValue ( "false" ) @QueryParam ( "includeAcls" ) Boolean includeAcls ); @GET @Path ( "/deleted" ) @Produces ( {MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of files from trash folder of the repository." ), @ResponseCode ( code = 500, condition = "Server Error." ) } ) List<RepositoryFileDto> doGetDeletedFiles(); @GET @Path ( "{pathId : .+}/metadata" ) @Produces ( { MediaType.APPLICATION_JSON } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully retrieved metadata." ), @ResponseCode( code = 403, condition = "Invalid path." ), @ResponseCode( code = 500, condition = "Server Error." ) } ) List<StringKeyStringValueDto> doGetMetadata( @PathParam ( "pathId" ) String pathId ); @PUT @Path ( "{pathId : .+}/rename" ) @Consumes ( { MediaType.WILDCARD } ) @Produces ( { MediaType.WILDCARD } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully renamed file." ), @ResponseCode( code = 403, condition = "Forbidden." ), @ResponseCode( code = 404, condition = "File not found." ) } ) Response doRename( @PathParam( "pathId" ) String pathId, @QueryParam( "newName" ) String newName ); @PUT @Path ( "{pathId : .+}/metadata" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved metadata." ), @ResponseCode ( code = 403, condition = "Invalid path." ), @ResponseCode ( code = 400, condition = "Invalid payload." ), @ResponseCode ( code = 500, condition = "Server Error." ) } ) Response doSetMetadata( @PathParam ( "pathId" ) String pathId, List<StringKeyStringValueDto> metadata ); @PUT @Path ( "{pathId : .+}/createDir" ) @Consumes ( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully created folder." ), @ResponseCode ( code = 403, condition = "Forbidden." ), @ResponseCode ( code = 409, condition = "Path already exists." ), @ResponseCode ( code = 500, condition = "Server Error." ) } ) Response doCreateDirs( @PathParam ( "pathId" ) String pathId ); @GET @Path ( "{pathId : .+}/versioningConfiguration" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode( code = 200, condition = "Successfully returns the versioning configuration" ) } ) FileVersioningConfiguration doVersioningConfiguration( @PathParam( "pathId" ) String pathId ); @GET @Path ( "/canDownload" ) @Produces ( { MediaType.TEXT_PLAIN } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Returns a boolean response." ) } ) Response canDownload( @QueryParam ( "dirPath" ) @DefaultValue( "" ) String dirPath ); @GET @Path ( "/canUpload" ) @Produces ( { MediaType.TEXT_PLAIN } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Returns a boolean response." ) } ) Response canUpload( @QueryParam ( "dirPath" ) @DefaultValue( "" ) String dirPath ); RepositoryDownloadWhitelist getWhitelist(); void setWhitelist( RepositoryDownloadWhitelist whitelist ); static IAuthorizationPolicy getPolicy(); static IUnifiedRepository getRepository(); static DefaultUnifiedRepositoryWebService getRepoWs(); void setConverterHandler( IRepositoryContentConverterHandler converterHandler ); void setMimeResolver( IPlatformMimeResolver mimeResolver ); static final String APPLICATION_ZIP; static final String REPOSITORY_ADMIN_USERNAME; }
@Test public void testDoIsParameterizable() throws Exception { String path = "path"; doReturn( path ).when( fileResource.fileService ).idToPath( PATH_ID ); RepositoryFile mockRepositoryFile = mock( RepositoryFile.class ); doReturn( mockRepositoryFile ).when( fileResource.repository ).getFile( path ); doReturn( true ).when( fileResource ).hasParameterUi( mockRepositoryFile ); IContentGenerator mockContentGenerator = mock( IContentGenerator.class ); doReturn( mockContentGenerator ).when( fileResource ).getContentGenerator( mockRepositoryFile ); SimpleParameterProvider mockSimpleParameterProvider = mock( SimpleParameterProvider.class ); doReturn( mockSimpleParameterProvider ).when( fileResource ).getSimpleParameterProvider(); String repositoryPath = "repositoryPath"; doReturn( repositoryPath ).when( mockRepositoryFile ).getPath(); String encodedPath = "encodedPath"; doReturn( encodedPath ).when( fileResource ).encode( repositoryPath ); IPentahoSession mockPentahoSession = mock( IPentahoSession.class ); doReturn( mockPentahoSession ).when( fileResource ).getSession(); ByteArrayOutputStream mockByteArrayOutputStream = mock( ByteArrayOutputStream.class ); doReturn( mockByteArrayOutputStream ).when( fileResource ).getByteArrayOutputStream(); doReturn( 1 ).when( mockByteArrayOutputStream ).size(); String outputStreamToString = "outputStreamToString"; doReturn( outputStreamToString ).when( mockByteArrayOutputStream ).toString(); Document mockDocument = mock( Document.class ); doReturn( mockDocument ).when( fileResource ).parseText( outputStreamToString ); String selectNodesParam = "parameters/parameter"; List<Element> elements = new ArrayList<Element>(); doReturn( elements ).when( mockDocument ).selectNodes( selectNodesParam ); Element mockElement = mock( Element.class ); doReturn( "output-target" ).when( mockElement ).attributeValue( "name" ); doReturn( "true" ).when( mockElement ).attributeValue( "is-mandatory" ); String testString = fileResource.doIsParameterizable( PATH_ID ); assertEquals( Boolean.FALSE.toString(), testString ); elements.add( mockElement ); testString = fileResource.doIsParameterizable( PATH_ID ); assertEquals( Boolean.TRUE.toString(), testString ); doReturn( "false" ).when( mockElement ).attributeValue( "is-mandatory" ); testString = fileResource.doIsParameterizable( PATH_ID ); assertEquals( Boolean.TRUE.toString(), testString ); Element mockAttribElement = mock( Element.class ); doReturn( mockAttribElement ).when( mockElement ).selectSingleNode( "attribute[@namespace='http: + ".org/namespaces/engine/parameter-attributes/core' and @name='role']" ); testString = fileResource.doIsParameterizable( PATH_ID ); assertEquals( Boolean.TRUE.toString(), testString ); verify( fileResource.fileService, times( 4 ) ).idToPath( PATH_ID ); verify( fileResource.repository, times( 4 ) ).getFile( path ); verify( fileResource, times( 4 ) ).hasParameterUi( mockRepositoryFile ); verify( fileResource, times( 4 ) ).getContentGenerator( mockRepositoryFile ); verify( mockContentGenerator, times( 4 ) ).setOutputHandler( any( SimpleOutputHandler.class ) ); verify( mockContentGenerator, times( 4 ) ).setMessagesList( anyList() ); verify( fileResource, times( 4 ) ).getSimpleParameterProvider(); verify( mockRepositoryFile, times( 4 ) ).getPath(); verify( fileResource, times( 4 ) ).encode( repositoryPath ); verify( mockSimpleParameterProvider, times( 4 ) ).setParameter( "path", encodedPath ); verify( mockSimpleParameterProvider, times( 4 ) ).setParameter( "renderMode", "PARAMETER" ); verify( mockContentGenerator, times( 4 ) ).setParameterProviders( anyMap() ); verify( fileResource, times( 4 ) ).getSession(); verify( mockContentGenerator, times( 4 ) ).setSession( mockPentahoSession ); verify( mockContentGenerator, times( 4 ) ).createContent(); verify( fileResource, times( 4 ) ).getByteArrayOutputStream(); verify( mockDocument, times( 4 ) ).selectNodes( selectNodesParam ); verify( mockElement, times( 3 ) ).attributeValue( "name" ); verify( mockElement, times( 3 ) ).attributeValue( "is-mandatory" ); verify( mockAttribElement, times( 1 ) ).attributeValue( "value" ); }