You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/12/11 13:38:10 UTC

[sling-org-apache-sling-committer-cli] 02/02: SLING-8864 - Report authentication errors immediately without looking at the response's body

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

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git

commit 59bd129e61683ec6ceb405cf0c9771e5b3ea7383
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Dec 11 14:37:49 2019 +0100

    SLING-8864 - Report authentication errors immediately without looking at the response's body
    
    * simplified HttpClientFactoryTest since the logic to work with test system properties
    was already available in SystemPropertiesRule
---
 .../sling/cli/impl/http/HttpClientFactoryTest.java | 30 ++++++------------
 .../sling/cli/impl/jira/VersionClientTest.java     |  1 +
 .../impl/{jira => junit}/SystemPropertiesRule.java | 36 ++++++++++++----------
 .../cli/impl/nexus/RepositoryServiceTest.java      |  2 +-
 .../cli/impl/pgp/PGPSignatureValidatorTest.java    |  2 +-
 5 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/src/test/java/org/apache/sling/cli/impl/http/HttpClientFactoryTest.java b/src/test/java/org/apache/sling/cli/impl/http/HttpClientFactoryTest.java
index e468314..d327203 100644
--- a/src/test/java/org/apache/sling/cli/impl/http/HttpClientFactoryTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/http/HttpClientFactoryTest.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.sling.cli.impl.CredentialsService;
+import org.apache.sling.cli.impl.junit.SystemPropertiesRule;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.After;
 import org.junit.Before;
@@ -40,27 +41,20 @@ import static org.junit.Assert.assertTrue;
 public class HttpClientFactoryTest {
 
     private HttpServer server;
-    private Map<String, String> replacedProperties;
-    private Map<String, String> testProperties;
+    private static final Map<String, String> SYSTEM_PROPS = new HashMap<>();
 
+    static {
+        SYSTEM_PROPS.put("asf.username", "asf-user");
+        SYSTEM_PROPS.put("asf.password", "asf-password");
+    }
     @Rule
     public OsgiContext osgiContext = new OsgiContext();
 
+    @Rule
+    public SystemPropertiesRule systemProperties = new SystemPropertiesRule(SYSTEM_PROPS);
+
     @Before
     public void before() throws Throwable {
-        replacedProperties = new HashMap<>();
-        testProperties = new HashMap<>();
-        testProperties.put("asf.username", "asf.username");
-        testProperties.put("asf.password", "asf.password");
-        testProperties.put("jira.username", "jira.username");
-        testProperties.put("jira.password", "jira.password");
-        for (Map.Entry<String, String> testProperty : testProperties.entrySet()) {
-            String originalValue = System.getProperty(testProperty.getKey());
-            if (originalValue != null) {
-                replacedProperties.put(testProperty.getKey(), originalValue);
-            }
-            System.setProperty(testProperty.getKey(), testProperty.getValue());
-        }
         server = HttpServer.create(new InetSocketAddress("localhost", 0), 0);
         HttpContext rootContext = server.createContext("/");
         rootContext.setHandler(ex -> {
@@ -93,11 +87,5 @@ public class HttpClientFactoryTest {
     @After
     public void after() {
         server.stop(0);
-        for (String testProperty : testProperties.keySet()) {
-            System.clearProperty(testProperty);
-        }
-        for (Map.Entry<String, String> replacedProperty : replacedProperties.entrySet()) {
-            System.setProperty(replacedProperty.getKey(), replacedProperty.getValue());
-        }
     }
 }
diff --git a/src/test/java/org/apache/sling/cli/impl/jira/VersionClientTest.java b/src/test/java/org/apache/sling/cli/impl/jira/VersionClientTest.java
index bdf1cda..ae75090 100644
--- a/src/test/java/org/apache/sling/cli/impl/jira/VersionClientTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/jira/VersionClientTest.java
@@ -29,6 +29,7 @@ import java.util.Map;
 
 import org.apache.sling.cli.impl.CredentialsService;
 import org.apache.sling.cli.impl.http.HttpClientFactory;
+import org.apache.sling.cli.impl.junit.SystemPropertiesRule;
 import org.apache.sling.cli.impl.release.Release;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.Before;
diff --git a/src/test/java/org/apache/sling/cli/impl/jira/SystemPropertiesRule.java b/src/test/java/org/apache/sling/cli/impl/junit/SystemPropertiesRule.java
similarity index 50%
rename from src/test/java/org/apache/sling/cli/impl/jira/SystemPropertiesRule.java
rename to src/test/java/org/apache/sling/cli/impl/junit/SystemPropertiesRule.java
index c6273b5..81a665a 100644
--- a/src/test/java/org/apache/sling/cli/impl/jira/SystemPropertiesRule.java
+++ b/src/test/java/org/apache/sling/cli/impl/junit/SystemPropertiesRule.java
@@ -1,20 +1,22 @@
-/*
- * 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.cli.impl.jira;
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.cli.impl.junit;
 
 import java.util.HashMap;
 import java.util.Map;
diff --git a/src/test/java/org/apache/sling/cli/impl/nexus/RepositoryServiceTest.java b/src/test/java/org/apache/sling/cli/impl/nexus/RepositoryServiceTest.java
index 6f7cdea..bc48786 100644
--- a/src/test/java/org/apache/sling/cli/impl/nexus/RepositoryServiceTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/nexus/RepositoryServiceTest.java
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
 import org.apache.commons.io.IOUtils;
 import org.apache.sling.cli.impl.CredentialsService;
 import org.apache.sling.cli.impl.http.HttpClientFactory;
-import org.apache.sling.cli.impl.jira.SystemPropertiesRule;
+import org.apache.sling.cli.impl.junit.SystemPropertiesRule;
 import org.apache.sling.cli.impl.release.Release;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.Before;
diff --git a/src/test/java/org/apache/sling/cli/impl/pgp/PGPSignatureValidatorTest.java b/src/test/java/org/apache/sling/cli/impl/pgp/PGPSignatureValidatorTest.java
index 43f3a39..ce9a2f9 100644
--- a/src/test/java/org/apache/sling/cli/impl/pgp/PGPSignatureValidatorTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/pgp/PGPSignatureValidatorTest.java
@@ -25,7 +25,7 @@ import java.util.Map;
 
 import org.apache.sling.cli.impl.CredentialsService;
 import org.apache.sling.cli.impl.http.HttpClientFactory;
-import org.apache.sling.cli.impl.jira.SystemPropertiesRule;
+import org.apache.sling.cli.impl.junit.SystemPropertiesRule;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.Before;
 import org.junit.Rule;