package tool.repository;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.wizard.IWizardContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import tool.ToolPlugin;
import tool.ToolProjectSupport;
public class ImportWexTest {
protected static ImportWex importWex;
protected static CreateRepository createRepos;
protected static File forteRoot;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
importWex = new ImportWex(new File("TestWEX/DSBook.wex"), new File("localReposTest/DSBook"), "DSBook");
createRepos = new CreateRepository("localReposTest/DSBook");
forteRoot = new File("Forte");
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
//@Test
public void listWorkspaces() throws IOException, InterruptedException, ToolSystemException, InvalidToolRepositoryException{
//create and write the commands
String reposString = "bt:c:\\workspace\\Tool\\localReposTest\\DSBook";
FScript repos = new FScript(forteRoot.getAbsolutePath(),
reposString,
"", "", ToolProjectSupport.DEFAULT_LOG_FLAGS, true);
String commands = repos.createCommand("FscriptUtils.stg", "listWorkspaces",
new TemplateAttribute("repos", reposString));
String result = repos.executeCMD(commands);
}
//@Test
public void listPublicPlans() throws IOException, InterruptedException, ToolSystemException, InvalidToolRepositoryException{
//create and write the commands
String reposString = "bt:c:\\workspace\\Tool\\localReposTest\\DSBook";
FScript repos = new FScript(forteRoot.getAbsolutePath(),
reposString,
"", "", ToolProjectSupport.DEFAULT_LOG_FLAGS, true);
String commands = repos.createCommand("FscriptUtils.stg", "listPublicPlans",
new TemplateAttribute("repos", reposString),
new TemplateAttribute("workspace", "DSBook"));
String result = repos.executeCMD(commands);
System.out.println(result);
}
//@Test
public void createAnImportReposRaw() throws IOException, InterruptedException, ToolSystemException, InvalidToolRepositoryException{
OutputContainer container = new OutputContainer();
createRepos.rpcreate(forteRoot, new File("localReposTest/DSBook"), container).waitFor();
importWex.consumeWex().waitFor();
}
@Test
public void createAnImportRepos() throws IOException, InterruptedException, ToolSystemException, InvalidToolRepositoryException{
performFinish();
}
//@Test
public void createRepos() throws IOException, InterruptedException{
OutputContainer container = new OutputContainer();
createRepos.rpcreate(forteRoot, new File("localReposTest/DSBook"), container);
}
public void performFinish() {
try {
String name = "TestRepository3";
URI location = null;
File wexFile = new File("TestWEX/DSBook.wex");
String forteLogger = ToolProjectSupport.DEFAULT_LOG_FLAGS;
String repository = null;
String workspace = null;
String workspacePassword = null;
IProject project = ToolProjectSupport.createProject(name, location, forteLogger, repository, workspace, workspacePassword);
project.refreshLocal(IResource.DEPTH_ZERO, null);
CreateRepository creator = new CreateRepository(project, project.getName());
creator.run(new NullProgressMonitor()) ;
ImportWex importer = new ImportWex(project, wexFile);
importer.run(new NullProgressMonitor());
RepositoryExport exporter = new RepositoryExport(project);
exporter.run(new NullProgressMonitor());
} catch (CoreException e) {
ToolPlugin.showError("Error importing from Tool repository",e);
} catch (ToolRepositoryException e) {
ToolPlugin.showError("Error importing from Tool repository",e);
} catch (IOException e) {
ToolPlugin.showError("Error importing from Tool repository",e);
}
}
}