List of usage examples for java.io OutputStream toString
public String toString()
From source file:org.exoplatform.calendar.service.impl.JCRDataStorage.java
/** * {@inheritDoc}//from ww w .ja v a 2 s. co m */ @Deprecated public int generateCalDav(String username, LinkedHashMap<String, Calendar> calendars, RssData rssData, CalendarImportExport importExport) throws Exception { Node rssHomeNode = getRssHome(username); Node iCalHome = null; try { iCalHome = rssHomeNode.getNode(Utils.CALDAV_NODE); } catch (Exception e) { iCalHome = rssHomeNode.addNode(Utils.CALDAV_NODE, Utils.NT_UNSTRUCTURED); } try { SyndFeed feed = new SyndFeedImpl(); feed.setFeedType(rssData.getVersion()); feed.setTitle(rssData.getTitle()); feed.setLink(rssData.getLink()); feed.setDescription(rssData.getDescription()); List<SyndEntry> entries = new ArrayList<SyndEntry>(); SyndEntry entry; SyndContent description; for (String calendarMap : calendars.keySet()) { String calendarId = calendarMap.split(Utils.SPLITTER)[0]; String type = calendarMap.split(Utils.SPLITTER)[1]; OutputStream out = importExport.exportCalendar(username, Arrays.asList(new String[] { calendarId }), type, -1); if (out != null) { ByteArrayInputStream is = new ByteArrayInputStream(out.toString().getBytes()); Node ical = null; Node nodeContent = null; try { ical = iCalHome.getNode(calendarMap + Utils.ICS_EXT); nodeContent = ical.getNode(Utils.JCR_CONTENT); } catch (Exception e) { ical = iCalHome.addNode(calendarMap + Utils.ICS_EXT, Utils.NT_FILE); nodeContent = ical.addNode(Utils.JCR_CONTENT, Utils.NT_RESOURCE); } nodeContent.setProperty(Utils.JCR_LASTMODIFIED, java.util.Calendar.getInstance().getTimeInMillis()); nodeContent.setProperty(Utils.JCR_MIMETYPE, Utils.MIMETYPE_ICALENDAR); nodeContent.setProperty(Utils.JCR_DATA, is); if (!iCalHome.isNew()) iCalHome.save(); else iCalHome.getSession().save(); String link = rssData.getLink() + ical.getPath(); Calendar exoCal = calendars.get(calendarMap); entry = new SyndEntryImpl(); entry.setTitle(exoCal.getName()); entry.setLink(link); description = new SyndContentImpl(); description.setType(Utils.MIMETYPE_TEXTPLAIN); description.setValue(exoCal.getDescription()); entry.setDescription(description); entry.setAuthor(username); entries.add(entry); entry.getEnclosures(); } } if (!entries.isEmpty()) { feed.setEntries(entries); feed.setEncoding("UTF-8"); SyndFeedOutput output = new SyndFeedOutput(); String feedXML = output.outputString(feed); feedXML = StringUtils.replace(feedXML, "&", "&"); storeXML(feedXML, rssHomeNode, rssData); rssHomeNode.getSession().save(); } else { log.info("No data to make caldav!"); return -1; } } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e); return -1; } return 1; }
From source file:org.sdm.spa.actors.transport.SrmliteCopier.java
@Override // Anusua Change - Starts protected CopyResult copyFrom(ConnectionDetails srcDetails, String srcFile, String destFile, boolean recursive) throws SshException { int exitCode = 0; StringBuffer cmd = new StringBuffer(100); OutputStream streamOut = new ByteArrayOutputStream(); OutputStream streamErr = new ByteArrayOutputStream(); LocalExec localObject = new LocalExec(); localObject.setTimeout(timeout, false, false); String[] srcFileList = null;/* www .j a v a2 s. c o m*/ String[] srcFile_list = null; StringBuffer warn = new StringBuffer(100); boolean warn_flag = false; String cmdWithPath; String osname = (System.getProperty("os.name")).toLowerCase(); String userhome = (System.getProperty("user.home")).toLowerCase(); String cmdFile = userhome + File.separatorChar + "srmlite_" + System.currentTimeMillis() + ".xml"; if (srcFile.contains(",")) { srcFileList = srcFile.split(","); srcFile_list = new String[srcFileList.length]; for (int count = 0; count < srcFileList.length; count++) { if ((srcFileList[count].trim()).startsWith("/")) { srcFile_list[count] = srcFileList[count].trim(); } else { warn.append(srcFile_list[count].trim() + " "); if (!warn_flag) warn_flag = true; } } if (warn_flag) { warn.append(" does not contain full path to the source file. Please provide full path. "); warn_flag = false; } } else { if (!srcFile.startsWith("/")) { throw new SshException( srcFile + "does not contain full path to the file. Please provide full path."); } } try { if (srcFile.contains(",")) { build_xmlForRemoteSource(cmdFile, srcFile_list, srcDetails); } } catch (Exception e) {// Catch exception if any e.printStackTrace(); return new CopyResult(1, e.getMessage(), warn.toString()); } // command format // "<path>/srmlite -s file:////<srcfile> -t scp://user@host/<dest path>" // srmlite -f <cmdFile> if (srcFile.contains(",")) { if (osname.contains("windows")) cmd.append("srmlite.bat -f "); else cmd.append("srmlite -f "); cmd.append("file:///"); cmd.append(cmdFile); cmd.append(" -td "); } else { if (osname.contains("windows")) cmd.append("srmlite.bat -s "); else cmd.append("srmlite -s "); cmd.append("\""); if (srmProtocol.equals("")) { cmd.append("scp://"); } else { cmd.append(srmProtocol); cmd.append("://"); } cmd.append(srcDetails.toString()); // Anand: we dont need this / // cmd.append("/"); cmd.append(srcFile); cmd.append("\""); if (recursive) { cmd.append(" -recursive"); } File tempSrcFile = new File(destFile); if (tempSrcFile.isDirectory()) cmd.append(" -td "); else cmd.append(" -t "); } cmd.append("file:///"); cmd.append(destFile); if (protocolPathSrc.equals("")) { if (osname.contains("windows")) { cmdWithPath = cmd.toString(); } else { cmdWithPath = getCmdWithDefaultPath(cmd); } } else { cmdWithPath = protocolPathSrc + cmd; } // TODO Anand: Adjust path variable // cmdWithPath = "C:\\Projects\\srmlite\\bin\\" + cmd; System.out.println("*************Full command executed is :: " + cmdWithPath); try { if (isDebugging) log.debug("copy cmd=" + cmdWithPath); streamOut = new ByteArrayOutputStream(); streamErr = new ByteArrayOutputStream(); try { exitCode = localObject.executeCmd(cmdWithPath, streamOut, streamErr, srcDetails.toString()); } catch (ExecException e) { return new CopyResult(exitCode, e.toString(), ""); } if (isDebugging) { log.error("Output on stdout:" + streamOut); log.error("Output on stderr:" + streamErr); } } catch (Exception e) { return new CopyResult(1, "SRMLite Copy failed!\n" + streamErr.toString(), ""); } String message = streamErr.toString(); message = message + " \n\n" + streamOut.toString(); String fileDeleteMsg = ""; if (srcFile.contains(",")) { try { boolean success = false; success = localObject.deleteFile(cmdFile, false, false); if (success) { log.debug("deleted the xml script file " + cmdFile + " created for file copy"); } if (!success) { log.warn("Unable to delete the xml script file " + cmdFile + " created for file copy"); fileDeleteMsg = "Unable to delete the xml script file " + cmdFile + " created for file copy"; } } catch (ExecException e) { log.warn("Unable to delete the xml script file " + cmdFile + " created for file copy : " + e.toString()); } } return new CopyResult(exitCode, message + fileDeleteMsg, ""); }
From source file:org.sdm.spa.actors.transport.BbcpCopier.java
@Override // ANUSUA Change -Starts protected CopyResult copyFrom(ConnectionDetails srcDetails, String srcFile, String destFile, boolean recursive) throws SshException { // force copy - overwrite files if already exist cmdLineOptions += "-f"; String osname = (System.getProperty("os.name")).toLowerCase(); /*//from w w w . ja va 2 s. c o m * if (osname.contains("windows")) { throw new * SshException("BBCP is not supported on Windows machines"); } */ int exitCode = 0; StringBuffer cmd = new StringBuffer(100); OutputStream streamOut = new ByteArrayOutputStream(); OutputStream streamErr = new ByteArrayOutputStream(); // Connecting to local destination SshExec localSshObj = new SshExec(System.getProperty("user.name"), "localhost"); localSshObj.setTimeout(timeout, false, false); localSshObj.setPseudoTerminal(true); localSshObj.setForcedCleanUp(forcedCleanup); String cmdWithPath = ""; File single_srcFileObj = null; File srcFile_Obj = null; File srcFileObjlst = null; boolean flag = false; String[] srcFileList = null; String[] srcFile_list = null; String wildcardFileList; StringBuffer warn = new StringBuffer(100); boolean warn_flag = false; SshExec sshObject = new SshExec(srcDetails.getUser(), srcDetails.getHost(), srcDetails.getPort()); if (!(srcFile.contains(","))) { if (srcFile.startsWith("/")) { srcFile_list = new String[1]; srcFile_list[0] = srcFile.trim(); } else { return new CopyResult(1, "", srcFile + " does not contain full path to the file. Please provide full path. "); } } else { if (srcFile.contains(",")) { srcFileList = srcFile.split(","); srcFile_list = new String[srcFileList.length]; for (int count = 0; count < srcFileList.length; count++) { if ((srcFileList[count].trim()).startsWith("/")) { srcFile_list[count] = srcFileList[count].trim(); } else { warn.append(srcFile_list[count].trim() + " "); if (!warn_flag) warn_flag = true; } } } } if (warn_flag) { warn.append(" does not contain full path to the source file. Please provide full path. "); warn_flag = false; } try { cmd.append("bbcp "); cmd.append(cmdLineOptions); // Review - Check if cmdLineOptions // already has a -z******************#DONE if (!(cmdLineOptions.equals("-z"))) {// dealing with firewall cmd.append(" -z "); } // BBCP does not handle error when directory is specified without // recursive flag. // Better to have recursive always on, rather than giving out wrong // output. cmd.append("-r "); if (!protocolPathSrc.equals("")) { cmd.append("-S \"ssh -l %U %H "); cmd.append(protocolPathSrc); cmd.append("bbcp\" "); } if (!protocolPathDest.equals("")) { cmd.append("-T \"ssh -l %U %H "); cmd.append(protocolPathDest); cmd.append("bbcp\" "); } cmd.append(srcDetails.toString()); cmd.append(":"); for (int i = 0; i < srcFile_list.length; i++) { if (srcFile_list[i].contains("*") || (srcFile_list[i].contains("+"))) { // BBCP cannot handle wildcard pattern * if copy is // being done from destination to source. We need // function to list files matching the pattern System.out.println("wildcard found in filename :" + srcFile_list[i]); wildcardFileList = sshObject.getwildcardFileListingBBCP(srcDetails.toString(), srcFile_list[i]); cmd.append(wildcardFileList); } else { // quotes if file contains wildcard - it might contain space // in file name cmd.append(srcDetails.toString()); cmd.append(":"); cmd.append("\""); cmd.append(srcFile_list[i]); cmd.append("\""); cmd.append(" "); } } cmd.append(" "); cmd.append(destFile);// Review - check if dest is // dir**********#DONE, Checked earlier if (protocolPathDest.equals("")) { cmdWithPath = getCmdWithDefaultPath(cmd); } else { cmdWithPath = protocolPathDest + cmd; } // Execute bbcp command if (isDebugging) log.debug("copy cmd=" + cmdWithPath); System.out.println("BBCP command is : " + cmdWithPath); exitCode = localSshObj.executeCmd(cmdWithPath, streamOut, streamErr, srcDetails.toString()); } catch (Exception e) { return new CopyResult(1, e.toString(), ""); } if (exitCode > 0) { log.error("Output on stdout:" + streamOut); log.error("Output on stderr:" + streamErr); } String message = streamErr.toString(); if (message == null || message.trim().equals("")) { message = streamOut.toString(); } return new CopyResult(exitCode, message, warn.toString()); }
From source file:com.amalto.core.query.StorageQueryTest.java
License:asdf
public void testFetchAllE1ByAliasI() { UserQueryBuilder qb = from(e1);//from ww w. ja va 2 s . c o m qb.selectId(e1); qb.select(e1, "../../i"); qb.select(e1, "name"); StorageResults results = storage.fetch(qb.getSelect()); assertEquals(3, results.getCount()); DataRecordWriter writer = new DataRecordWriter() { @Override public void write(DataRecord record, OutputStream output) throws IOException { Writer out = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); //$NON-NLS-1$ write(record, out); } @Override public void write(DataRecord record, Writer writer) throws IOException { writer.write("<result>"); //$NON-NLS-1$ for (FieldMetadata fieldMetadata : record.getSetFields()) { Object value = record.get(fieldMetadata); if (value != null) { writer.append("<").append(fieldMetadata.getName()).append(">"); writer.append(StringEscapeUtils.escapeXml(String.valueOf(value))); writer.append("</").append(fieldMetadata.getName()).append(">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } writer.append("</result>"); //$NON-NLS-1$ writer.flush(); } @Override public void setSecurityDelegator(SecuredStorage.UserDelegator delegator) { // Not needed for test. } }; Set<String> expectedStrings = new HashSet<String>(); expectedStrings.add( "<result><subelement>aaa</subelement><subelement1>bbb</subelement1><i>aaa</i><i>bbb</i><name>asdf</name></result>"); expectedStrings.add( "<result><subelement>ccc</subelement><subelement1>ddd</subelement1><i>ccc</i><i>ddd</i><name>cvcvc</name></result>"); expectedStrings.add( "<result><subelement>ttt</subelement><subelement1>yyy</subelement1><i>ttt</i><i>yyy</i><name>nhhn</name></result>"); for (DataRecord result : results) { ByteArrayOutputStream output = new ByteArrayOutputStream(); try { writer.write(result, output); } catch (IOException e) { throw new RuntimeException(e); } expectedStrings.remove(output.toString()); } assertTrue(expectedStrings.isEmpty()); }
From source file:org.sdm.spa.actors.transport.BbcpCopier.java
@Override protected CopyResult copyRemote(ConnectionDetails srcDetails, String srcFile, ConnectionDetails destDetails, String destFile, boolean recursive) throws ExecException { cmdLineOptions = ""; // Review - don't force overwrite***********#DONE if (isDebugging) log.debug("remote bbcp copy"); OutputStream cmdStdout = new ByteArrayOutputStream(); OutputStream cmdStderr = new ByteArrayOutputStream(); // OutputStream streamOut = new ByteArrayOutputStream(); // OutputStream streamErr = new ByteArrayOutputStream(); String remoteHostStr = ""; SshExec sshObjectSrc = null;// ww w . jav a2s . c o m SshExec sshObjectDest = null; // File single_srcFileObj = null; // File srcFile_Obj = null; // File srcFileObjlst = null; // boolean flag = false; String[] srcFileList = null; String[] srcFile_list = null; String wildcardFileList = ""; StringBuffer warn = new StringBuffer(100); boolean warn_flag = false; // bbcp needs pseudo terminal enabled, so that password request is sent // to stdout instead of terminal // source connection object sshObjectSrc = new SshExec(srcDetails.getUser(), srcDetails.getHost(), srcDetails.getPort()); sshObjectSrc.setTimeout(timeout, false, false); sshObjectSrc.setForcedCleanUp(forcedCleanup); sshObjectSrc.setPseudoTerminal(true); // destination connection object sshObjectDest = new SshExec(destDetails.getUser(), destDetails.getHost(), destDetails.getPort()); sshObjectDest.setTimeout(timeout, false, false); sshObjectDest.setForcedCleanUp(forcedCleanup); sshObjectDest.setPseudoTerminal(true); if (srcDetails.isConnectionOrigin()) { remoteHostStr = destDetails.toString(); } else { remoteHostStr = srcDetails.toString(); } StringBuffer cmd = new StringBuffer(100); String cmdWithPath = null; int exitCode = 0; if (srcFile.contains(",")) { // list of files srcFileList = srcFile.split(","); srcFile_list = new String[srcFileList.length]; for (int count = 0; count < srcFileList.length; count++) { if ((srcFileList[count].trim()).startsWith("/")) { srcFile_list[count] = srcFileList[count].trim(); } else { warn.append(srcFileList[count].trim() + " "); if (!warn_flag) warn_flag = true; } } if (warn_flag) { warn.append(" does not contain full path to the source file. Please provide full path. "); warn_flag = false; } } else { // single file if (srcFile.startsWith("/")) { srcFile_list = new String[1]; srcFile_list[0] = srcFile.trim(); } else { throw new SshException( srcFile + "does not contain full path to the file. Please provide full path."); } } // build bbcp command try { cmd.append("bbcp "); cmd.append(cmdLineOptions); if (!srcDetails.isConnectionOrigin()) { // -z option for destination to source copy cmd.append(" -z "); } // if (recursive) { // BBCP does not handle error when directory is specified without // recursive flag. // Better to have recursive always on, rather than giving out wrong // output. cmd.append("-r "); // } log.debug("Protocol path src =" + protocolPathSrc); if (!protocolPathSrc.equals("")) { cmd.append("-S \"ssh -l %U %H "); cmd.append(protocolPathSrc); cmd.append("bbcp\" "); } if (!protocolPathDest.equals("")) { cmd.append("-T \"ssh -l %U %H "); cmd.append(protocolPathDest); cmd.append("bbcp\" "); } if (srcDetails.isConnectionOrigin()) { // BBCP can handle wildcard pattern * if copy is done // from source machine to destination machine for (int i = 0; i < srcFile_list.length; i++) { if (srcFile_list[i].contains("*") || (srcFile_list[i].contains("+"))) { cmd.append(srcFile_list[i]); cmd.append(" "); } else { cmd.append("\""); cmd.append(srcFile_list[i]); cmd.append("\""); cmd.append(" "); } } cmd.append(destDetails.toString()); cmd.append(":"); cmd.append(destFile); } else { for (int i = 0; i < srcFile_list.length; i++) { // BBCP cannot handle wildcard pattern * if copy is // being done from destination to source. We need // function to list files matching the pattern if (srcFile_list[i].contains("*") || (srcFile_list[i].contains("+"))) { wildcardFileList = sshObjectSrc.getwildcardFileListingBBCP(srcDetails.toString(), srcFile_list[i]); cmd.append(wildcardFileList); } else { cmd.append(srcDetails.toString()); cmd.append(":"); cmd.append("\""); cmd.append(srcFile_list[i]); cmd.append("\""); cmd.append(" "); } } // cmd.append(destDetails.toString()); // cmd.append(":"); cmd.append(destFile); } if (protocolPathDest.equals("")) { cmdWithPath = getCmdWithDefaultPath(cmd); } else { cmdWithPath = protocolPathDest + cmd; } log.debug("copy cmd without default path=" + cmd); if (isDebugging) log.debug("remote copy cmd=" + cmdWithPath); System.out.println("cmdwithpath : " + cmdWithPath); if (srcDetails.isConnectionOrigin()) { exitCode = sshObjectSrc.executeCmd(cmdWithPath, cmdStdout, cmdStderr, remoteHostStr); } else { exitCode = sshObjectDest.executeCmd(cmdWithPath, cmdStdout, cmdStderr, remoteHostStr); } } catch (ExecException e) { return new CopyResult(1, e.toString(), ""); } if (exitCode > 0) { log.error("Output on stdout:" + cmdStdout); log.error("Output on stderr:" + cmdStderr); } String message = cmdStderr.toString(); if (message == null || message.trim().equals("")) { message = cmdStdout.toString(); } return new CopyResult(exitCode, message, warn.toString()); }
From source file:org.jahia.services.content.nodetypes.NodeTypesChangesIT.java
private void checkOperations(final VersionInfo versionInfo, final ModificationInfo modificationInfo, Map<Operation, Boolean> expectedResults) { final String unchangedProperty = "stable"; final String nodePath = versionInfo.getTestNodePath(); final String versionName = versionInfo.getVersionName(); List<Result> resultsForModification = new ArrayList<>(); // get node/*from ww w . j ava2s . co m*/ resultsForModification.addAll(doOperation(Operation.GET_NODE, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { session.getNode(nodePath); return Collections.emptyList(); } })); if (modificationInfo.getChildNodeType() != null) { // get child nodes resultsForModification .addAll(doOperation(Operation.GET_CHILD_NODES, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { JCRNodeIteratorWrapper it = session.getNode(nodePath).getNodes(); int i = 0; while (it.hasNext()) { it.nextNode(); i++; } if (i < 3) { throw new ItemNotFoundException("Child node is missing"); } return Collections.emptyList(); } })); } //export final OutputStream exportOutputStream = new StringOutputStream(); final List<Result> exportNodeResults = doOperation(Operation.EXPORT_NODE, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { HashMap<String, Object> params = new HashMap<>(); ImportExportBaseService.getInstance().exportNode(session.getNode(nodePath), session.getNode("/"), exportOutputStream, params); return Collections.emptyList(); } }); resultsForModification.addAll(exportNodeResults); // copy node resultsForModification.addAll(doOperation(Operation.COPY_NODE, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { List<Result> results = new ArrayList<>(); JCRNodeWrapper nread = session.getNode(nodePath); if (!nread.copy(session.getNodeByIdentifier(testNodeIdentifier), "test-copy", false)) { throw new RepositoryException("copy was not successful"); } else if (modificationInfo.getChildNodeType() != null) { results.add(new Result(Operation.COPY_NODE, modificationInfo, true)); try { JCRNodeIteratorWrapper it = session.getNodeByIdentifier(testNodeIdentifier) .getNode("test-copy").getNodes(); int i = 0; while (it.hasNext()) { it.nextNode(); i++; } if (i < 3) { results.add(new Result(Operation.CHECK_COPIED_CHILD_NODES, modificationInfo, false, "Copied child nodes are missing")); } else { results.add(new Result(Operation.CHECK_COPIED_CHILD_NODES, modificationInfo, true)); } } catch (RepositoryException ex) { results.add(new Result(Operation.CHECK_COPIED_CHILD_NODES, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.CHECK_COPIED_CHILD_NODES + " after " + modificationInfo.getModificationDescription(), ex); } } return results; } })); // read property resultsForModification .addAll(doOperation(Operation.READ_PROPERTIES, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { List<Result> results = new ArrayList<>(); JCRNodeWrapper nread = session.getNode(nodePath); try { String s = nread.getProperty(unchangedProperty).getValue().getString(); results.add(new Result(Operation.READ_STABLE_PROPERTY_VALUE, modificationInfo, "test".equals(s))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_STABLE_PROPERTY_VALUE, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_STABLE_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } try { String s = nread.getProperty("test").getValue().getString(); results.add(new Result(Operation.READ_STRING_PROPERTY_VALUE, modificationInfo, "test".equals(s))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_STRING_PROPERTY_VALUE, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_STRING_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } try { boolean isMultiple = nread.getProperty("test_multiple").getDefinition().isMultiple(); boolean b = true; if (isMultiple) { for (Value v : nread.getProperty("test_multiple").getValues()) { b &= "test".equals(v.getString()); } } else { String s = nread.getProperty("test").getValue().getString(); b = s.equals("test"); } results.add(new Result(Operation.READ_MULTIPLE_PROPERTY_VALUE, modificationInfo, b)); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_MULTIPLE_PROPERTY_VALUE, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_MULTIPLE_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } try { String s = nread.getProperty("test_i18n").getValue().getString(); results.add(new Result(Operation.READ_I18N_PROPERTY_VALUE, modificationInfo, "test".equals(s))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_I18N_PROPERTY_VALUE, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_I18N_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } try { String s = nread.getProperty("decimalNumber").getValue().getString(); results.add(new Result(Operation.READ_DECIMAL_PROPERTY_VALUE, modificationInfo, "2.5".equals(s))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_DECIMAL_PROPERTY_VALUE, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_DECIMAL_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } try { String s = nread.getProperty("integer").getValue().getString(); results.add(new Result(Operation.READ_INTEGER_PROPERTY_VALUE, modificationInfo, "10".equals(s))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_INTEGER_PROPERTY_VALUE, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_INTEGER_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } try { Node node = nread.getProperty("reference").getValue().getNode(); results.add(new Result(Operation.READ_REFERENCE_PROPERTY_VALUE, modificationInfo, testNodeIdentifier.equals(node.getIdentifier()))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_REFERENCE_PROPERTY_VALUE, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_REFERENCE_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } if (modificationInfo.getChildNodeType() != null) { try { JCRNodeIteratorWrapper it = nread.getNodes(); String childNodeProperty = StringUtils .isNotBlank(modificationInfo.getChildNodeProperty()) ? modificationInfo.getChildNodeProperty() : "text"; int i = 0; boolean expectedTextFound = true; while (it.hasNext()) { Node childNode = it.nextNode(); i++; String expectedValue = StringUtils .isNotBlank(modificationInfo.getChildNodePropertyValue()) ? modificationInfo.getChildNodePropertyValue() : childNode.getName(); expectedTextFound = expectedTextFound && expectedValue.equals( childNode.getProperty(childNodeProperty).getValue().getString()); } if (i == 3 && expectedTextFound) { results.add( new Result(Operation.READ_CHILD_PROPERTIES, modificationInfo, true)); } else { results.add(new Result(Operation.READ_CHILD_PROPERTIES, modificationInfo, false, "Expected text not found in childnodes")); } } catch (RepositoryException ex) { results.add(new Result(Operation.READ_CHILD_PROPERTIES, modificationInfo, false, ex.toString())); logger.info("unable to perform " + Operation.READ_CHILD_PROPERTIES + " after " + modificationInfo.getModificationDescription(), ex); } } return results; } })); // edit property resultsForModification .addAll(doOperation(Operation.EDIT_PROPERTY, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { List<Result> results = new ArrayList<>(); try { editProperty(session, unchangedProperty); results.add(new Result(Operation.EDIT_PROPERTY, modificationInfo, true)); } catch (RepositoryException ex) { results.add( new Result(Operation.EDIT_PROPERTY, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.EDIT_PROPERTY + " after " + modificationInfo.getModificationDescription(), ex); } if (StringUtils.isNotEmpty(modificationInfo.getChangedProperty())) { try { editProperty(session, modificationInfo.getChangedProperty()); results.add(new Result(Operation.EDIT_CHANGED_PROPERTY, modificationInfo, true)); } catch (RepositoryException ex) { results.add(new Result(Operation.EDIT_CHANGED_PROPERTY, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.EDIT_CHANGED_PROPERTY + " after " + modificationInfo.getModificationDescription(), ex); } } return results; } private void editProperty(final JCRSessionWrapper session, final String propertyToTest) throws Exception { JCRNodeWrapper nread = session.getNode(nodePath); boolean isMultiple = nread.hasProperty(propertyToTest) ? nread.getProperty(propertyToTest).getDefinition().isMultiple() : false; if (isMultiple) { nread.setProperty(propertyToTest, new String[] { "100" }); } else if ("reference".equals(propertyToTest)) { nread.setProperty(propertyToTest, nread.getNodes().iterator().next()); } else { nread.setProperty(propertyToTest, "100"); } session.save(); } })); // remove property resultsForModification .addAll(doOperation(Operation.REMOVE_PROPERTY, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { List<Result> results = new ArrayList<>(); JCRNodeWrapper nread = session.getNode(nodePath); try { nread.getProperty(unchangedProperty).remove(); session.save(); results.add(new Result(Operation.REMOVE_PROPERTY, modificationInfo, true)); } catch (RepositoryException ex) { results.add( new Result(Operation.REMOVE_PROPERTY, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.REMOVE_PROPERTY + " after " + modificationInfo.getModificationDescription(), ex); } if (StringUtils.isNotEmpty(modificationInfo.getChangedProperty())) { try { nread.getProperty(modificationInfo.getChangedProperty()).remove(); session.save(); results.add(new Result(Operation.REMOVE_CHANGED_PROPERTY, modificationInfo, true)); } catch (RepositoryException ex) { results.add(new Result(Operation.REMOVE_CHANGED_PROPERTY, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.REMOVE_CHANGED_PROPERTY + " after " + modificationInfo.getModificationDescription(), ex); } } return results; } })); if (StringUtils.isNotBlank(modificationInfo.getChildNodeType())) { //add child node resultsForModification .addAll(doOperation(Operation.ADD_CHILD_NODE, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { JCRNodeWrapper nread = session.getNode(nodePath); JCRNodeWrapper addedNode = nread.addNode("addedChildNode", modificationInfo.getChildNodeType()); addedNode.setProperty("text", "added text"); session.save(); return Collections.emptyList(); } })); if (expectedResults.containsKey(Operation.CHECK_MIXIN)) { resultsForModification .addAll(doOperation(Operation.CHECK_MIXIN, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { List<Result> results = new ArrayList<>(); JCRNodeWrapper nread = session.getNode(nodePath); JCRNodeIteratorWrapper it = nread.getNodes(); boolean expectedMixinFound = true; while (it.hasNext()) { Node childNode = it.nextNode(); expectedMixinFound = expectedMixinFound && childNode.isNodeType(modificationInfo.getChildNodeMixin()); } results.add( new Result(Operation.CHECK_MIXIN, modificationInfo, expectedMixinFound)); return Collections.emptyList(); } })); } } //restore version resultsForModification .addAll(doOperation(Operation.RESTORE_VERSION, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { List<Result> results = new ArrayList<>(); session.getWorkspace().getVersionManager().checkout(nodePath); session.getWorkspace().getVersionManager().restore(nodePath, versionName, true); session.save(); results.add(new Result(Operation.RESTORE_VERSION, modificationInfo, true)); JCRNodeWrapper nread = session.getNode(nodePath); try { JCRPropertyWrapper property = nread.getProperty(unchangedProperty); String s = property.getDefinition().isMultiple() ? property.getValues()[0].getString() : property.getValue().getString(); results.add(new Result(Operation.READ_RESTORED_PROPERTY_VALUE, modificationInfo, "new value".equals(s))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_RESTORED_PROPERTY_VALUE, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.READ_RESTORED_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } if (StringUtils.isNotEmpty(modificationInfo.getChangedProperty())) { try { JCRPropertyWrapper property = nread .getProperty(modificationInfo.getChangedProperty()); if ("reference".equals(modificationInfo.getChangedProperty())) { results.add(new Result(Operation.READ_CHANGED_RESTORED_PROPERTY_VALUE, modificationInfo, testNodeIdentifier.equals(property.getNode().getIdentifier()))); } else { String s = property.getDefinition().isMultiple() ? property.getValues()[0].getString() : property.getValue().getString(); results.add(new Result(Operation.READ_CHANGED_RESTORED_PROPERTY_VALUE, modificationInfo, "new value".equals(s))); } } catch (RepositoryException ex) { results.add(new Result(Operation.READ_CHANGED_RESTORED_PROPERTY_VALUE, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.READ_CHANGED_RESTORED_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } } return results; } })); if (modificationInfo.getChildNodeType() != null) { // remove child node resultsForModification .addAll(doOperation(Operation.REMOVE_CHILD_NODE, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { session.getWorkspace().getVersionManager().checkout(nodePath); JCRNodeWrapper nread = session.getNode(nodePath).getNodes().iterator().next(); nread.remove(); session.save(); return Collections.emptyList(); } })); } // remove node resultsForModification .addAll(doOperation(Operation.REMOVE_NODE, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { JCRNodeWrapper nread = session.getNode(nodePath); nread.remove(); session.save(); return Collections.emptyList(); } })); // import node if (exportNodeResults.get(0).result) { resultsForModification .addAll(doOperation(Operation.IMPORT_NODE, modificationInfo, nodePath, new CallBack() { @Override public List<Result> execute(final JCRSessionWrapper session) throws Exception { List<Result> results = new ArrayList<>(); ByteArrayInputStream stream = new ByteArrayInputStream( exportOutputStream.toString().getBytes(StandardCharsets.UTF_8)); JCRNodeWrapper importFolder = session.getNode("/").addNode("nodeTypesImported", "nt:unstructured"); session.save(); ImportExportBaseService.getInstance().importXML(importFolder.getPath(), stream, DocumentViewImportHandler.ROOT_BEHAVIOUR_IGNORE); JCRNodeWrapper nread = importFolder.getNode("nodeTypeChanges/test"); results.add(new Result(Operation.IMPORT_NODE, modificationInfo, true)); try { String s = nread.getProperty(unchangedProperty).getValue().getString(); results.add(new Result(Operation.READ_IMPORTED_PROPERTY_VALUE, modificationInfo, "test".equals(s))); } catch (RepositoryException ex) { results.add(new Result(Operation.READ_IMPORTED_PROPERTY_VALUE, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.READ_IMPORTED_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } if (StringUtils.isNotEmpty(modificationInfo.getChangedProperty())) { try { if ("reference".equals(modificationInfo.getChangedProperty())) { results.add( new Result(Operation.READ_CHANGED_IMPORTED_PROPERTY_VALUE, modificationInfo, testNodeIdentifier.equals(nread .getProperty(modificationInfo.getChangedProperty()) .getNode().getIdentifier()))); } else { String s = nread.getProperty(modificationInfo.getChangedProperty()) .getValue().getString(); results.add(new Result(Operation.READ_CHANGED_IMPORTED_PROPERTY_VALUE, modificationInfo, "test".equals(s))); } } catch (RepositoryException ex) { results.add(new Result(Operation.READ_CHANGED_IMPORTED_PROPERTY_VALUE, modificationInfo, false, ex.toString())); session.refresh(false); logger.info( "unable to perform " + Operation.READ_CHANGED_IMPORTED_PROPERTY_VALUE + " after " + modificationInfo.getModificationDescription(), ex); } } if (modificationInfo.getChildNodeType() != null) { try { JCRNodeIteratorWrapper it = nread.getNodes(); int i = 0; while (it.hasNext()) { it.nextNode(); i++; } if (i == 3) { results.add(new Result(Operation.READ_IMPORTED_CHILD_NODES, modificationInfo, true)); } else { results.add( new Result(Operation.READ_IMPORTED_CHILD_NODES, modificationInfo, false, "Unexpected number of imported child nodes: " + i)); } } catch (RepositoryException ex) { results.add(new Result(Operation.READ_IMPORTED_CHILD_NODES, modificationInfo, false, ex.toString())); session.refresh(false); logger.info("unable to perform " + Operation.READ_IMPORTED_CHILD_NODES + " after " + modificationInfo.getModificationDescription(), ex); } } return results; } })); } overallResults.addAll(resultsForModification); SoftAssertions softly = new SoftAssertions(); for (Result result : resultsForModification) { softly.assertThat(result.result) .describedAs(result.modificationInfo.getModificationDescription() + " - " + result.operation) .isEqualTo(expectedResults.get(result.operation)); } softly.assertAll(); }