Peter Centgraf pushed to branch master at cms-community / hippo-configuration-management
Commits: 942071f3 by Peter Centgraf at 2017-12-29T10:08:27+01:00 HCM-240 Include type in ActionItemImpl.hashCode() and equals() - - - - - eb36465c by Peter Centgraf at 2018-02-06T17:07:16+01:00 HCM-240 Update ActionListParser to explicitly check path uniqueness - - - - - 9c8785a1 by Peter Centgraf at 2018-02-06T17:22:59+01:00 HCM-240 Update copyright year on changed files - - - - - dd00260b by Peter Centgraf at 2018-02-08T18:20:30+01:00 HCM-240 merge master - - - - - 7c962ae8 by Peter Centgraf at 2018-02-08T18:22:20+01:00 HCM-240 Update to use JcrPath in ActionListParser - - - - - d2ec5f86 by Peter Centgraf at 2018-02-08T18:22:57+01:00 HCM-240 reintegrate feature/HCM-240 - - - - - 3 changed files: - model/src/main/java/org/onehippo/cm/model/impl/definition/ActionItemImpl.java - model/src/main/java/org/onehippo/cm/model/parser/ActionListParser.java - model/src/test/java/org/onehippo/cm/model/parser/ActionListParserTest.java Changes: ===================================== model/src/main/java/org/onehippo/cm/model/impl/definition/ActionItemImpl.java ===================================== --- a/model/src/main/java/org/onehippo/cm/model/impl/definition/ActionItemImpl.java +++ b/model/src/main/java/org/onehippo/cm/model/impl/definition/ActionItemImpl.java @@ -49,12 +49,12 @@ public class ActionItemImpl implements ActionItem { return false; } final ActionItem that = (ActionItem) o; - return Objects.equals(path, that.getPath()); + return Objects.equals(type, that.getType()) && Objects.equals(path, that.getPath()); } @Override public int hashCode() { - return Objects.hash(path); + return Objects.hash(path, type); } @Override ===================================== model/src/main/java/org/onehippo/cm/model/parser/ActionListParser.java ===================================== --- a/model/src/main/java/org/onehippo/cm/model/parser/ActionListParser.java +++ b/model/src/main/java/org/onehippo/cm/model/parser/ActionListParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Hippo B.V. (http://www.onehippo.com) + * Copyright 2017,2018 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.onehippo.cm.model.parser; import java.io.InputStream; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -25,6 +26,7 @@ import org.onehippo.cm.model.definition.ActionItem; import org.onehippo.cm.model.definition.ActionType; import org.onehippo.cm.model.impl.ModuleImpl; import org.onehippo.cm.model.impl.definition.ActionItemImpl; +import org.onehippo.cm.model.path.JcrPath; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.nodes.Node; import org.yaml.snakeyaml.nodes.NodeTuple; @@ -67,12 +69,14 @@ public class ActionListParser extends AbstractBaseParser { protected Set<ActionItem> collectActionItems(final Node node) throws ParserException { final Set<ActionItem> actionItems = new LinkedHashSet<>(); + final Set<JcrPath> paths = new HashSet<>(); for (NodeTuple tuple : asTuples(node)) { final String path = asPathScalar(tuple.getKeyNode(), true, false); final ActionItem actionItem = asActionItem(tuple.getValueNode(), path); - if (!actionItems.add(actionItem)) { - throw new RuntimeException(String.format("Duplicate items are not allowed: %s", actionItem)); + if (!paths.add(actionItem.getPath())) { + throw new ParserException(String.format("Duplicate paths are not allowed in the same version: %s", actionItem.getPath())); } + actionItems.add(actionItem); } return actionItems; } @@ -81,7 +85,7 @@ public class ActionListParser extends AbstractBaseParser { String action = asStringScalar(node); ActionType type = ActionType.valueOf(StringUtils.upperCase(action)); if (type == ActionType.APPEND) { - throw new RuntimeException("APPEND action type can't be specified in action lists file"); + throw new ParserException("APPEND action type can't be specified in action lists file"); } return new ActionItemImpl(path, type); } ===================================== model/src/test/java/org/onehippo/cm/model/parser/ActionListParserTest.java ===================================== --- a/model/src/test/java/org/onehippo/cm/model/parser/ActionListParserTest.java +++ b/model/src/test/java/org/onehippo/cm/model/parser/ActionListParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Hippo B.V. (http://www.onehippo.com) + * Copyright 2017,2018 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,6 +63,37 @@ public class ActionListParserTest extends AbstractBaseTest { } @Test + public void expect_error_for_append_action() { + final String yaml = + "action-lists:\n" + + "- 1.0:\n" + + " /content/dup: append\n"; + + try { + parseActionMap(yaml); + fail("Expected exception"); + } catch (ParserException e) { + assertEquals("APPEND action type can't be specified in action lists file", e.getMessage()); + } + } + + @Test + public void expect_error_for_duplicate_path() { + final String yaml = + "action-lists:\n" + + "- 1.0:\n" + + " /content/dup: delete\n" + + " /content/dup: reload\n"; + + try { + parseActionMap(yaml); + fail("Expected exception"); + } catch (ParserException e) { + assertEquals("Duplicate paths are not allowed in the same version: /content/dup", e.getMessage()); + } + } + + @Test public void expect_error_when_using_not_absolute_path() { final String yaml = "action-lists:\n" + View it on GitLab: https://code.onehippo.org/cms-community/hippo-configuration-management/compare/872d2b3a0dfbaf888278f573170db78e9eb29514...d2ec5f869e2e00154634b55051e2ef1b76b88f3b --- View it on GitLab: https://code.onehippo.org/cms-community/hippo-configuration-management/compare/872d2b3a0dfbaf888278f573170db78e9eb29514...d2ec5f869e2e00154634b55051e2ef1b76b88f3b 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