use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.
the class FileResourceTest method testSetFileAclsError.
@Test
public void testSetFileAclsError() throws Exception {
RepositoryFileAclDto mockRepositoryFileAclDto = mock(RepositoryFileAclDto.class);
Messages mockMessages = mock(Messages.class);
doReturn(mockMessages).when(fileResource).getMessagesInstance();
Response mockInternalServerErrorResponse = mock(Response.class);
doReturn(mockInternalServerErrorResponse).when(fileResource).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
Exception mockRuntimeException = mock(RuntimeException.class);
doThrow(mockRuntimeException).when(fileResource.fileService).setFileAcls(PATH_ID, mockRepositoryFileAclDto);
Response testResponse = fileResource.setFileAcls(PATH_ID, mockRepositoryFileAclDto);
assertEquals(mockInternalServerErrorResponse, testResponse);
verify(fileResource, times(1)).getMessagesInstance();
verify(fileResource, times(1)).buildStatusResponse(Response.Status.INTERNAL_SERVER_ERROR);
verify(fileResource.fileService, times(1)).setFileAcls(PATH_ID, mockRepositoryFileAclDto);
}
use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.
the class FileResourceTest method testDoIsParameterizableError.
@Test
public void testDoIsParameterizableError() 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);
Exception mockNoSuchBeanDefinitionException = mock(NoSuchBeanDefinitionException.class);
doThrow(mockNoSuchBeanDefinitionException).when(fileResource).hasParameterUi(mockRepositoryFile);
String exceptionMessage = "exceptionMessage";
doReturn(exceptionMessage).when(mockNoSuchBeanDefinitionException).getMessage();
Messages mockMessages = mock(Messages.class);
doReturn(mockMessages).when(fileResource).getMessagesInstance();
String message = "message";
String key = "FileResource.PARAM_FAILURE";
doReturn(message).when(mockMessages).getString(key, exceptionMessage);
// Test 1
String testResult = fileResource.doIsParameterizable(PATH_ID);
assertEquals(Boolean.FALSE.toString(), testResult);
// Test 2
doReturn(true).when(fileResource).hasParameterUi(mockRepositoryFile);
doThrow(mockNoSuchBeanDefinitionException).when(fileResource).getContentGenerator(mockRepositoryFile);
testResult = fileResource.doIsParameterizable(PATH_ID);
assertEquals(Boolean.FALSE.toString(), testResult);
verify(fileResource.fileService, times(2)).idToPath(PATH_ID);
verify(fileResource.repository, times(2)).getFile(path);
verify(fileResource, times(2)).hasParameterUi(mockRepositoryFile);
verify(mockNoSuchBeanDefinitionException, times(1)).getMessage();
verify(mockMessages, times(1)).getString(key, exceptionMessage);
}
use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.
the class FileResourceTest method testDoGetMetadataError.
@Test
public void testDoGetMetadataError() throws Exception {
Exception mockFileNotFoundException = mock(FileNotFoundException.class);
doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetMetadata(PATH_ID);
Messages mockMessages = mock(Messages.class);
doReturn(mockMessages).when(fileResource).getMessagesInstance();
List<StringKeyStringValueDto> testList = fileResource.doGetMetadata(PATH_ID);
assertNull(testList);
verify(fileResource.fileService, times(1)).doGetMetadata(PATH_ID);
verify(fileResource, times(1)).getMessagesInstance();
verify(mockMessages, times(1)).getErrorString("FileResource.FILE_UNKNOWN", PATH_ID);
}
use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.
the class FileResourceTest method testDoGetFileLocalesError.
@Test
public void testDoGetFileLocalesError() throws Exception {
Messages mockMessages = mock(Messages.class);
doReturn(mockMessages).when(fileResource).getMessagesInstance();
// Test 1
Exception mockFileNotFoundException = mock(FileNotFoundException.class);
doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetFileLocales(PATH_ID);
List<LocaleMapDto> testLocales = fileResource.doGetFileLocales(PATH_ID);
assertEquals(0, testLocales.size());
// Test 2
Throwable mockThrowable = mock(RuntimeException.class);
doThrow(mockThrowable).when(fileResource.fileService).doGetFileLocales(PATH_ID);
testLocales = fileResource.doGetFileLocales(PATH_ID);
assertEquals(0, testLocales.size());
verify(fileResource, times(2)).getMessagesInstance();
verify(mockMessages, times(1)).getErrorString("FileResource.FILE_NOT_FOUND", PATH_ID);
verify(mockMessages, times(1)).getString("SystemResource.GENERAL_ERROR");
}
use of org.pentaho.platform.web.http.messages.Messages in project pentaho-platform by pentaho.
the class FileResourceTest method testDoGetGeneratedContentError.
@Test
public void testDoGetGeneratedContentError() throws Exception {
Exception mockFileNotFoundException = mock(FileNotFoundException.class);
doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetGeneratedContent(PATH_ID);
Messages mockMessages = mock(Messages.class);
doReturn(mockMessages).when(fileResource).getMessagesInstance();
// Test 1
List<RepositoryFileDto> testList = fileResource.doGetGeneratedContent(PATH_ID);
assertEquals(0, testList.size());
// Test 2
Throwable mockThrowable = mock(RuntimeException.class);
doThrow(mockThrowable).when(fileResource.fileService).doGetGeneratedContent(PATH_ID);
testList = fileResource.doGetGeneratedContent(PATH_ID);
assertEquals(0, testList.size());
verify(fileResource.fileService, times(2)).doGetGeneratedContent(PATH_ID);
verify(fileResource, times(1)).getMessagesInstance();
verify(mockMessages, times(1)).getString("FileResource.GENERATED_CONTENT_FAILED", PATH_ID);
}
Aggregations