1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.test.fixture.setup;
35
36 import static info.magnolia.nodebuilder.Ops.*;
37
38 import info.magnolia.module.AbstractModuleVersionHandler;
39 import info.magnolia.module.InstallContext;
40 import info.magnolia.module.delta.ArrayDelegateTask;
41 import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
42 import info.magnolia.module.delta.CopyNodeTask;
43 import info.magnolia.module.delta.Delta;
44 import info.magnolia.module.delta.ModuleFilesExtraction;
45 import info.magnolia.module.delta.NodeExistsDelegateTask;
46 import info.magnolia.module.delta.PropertiesImportTask;
47 import info.magnolia.module.delta.RegisterModuleServletsTask;
48 import info.magnolia.module.delta.RemoveNodeTask;
49 import info.magnolia.module.delta.Task;
50 import info.magnolia.module.model.Version;
51 import info.magnolia.nodebuilder.task.ErrorHandling;
52 import info.magnolia.nodebuilder.task.ModuleNodeBuilderTask;
53 import info.magnolia.repository.RepositoryConstants;
54 import info.magnolia.testframework.AbstractMagnoliaIntegrationTest;
55
56 import java.util.ArrayList;
57 import java.util.List;
58
59
60
61
62
63
64
65
66 public abstract class AbstractTestingVersionHandler extends AbstractModuleVersionHandler {
67 @Override
68 public List<Delta> getDeltas(InstallContext installContext, Version from) {
69 if (from != null) {
70 final String s = "Updates are not supported - please do a fresh install !";
71 final IllegalStateException e = new IllegalStateException(s);
72 installContext.error(s, e);
73 throw e;
74 }
75
76
77 return super.getDeltas(installContext, null);
78 }
79
80 @Override
81 protected List<Task> getBasicInstallTasks(InstallContext installContext) {
82 final ArrayList<Task> list = new ArrayList<Task>();
83 list.add(new ModuleFilesExtraction());
84 list.add(new RegisterModuleServletsTask());
85 list.add(new ModuleNodeBuilderTask("", "", ErrorHandling.strict,
86 addNode("templates", "mgnl:content"),
87 addNode("components", "mgnl:content"),
88 addNode("dialogs", "mgnl:content")
89 ));
90 list.add(new PropertiesImportTask("Test config content", "Imports content in the config workspace", "config", getConfigImportPropertiesFile()));
91 list.add(new PropertiesImportTask("Test website content", "Imports content in the website workspace", "website", getWebsiteImportPropertiesFile()));
92
93 list.add(new NodeExistsDelegateTask("Activation", "Changes public URL", RepositoryConstants.CONFIG,
94 "/server/activation/subscribers/magnoliaPublic8080", new CheckAndModifyPropertyValueTask("Activation", "Changes public URL", RepositoryConstants.CONFIG,
95 "/server/activation/subscribers/magnoliaPublic8080", "URL", "http://localhost:8080/magnoliaPublic", AbstractMagnoliaIntegrationTest.Instance.PUBLIC.getURL())));
96
97
98
99
100
101
102
103
104
105
106 return list;
107 }
108
109 protected abstract String getWebsiteImportPropertiesFile();
110
111 protected abstract String getConfigImportPropertiesFile();
112
113 @Override
114 protected abstract List<Task> getExtraInstallTasks(InstallContext installContext);
115
116 protected ModuleNodeBuilderTask newTemplateDefinition(String name, String templateScript, String renderType) {
117 return new ModuleNodeBuilderTask("test template", "", ErrorHandling.strict,
118 getNode("templates").then(
119 addNode(name, "mgnl:contentNode").then(
120 addProperty("dialog", "sampleDialog"),
121 addProperty("templateScript", templateScript),
122 addProperty("renderType", renderType),
123 addProperty("title", name),
124 addProperty("visible", "true")
125 )
126 )
127 );
128 }
129
130 protected ModuleNodeBuilderTask newComponentDefinition(String name, String templateScript, String renderType, Class modelClass) {
131 return new ModuleNodeBuilderTask("test component", "", ErrorHandling.strict,
132 getNode("templates").then(
133 addNode(name, "mgnl:contentNode").then(
134 addProperty("templateScript", templateScript),
135 addProperty("renderType", renderType),
136 modelClass != null ? addProperty("modelClass", modelClass.getName()) : noop()
137 )
138 )
139 );
140 }
141
142 protected Task copyArchetypeDialog(final String archetypeName, final String newName) {
143 final String pathPrefix = "/modules/test/dialogs/";
144 final String archetypePath = pathPrefix + archetypeName;
145 final String copyPath = pathPrefix + newName;
146 return new CopyNodeTask("Copy " + archetypeName + " dialog to " + newName, "", "config", archetypePath, copyPath, false);
147 }
148
149 protected ArrayDelegateTask copyArchetypePageAndChangeTemplate(final String name, final String newPageName, final String newTemplate, final String newTitle, String renderType, String templateScript) {
150 return new ArrayDelegateTask(name, "",
151 new CopyNodeTask(null, null, "website", "/testpages/test_template_archetype", "/testpages/" + newPageName, false),
152 new CheckAndModifyPropertyValueTask(null, null, "website", "/testpages/" + newPageName, "mgnl:template", "test:test_template_archetype", "test:"+newTemplate),
153 new CheckAndModifyPropertyValueTask(null, null, "website", "/testpages/" + newPageName, "title", "Archetype test page for rendering", newTitle),
154 new CheckAndModifyPropertyValueTask(null, null, "website", "/testpages/" + newPageName, "renderType", "foo", renderType),
155 new CheckAndModifyPropertyValueTask(null, null, "website", "/testpages/" + newPageName, "templateScript", "bar", templateScript)
156 );
157 }
158
159 protected Task removeArchetypePage() {
160 return new RemoveNodeTask("", "Remove archetype testpage", "website", "/testpages/test_template_archetype");
161 }
162 }