*****************************************************************************/
package test.splat.service;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import org.splat.dal.bo.kernel.User;
import org.splat.dal.bo.som.Document;
import org.splat.dal.bo.som.DocumentType;
-import org.splat.dal.bo.som.KnowledgeElement;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.Scenario;
import org.splat.dal.bo.som.Study;
import org.splat.service.PublicationService;
import org.splat.service.ScenarioService;
import org.splat.service.StepService;
+import org.splat.service.dto.DocumentDTO;
+import org.splat.service.dto.FileDTO;
import org.splat.service.dto.StepDTO;
-import org.splat.som.Step;
+import org.splat.service.technical.ProjectSettingsService;
+import org.splat.service.technical.ProjectSettingsService.Step;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.HibernateTemplate;
@Qualifier("projectElementService")
private transient ProjectElementService _projectElementService;
+ /**
+ * The ProjectSettingsService. Later injected by Spring.
+ */
+ @Autowired
+ @Qualifier("projectSettings")
+ private transient ProjectSettingsService _projectSettings;
+
/**
* The DocumentTypeService. Later injected by Spring.
*/
* if a mandatory property is not defined for an object to be created
* @throws IOException
* if scenario creation is failed
- *
+ * @throws SQLException
+ * if scenario creation is failed
*/
@Test
public void testGetScenarioInfo() throws InvalidPropertyException,
- MissedPropertyException, MultiplyDefinedException, IOException {
+ MissedPropertyException, MultiplyDefinedException, IOException,
+ SQLException {
LOG.debug(">>>>> BEGIN testGetScenarioInfo()");
long scenarioId = createScenario();
// Call DAO's create method for a good transient knowledge element.
Assert.assertNotNull(steps, "List of steps must not be null.");
Assert.assertTrue(steps.size() > 0, "No steps are read.");
+ List<Step> projSteps = _projectSettings.getStepsOf(Scenario.class);
+ Assert.assertEquals(steps.size(), projSteps.size(),
+ "Not all steps are listed.");
+ int docIndex = 0;
+ for (StepDTO step : steps) {
+ LOG.debug("check the step " + step.getNumber() + ":\n" + step);
+ Assert.assertNotNull(step, "Step DTO must not be null.");
+ Assert.assertNotNull(step.getKey(), "Step name must not be null.");
+ Assert.assertFalse(step.getKey().isEmpty(),
+ "Step name must not empty.");
+ Assert.assertTrue(step.getNumber() > 0,
+ "Step number must be positive integer.");
+ Assert.assertNotNull(step.getDocs(),
+ "Step documents list must not be null.");
+
+ Step aProjStep = null;
+ for (Step projStep : projSteps) {
+ if (projStep.getNumber() == step.getNumber()) {
+ aProjStep = projStep;
+ break;
+ }
+ }
+
+ List<DocumentType> dtypes = _documentTypeService
+ .selectTypesOf(aProjStep);
+ for (DocumentType dtype : dtypes) {
+ Assert.assertTrue(step.getDocs().size() > 0,
+ "Step documents list must not be empty.");
+ String docName = "document" + docIndex;
+ for (DocumentDTO doc : step.getDocs()) {
+ if (docName.equals(doc.getTitle())) {
+ Assert.assertTrue(doc.getId() > 0,
+ "Document id must be positive integer.");
+ Assert.assertEquals(doc.getTitle(), docName);
+ Assert.assertNotNull(doc.getFiles(),
+ "Document files list must not be null.");
+ Assert.assertTrue(doc.getFiles().size() > 1,
+ "Document must have more then 1 attached file.");
+
+ for (FileDTO file : doc.getFiles()) {
+ Assert.assertNotNull(file.getPath(),
+ "File path must not be null.");
+ Assert.assertFalse(file.getPath().isEmpty(),
+ "File path must not be empty.");
+ /*
+ <mappings>
+ <document type="geometry">
+ <import format="brep"/> <!-- Result Shape -->
+ </document>
+ <document type="model">
+ <import format="med"/> <!-- Result mesh without input parameters -->
+ </document>
+ <document type="loads">
+ <import format="c3m"/> <!-- Input data created interactively -->
+ </document>
+ <document type="results">
+ <import format="med"/> <!-- Calculation results source file -->
+ </document>
+ </mappings>
+ */
+ // Check state and processing instruction
+ String fileFormat = file.getPath().substring(
+ file.getPath().lastIndexOf('.') + 1);
+/* if (_projectSettings.doImport(dtype.getName(),
+ fileFormat)) {
+ Assert.assertTrue(file.isResult(),
+ "The file must be a result file.");
+ } else {
+ Assert.assertFalse(file.isResult(),
+ "The file must be a source file.");
+ }
+*/ if ((docIndex % 2) == 0) { // New
+ Assert.assertEquals(file.getState(), 'Y',
+ "File state must be actual ('Y').");
+ if (_projectSettings.doImport(dtype.getName(),
+ fileFormat)) {
+ Assert.assertEquals(file.getProcessing(),
+ "file-import",
+ "File must be imported.");
+ } else {
+ Assert.assertEquals(file.getProcessing(),
+ "file-download",
+ "File must be downloaded.");
+ }
+ } else { // Outdated
+ Assert.assertEquals(file.getState(), 'O',
+ "File state must be actual ('O').");
+ Assert
+ .assertEquals(file.getProcessing(),
+ "file-download",
+ "Outdated document should not be imported but downloaded.");
+ }
+ }
+ }
+ }
+ docIndex++;
+ }
+ }
+
// Call DAO's get method for a not existing id.
try {
steps = _scenarioService.getScenarioInfo(-1L);
* if a mandatory property is not defined for an object to be created
* @throws IOException
* if document creation is failed
+ * @throws SQLException
+ * if project settings loading is failed
*/
private long createScenario() throws InvalidPropertyException,
- MissedPropertyException, MultiplyDefinedException, IOException {
+ MissedPropertyException, MultiplyDefinedException, IOException,
+ SQLException {
// Create a scenario for tests
HibernateTemplate ht = getHibernateTemplate();
+ // Load workflow customization
+ try {
+ _projectSettings.configure(ClassLoader.getSystemResource("test/som.xml").getPath());
+ } catch (FileNotFoundException e) {
+ Assert.fail("Can't find som.xml: ", e);
+ }
+ List<Step> steps = _projectSettings.getStepsOf(Scenario.class);
+ Assert.assertTrue(steps.size() > 0, "No steps are created.");
+
// Create a test user
User.Properties uprop = new User.Properties();
uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
"noreply@salome-platform.org");
uprop.disableCheck();
User anAuthor = new User(uprop);
- ht.update(anAuthor);
+ ht.save(anAuthor);
// Create a test study
Study.Properties stprops = new Study.Properties().setReference(
Scenario aScenario = new Scenario(sprops);
aStudy.getScenariiList().add(aScenario);
ht.saveOrUpdate(anAuthor);
- ht.update(aStudy);
+ ht.saveOrUpdate(aStudy);
ht.saveOrUpdate(aScenario);
Document.Properties dprop = new Document.Properties().setAuthor(
anAuthor).setDate(new Date());
- Step[] steps = _projectElementService.getSteps(aScenario);
- Assert.assertTrue(steps.length > 0, "No steps are created.");
+ // Create documents
int i = 0;
for (Step step : steps) {
- List<DocumentType> dtypes = _documentTypeService.selectTypesOf(step
- .getStep());
- dprop.setName("document" + i++).setType(dtypes.get(0));
- // Create a document published in the scenario
- Publication pub = _stepService.createDocument(step, dprop);
- // Attach a file
- _publicationService.attach(pub, "brep"); // TODO: test for different formats
+ LOG.debug("Create scenario step: " + i);
+
+ org.splat.som.Step aScStep = new org.splat.som.Step(step, aScenario);
+ List<DocumentType> dtypes = _documentTypeService
+ .selectTypesOf(step);
+ for (DocumentType dtype : dtypes) {
+ dprop.setName("document" + i++).setType(dtype).setFormat(
+ "brep");
+ // Create a document published in the scenario
+ // document<i>: document type[0] - first type used on the step
+ // <source-file>.brep
+ // <attached-file>.med
+ Publication pub = _stepService.createDocument(aScStep, dprop);
+ Assert.assertNotNull(pub.getOwner(),
+ "The publication must be attached to the scenario.");
+ Assert.assertEquals(pub.getOwner().getIndex(), aScenario
+ .getIndex(),
+ "The publication was not attached to the scenario.");
+
+ aScenario.add(pub);
+ ht.saveOrUpdate(pub);
+
+ // Attach a file
+ ht.saveOrUpdate(pub.value());
+ ht.saveOrUpdate(_publicationService.attach(pub, "med"));
+
+ // Create a document with outdated publication
+ dprop.setName("document" + i++).setType(dtype).setFormat(
+ "brep");
+ // Create a document published in the scenario
+ // document<i>: document type[0] - first type used on the step
+ // <source-file>.brep
+ // <attached-file>.med
+ pub = _stepService.createDocument(aScStep, dprop);
+ Assert.assertNotNull(pub.getOwner(),
+ "The publication must be attached to the scenario.");
+ Assert.assertEquals(pub.getOwner().getIndex(), aScenario
+ .getIndex(),
+ "The publication was not attached to the scenario.");
+
+ pub.setIsnew('O');
+ aScenario.add(pub);
+ ht.saveOrUpdate(pub);
+
+ // Attach a file
+ ht.saveOrUpdate(pub.value());
+ ht.saveOrUpdate(_publicationService.attach(pub, "med"));
+
+ }
+ if (dtypes.size() <= 0) {
+ LOG.debug("No document types are found for scenario step " + i);
+ }
}
- return aScenario.getIndex();
- }
+ Assert.assertNotNull(ht.find("from Document"),
+ "No documents in the database.");
+ Assert.assertTrue(ht.find("from Document").size() > 0,
+ "No documents in the database.");
- /**
- * Check that given objects are equal.
- *
- * @param anActual
- * the object to check
- * @param anExpected
- * the expected object
- */
- private void compareObjects(final KnowledgeElement anActual,
- final KnowledgeElement anExpected) {
- Assert.assertNotNull(anActual,
- "Created object is not found in the database.");
- Assert.assertEquals(anActual.getAuthor(), anExpected.getAuthor(),
- "Knowledge Element author is not saved.");
- Assert.assertEquals(anActual.getDate(), anExpected.getDate(),
- "Knowledge Element date is not saved.");
- Assert
- .assertEquals(anActual.getOwnerScenario(), anExpected
- .getOwnerScenario(),
- "Knowledge Element scenario is not saved.");
- Assert.assertEquals(anActual.getProgressState(), anExpected
- .getProgressState(), "Knowledge Element state is not saved.");
- Assert.assertEquals(anActual.getTitle(), anExpected.getTitle(),
- "Knowledge Element title is not saved.");
- Assert.assertEquals(anActual.getType(), anExpected.getType(),
- "Knowledge Element type is not saved.");
- Assert.assertEquals(anActual.getValue(), anExpected.getValue(),
- "Knowledge Element value is not saved.");
- Assert.assertEquals(anActual.getIndex(), anExpected.getIndex(),
- "Knowledge Element index is not saved.");
+ Assert.assertNotNull(ht.find("from Publication where owner="
+ + aScenario.getIndex()), "No publications in the database.");
+ Assert.assertTrue(
+ ht.find("from Publication where owner=" + aScenario.getIndex())
+ .size() > 0, "No publications in the database.");
+
+ for (Publication p : (List<Publication>) ht
+ .find("from Publication where owner=" + aScenario.getIndex())) {
+ LOG.debug("Publication found: [id=" + p.getIndex() + ", owner="
+ + p.getOwner().getIndex() + ", doc=" + p.value().getIndex()
+ + "]");
+ Assert.assertEquals(p.getOwner().getIndex(), aScenario.getIndex(),
+ "The publication was not attached to the scenario.");
+ }
+
+ ht.evict(aScenario);
+ Scenario aScen = ht.load(Scenario.class, aScenario.getIndex());
+ Assert.assertNotNull(aScen, "Scenario was not saved in the database.");
+ Assert.assertTrue(aScen.getDocums().size() > 0,
+ "No publications in the scenario.");
+
+ Assert.assertTrue(i > 0,
+ "More then one document must be in the database");
+
+ return aScenario.getIndex();
}
}