use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class MetadataResourceTest method testDoRemoveMetadataError.
@Test
public void testDoRemoveMetadataError() throws Exception {
Response mockResponse = mock(Response.class);
PentahoAccessControlException mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
doThrow(mockPentahoAccessControlException).when(metadataResource.service).removeMetadata("metadataId");
doReturn(mockResponse).when(metadataResource).buildUnauthorizedResponse();
try {
Response response = metadataResource.deleteMetadata("metadataId");
fail("Should have had a WebApplicationException");
} catch (WebApplicationException e) {
// Good
assertEquals(401, e.getResponse().getStatus());
}
verify(metadataResource, times(1)).deleteMetadata("metadataId");
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class MetadataResourceTest method doGetMetadataAcl.
@Test
public void doGetMetadataAcl() throws Exception {
String domainId = "domainId";
doReturn(new HashMap<String, InputStream>() {
{
put("test", null);
}
}).when(metadataResource).getDomainFilesData(domainId);
doReturn(new RepositoryFileAclDto()).when(metadataResource.service).getMetadataAcl(domainId);
// no exception thrown
metadataResource.doGetMetadataAcl(domainId);
//
doThrow(new PentahoAccessControlException()).when(metadataResource.service).getMetadataAcl(domainId);
try {
metadataResource.doGetMetadataAcl(domainId);
fail();
} catch (WebApplicationException e) {
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), e.getResponse().getStatus());
}
//
doThrow(new FileNotFoundException()).when(metadataResource.service).getMetadataAcl(domainId);
try {
metadataResource.doGetMetadataAcl(domainId);
fail();
} catch (WebApplicationException e) {
assertEquals(Response.Status.CONFLICT.getStatusCode(), e.getResponse().getStatus());
}
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardServiceTest method testPublishDswError.
@Test
public void testPublishDswError() throws Exception {
String domainId = "domainId";
InputStream metadataFile = mock(InputStream.class);
boolean overwrite = true;
boolean checkConnection = false;
XmiParser mockXmiParser = mock(XmiParser.class);
Domain mockDomain = mock(Domain.class);
InputStream mockInputStream = mock(InputStream.class);
IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
String mockObject = "not null";
String dswId = "dswId";
// Test 1
doReturn(false).when(dataSourceWizardService).hasManageAccessCheck();
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
fail();
} catch (PentahoAccessControlException e) {
// expected
}
// Test 2
doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
doReturn(false).when(dataSourceWizardService).endsWith(anyString(), anyString());
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
fail();
} catch (IllegalArgumentException e) {
// expected
}
// Test 3
doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
try {
dataSourceWizardService.publishDsw(domainId, null, overwrite, checkConnection, null);
fail();
} catch (IllegalArgumentException e) {
// expected
}
// Test 4
List<String> mockList = new ArrayList<String>();
mockList.add("string1");
doReturn(mockList).when(dataSourceWizardService).getOverwrittenDomains(domainId);
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, false, checkConnection, null);
fail();
} catch (Exception e) {
// expected
}
// Test 5
doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
RuntimeException mockException = mock(RuntimeException.class);
doThrow(mockException).when(mockXmiParser).parseXmi(metadataFile);
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
fail();
} catch (Exception e) {
// expected
}
// Test 6
doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
doReturn(null).when(dataSourceWizardService).getMondrianDatasourceWrapper(mockDomain);
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, true, null);
fail();
} catch (Exception e) {
// expected
}
verify(dataSourceWizardService, times(3)).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, null, overwrite, checkConnection, null);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, false, checkConnection, null);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, true, null);
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class MetadataServiceTest method testImportMetadataDatasourceNoPublishPermission.
@Test
public void testImportMetadataDatasourceNoPublishPermission() throws Exception {
String domainId = DOMAIN_ID;
InputStream metadataFile = mock(InputStream.class);
FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
doThrow(new PentahoAccessControlException()).when(metadataService).accessValidation();
try {
metadataService.importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, Collections.emptyList(), Collections.emptyList(), null);
fail();
} catch (PentahoAccessControlException e) {
// expected
}
verify(metadataService, never()).getImporter();
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class MetadataServiceTest method testRemoveMetadataError.
@Test
public void testRemoveMetadataError() throws Exception {
ConnectionServiceException cse = new ConnectionServiceException();
doThrow(cse).when(metadataService).ensureDataAccessPermissionCheck();
try {
metadataService.removeMetadata("metadataId");
fail();
} catch (PentahoAccessControlException e) {
// expected
}
verify(metadataService, times(1)).removeMetadata("metadataId");
}
Aggregations