gvsig-scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / test / java / org / gvsig / scripting / swing / impl / composer / TestJNewScriptModel.java @ 212
History | View | Annotate | Download (3.02 KB)
1 |
package org.gvsig.scripting.swing.impl.composer; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import junit.framework.Assert; |
6 |
|
7 |
import org.gvsig.scripting.ScriptingFolder; |
8 |
import org.gvsig.scripting.ScriptingLocator; |
9 |
import org.gvsig.scripting.ScriptingManager; |
10 |
import org.gvsig.scripting.ScriptingUnit; |
11 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
12 |
|
13 |
public class TestJNewScriptModel extends AbstractLibraryAutoInitTestCase { |
14 |
|
15 |
protected ScriptingManager manager;
|
16 |
protected JNewScriptModel model;
|
17 |
protected JNewScriptModel model2;
|
18 |
|
19 |
@Override
|
20 |
protected void doSetUp() throws Exception { |
21 |
manager = ScriptingLocator.getManager(); |
22 |
} |
23 |
|
24 |
public void setWorkingFolder(){ |
25 |
File file =new File(this.getClass().getClassLoader().getResource("org/gvsig/scripting/home").getFile()); |
26 |
if (!file.exists()) {
|
27 |
file.mkdir(); |
28 |
} |
29 |
manager.setRootUserFolder(file.getAbsolutePath()); |
30 |
} |
31 |
|
32 |
public void testCreate(){ |
33 |
setWorkingFolder(); |
34 |
model.setType(ScriptingManager.UNIT_SCRIPT); |
35 |
model.setName("TestScript01");
|
36 |
model.setDescription("Test Script 01");
|
37 |
model.setCreatedBy("Anonymus");
|
38 |
model.setVersion("v0.1");
|
39 |
model.setPath(manager.getRootUserFolder()); |
40 |
try {
|
41 |
model.validate(); |
42 |
} catch (Exception e) { |
43 |
Assert.fail("The data model is correct. Validation couldn't fail");
|
44 |
} |
45 |
} |
46 |
|
47 |
public void TestCreateWithEmptyName(){ |
48 |
testCreate(); |
49 |
model.setType(ScriptingManager.UNIT_SCRIPT); |
50 |
model.setName("");
|
51 |
model.setDescription("Test Script 01");
|
52 |
model.setCreatedBy("Anonymus");
|
53 |
model.setVersion("v0.1");
|
54 |
model.setPath(manager.getRootUserFolder()); |
55 |
try {
|
56 |
model.validate(); |
57 |
} catch (Exception e) { |
58 |
Assert.assertEquals(e.getMessage(), "Name must not be empty.");
|
59 |
} |
60 |
} |
61 |
|
62 |
public void TestCreateWithSameName(){ |
63 |
testCreate(); |
64 |
this.manager.createUnit(
|
65 |
model.getType(), |
66 |
manager.getFolder(new File(model.getPath())), |
67 |
model.getName()+model.getExtension() |
68 |
); |
69 |
|
70 |
model.setType(ScriptingManager.UNIT_SCRIPT); |
71 |
model.setName("TestScript01");
|
72 |
model.setDescription("Test Script 01");
|
73 |
model.setCreatedBy("Anonymus");
|
74 |
model.setVersion("v0.1");
|
75 |
model.setPath(manager.getRootUserFolder()); |
76 |
try {
|
77 |
model.validate(); |
78 |
} catch (Exception e) { |
79 |
Assert.assertEquals(e.getMessage(), "This file already exists.\nWrite another name for the script");
|
80 |
|
81 |
} |
82 |
ScriptingUnit newFolder= this.manager.createUnit(
|
83 |
ScriptingManager.UNIT_FOLDER, |
84 |
manager.getFolder(new File(model.getPath())), |
85 |
"scripts"
|
86 |
); |
87 |
model.setPath(((ScriptingFolder) newFolder).getPath()); |
88 |
try {
|
89 |
model.validate(); |
90 |
} catch (Exception e) { |
91 |
Assert.fail("The data model is correct. Validation couldn't fail");
|
92 |
} |
93 |
|
94 |
} |
95 |
|
96 |
public void TestCreateProjects(){ |
97 |
testCreate(); |
98 |
|
99 |
model.setType(ScriptingManager.UNIT_PROJECT); |
100 |
model.setName("TestScript01");
|
101 |
model.setDescription("Test Script 01");
|
102 |
model.setCreatedBy("Anonymus");
|
103 |
model.setVersion("v0.1");
|
104 |
model.setPath(manager.getRootUserFolder()); |
105 |
try {
|
106 |
model.validate(); |
107 |
} catch (Exception e) { |
108 |
Assert.assertEquals(e.getMessage(), "Projects will be supported in future versions");
|
109 |
|
110 |
} |
111 |
} |
112 |
|
113 |
} |