You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2019/02/27 12:40:24 UTC

[sling-org-apache-sling-distribution-core] branch master updated: SLING-4075 - Improve test coverage of SCD

This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 35f0a7d  SLING-4075 - Improve test coverage of SCD
35f0a7d is described below

commit 35f0a7d10f024e06f5c765b3e1512a6685d91599
Author: tmaret <tm...@adobe.com>
AuthorDate: Wed Feb 27 13:35:02 2019 +0100

    SLING-4075 - Improve test coverage of SCD
    
    * Add RequestUtils unit test coverage
---
 .../sling/distribution/util/RequestUtilsTest.java  | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src/test/java/org/apache/sling/distribution/util/RequestUtilsTest.java b/src/test/java/org/apache/sling/distribution/util/RequestUtilsTest.java
new file mode 100644
index 0000000..7b42b5d
--- /dev/null
+++ b/src/test/java/org/apache/sling/distribution/util/RequestUtilsTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.distribution.util;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.distribution.DistributionRequest;
+import org.apache.sling.distribution.DistributionRequestType;
+import org.junit.Test;
+
+import static org.apache.sling.distribution.util.RequestUtils.fromServletRequest;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class RequestUtilsTest {
+
+    private DistributionRequestType REQ_TYPE = DistributionRequestType.ADD;
+
+    private String[] P_PATHS = {"/some/path"};
+
+    private String[] EMPTY_PATHS = {};
+
+    @Test
+    public void testFromServletRequest() throws Exception {
+        DistributionRequest dr = fromServletRequest(buildServletRequest(REQ_TYPE.toString(), P_PATHS, "true"));
+        assertEquals(REQ_TYPE, dr.getRequestType());
+        assertArrayEquals(P_PATHS, dr.getPaths());
+    }
+
+    @Test
+    public void testFromServletRequestEmptyPath() throws Exception {
+        DistributionRequest dr = fromServletRequest(buildServletRequest(REQ_TYPE.toString(), null, "true"));
+        assertEquals(REQ_TYPE, dr.getRequestType());
+        assertArrayEquals(EMPTY_PATHS, dr.getPaths());
+    }
+
+    private HttpServletRequest buildServletRequest(String action, String[] paths, String deep) {
+        HttpServletRequest request = mock(HttpServletRequest.class);
+        when(request.getParameter("action"))
+                .thenReturn(action);
+        when(request.getParameterValues("path"))
+                .thenReturn(paths);
+        when(request.getParameter("deep"))
+                .thenReturn(deep);
+        return request;
+
+    }
+}
\ No newline at end of file