integration-tests/src/test/java/oracle/kubernetes/operator/ItPodTemplates.java
@Test
  public void testPodTemplateUsingVariables() throws Exception {
    Assumptions.assumeTrue(QUICKTEST);
    String testMethodName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    logTestBegin(testMethodName);
    LoggerHelper.getLocal().log(Level.INFO, "Creating Operator & waiting for the script to complete execution");
    Domain domain = null;
    boolean testCompletedSuccessfully = false;
    try {
      Map<String, Object> domainMap = createDomainMap(getNewSuffixCount(), testClassName);
      // domainMap.put("domainUID", "podtemplatedomain");
      domainMap.put("namespace", domainNS);
      // just create domain yaml, dont apply
      domain = TestUtils.createDomain(domainMap, false);
      String originalYaml =
          getUserProjectsDir()
              + "/weblogic-domains/"
              + domain.getDomainUid()
              + "/domain.yaml";

      // Modify the original domain yaml to include labels in serverPod
      // node
      final DomainCrd crd = new DomainCrd(originalYaml);
      // add labels to serverPod
      Map<String, String> labelKeyValue = new HashMap();
      labelKeyValue.put("servername", "$(SERVER_NAME)");
      labelKeyValue.put("domainname", "$(DOMAIN_NAME)");
      labelKeyValue.put("domainuid", "$(DOMAIN_UID)");
      crd.addObjectNodeToServerPod("labels", labelKeyValue);

      // add annotations to serverPod as DOMAIN_HOME and LOG_HOME contains "/" which is not allowed
      // in labels
      Map<String, String> envKeyValue = new HashMap();
      envKeyValue.put("domainhome", "$(DOMAIN_HOME)");
      envKeyValue.put("loghome", "$(LOG_HOME)");
      crd.addObjectNodeToServerPod("annotations", envKeyValue);

      // add label to cluster serverPod for CLUSTER_NAME
      Map<String, String> clusterLabelKeyValue = new HashMap();
      clusterLabelKeyValue.put("clustername", "$(CLUSTER_NAME)");
      crd.addObjectNodeToClusterServerPod(domain.getClusterName(), "labels", clusterLabelKeyValue);

      String modYaml = crd.getYamlTree();
      LoggerHelper.getLocal().log(Level.INFO, modYaml);

      // Write the modified yaml to a new file
      Path path =
          Paths.get(
              getUserProjectsDir() + "/weblogic-domains/" + domain.getDomainUid(),
              "domain.modified.yaml");
      LoggerHelper.getLocal().log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
      Charset charset = StandardCharsets.UTF_8;
      Files.write(path, modYaml.getBytes(charset));

      // Apply the new yaml to update the domain
      LoggerHelper.getLocal().log(Level.INFO, "kubectl apply -f {0}", path.toString());
      ExecResult exec = TestUtils.execOrAbortProcess("kubectl apply -f " + path.toString());
      LoggerHelper.getLocal().log(Level.INFO, exec.stdout());

      domain.verifyDomainCreated();
      testCompletedSuccessfully = true;
    } finally {
      if (domain != null && (JENKINS || testCompletedSuccessfully)) {
        domain.shutdownUsingServerStartPolicy();
        TestUtils.deleteWeblogicDomainResources(domain.getDomainUid());
        TestUtils.verifyAfterDeletion(domain);
      }
    }

    LoggerHelper.getLocal().log(Level.INFO, "SUCCESS - " + testMethodName);
  }
/**
   * Test pod templates using all the variables $(SERVER_NAME), $(DOMAIN_NAME), $(DOMAIN_UID),
   * $(DOMAIN_HOME), $(LOG_HOME) and $(CLUSTER_NAME) in serverPod. Make sure the domain comes up
   * successfully.
   *
   * @throws Exception when the domain crd creation fails or when updating the serverPod with
   *                   variables
   */


@throws Exception when the domain crd creation fails or when updating the serverPod with
variables
@throws Exception when the domain crd creation fails or when updating the serverPod with variables
@Test
  public void testPodTemplateUsingVariables() throws Exception {
    Assumptions.assumeTrue(QUICKTEST);
    String testMethodName = new Object() {
    }.getClass().getEnclosingMethod().getName();
    logTestBegin(testMethodName);
    LoggerHelper.getLocal().log(Level.INFO, "Creating Operator & waiting for the script to complete execution");
    Domain domain = null;
    boolean testCompletedSuccessfully = false;
    try {
      Map<String, Object> domainMap = createDomainMap(getNewSuffixCount(), testClassName);
      domainMap.put("namespace", domainNS);
      domain = TestUtils.createDomain(domainMap, false);
      String originalYaml =
          getUserProjectsDir()
              + "/weblogic-domains/"
              + domain.getDomainUid()
              + "/domain.yaml";
      final DomainCrd crd = new DomainCrd(originalYaml);
      Map<String, String> labelKeyValue = new HashMap();
      labelKeyValue.put("servername", "$(SERVER_NAME)");
      labelKeyValue.put("domainname", "$(DOMAIN_NAME)");
      labelKeyValue.put("domainuid", "$(DOMAIN_UID)");
      crd.addObjectNodeToServerPod("labels", labelKeyValue);
      Map<String, String> envKeyValue = new HashMap();
      envKeyValue.put("domainhome", "$(DOMAIN_HOME)");
      envKeyValue.put("loghome", "$(LOG_HOME)");
      crd.addObjectNodeToServerPod("annotations", envKeyValue);
      Map<String, String> clusterLabelKeyValue = new HashMap();
      clusterLabelKeyValue.put("clustername", "$(CLUSTER_NAME)");
      crd.addObjectNodeToClusterServerPod(domain.getClusterName(), "labels", clusterLabelKeyValue);
      String modYaml = crd.getYamlTree();
      LoggerHelper.getLocal().log(Level.INFO, modYaml);
      Path path =
          Paths.get(
              getUserProjectsDir() + "/weblogic-domains/" + domain.getDomainUid(),
              "domain.modified.yaml");
      LoggerHelper.getLocal().log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
      Charset charset = StandardCharsets.UTF_8;
      Files.write(path, modYaml.getBytes(charset));
      LoggerHelper.getLocal().log(Level.INFO, "kubectl apply -f {0}", path.toString());
      ExecResult exec = TestUtils.execOrAbortProcess("kubectl apply -f " + path.toString());
      LoggerHelper.getLocal().log(Level.INFO, exec.stdout());
      domain.verifyDomainCreated();
      testCompletedSuccessfully = true;
    } finally {
      if (domain != null && (JENKINS || testCompletedSuccessfully)) {
        domain.shutdownUsingServerStartPolicy();
        TestUtils.deleteWeblogicDomainResources(domain.getDomainUid());
        TestUtils.verifyAfterDeletion(domain);
      }
    }
    LoggerHelper.getLocal().log(Level.INFO, "SUCCESS - " + testMethodName);
  }
@ Test public void testPodTemplateUsingVariables ( ) throws Exception { Assumptions . assumeTrue ( QUICKTEST ) ; String testMethodName = new Object ( ) { } . getClass ( ) . getEnclosingMethod ( ) . getName ( ) ; logTestBegin ( testMethodName ) ; LoggerHelper . getLocal ( ) . log ( Level . INFO , "Creating Operator & waiting for the script to complete execution" ) ; Domain domain = null ; boolean testCompletedSuccessfully = false ; try { Map < String , Object > domainMap = createDomainMap ( getNewSuffixCount ( ) , testClassName ) ; domainMap . put ( "namespace" , domainNS ) ; domain = TestUtils . createDomain ( domainMap , false ) ; String originalYaml = getUserProjectsDir ( ) + "/weblogic-domains/" + domain . getDomainUid ( ) + "/domain.yaml" ; final DomainCrd crd = new DomainCrd ( originalYaml ) ; Map < String , String > labelKeyValue = new HashMap ( ) ; labelKeyValue . put ( "servername" , "$(SERVER_NAME)" ) ; labelKeyValue . put ( "domainname" , "$(DOMAIN_NAME)" ) ; labelKeyValue . put ( "domainuid" , "$(DOMAIN_UID)" ) ; crd . addObjectNodeToServerPod ( "labels" , labelKeyValue ) ; Map < String , String > envKeyValue = new HashMap ( ) ; envKeyValue . put ( "domainhome" , "$(DOMAIN_HOME)" ) ; envKeyValue . put ( "loghome" , "$(LOG_HOME)" ) ; crd . addObjectNodeToServerPod ( "annotations" , envKeyValue ) ; Map < String , String > clusterLabelKeyValue = new HashMap ( ) ; clusterLabelKeyValue . put ( "clustername" , "$(CLUSTER_NAME)" ) ; crd . addObjectNodeToClusterServerPod ( domain . getClusterName ( ) , "labels" , clusterLabelKeyValue ) ; String modYaml = crd . getYamlTree ( ) ; LoggerHelper . getLocal ( ) . log ( Level . INFO , modYaml ) ; Path path = Paths . get ( getUserProjectsDir ( ) + "/weblogic-domains/" + domain . getDomainUid ( ) , "domain.modified.yaml" ) ; LoggerHelper . getLocal ( ) . log ( Level . INFO , "Path of the modified domain.yaml :{0}" , path . toString ( ) ) ; Charset charset = StandardCharsets . UTF_8 ; Files . write ( path , modYaml . getBytes ( charset ) ) ; LoggerHelper . getLocal ( ) . log ( Level . INFO , "kubectl apply -f {0}" , path . toString ( ) ) ; ExecResult exec = TestUtils . execOrAbortProcess ( "kubectl apply -f " + path . toString ( ) ) ; LoggerHelper . getLocal ( ) . log ( Level . INFO , exec . stdout ( ) ) ; domain . verifyDomainCreated ( ) ; testCompletedSuccessfully = true ; } finally { if ( domain != null && ( JENKINS || testCompletedSuccessfully ) ) { domain . shutdownUsingServerStartPolicy ( ) ; TestUtils . deleteWeblogicDomainResources ( domain . getDomainUid ( ) ) ; TestUtils . verifyAfterDeletion ( domain ) ; } } LoggerHelper . getLocal ( ) . log ( Level . INFO , "SUCCESS - " + testMethodName ) ; }
Test pod templates using all the variables $(SERVER_NAME), $(DOMAIN_NAME), $(DOMAIN_UID),
 $(DOMAIN_HOME), $(LOG_HOME) and $(CLUSTER_NAME) in serverPod.
Test pod templates using all the variables $ ( SERVER_NAME ) $ ( DOMAIN_NAME ) $ ( DOMAIN_UID ) $ ( DOMAIN_HOME ) $ ( LOG_HOME ) and $ ( CLUSTER_NAME ) in serverPod .
// domainMap.put("domainUID", "podtemplatedomain"); // just create domain yaml, dont apply // Modify the original domain yaml to include labels in serverPod // node // add labels to serverPod // add annotations to serverPod as DOMAIN_HOME and LOG_HOME contains "/" which is not allowed // in labels // add label to cluster serverPod for CLUSTER_NAME // Write the modified yaml to a new file // Apply the new yaml to update the domain