/*
 * 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.hadoop.hdds.scm.ha.invoker;

import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.File;
import org.apache.hadoop.hdds.scm.block.DeletedBlockLogStateManager;
import org.apache.hadoop.hdds.scm.container.ContainerStateManager;
import org.apache.hadoop.hdds.scm.ha.SequenceIdGenerator;
import org.apache.hadoop.hdds.scm.ha.StatefulServiceStateManager;
import org.apache.hadoop.hdds.scm.pipeline.PipelineStateManager;
import org.apache.hadoop.hdds.scm.security.RootCARotationHandler;
import org.apache.hadoop.hdds.scm.server.upgrade.FinalizationStateManager;
import org.apache.hadoop.hdds.security.symmetric.SecretKeyState;
import org.apache.hadoop.hdds.security.x509.certificate.authority.CertificateStore;
import org.junit.jupiter.api.Test;

/** Test the code generated by {@link ScmInvokerCodeGenerator}. */
public final class TestScmInvokerCodeGenerator {
  static final String DIR = "src/main/java/org/apache/hadoop/hdds/scm/ha/invoker/";

  static void runTest(Class<?> api) throws Exception {
    final ScmInvokerCodeGenerator generator = new ScmInvokerCodeGenerator(api);
    final String classString = generator.generateClass();
    final File file = generator.updateFile(classString, DIR, false);
    assertNull(file, () -> ScmInvokerCodeGenerator.getInvokerClassName(api) + " is changed.");
  }

  @Test
  public void testDeletedBlockLogStateManager() throws Exception {
    runTest(DeletedBlockLogStateManager.class);
  }

  @Test
  public void testContainerStateManager() throws Exception {
    runTest(ContainerStateManager.class);
  }

  @Test
  public void testPipelineStateManager() throws Exception {
    runTest(PipelineStateManager.class);
  }

  @Test
  public void testRootCARotationHandler() throws Exception {
    runTest(RootCARotationHandler.class);
  }

  @Test
  public void testFinalizationStateManager() throws Exception {
    runTest(FinalizationStateManager.class);
  }

  @Test
  public void testSecretKeyState() throws Exception {
    runTest(SecretKeyState.class);
  }

  @Test
  public void testSequenceIdGeneratorStateManager() throws Exception {
    runTest(SequenceIdGenerator.StateManager.class);
  }

  @Test
  public void testStatefulServiceStateManager() throws Exception {
    runTest(StatefulServiceStateManager.class);
  }

  @Test
  public void testCertificateStore() throws Exception {
    runTest(CertificateStore.class);
  }
}
