package org.docksidestage.hangar.dbflute.whitebox.world.spolicyworld;

import org.dbflute.helper.process.SystemScript;
import org.dbflute.utflute.core.PlainTestCase;
import org.dbflute.util.DfTraceViewUtil;

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

/**
 * @author subaru
 */
public class WxSPolicyworldTest extends PlainTestCase {
    public void test_spolicyworld() {
        doTest_spolicyworld(/*clean*/true);
        doTest_spolicyworld(/*clean*/false);
    }

    protected void doTest_spolicyworld(boolean clean) {
        // ## Arrange ##
        long before = System.currentTimeMillis();
        try {
            SystemScript script = new SystemScript();
            String clientPath = getClientPath();
            File clientDir = new File(clientPath);
            assertTrue(clientDir.exists());
            String fileName = "spolicyworld-test.sh";

            // ## Act ##

            // ## Assert ##

        } finally {
            long after = System.currentTimeMillis();
            log("performanceCost:[{}]", DfTraceViewUtil.convertToPerformanceView(after - before));
        }
    }

    // ===================================================================================
    //                                                                   SchemaPolicyCheck
    //                                                                   =================

    // ===================================================================================
    //                                                                        Small Helper
    //                                                                        ============
    private String getClientPath() {
        try {
            return getProjectDir().getCanonicalPath() + "/dbflute_maihamadb";
        } catch (IOException e) {
            throw new IllegalStateException("Cannot get canonical path.", e);
        }
    }
}

@@ -64,16 +64,65 @@
 world;%0A%0A
+import org.dbflute.helper.process.ProcessResult;%0A
 import o
@@ -298,16 +298,41 @@
 ception;
+%0Aimport java.util.Arrays;
 %0A%0A/**%0A *
@@ -477,66 +477,8 @@
 rld(
-/*clean*/true);%0A        doTest_spolicyworld(/*clean*/false
 );%0A 
@@ -526,21 +526,8 @@
 rld(
-boolean clean
 ) %7B%0A
@@ -897,37 +897,735 @@
  ##%0A
-%0A            // ## Assert ##%0A
+            String%5B%5D scriptArgs = new String%5B%5D %7B%7D;%0A            log(%22...Executing spolicyworld: %7B%7D, %7B%7D%22, fileName, Arrays.asList(scriptArgs));%0A            ProcessResult result = script.execute(clientDir, fileName, scriptArgs);%0A%0A            // ## Assert ##%0A            log(%22Finished the spolicyworld: %7B%7D, %7B%7D%22, result.getProcessName(), result.getExitCode());%0A            assertEquals(0, result.getExitCode());%0A            String console = result.getConsole();%0A            log(console);%0A            assertContains(console, %22column.statement: if columnName is suffix:_SERVICE_RANK then classification%22);%0A            assertContains(console, %22column.statement: if columnName is suffix:_SERVICE_RANK then classification(ServiceRank)%22);
 %0A   

add test for classification and classification(...) statement