/*
 * 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.accumulo.core.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.nio.file.Paths;
import java.util.Properties;

import org.apache.accumulo.core.conf.ClientProperty;
import org.junit.Test;

public class ClientPropertiesTest {

  @Test
  public void testBasic() {
    Properties props1 =
        Accumulo.newClientProperties().to("inst1", "zoo1").as("user1", "pass1").build();
    assertEquals("inst1", ClientProperty.INSTANCE_NAME.getValue(props1));
    assertEquals("zoo1", ClientProperty.INSTANCE_ZOOKEEPERS.getValue(props1));
    assertEquals("user1", ClientProperty.AUTH_PRINCIPAL.getValue(props1));
    assertEquals("password", ClientProperty.AUTH_TYPE.getValue(props1));
    assertEquals("pass1", ClientProperty.AUTH_TOKEN.getValue(props1));

    Properties props2 =
        Accumulo.newClientProperties().from(props1).as("user2", Paths.get("/path2")).build();
    assertEquals("inst1", ClientProperty.INSTANCE_NAME.getValue(props1));
    assertEquals("zoo1", ClientProperty.INSTANCE_ZOOKEEPERS.getValue(props1));
    assertEquals("user2", ClientProperty.AUTH_PRINCIPAL.getValue(props1));
    assertEquals("kerberos", ClientProperty.AUTH_TYPE.getValue(props1));
    assertEquals("/path2", ClientProperty.AUTH_TOKEN.getValue(props1));

    props2.remove(ClientProperty.AUTH_PRINCIPAL.getKey());
    try {
      ClientProperty.validate(props2);
      fail();
    } catch (IllegalArgumentException e) {
      // expected
    }
  }
}

@@ -919,20 +919,28 @@
 .Assert.
-fail
+assertThrows
 ;%0A%0Aimpor
@@ -1624,24 +1624,62 @@
 (props1));%0A%0A
+    ClientProperty.validate(props1);%0A%0A
     Properti
@@ -1775,32 +1775,67 @@
 ath2%22)).build();
+%0A%0A    // verify props1 is unchanged
 %0A    assertEqual
@@ -1994,17 +1994,17 @@
 ls(%22user
-2
+1
 %22, Clien
@@ -2069,16 +2069,16 @@
 ls(%22
-kerberos
+password
 %22, C
@@ -2138,22 +2138,21 @@
 Equals(%22
-/
 pa
-th2
+ss1
 %22, Clien
@@ -2200,101 +2200,423 @@
     
-props2.remove(ClientProperty.AUTH_PRINCIPAL.getKey());%0A    try %7B%0A      ClientProperty.validat
+// verify props2 has new values for overridden fields%0A    assertEquals(%22inst1%22, ClientProperty.INSTANCE_NAME.getValue(props2));%0A    assertEquals(%22zoo1%22, ClientProperty.INSTANCE_ZOOKEEPERS.getValue(props2));%0A    assertEquals(%22user2%22, ClientProperty.AUTH_PRINCIPAL.getValue(props2));%0A    assertEquals(%22kerberos%22, ClientProperty.AUTH_TYPE.getValue(props2));%0A    assertEquals(%22/path2%22, ClientProperty.AUTH_TOKEN.getValu
 e(pr
@@ -2624,90 +2624,230 @@
 ps2)
-;
+);%0A
 %0A    
-  fail();%0A    %7D catch (IllegalArgumentException e) %7B%0A      // expected%0A    %7D
+props2.remove(ClientProperty.AUTH_PRINCIPAL.getKey());%0A    var e = assertThrows(IllegalArgumentException.class, () -%3E ClientProperty.validate(props2));%0A    assertEquals(%22auth.principal is not set%22, e.getMessage());
 %0A  %7D

Fix ClientPropertiesTest for #1839