use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testUpdateDatasourceWithName.
@Test
public void testUpdateDatasourceWithName() throws Exception {
final String fileId = "456";
final String databasesFolderPath = "/etc/pdi/databases";
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to update
RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
// stub out update file which requires a file to be returned
doReturn(f).when(repo).updateFile(any(RepositoryFile.class), any(NodeRepositoryFileData.class), anyString());
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
IDatabaseConnection databaseConnection = createDatabaseConnection(EXP_DBMETA_NAME);
updateDatabaseConnection(databaseConnection);
datasourceMgmtService.updateDatasourceByName(EXP_DBMETA_NAME, databaseConnection);
verify(repo).updateFile(argThat(isLikeFile(new RepositoryFile.Builder(EXP_DBMETA_NAME + ".kdb").build())), argThat(hasData(pathPropertyPair("/databaseMeta/HOST_NAME", EXP_UPDATED_DBMETA_HOSTNAME))), anyString());
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testDatasourceNotFound.
@Test
public void testDatasourceNotFound() throws Exception {
final String datasourceName = "not_here";
final String dotKdb = ".kdb";
final String fileName = datasourceName + dotKdb;
final String databasesFolderPath = "/etc/pdi/databases";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file not found
doReturn(null).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + fileName);
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
Assert.assertNull(datasourceMgmtService.getDatasourceByName(datasourceName));
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class DatasourceMgmtToWebServiceAdapterTest method setUp.
@Override
protected void setUp() throws Exception {
IUnifiedRepository repository = new MockUnifiedRepository(new MockUnifiedRepository.SpringSecurityCurrentUserProvider());
datasourceMgmtService = new JcrBackedDatasourceMgmtService(repository, new DatabaseDialectService());
datasourceMgmtWS = new DefaultDatasourceMgmtWebService(datasourceMgmtService);
adapter = new DatasourceMgmtToWebServiceAdapter(datasourceMgmtWS);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(MockUnifiedRepository.root().getName(), null, new ArrayList<GrantedAuthority>()));
repository.createFolder(repository.getFile("/etc").getId(), new RepositoryFile.Builder(FOLDER_PDI).folder(true).build(), new RepositoryFileAcl.Builder(MockUnifiedRepository.root()).ace(MockUnifiedRepository.everyone(), READ, WRITE).build(), null);
repository.createFolder(repository.getFile("/etc/pdi").getId(), new RepositoryFile.Builder(FOLDER_DATABASES).folder(true).build(), null);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(EXP_LOGIN, null, new ArrayList<GrantedAuthority>()));
KettleClientEnvironment.init();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class UnifiedRepositoryTestUtils method stubGetFile.
/**
* Stubs a {@code getFile} call.
*/
private static void stubGetFile(final IUnifiedRepository repo, final String path, final boolean folder) {
final String fileName = StringUtils.substringAfterLast(path, RepositoryFile.SEPARATOR);
RepositoryFile file = new RepositoryFile.Builder(makeIdObject(path), fileName).path(path).folder(folder).build();
doReturn(file).when(repo).getFile(path);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class UnifiedRepositoryTestUtils method stubGetData.
/**
* Stubs a {@code getDataForRead} call. The pairs specified will be used to construct a
* {@code NodeRepositoryFileData} .
*/
public static void stubGetData(final IUnifiedRepository repo, final String path, final String rootNodeName, final PathPropertyPair... pairs) {
final String prefix = RepositoryFile.SEPARATOR + rootNodeName;
DataNode rootNode = new DataNode(rootNodeName);
for (PathPropertyPair pair : pairs) {
if (!pair.getPath().startsWith(prefix)) {
throw new IllegalArgumentException("all paths must have a common prefix");
}
String[] pathSegments = pair.getPath().substring(prefix.length() + 1).split("/");
addChild(rootNode, pair.getProperty(), pathSegments, 0);
}
doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(makeIdObject(path), NodeRepositoryFileData.class);
}
Aggregations