<commit_before>'use strict';

var tap = require('tap');
var pz = require('promzard');
var spawn = require('child_process').spawn;
var utils = require('./../util/utils');
var path = require('path');
var helpers = require('./../util/helpers');

var node = process.execPath;
var output = '';
function respond(c, lastOutput, custom) {
    custom = custom || function () {
        c.stdin.write('\n');
    };
    var regex = new RegExp(lastOutput + ' $');
    if (output.match(regex)) {
        c.stdin.write('\n');
        c.stdin.end();
        return;
    }

    custom(c, output);
    return;
}

function spawnProcess(t, process, expect, lastAttributeOutput, custom) {
    var c = spawn(node, [process], { customFds: [-1, -1, -1] });
    output = '';
    c.stdout.on('data', function (d) {
        output += d;
        respond(c, lastAttributeOutput, custom);
    });

    var actual = '';
    c.stderr.on('data', function (d) {
        actual += d;
    });

    c.on('close', function () {
//        console.error('actual', actual);
//        console.error('expect', expect);
        actual = JSON.parse(actual);
        t.deepEqual(actual, expect);
        t.end();
    });
}

tap.test('bikini', function (t) {

    var process = require.resolve('./../process/bikini.js');

    var expect = {
        'name': '',
        'description': '',
        'endpoint': '',
        'model': '',
        'idAttribute': ''
    };

    var lastAttributeOutput = 'Models ID Attribute:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput);
});

tap.test('connectionconfiguration', function (t) {

    var process = require.resolve('./../process/connectionconfiguration.js');

    var expect = {
        'name': '',
        'description': '',
        'configurationId': '',
        'configurationDescription': '',
        'authentication': '',
        'client': '',
        'user': '',
        'alias': '',
        'password': '',
        'language': '',
        'sapCookie': '',
        'x.509Certificate': '',
        'externalIdData': '',
        'externalIdType': '',
        'applicationServer': '',
        'systemNumber': '',
        'messageServer': '',
        'messagePort': '',
        'systemId': '',
        'logonGroup': '',
        'gatewayServer': '',
        'gatewayPort': '',
        'sapRouterString': '',
        'logonCheck': '',
        'logonCodepage': '',
        'logonCodepageType': '',
        'tableParameterDeltaMngmt': '',
        'getSsoTicket': '',
        'denyInitialPwds': '',
        'activeConnections': '',
        'idleConnections': '',
        'expirationTimeout': '',
        'expirationPeriod': '',
        'queuedTimeout': '',
        'sncMode': '',
        'sncPartner': '',
        'sncLevel': '',
        'sncName': '',
        'sncLibrary': '',
        'sncSso': '',
        'repositoryDestination': '',
        'repositoryUser': '',
        'repositoryPassword': '',
        'repositorySncMode': '',
        'repositoryRoundtripOptimization': '',
        'properties': {
            'key': {
                'type': 'type',
                'value': 'value'
            },
            'key1': {
                'type': 'type1',
                'value': 'value1'
            }
        },
        'factoryPid': '',
        'bundleLocation': ''
    };

    var lastAttributeOutput = 'Bundle Location:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput, function (c, output) {
        if (output.match(/Properties \(key:type:value key:type:value\): $/)) {
            c.stdin.write('key:type:value key1:type1:value1\n');
            return;
        }
        c.stdin.write('\n');
    });
});

tap.test('model', function (t) {

    var process = require.resolve('./../process/model.js');

    var expect = {
        'name': 'book',
        'label': 'book',
        'attributes': {
            'author': {
                'type': 'string',
                'mandatory': false,
                'key': false
            },
            'isbn': {
                'type': 'integer',
                'mandatory': true,
                'key': false
            }
        }
    };

    var lastAttributeOutput = 'Models ID Attribute:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput, function (c, output) {
        if (output.match(/Name: $/)) {
            c.stdin.write('book\n');
            return;
        }
        if (output.match(/Attributes \(name:type:mandatory:key name:type:mandatory:key\): $/)) {
            c.stdin.write('author:string isbn:integer:true:key\n');
            c.stdin.end();
            return;
        }
        c.stdin.write('\n');
    });
});

tap.test('rest', function (t) {

    var process = require.resolve('./../process/rest.js');

    var expect = {
        name: '',
        description: '',
        connectorProvider: 'HTTP',
        protocol: 'com.mwaysolutions.mcap.connector.http.RestConnectionConfig',
        properties: {
            descriptorUrl: '',
            userName: '',
            password: ''
        }
    };

    var lastAttributeOutput = 'Password:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput);
});

tap.test('saprfc', function (t) {

    var process = require.resolve('./../process/saprfc.js');

    var expect = {
        'name': '',
        'description': '',
        'connector': '',
        'protocol': '',
        'properties': {
            'authentication': '',
            'client': '',
            'user': '',
            'alias': '',
            'password': '',<commit_msg>update test to last commit<commit_after>'use strict';

var tap = require('tap');
var pz = require('promzard');
var spawn = require('child_process').spawn;
var utils = require('./../util/utils');
var path = require('path');
var helpers = require('./../util/helpers');

var node = process.execPath;
var output = '';
function respond(c, lastOutput, custom) {
    custom = custom || function () {
        c.stdin.write('\n');
    };
    var regex = new RegExp(lastOutput + ' $');
    if (output.match(regex)) {
        c.stdin.write('\n');
        c.stdin.end();
        return;
    }

    custom(c, output);
    return;
}

function spawnProcess(t, process, expect, lastAttributeOutput, custom) {
    var c = spawn(node, [process], { customFds: [-1, -1, -1] });
    output = '';
    c.stdout.on('data', function (d) {
        output += d;
        respond(c, lastAttributeOutput, custom);
    });

    var actual = '';
    c.stderr.on('data', function (d) {
        actual += d;
    });

    c.on('close', function () {
//        console.error('actual', actual);
//        console.error('expect', expect);
        actual = JSON.parse(actual);
        t.deepEqual(actual, expect);
        t.end();
    });
}

tap.test('bikini', function (t) {

    var process = require.resolve('./../process/bikini.js');

    var expect = {
        'name': '',
        'description': '',
        'endpoint': '',
        'model': '',
        'idAttribute': ''
    };

    var lastAttributeOutput = 'Models ID Attribute:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput);
});

tap.test('connectionconfiguration', function (t) {

    var process = require.resolve('./../process/connectionconfiguration.js');

    var expect = {
        'name': '',
        'description': '',
        'configurationId': '',
        'configurationDescription': '',
        'authentication': '',
        'client': '',
        'user': '',
        'alias': '',
        'password': '',
        'language': '',
        'sapCookie': '',
        'x.509Certificate': '',
        'externalIdData': '',
        'externalIdType': '',
        'applicationServer': '',
        'systemNumber': '',
        'messageServer': '',
        'messagePort': '',
        'systemId': '',
        'logonGroup': '',
        'gatewayServer': '',
        'gatewayPort': '',
        'sapRouterString': '',
        'logonCheck': '',
        'logonCodepage': '',
        'logonCodepageType': '',
        'tableParameterDeltaMngmt': '',
        'getSsoTicket': '',
        'denyInitialPwds': '',
        'activeConnections': '',
        'idleConnections': '',
        'expirationTimeout': '',
        'expirationPeriod': '',
        'queuedTimeout': '',
        'sncMode': '',
        'sncPartner': '',
        'sncLevel': '',
        'sncName': '',
        'sncLibrary': '',
        'sncSso': '',
        'repositoryDestination': '',
        'repositoryUser': '',
        'repositoryPassword': '',
        'repositorySncMode': '',
        'repositoryRoundtripOptimization': '',
        'properties': {
            'key': {
                'type': 'type',
                'value': 'value'
            },
            'key1': {
                'type': 'type1',
                'value': 'value1'
            }
        },
        'factoryPid': '',
        'bundleLocation': ''
    };

    var lastAttributeOutput = 'Bundle Location:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput, function (c, output) {
        if (output.match(/Properties \(key:type:value key:type:value\): $/)) {
            c.stdin.write('key:type:value key1:type1:value1\n');
            return;
        }
        c.stdin.write('\n');
    });
});

tap.test('model', function (t) {

    var process = require.resolve('./../process/model.js');

    var expect = {
        'name': 'book',
        'label': 'book',
        'attributes': {
            'author': {
                'type': 'string',
                'mandatory': false,
                'key': false
            },
            'isbn': {
                'type': 'integer',
                'mandatory': true,
                'key': false
            }
        }
    };

    var lastAttributeOutput = 'Models ID Attribute:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput, function (c, output) {
        if (output.match(/Name: $/)) {
            c.stdin.write('book\n');
            return;
        }
        if (output.match(/Attributes \(name:type:mandatory:key name:type:mandatory:key\): $/)) {
            c.stdin.write('author:string isbn:integer:true:key\n');
            c.stdin.end();
            return;
        }
        c.stdin.write('\n');
    });
});

tap.test('rest', function (t) {

    var process = require.resolve('./../process/rest.js');

    var expect = {
        name: '',
        description: '',
//        connectorProvider: 'HTTP',
//        protocol: 'com.mwaysolutions.mcap.connector.http.RestConnectionConfig',
        type: 'rest',
        properties: {
            descriptorUrl: '',
            userName: '',
            password: ''
        }
    };

    var lastAttributeOutput = 'Password:';

    //console.error('%s %s', node, process);
    spawnProcess(t, process, expect, lastAttributeOutput);
});

tap.test('saprfc', function (t) {

    var process = require.resolve('./../process/saprfc.js');

    var expect = {
        'name': '',
        'description': '',
        'connector': '',
        'protocol': '',
        'properties': {
            'authentication': '',
            'client': '',
            'user': '',
            'alias': '',
            'password': '',
{'fraction_non_alphanumeric': 0.18960834136510996, 'fraction_numerical': 0.0021028651537720144, 'mean_word_length': 1.9035868735690664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7450343', 'n_tokens_mistral': 3358, 'n_tokens_neox': 3313, 'n_words': 614}