adoroszlai commented on code in PR #5733:
URL: https://github.com/apache/ozone/pull/5733#discussion_r1418691511


##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/conf/TestHddsConfServlet.java:
##########
@@ -0,0 +1,318 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.conf;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import com.google.gson.Gson;
+import org.apache.hadoop.http.HttpServer2;
+import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
+import org.apache.hadoop.util.XMLUtils;
+import org.eclipse.jetty.util.ajax.JSON;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.mockito.Mockito;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.HttpHeaders;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test for {@link HddsConfServlet}. */
+public class TestHddsConfServlet {
+
+  private static final Map<String, String> TEST_PROPERTIES = new HashMap<>();
+  private static final Map<String, String> TEST_FORMATS = new HashMap<>();
+  private static final String TEST_KEY = "testconfservlet.key";
+  private static final String TEST_VAL = "testval";
+
+  @BeforeAll
+  public static void setup() {
+    TEST_PROPERTIES.put("test.key1", "value1");
+    TEST_PROPERTIES.put("test.key2", "value2");
+    TEST_PROPERTIES.put("test.key3", "value3");
+    TEST_FORMATS.put(HddsConfServlet.FORMAT_XML, "application/xml");
+    TEST_FORMATS.put(HddsConfServlet.FORMAT_JSON, "application/json");
+  }
+
+  @Test
+  public void testParseHeaders() throws Exception {
+    HashMap<String, String> verifyMap = new HashMap<String, String>();
+    verifyMap.put("text/plain", HddsConfServlet.FORMAT_XML);
+    verifyMap.put(null, HddsConfServlet.FORMAT_XML);
+    verifyMap.put("text/xml", HddsConfServlet.FORMAT_XML);
+    verifyMap.put("application/xml", HddsConfServlet.FORMAT_XML);
+    verifyMap.put("application/json", HddsConfServlet.FORMAT_JSON);
+
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    for (Map.Entry<String, String> entry : verifyMap.entrySet()) {
+      String contenTypeActual = entry.getValue();
+      Mockito.when(request.getHeader(HttpHeaders.ACCEPT))
+          .thenReturn(entry.getKey());
+      assertEquals(contenTypeActual,
+          HddsConfServlet.parseAcceptHeader(request));
+    }
+  }
+
+  @Test
+  public void testGetProperty() throws Exception {
+    OzoneConfiguration conf = getPropertiesConf();
+    // list various of property names
+    String[] keys = new String[] {"test1.key1",
+        "test.unknown.key",
+        "",
+        "test.key2",
+        null};
+    for (Map.Entry<String, String> entry : TEST_FORMATS.entrySet()) {
+      for (String key : keys) {
+        verifyGetProperty(conf, entry.getKey(), key);
+      }
+    }
+  }
+
+  @Test
+  public void testGetPropertyWithCmd() throws Exception {
+    OzoneConfiguration conf = getPropertiesConf();
+    conf.getObject(OzoneTestConfig.class);

Review Comment:
   FYI `getObject` call is unnecessary here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to