<commit_before>/**
 * LIZENZBEDINGUNGEN - Seanox Software Solutions ist ein Open-Source-Projekt,
 * im Folgenden Seanox Software Solutions oder kurz Seanox genannt.
 * Diese Software unterliegt der Version 2 der GNU General Public License.
 *
 * Devwex, Advanced Server Development
 * Copyright (C) 2020 Seanox Software Solutions
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of version 2 of the GNU General Public License as published by the
 * Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package com.seanox.devwex;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Test cases for {@link com.seanox.devwex.Service}.<br>
 * <br>
 * ServiceTest_Remote 5.1.0 20171231<br>
 * Copyright (C) 2017 Seanox Software Solutions<br>
 * All rights reserved.
 *
 * @author  Seanox Software Solutions
 * @version 5.1.0 20171231
 */
public class ServiceTest_Remote extends AbstractTest {
    
    /** 
     * Preparation of the runtime environment.
     * @throws Exception
     */
    @BeforeClass
    public static void initiate() throws Exception {
        
        Files.copy(Paths.get("./devwex.ini"), Paths.get("./devwex.ini_"), StandardCopyOption.REPLACE_EXISTING); 
        Files.copy(Paths.get("./devwex.sapi"), Paths.get("./devwex.ini"), StandardCopyOption.REPLACE_EXISTING);
        
        Thread.sleep(250);
        AbstractTestUtils.waitOutputFacadeStream(AbstractSuite.outputStream);
    }
    
    /** 
     * Restoration of the runtime environment.
     * @throws Exception
     */
    @AfterClass
    public static void terminate() throws Exception {
        
        Files.copy(Paths.get("./devwex.ini_"), Paths.get("./devwex.ini"), StandardCopyOption.REPLACE_EXISTING); 
        Files.delete(Paths.get("./devwex.ini_"));
        
        Thread.sleep(250);
        AbstractTestUtils.waitOutputFacadeStream(AbstractSuite.outputStream);
    } 
    
    /** 
     * Test case for acceptance.
     * Default connection must work.
     * But not here because the default is not used.
     * @throws Exception
     */     
    @Test
    public void testAcceptance_01() throws Exception {
        
        Service.main(new String[] {"status"});
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        if (!output.contains("SAPI: TCP 127.0.0.1:25000")) {
            Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
            Assert.assertTrue(output.contains("Connection refused: connect"));
            Assert.assertFalse(output.contains("Network is unreachable: connect"));
            Assert.assertFalse(output.contains("unknow_host")); 
            Assert.assertFalse(output.contains("SAPI"));
        }
    } 
    
    /** 
     * Test case for acceptance.
     * If an unknown host is used, an error must occur.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_02() throws Exception {
        
        Service.main(new String[] {"status", "unknow_host"});
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertTrue(output.contains("unknow_host")); 
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("SAPI"));       
    } 
    
    /** 
     * Test case for acceptance.
     * If an invalid port is used, an error must occur.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_03() throws Exception {
        
        Service.main(new String[] {"status", "1234"});

        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertTrue(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("unknow_host")); 
        Assert.assertFalse(output.contains("SAPI"));
    }     
    
    /** 
     * Test case for acceptance.
     * If an invalid port is used, an error must occur.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_04() throws Exception {

        Service.main(new String[] {"status", "127.0.0.1:18000"});

        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertTrue(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));        
        Assert.assertFalse(output.contains("SAPI"));
    } 
    
    /** 
     * Test case for acceptance.
     * If the correct connection is used, a status response must be returned.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_05() throws Exception {

        Service.main(new String[] {"status", "127.0.0.1:18001"});
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertFalse(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));
        Assert.assertTrue(output.contains("SAPI"));
    }     
}<commit_msg>#0000 Test: Update of test cases<commit_after>/**
 * LIZENZBEDINGUNGEN - Seanox Software Solutions ist ein Open-Source-Projekt,
 * im Folgenden Seanox Software Solutions oder kurz Seanox genannt.
 * Diese Software unterliegt der Version 2 der GNU General Public License.
 *
 * Devwex, Advanced Server Development
 * Copyright (C) 2021 Seanox Software Solutions
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of version 2 of the GNU General Public License as published by the
 * Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package com.seanox.devwex;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Test cases for {@link com.seanox.devwex.Service}.<br>
 * <br>
 * ServiceTest_Remote 5.4.0 20210403<br>
 * Copyright (C) 2021 Seanox Software Solutions<br>
 * All rights reserved.
 *
 * @author  Seanox Software Solutions
 * @version 5.4.0 20210403
 */
public class ServiceTest_Remote extends AbstractTest {
    
    /** 
     * Preparation of the runtime environment.
     * @throws Exception
     */
    @BeforeClass
    public static void initiate() throws Exception {
        
        Files.copy(Paths.get("./devwex.ini"), Paths.get("./devwex.ini_"), StandardCopyOption.REPLACE_EXISTING); 
        Files.copy(Paths.get("./devwex.sapi"), Paths.get("./devwex.ini"), StandardCopyOption.REPLACE_EXISTING);
        
        Thread.sleep(250);
        AbstractTestUtils.waitOutputFacadeStream(AbstractSuite.outputStream);
    }
    
    /** 
     * Restoration of the runtime environment.
     * @throws Exception
     */
    @AfterClass
    public static void terminate() throws Exception {
        
        Files.copy(Paths.get("./devwex.ini_"), Paths.get("./devwex.ini"), StandardCopyOption.REPLACE_EXISTING); 
        Files.delete(Paths.get("./devwex.ini_"));
        
        Thread.sleep(250);
        AbstractTestUtils.waitOutputFacadeStream(AbstractSuite.outputStream);
    } 
    
    /** 
     * Test case for acceptance.
     * Internally uses only the internal commands RESTART | STATUS | STOP if the
     * server instance is already running. Parameters for the remote connections
     * are ignored. 
     * @throws Exception
     */     
    @Test
    public void testAcceptance_01_internal() throws Exception {
        
        Service.main(new String[] {"status"});
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertFalse(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));
        Assert.assertTrue(output.contains("SAPI: TCP 127.0.0.1"));
    } 
    
    /** 
     * Test case for acceptance.
     * Internally uses only the internal commands RESTART | STATUS | STOP if the
     * server instance is already running. Parameters for the remote connections
     * are ignored. 
     * @throws Exception
     */      
    @Test
    public void testAcceptance_02_internal() throws Exception {
        
        Service.main(new String[] {"status", "unknow_host"});
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertFalse(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));
        Assert.assertTrue(output.contains("SAPI: TCP 127.0.0.1"));     
    } 
    
    /** 
     * Test case for acceptance.
     * Internally uses only the internal commands RESTART | STATUS | STOP if the
     * server instance is already running. Parameters for the remote connections
     * are ignored. 
     * @throws Exception
     */      
    @Test
    public void testAcceptance_03_internal() throws Exception {
        
        Service.main(new String[] {"status", "1234"});

        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertFalse(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));
        Assert.assertTrue(output.contains("SAPI: TCP 127.0.0.1"));
    }     
    
    /** 
     * Test case for acceptance.
     * Internally uses only the internal commands RESTART | STATUS | STOP if the
     * server instance is already running. Parameters for the remote connections
     * are ignored. 
     * @throws Exception
     */      
    @Test
    public void testAcceptance_04_internal() throws Exception {

        Service.main(new String[] {"status", "127.0.0.1:18000"});

        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertFalse(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));
        Assert.assertTrue(output.contains("SAPI: TCP 127.0.0.1"));
    } 
    
    /** 
     * Test case for acceptance.
     * Internally uses only the internal commands RESTART | STATUS | STOP if the
     * server instance is already running. Parameters for the remote connections
     * are ignored. 
     * @throws Exception
     */      
    @Test
    public void testAcceptance_05_internal() throws Exception {

        Service.main(new String[] {"status", "127.0.0.1:18001"});
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = this.outputStreamCapture.toString();
        Assert.assertFalse(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));
        Assert.assertTrue(output.contains("SAPI: TCP 127.0.0.1"));
    }   
    
    
    
    
    
    
    
    
    
    
    
    
    private static String remoteCall(String[] options)
            throws IOException {
        
        if (options == null)
            options = new String[0];
        String command = "java -cp ./classes com.seanox.devwex.Service";
        for (String option : options)
            command += " " + option;
        Process process = Runtime.getRuntime().exec(command);
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        StringBuilder output = new StringBuilder();
        for (String line; (line = reader.readLine()) != null;) {
            output.append(line);
            output.append(System.lineSeparator());
        }
        return output.toString();
    }
    
    /** 
     * Test case for acceptance.
     * Default connection must work.
     * But not here because the default is not used.
     * @throws Exception
     */     
    @Test
    public void testAcceptance_01_external() throws Exception {
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = ServiceTest_Remote.remoteCall(new String[] {"status"});
        if (!output.contains("SAPI: TCP 127.0.0.1:25000")) {
            Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
            Assert.assertTrue(output.contains("Connection refused: connect"));
            Assert.assertFalse(output.contains("Network is unreachable: connect"));
            Assert.assertFalse(output.contains("unknow_host")); 
            Assert.assertFalse(output.contains("SAPI"));
        }
    } 
    
    /** 
     * Test case for acceptance.
     * If an unknown host is used, an error must occur.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_02_external() throws Exception {
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = ServiceTest_Remote.remoteCall(new String[] {"status", "unknow_host"});
        Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertTrue(output.contains("unknow_host")); 
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("SAPI"));       
    } 
    
    /** 
     * Test case for acceptance.
     * If an invalid port is used, an error must occur.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_03_external() throws Exception {
        
        Thread.sleep(AbstractTest.SLEEP);
        String output = ServiceTest_Remote.remoteCall(new String[] {"status", "1234"});
        Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertTrue(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("unknow_host")); 
        Assert.assertFalse(output.contains("SAPI"));
    }     
    
    /** 
     * Test case for acceptance.
     * If an invalid port is used, an error must occur.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_04_external() throws Exception {

        Thread.sleep(AbstractTest.SLEEP);
        String output = ServiceTest_Remote.remoteCall(new String[] {"status", "127.0.0.1:18000"});
        Assert.assertTrue(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertTrue(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));        
        Assert.assertFalse(output.contains("SAPI"));
    } 
    
    /** 
     * Test case for acceptance.
     * If the correct connection is used, a status response must be returned.
     * @throws Exception
     */      
    @Test
    public void testAcceptance_05_external() throws Exception {

        Thread.sleep(AbstractTest.SLEEP);
        String output = ServiceTest_Remote.remoteCall(new String[] {"status", "127.0.0.1:18001"});
        Assert.assertFalse(output.contains("REMOTE ACCESS FAILED"));
        Assert.assertFalse(output.contains("Connection refused: connect"));
        Assert.assertFalse(output.contains("Network is unreachable: connect"));
        Assert.assertFalse(output.contains("unknow_host"));
        Assert.assertTrue(output.contains("SAPI"));
    }   
}
{'fraction_non_alphanumeric': 0.10786836773804961, 'fraction_numerical': 0.014400700870612715, 'mean_word_length': 2.583284284873455, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 13, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5208872', 'n_tokens_mistral': 5200, 'n_tokens_neox': 4785, 'n_words': 1231}