package q_impress.pmi.tests;
import static org.junit.Assert.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Set;
import org.junit.Test;
import q_impress.pmi.lib.project.IModelingProject;
import q_impress.pmi.lib.project.IResource;
import q_impress.pmi.lib.project.ModelingProject;
import q_impress.pmi.lib.project.ResourceException;
import q_impress.pmi.lib.project.SimpleLocationSolver;
import q_impress.pmi.lib.project.UmlResource;
import q_impress.pmi.lib.services.ServiceException;
import q_impress.pmi.lib.services.loadsave.LoadingService;
import q_impress.pmi.lib.services.loadsave.SavingService;
public class LoadSaveTests {
@Test
public void testSave() {
IModelingProject project = new ModelingProject();
project.setName("test-project");
project.setConfigProperty("dummy-prop", "myvalue");
UmlResource resource = new UmlResource();
resource.setName("xmi.1");
resource.setLocation("/home/goldivan/Documenti/poli/gallotti/Examples_Input/CaseStudyPolimi(ATOP).uml");
resource.setConfigProperty("isXmiValid", "true");
try {
project.addResource(resource);
} catch (ResourceException e) {
e.printStackTrace();
assertTrue(false);
}
// now try to save the project
String filename = "/tmp/test.pmi";
try {
FileOutputStream stream = new FileOutputStream(filename);
try {
SavingService savingService = new SavingService();
savingService.setOutStream(stream);
savingService.setTarget(project);
try {
savingService.initialize();
savingService.invoke();
} catch (ServiceException e) {
e.printStackTrace();
assertTrue(false);
}
} finally {
stream.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
assertTrue(false);
} catch (IOException e ) {
e.printStackTrace();
assertTrue(false);
}
//TODO reenable me
// now try to save the graphs
// for (IResource res : project.getAllResources().values()) {
// if (res instanceof ActivityGraph) {
// ActivityGraph graph = (ActivityGraph) res;
// try {
// FileOutputStream stream = new FileOutputStream(new File(new URI(graph.getLocation())));
// try {
// SavingService savingService = new SavingService();
// savingService.setOutStream(stream);
// savingService.setTarget(graph);
// try {
// savingService.initialize();
// savingService.invoke();
// } catch (ServiceException e) {
// e.printStackTrace();
// assertTrue(false);
// }
// } finally {
// stream.close();
// }
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// assertTrue(false);
// } catch (IOException e ) {
// e.printStackTrace();
// assertTrue(false);
// } catch (URISyntaxException e) {
// e.printStackTrace();
// assertTrue(false);
// }
// }
// }
}
@Test
public void testLoad() {
// try to load the project
String filename = "/tmp/test.pmi";
try {
FileInputStream stream = new FileInputStream(filename);
try {
LoadingService loadingService = new LoadingService();
loadingService.setInStream(stream);
try {
loadingService.initialize();
loadingService.invoke();
IResource prj = loadingService.getLoadedResource();
int a = 1;
a++;
} catch (ServiceException e) {
e.printStackTrace();
assertTrue(false);
}
} finally {
stream.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
assertTrue(false);
} catch (IOException e ) {
e.printStackTrace();
assertTrue(false);
}
}
}