/**
 *  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.kerby.kerberos.kerb.server;

import org.apache.kerby.kerberos.kerb.KrbException;
import org.apache.kerby.kerberos.kerb.client.KrbClient;
import org.apache.kerby.util.IOUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;

import java.io.File;
import java.io.IOException;

public abstract class KdcTestBase {
    private static File testDir;

    private final String clientPassword = "123456";
    private final String hostname = "localhost";
    private final String clientPrincipalName = "drankye";
    private final String clientPrincipal =
            clientPrincipalName + "@" + TestKdcServer.kdcRealm;
    private final String serverPrincipalName = "test-service";
    private final String serverPrincipal =
            serverPrincipalName + "/" + hostname + "@" + TestKdcServer.kdcRealm;

    private SimpleKdcServer kdcServer;

    @BeforeClass
    public static void createTestDir() throws IOException {
        String basedir = System.getProperty("basedir");
        if (basedir == null) {
            basedir = new File(".").getCanonicalPath();
        }
        File targetdir= new File(basedir, "target");
        testDir = new File(targetdir, "tmp");
        testDir.mkdirs();
    }

    @AfterClass
    public static void deleteTestDir() throws IOException {
        testDir.delete();
    }

    protected File getTestDir() {
        return testDir;
    }

    protected SimpleKdcServer getKdcServer() {
        return kdcServer;
    }

    protected KrbClient getKrbClient() {
        return kdcServer.getKrbClient();
    }

    protected String getClientPrincipalName() {
        return clientPrincipalName;
    }

    protected String getClientPrincipal() {
        return clientPrincipal;
    }

    protected String getServerPrincipalName() {
        return serverPrincipalName;
    }

    protected String getClientPassword() {
        return clientPassword;
    }

    protected String getServerPrincipal() {
        return serverPrincipal;
    }

    protected boolean allowUdp() {
        return true;
    }

    protected boolean allowTcp() {
        return true;
    }

    protected String getFileContent(String path) throws IOException {
        return IOUtil.readFile(new File(path));
    }

    protected String writeToTestDir(String content,
                                    String fileName) throws IOException {
        File file = new File(testDir, fileName);
        if (file.exists()) {
            file.delete();
        }
        IOUtil.writeFile(content, file);
        return file.getPath();
    }

    @Before
    public void setUp() throws Exception {
        setUpKdcServer();

        createPrincipals();

        setUpClient();
    }

    protected void prepareKdc() throws KrbException {
        kdcServer.init();
    }

    protected void setUpKdcServer() throws Exception {
        kdcServer = new TestKdcServer(allowTcp(), allowUdp());
        kdcServer.setWorkDir(testDir);

        prepareKdc();

        kdcServer.start();
    }

    protected void setUpClient() throws Exception {
    }

    protected void createPrincipals() throws KrbException {
        kdcServer.createPrincipals(serverPrincipal);
        kdcServer.createPrincipal(clientPrincipal, clientPassword);
    }

    protected void deletePrincipals() throws KrbException {
        kdcServer.getKadmin().deleteBuiltinPrincipals();
        kdcServer.deletePrincipals(serverPrincipal);
        kdcServer.deletePrincipal(clientPrincipal);
    }

    @After
    public void tearDown() throws Exception {
        deletePrincipals();
        kdcServer.stop();
    }
}
@@ -986,45 +986,8 @@
 nt;%0A
-import org.apache.kerby.util.IOUtil;%0A
 impo
@@ -2968,453 +2968,12 @@
   %7D%0A
-%0A
     
-protected String getFileContent(String path) throws IOException %7B%0A        return IOUtil.readFile(new File(path));%0A    %7D%0A%0A    protected String writeToTestDir(String content,%0A                                    String fileName) throws IOException %7B%0A        File file = new File(testDir, fileName);%0A        if (file.exists()) %7B%0A            file.delete();%0A        %7D%0A        IOUtil.writeFile(content, file);%0A        return file.getPath();%0A    %7D%0A
 %0A   

Clean up unused codes