RepositoryService service = (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
String dsName = helper.createDatasource();
RepositoryEntry repoEntry = helper.createRepositoryEntry(false, null, dsName);
service.createRepository(repoEntry);
ManageableRepository repository = service.getRepository(repoEntry.getName());
WorkspaceEntry wsEntry = helper.createWorkspaceEntry(false, dsName);
helper.addWorkspace(repository, wsEntry);
service.getConfig().retain();
addConent(repository, repository.getConfiguration().getSystemWorkspaceName());
// backup
File backDir = new File("target/backup/" + IdGenerator.generate());
backDir.mkdirs();
RepositoryBackupConfig config = new RepositoryBackupConfig();
config.setRepository(repository.getConfiguration().getName());
config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
config.setBackupDir(backDir);
RepositoryBackupChain bch = backup.startBackup(config);
waitEndOfBackup(bch);
backup.stopBackup(bch);
File backLog = new File(bch.getLogFilePath());
assertTrue(backLog.exists());
// copy repository entry and set new ata source
RepositoryEntry newRepoEntry = helper.copyRepositoryEntry(repoEntry);
String newDSName = helper.createDatasource();
for (WorkspaceEntry ws : newRepoEntry.getWorkspaceEntries())
{
for (int i = 0; i < ws.getContainer().getParameters().size(); i++)
{
SimpleParameterEntry spe = ws.getContainer().getParameters().get(i);
if (spe.getName().equals("source-name"))
{
ws.getContainer().getParameters().set(i, new SimpleParameterEntry(spe.getName(), newDSName));
break;
}
}
}
// create repository entry with name of data source name is wrong in system workspace
RepositoryEntry wrongRepoEntry = helper.copyRepositoryEntry(repoEntry);
for (WorkspaceEntry ws : wrongRepoEntry.getWorkspaceEntries())
{
if (repository.getConfiguration().getSystemWorkspaceName().equals(ws.getName()))
{
for (int i = 0; i < ws.getContainer().getParameters().size(); i++)
{
SimpleParameterEntry spe = ws.getContainer().getParameters().get(i);
if (spe.getName().equals("source-name"))
{
ws.getContainer().getParameters().set(i,
new SimpleParameterEntry(spe.getName(), spe.getValue() + "_wrong"));
break;
}
}
break;
}
}
// remove existed repository
removeRepositoryFully(repository.getConfiguration().getName());
// wrong restore
try
{
backup.restore(new RepositoryBackupChainLog(backLog), wrongRepoEntry, false);