Skip to content

Commit

Permalink
add JUnits for author mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DunaMariusCosmin committed Oct 31, 2017
1 parent dcc8a1f commit 7751cbd
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 167 deletions.
9 changes: 0 additions & 9 deletions src/main/java/com/oxygenxml/prolog/updater/DitaUpdater.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package com.oxygenxml.prolog.updater;

import com.ibm.icu.text.IDNA.Info;
import com.oxygenxml.prolog.updater.dita.editor.DitaTopicAuthorEditor;
import com.oxygenxml.prolog.updater.dita.editor.DitaTopicEditor;
import com.oxygenxml.prolog.updater.dita.editor.DitaTopicTextEditor;

import ro.sync.ecss.extensions.api.AuthorReviewController;
import ro.sync.ecss.extensions.api.AuthorReviewerNameController;
import ro.sync.ecss.extensions.api.review.ReviewActionsProvider;
import ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension;
import ro.sync.exml.workspace.api.PluginWorkspace;
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
import ro.sync.exml.workspace.api.editor.WSEditor;
import ro.sync.exml.workspace.api.editor.page.WSEditorPage;
import ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage;
import ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage;
import ro.sync.exml.workspace.api.options.WSOptionsStorage;
import ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace;

/**
* Update the prolog in DITA topics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,28 +195,30 @@ private void updateCritdatesElements(AuthorElement authorPrologElement, boolean

if (reviDateElementsLength == 0) {
addXmlFragment(prologContentCreater.getResivedModifiedXmlFragment(), critdatesElements[0].getEndOffset());

} else {
boolean localDateWithAuthorExist = false;
//Iterate over revised elements
for (int i = 0; i < reviDateElementsLength; i++) {
AuthorElement curentRevisedElement = reviDateElements[i];

//check the modified value.
String currentModifiedDate = curentRevisedElement.getAttribute("modified").getRawValue();
if (prologContentCreater.getLocalDate().equals(currentModifiedDate)) {

//check the comment
int currentElemetStartOffSet = curentRevisedElement.getStartOffset();
AuthorNode anteriorNode;
try {
anteriorNode = documentController.getNodeAtOffset(currentElemetStartOffSet - 1);

System.out.println("anterior node: " + anteriorNode);
if (anteriorNode.getType() == AuthorNode.NODE_TYPE_COMMENT) {
if (prologContentCreater.getAuthor().equals(anteriorNode.getTextContent())) {
localDateWithAuthorExist = true;
break;
}
}
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Expand Down Expand Up @@ -323,7 +325,7 @@ private AuthorElement getPrologAnteriorAuthorElement(AuthorElement rootElement)
AttrValue attribute = authorElement.getAttribute("class");

//if value of attribute contains ANTERIOR_NODE_CLASS_VALUE
if (attribute.toString().contains(ANTERIOR_NODE_CLASS_VALUE)) {
if (attribute.toString().contains(FOLLOWING_NODE_CLASS_VALUE)) {
// anterior node was found
return authorElement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface DitaTopicEditor {
/**
* Class's value of prolog anterior note.
*/
final String ANTERIOR_NODE_CLASS_VALUE = "topic/body";
final String FOLLOWING_NODE_CLASS_VALUE = "topic/body";

/**
* Update the prolog in DITA topic document according to given flag(isNewDocument)
Expand Down
51 changes: 0 additions & 51 deletions src/test/java/InexistentPrologTagText1.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DitaUpdateTestUtil extends TestCase{
* @throws SAXException
* @throws BadLocationException
*/
public static void testAuthorMode(String inputXML, boolean isNewDocument, String expectedXML) throws IOException, SAXException, BadLocationException{
public static void testInAuthorMode(String inputXML, boolean isNewDocument, String expectedXML) throws IOException, SAXException, BadLocationException{
//
//Create a AuthorDocumentController
//
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import org.xml.sax.SAXException;

public class DitaUpdaterWithAuthorTest {
import junit.framework.TestCase;

public class DitaUpdaterAuthorTest extends TestCase{

/**
* Test if the author tag is correct modified after save operation.
Expand Down Expand Up @@ -74,10 +76,10 @@ public void testUpdateAuthorInProlog() throws IOException, SAXException, BadLoca
" ";

// test when document is new
DitaUpdateTestUtil.testAuthorMode(xmlWithCreator, true, expectedNewXMLWithCreator);
DitaUpdateTestUtil.testInAuthorMode(xmlWithCreator, true, expectedNewXMLWithCreator);

//test when document isn't new
DitaUpdateTestUtil.testAuthorMode(xmlWithCreator, false , expectedOldXmlWithCreator);
DitaUpdateTestUtil.testInAuthorMode(xmlWithCreator, false , expectedOldXmlWithCreator);



Expand Down Expand Up @@ -129,10 +131,10 @@ public void testUpdateAuthorInProlog() throws IOException, SAXException, BadLoca
" ";

// test when document is new
DitaUpdateTestUtil.testAuthorMode(xmlWithContributor, true, expectedNewXMLWithContributor);
DitaUpdateTestUtil.testInAuthorMode(xmlWithContributor, true, expectedNewXMLWithContributor);

//test when document isn't new
DitaUpdateTestUtil.testAuthorMode(xmlWithContributor, false , expectedOldXmlWithContributor);
DitaUpdateTestUtil.testInAuthorMode(xmlWithContributor, false , expectedOldXmlWithContributor);



Expand Down Expand Up @@ -176,7 +178,7 @@ public void testUpdateAuthorInProlog() throws IOException, SAXException, BadLoca
" ";

// test when document isn't new
DitaUpdateTestUtil.testAuthorMode(xmlWithDifferentContributor, false, expectedOldXmlWithDifferentContributor);
DitaUpdateTestUtil.testInAuthorMode(xmlWithDifferentContributor, false, expectedOldXmlWithDifferentContributor);

}

Expand Down
Loading

0 comments on commit 7751cbd

Please sign in to comment.