#!/usr/bin/env nodejs

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

//This is the client side test for the standard Apache Thrift
//"ThriftTest" suite. This client will test any protocol/transport
//combination specified on the command line.

var fs = require('fs');
var assert = require('assert');
var thrift = require('thrift');
var ThriftTest = require('./gen-nodejs/ThriftTest');
var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
var ThriftTestDriverPromise = require('./thrift_test_driver_promise').ThriftTestDriver;

var program = require('commander');

program
  .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]')
  .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]')
  .option('--port <port>', 'Set thift server port number to connect')
  .option('--host <host>', 'Set thift server host to connect')
  .option('--ssl', 'use SSL transport')
  .option('--promise', 'test with promise style functions')
  .parse(process.argv);

var host = "localhost";
if(String(program.host) === "undefined") {
}else{
   host = program.host;
}

var port = 9090;
if(String(program.port) === "undefined") {
}else{
  port = program.port;
}

var protocol = thrift.TBinaryProtocol;
if (program.protocol === "json") {
  protocol = thrift.TJSONProtocol;
} else if (program.protocol === "compact") {
  protocol = thrift.TCompactProtocol;
} 

var transport =  thrift.TBufferedTransport;
if (program.transport === "framed") {
  transport = thrift.TFramedTransport;
}

var options = {
  transport: transport,
  protocol: protocol
};

var connection;

if (program.ssl) {
  options.rejectUnauthorized = false;
  connection = thrift.createSSLConnection(host, port, options);
} else {
  connection = thrift.createConnection(host,port, options);
}

var client = thrift.createClient(ThriftTest, connection);

connection.on('error', function(err) {
  assert(false, err);
});

var testDriver = ThriftTestDriver;
if (program.promise) {
  testDriver = ThriftTestDriverPromise;
} 
testDriver(client, function (status) {
  console.log(status);
  connection.end();
});

// to make it also run on expresso
exports.expressoTest = function() {};
