1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecms.upgrade.test;
18
19 import java.io.InputStream;
20
21
22 import javax.jcr.Node;
23 import javax.jcr.NodeIterator;
24 import javax.jcr.PathNotFoundException;
25 import javax.jcr.RepositoryException;
26 import javax.jcr.Session;
27 import javax.jcr.version.Version;
28 import org.exoplatform.commons.info.ProductInformations;
29 import org.exoplatform.commons.upgrade.UpgradeProductService;
30 import org.exoplatform.container.PortalContainer;
31 import org.exoplatform.container.configuration.ConfigurationManager;
32 import org.exoplatform.services.cms.templates.TemplateService;
33 import org.exoplatform.services.jcr.RepositoryService;
34 import org.exoplatform.services.wcm.core.NodetypeConstant;
35 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
36 import org.exoplatform.test.BasicTestCase;
37 import org.junit.Ignore;
38
39
40
41
42 @Ignore
43 public class TestECMSUpgrade extends BasicTestCase {
44 private static final String OLD_PRODUCT_INFORMATIONS_FILE = "classpath:/conf/product_old.properties";
45
46 private static final String OLD_VERSION = "1.0-old";
47
48 protected final String REPO_NAME = "repository";
49
50 protected final String COLLABORATION_WS = "collaboration";
51
52 protected PortalContainer container;
53
54 protected RepositoryService repositoryService;
55
56 protected TemplateService templateService;
57
58 protected ProductInformations productInformations;
59
60 protected ConfigurationManager configurationManager;
61
62 public void setUp() throws Exception {
63 container = PortalContainer.getInstance();
64 repositoryService = getService(RepositoryService.class);
65 templateService = getService(TemplateService.class);
66 productInformations = getService(ProductInformations.class);
67 UpgradeProductService upgradeService = getService(UpgradeProductService.class);
68 configurationManager = getService(ConfigurationManager.class);
69 Session session = null;
70 try {
71 InputStream oldVersionsContentIS = configurationManager.getInputStream(OLD_PRODUCT_INFORMATIONS_FILE);
72 byte[] binaries = new byte[oldVersionsContentIS.available()];
73 oldVersionsContentIS.read(binaries);
74 String oldVersionsContent = new String(binaries);
75
76 session = repositoryService.getDefaultRepository().getSystemSession(COLLABORATION_WS);
77
78 Node plfVersionDeclarationNode = getProductVersionNode(session);
79 Node plfVersionDeclarationContentNode = plfVersionDeclarationNode.getNode("jcr:content");
80 plfVersionDeclarationContentNode.setProperty("jcr:data", oldVersionsContent);
81
82 session.save();
83 session.refresh(true);
84 } finally {
85 if (session != null) {
86 session.logout();
87 }
88 }
89
90 productInformations.start();
91 upgradeService.start();
92 }
93
94 public void testUpgradeNodeTypesTemplates() throws Exception {
95 templateService.getAllDocumentNodeTypes();
96 NodeIterator iter = templateService.getAllTemplatesOfNodeType(true, "nt:file", WCMCoreUtils.getSystemSessionProvider());
97 while (iter.hasNext()) {
98 Node node = (Node) iter.next();
99 assertTrue(node.isNodeType(NodetypeConstant.MIX_VERSIONABLE));
100
101 Version version = node.getBaseVersion();
102 assertNotNull(version);
103
104 String[] versionLabels = node.getVersionHistory().getVersionLabels(version);
105 assertNotNull(versionLabels);
106 assertEquals(versionLabels.length, 1);
107 assertEquals(versionLabels[0], OLD_VERSION);
108 }
109 }
110
111 protected <T> T getService(Class<T> clazz) {
112 return clazz.cast(container.getComponentInstanceOfType(clazz));
113 }
114
115 private Node getProductVersionNode(Session session) throws PathNotFoundException, RepositoryException {
116 Node plfVersionDeclarationNodeContent = ((Node) session
117 .getItem("/Application Data/" + ProductInformations.UPGRADE_PRODUCT_SERVICE_NODE_NAME + "/"
118 + ProductInformations.PRODUCT_VERSION_DECLARATION_NODE_NAME));
119 return plfVersionDeclarationNodeContent;
120 }
121
122 }