Michiel Rop pushed to branch feature/projectdocs at cms-community / 
hippo-addon-channel-manager


Commits:
06452ec0 by Michiel Rop at 2017-11-06T21:08:45+01:00
CHANNELMGR-1559 Account for the 'drop' of contextPayload and 
'active project' logic

- copyToPreviewAndKeepEditing does not throw exception (anymore)
- check if Object wrapped by optional is present
- fix imports

- - - - -


3 changed files:

- 
content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java
- 
content-service/src/test/java/org/onehippo/cms/channelmanager/content/ContentResourceTest.java
- 
content-service/src/test/java/org/onehippo/cms/channelmanager/content/document/util/EditingUtilsTest.java


Changes:

=====================================
content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java
=====================================
--- 
a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java
+++ 
b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/document/DocumentsServiceImpl.java
@@ -130,8 +130,7 @@ public class DocumentsServiceImpl implements 
DocumentsService {
             throw new BadRequestException(document);
         }
 
-        editingUtils.copyToPreviewAndKeepEditing(workflow, session)
-                .orElseThrow(() -> new 
InternalServerErrorException(errorInfoFromHintsOrNoHolder(workflow, session)));
+        editingUtils.copyToPreviewAndKeepEditing(workflow, session);
 
         FieldTypeUtils.readFieldValues(draft, docType.getFields(), 
document.getFields());
 


=====================================
content-service/src/test/java/org/onehippo/cms/channelmanager/content/ContentResourceTest.java
=====================================
--- 
a/content-service/src/test/java/org/onehippo/cms/channelmanager/content/ContentResourceTest.java
+++ 
b/content-service/src/test/java/org/onehippo/cms/channelmanager/content/ContentResourceTest.java
@@ -29,7 +29,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.onehippo.cms.channelmanager.content.document.DocumentsService;
-import org.onehippo.cms.channelmanager.content.document.DocumentsServiceImpl;
 import org.onehippo.cms.channelmanager.content.document.model.Document;
 import 
org.onehippo.cms.channelmanager.content.documenttype.DocumentTypesService;
 import org.onehippo.cms.channelmanager.content.documenttype.model.DocumentType;


=====================================
content-service/src/test/java/org/onehippo/cms/channelmanager/content/document/util/EditingUtilsTest.java
=====================================
--- 
a/content-service/src/test/java/org/onehippo/cms/channelmanager/content/document/util/EditingUtilsTest.java
+++ 
b/content-service/src/test/java/org/onehippo/cms/channelmanager/content/document/util/EditingUtilsTest.java
@@ -19,6 +19,7 @@ package org.onehippo.cms.channelmanager.content.document.util;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -145,9 +146,15 @@ public class EditingUtilsTest {
         expect(workflow.hints()).andReturn(hints);
         replay(workflow);
 
-        final ErrorInfo errorInfo = 
editingUtils.determineEditingFailure(workflow, session).get();
-        assertThat(errorInfo.getReason(), 
equalTo(ErrorInfo.Reason.REQUEST_PENDING));
-        assertNull(errorInfo.getParams());
+        final Optional<ErrorInfo> errorInfoOptional = 
editingUtils.determineEditingFailure(workflow, session);
+        assertThat("Errorinfo should be 
present",errorInfoOptional.isPresent());
+        if (errorInfoOptional.isPresent()){
+            final ErrorInfo errorInfo = errorInfoOptional.get();
+            assertThat(errorInfo.getReason(), 
equalTo(ErrorInfo.Reason.REQUEST_PENDING));
+            assertNull(errorInfo.getParams());
+        }
+
+
 
         verify(workflow);
     }
@@ -170,10 +177,15 @@ public class EditingUtilsTest {
         expect(user.getLastName()).andReturn(" Doe ");
         replay(workflow, session, workspace, securityService, user);
 
-        final ErrorInfo errorInfo = 
editingUtils.determineEditingFailure(workflow, session).get();
-        assertThat(errorInfo.getReason(), 
equalTo(ErrorInfo.Reason.OTHER_HOLDER));
-        assertThat(errorInfo.getParams().get("userId"), equalTo("admin"));
-        assertThat(errorInfo.getParams().get("userName"), equalTo("John Doe"));
+        final Optional<ErrorInfo> errorInfoOptional = 
editingUtils.determineEditingFailure(workflow, session);
+        assertThat("Errorinfo should be 
present",errorInfoOptional.isPresent());
+        if (errorInfoOptional.isPresent()){
+            final ErrorInfo errorInfo = errorInfoOptional.get();
+            assertThat(errorInfo.getReason(), 
equalTo(ErrorInfo.Reason.OTHER_HOLDER));
+            assertThat(errorInfo.getParams().get("userId"), equalTo("admin"));
+            assertThat(errorInfo.getParams().get("userName"), equalTo("John 
Doe"));
+        }
+
 
         verify(workflow, session, workspace, securityService, user);
     }
@@ -191,10 +203,14 @@ public class EditingUtilsTest {
         expect(workspace.getSecurityService()).andThrow(new 
RepositoryException());
         replay(workflow, session, workspace);
 
-        final ErrorInfo errorInfo = 
editingUtils.determineEditingFailure(workflow, session).get();
-        assertThat(errorInfo.getReason(), 
equalTo(ErrorInfo.Reason.OTHER_HOLDER));
-        assertThat(errorInfo.getParams().get("userId"), equalTo("admin"));
-        assertNull(errorInfo.getParams().get("userName"));
+        final Optional<ErrorInfo> errorInfoOptional = 
editingUtils.determineEditingFailure(workflow, session);
+        assertThat("Errorinfo should be 
present",errorInfoOptional.isPresent());
+        if (errorInfoOptional.isPresent()) {
+            final ErrorInfo errorInfo = errorInfoOptional.get();
+            assertThat(errorInfo.getReason(), 
equalTo(ErrorInfo.Reason.OTHER_HOLDER));
+            assertThat(errorInfo.getParams().get("userId"), equalTo("admin"));
+            assertNull(errorInfo.getParams().get("userName"));
+        }
 
         verify(workflow, session, workspace);
     }
@@ -210,7 +226,11 @@ public class EditingUtilsTest {
         expect(document.getNode(session)).andReturn(draft);
         replay(workflow, document);
 
-        assertThat(editingUtils.createDraft(workflow, session).get(), 
equalTo(draft));
+        final Optional<Node> draftOptional = 
editingUtils.createDraft(workflow, session);
+        assertThat("There should be a draft", draftOptional.isPresent());
+        if (draftOptional.isPresent()){
+            assertThat(draftOptional.get(), equalTo(draft));
+        }
 
         verify(workflow, document);
     }
@@ -255,7 +275,11 @@ public class EditingUtilsTest {
         expect(document.getNode(session)).andReturn(draft);
         replay(workflow, document);
 
-        assertThat(editingUtils.copyToPreviewAndKeepEditing(workflow, 
session).get(), equalTo(draft));
+        final Optional<Node> draftOptional = 
editingUtils.copyToPreviewAndKeepEditing(workflow, session);
+        assertThat("Draft should be present",draftOptional.isPresent());
+        if (draftOptional.isPresent()){
+            assertThat(draftOptional.get(), equalTo(draft));
+        }
 
         verify(workflow, document);
     }



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/06452ec012d4f0a10ee23f6f55cdbcc07191cb11

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/06452ec012d4f0a10ee23f6f55cdbcc07191cb11
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to