content: package com.alipay.antchain.bridge.ptc.committee.supervisor.cli.command;
  
  import java.io.IOException;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.util.ArrayList;
  import java.util.List;
  
  import cn.hutool.core.util.StrUtil;
  import com.alipay.antchain.bridge.bcdns.factory.BlockChainDomainNameServiceFactory;
  import com.alipay.antchain.bridge.bcdns.service.BCDNSTypeEnum;
  import com.alipay.antchain.bridge.bcdns.service.IBlockChainDomainNameService;
  import com.alipay.antchain.bridge.commons.core.base.ObjectIdentityType;
  import com.alipay.antchain.bridge.commons.core.ptc.PTCTypeEnum;
  import com.alipay.antchain.bridge.commons.utils.crypto.SignAlgoEnum;
  import com.alipay.antchain.bridge.ptc.committee.supervisor.cli.Launcher;
  import jakarta.annotation.Resource;
  import org.junit.AfterClass;
  import org.junit.Assert;
  import org.junit.BeforeClass;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.mockito.MockedStatic;
  import org.mockito.Mockito;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.junit4.SpringRunner;
  
  import static org.mockito.Mockito.mock;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest(classes = Launcher.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
  public class SupervisorManagerCommandsTest {
  
      private static final String certPath = "src/test/resources/certs/";
  
      private static final String pubKeyPath = certPath + "public_key.pem";
  
      private static final String bcdnsDir = "src/test/resources/bcdns/";
  
      private static final String committeeNodeConfigDir = "src/test/resources/committeeNodes/";
  
      private static final String ptcTrustRootStr = "AAAECAAAAAAHAAAAeHh4Lm9yZwEAoAAAAAAAmgAAAAAAAwAAADEuMAEADQAAAGNvbW1pdHRlZS1wdGMCAAEAAAABAwBrAAAAAABlAAAAAAABAAAAAAEAWAAAADBWMBAGByqGSM49AgEGBSuBBAAKA0IABAuFrr4a+xRRyeBamtx6MXrj9K8zCa9zwRSP54OYMVsYWyXFOa8H3YOJnLic5aY1mHujouKInzqW+/LrFCkJP8MEAAAAAAACAKAFAAB7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Wkl6ajBDQVFZRks0RUVBQW9EUWdBRUM0V3V2aHI3RkZISjRGcWEzSG94ZXVQMHJ6TUpyM1BCXG5GSS9uZzVneFd4aGJKY1U1cndmZGc0bWN1SnpscGpXWWU2T2k0b2lmT3BiNzh1c1VLUWsvd3c9PVxuLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tXG4ifV19XSwiY29tbWl0dGVlX2lkIjoiY29tbWl0dGVlMSJ9BAAWAAAAS2VjY2FrMjU2V2l0aFNlY3AyNTZrMQUAQQAAABnx7AwMmFqxSdCGuSKHUCDh6mig1yLmlh1ppY5XsAyERLKvUXa4r68z2/4IdcnOI/hdVdA2CAfmXtbj5Jm7gSYA";
  
      private static IBlockChainDomainNameService bcdns;
  
      private static MockedStatic<BlockChainDomainNameServiceFactory> mockedBCDNSFactory;
  
      @BeforeClass
      public static void beforeClass() throws Exception {
          bcdns = mock(IBlockChainDomainNameService.class);
  
          mockedBCDNSFactory = Mockito.mockStatic(BlockChainDomainNameServiceFactory.class);
          mockedBCDNSFactory.when(() -> BlockChainDomainNameServiceFactory.create(Mockito.notNull(), Mockito.notNull())).thenReturn(bcdns);
  
          Mockito.doNothing().when(bcdns).addPTCTrustRoot(Mockito.any());
      }
  
      @AfterClass
      public static void afterClass() throws Exception {
          mockedBCDNSFactory.close();
      }
  
      @Resource
      private SupervisorManagerCommands supervisorManagerCommands;
  
      @Test
      public void testGeneratePTCAccount() throws IOException {
          supervisorManagerCommands.generatePtcAccount("committee1", SignAlgoEnum.KECCAK256_WITH_SECP256K1.getName(), certPath);
          Assert.assertNotEquals(supervisorManagerCommands.getSupervisorCLIConfig().getPrivateKey(), "");
          Assert.assertNotEquals(supervisorManagerCommands.getSupervisorCLIConfig().getPublicKey(), "");
          Assert.assertNotEquals(supervisorManagerCommands.getSupervisorCLIConfig().getSignAlgo(), "");
      }
  
      @Test
      public void testGeneratePtcCSR() {
          String response = supervisorManagerCommands.generatePtcCSR("2",
                  "myPTC",
                  ObjectIdentityType.X509_PUBLIC_KEY_INFO,
                  PTCTypeEnum.COMMITTEE,
                  pubKeyPath);
          Assert.assertNotEquals(response, "please input the path to the correct applicant public key file");
      }
  
      @Test
      public void testStartEmbeddedBCDNSClient() {
          String domainSpace = ".org";
          Path bcdnsClientConfigPath = Paths.get(bcdnsDir, "client1.json");
          supervisorManagerCommands.startBcdnsClient(domainSpace, BCDNSTypeEnum.EMBEDDED, bcdnsClientConfigPath.toString());
          Assert.assertNotNull(supervisorManagerCommands.getDomainSpaceToBcdnsMap().get(domainSpace));
          Assert.assertNotNull(supervisorManagerCommands.getSupervisorCLIConfig().getBcdnsConfig().get(domainSpace));
      }
  
      @Test
      public void testStartBifBCDNSClient() {
          String domainSpace = ".com";
          Path bcdnsClientConfigPath = Paths.get(bcdnsDir, "client2.json");
          supervisorManagerCommands.startBcdnsClient(domainSpace, BCDNSTypeEnum.BIF, bcdnsClientConfigPath.toString());
          Assert.assertNotNull(supervisorManagerCommands.getDomainSpaceToBcdnsMap().get(domainSpace));
          Assert.assertNotNull(supervisorManagerCommands.getSupervisorCLIConfig().getBcdnsConfig().get(domainSpace));
      }
  
      @Test
      public void testGeneratePTCTrustRoot() {
          List<String> committeeNodes = new ArrayList<>();
          committeeNodes.add("node1");
          Object response = supervisorManagerCommands.generatePtcTrustRoot(
                  ".org",
                  committeeNodeConfigDir,
                  committeeNodes
          );
          Assert.assertNotNull(response);
      }
  
      @Test
      public void testAddPTCTrustRoot() {
          String domainSpace = ".com";
          Object response = supervisorManagerCommands.addPtcTrustRoot(domainSpace, ptcTrustRootStr);
          Assert.assertNotNull(supervisorManagerCommands.getDomainSpaceToBcdnsMap().get(domainSpace));
          Assert.assertNotEquals(response, StrUtil.format("PTC service has not yet created domainSpace: {}'s BCDNS client", domainSpace));
      }
  }
  