You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2020/09/24 02:36:16 UTC
[sling-org-apache-sling-app-cms] branch master updated: Adding
tests for predicates
This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/master by this push:
new c866665 Adding tests for predicates
c866665 is described below
commit c8666652e26531443c743fa5a32a5164fae95a26
Author: Dan Klco <dk...@apache.org>
AuthorDate: Wed Sep 23 22:36:01 2020 -0400
Adding tests for predicates
---
.../IsPublishableResourceContainerTest.java | 61 ++++++++++++++++++++
.../publication/IsPublishableResourceTypeTest.java | 65 ++++++++++++++++++++++
2 files changed, 126 insertions(+)
diff --git a/api/src/test/java/org/apache/sling/cms/publication/IsPublishableResourceContainerTest.java b/api/src/test/java/org/apache/sling/cms/publication/IsPublishableResourceContainerTest.java
new file mode 100644
index 0000000..ca57718
--- /dev/null
+++ b/api/src/test/java/org/apache/sling/cms/publication/IsPublishableResourceContainerTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.cms.publication;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.CMSConstants;
+import org.apache.sling.jcr.resource.api.JcrResourceConstants;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class IsPublishableResourceContainerTest {
+
+ @Test
+ public void testTypes(){
+ IsPublishableResourceContainer predicate = new IsPublishableResourceContainer();
+ Resource folder = mockResource(JcrConstants.NT_FOLDER);
+ Resource slingFolder = mockResource(JcrResourceConstants.NT_SLING_FOLDER);
+ Resource orderedFolder = mockResource(JcrResourceConstants.NT_SLING_ORDERED_FOLDER);
+ Resource slingFile = mockResource(CMSConstants.NT_FILE);
+ Resource site = mockResource(CMSConstants.NT_SITE);
+ Resource page = mockResource(CMSConstants.NT_PAGE);
+ Resource config = mockResource(CMSConstants.NT_CONFIG);
+ Resource component = mockResource("a/resource/type");
+
+
+ assertFalse(predicate.test(null));
+ assertFalse(predicate.test(folder));
+ assertTrue(predicate.test(slingFolder));
+ assertTrue(predicate.test(orderedFolder));
+ assertTrue(predicate.test(slingFile));
+ assertTrue(predicate.test(site));
+ assertTrue(predicate.test(page));
+ assertFalse(predicate.test(config));
+ assertFalse(predicate.test(component));
+ }
+
+ public Resource mockResource(String type){
+ Resource resource = Mockito.mock(Resource.class);
+ Mockito.when(resource.getResourceType()).thenReturn(type);
+ return resource;
+ }
+
+}
diff --git a/api/src/test/java/org/apache/sling/cms/publication/IsPublishableResourceTypeTest.java b/api/src/test/java/org/apache/sling/cms/publication/IsPublishableResourceTypeTest.java
new file mode 100644
index 0000000..c3731d6
--- /dev/null
+++ b/api/src/test/java/org/apache/sling/cms/publication/IsPublishableResourceTypeTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.cms.publication;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.CMSConstants;
+import org.apache.sling.cms.ResourceTree;
+import org.apache.sling.jcr.resource.api.JcrResourceConstants;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class IsPublishableResourceTypeTest {
+
+ @Test
+ public void testTypes(){
+ IsPublishableResourceType predicate = new IsPublishableResourceType();
+ ResourceTree folder = mockResource(JcrConstants.NT_FOLDER);
+ ResourceTree slingFolder = mockResource(JcrResourceConstants.NT_SLING_FOLDER);
+ ResourceTree orderedFolder = mockResource(JcrResourceConstants.NT_SLING_ORDERED_FOLDER);
+ ResourceTree slingFile = mockResource(CMSConstants.NT_FILE);
+ ResourceTree site = mockResource(CMSConstants.NT_SITE);
+ ResourceTree page = mockResource(CMSConstants.NT_PAGE);
+ ResourceTree config = mockResource(CMSConstants.NT_CONFIG);
+ ResourceTree component = mockResource("a/resource/type");
+
+
+ assertFalse(predicate.test(null));
+ assertFalse(predicate.test(folder));
+ assertFalse(predicate.test(slingFolder));
+ assertFalse(predicate.test(orderedFolder));
+ assertTrue(predicate.test(slingFile));
+ assertFalse(predicate.test(site));
+ assertTrue(predicate.test(page));
+ assertFalse(predicate.test(config));
+ assertFalse(predicate.test(component));
+ }
+
+ public ResourceTree mockResource(String type){
+ Resource resource = Mockito.mock(Resource.class);
+ Mockito.when(resource.getResourceType()).thenReturn(type);
+
+ ResourceTree tree = Mockito.mock(ResourceTree.class);
+ Mockito.when(tree.getResource()).thenReturn(resource);
+ return tree;
+ }
+
+}