java mock 工具_「测试」 - 接口测试 & mock工具Moco

这篇博客介绍了如何通过bash脚本Moco实现Java应用的自动化安装、启动、升级及服务器管理。重点讲解了如何设置JAVA_HOME、选择合适的Java命令、下载最新Moco版本并配置HTTPS服务器。
摘要由CSDN通过智能技术生成

#!/usr/bin/env bash

# Ensure this file is executable via `chmod a+x moco`, then place it

# somewhere on your $PATH, like ~/bin. The rest of moco will be

# installed upon first run into the ~/.moco directory.

if [ `id -u` -eq 0 ] && [ "$MOCO_ROOT" = "" ]; then

echo "WARNING: You're currently running as root; probably by accident."

echo "Press control-C to abort or Enter to continue as root."

echo "Set MOCO_ROOT to disable this warning."

read _

fi

echo $*

#export MOCO_HOME="${MOCO_HOME:-"$HOME/.moco"}"

export MOCO_HOME=$(cd `dirname $0`; cd boot; pwd)

VERSION_LOG_FILE="$MOCO_HOME/.version"

# Determine the Java command to use to start the JVM.

if [ -n "$JAVA_HOME" ] ; then

if [ -x "$JAVA_HOME/jre/sh/java" ] ; then

# IBM's JDK on AIX uses strange locations for the executables

JAVACMD="$JAVA_HOME/jre/sh/java"

else

JAVACMD="$JAVA_HOME/bin/java"

fi

if [ ! -x "$JAVACMD" ] ; then

die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the

location of your Java installation."

fi

else

JAVACMD="java"

which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the

location of your Java installation."

fi

if [ "$HTTP_CLIENT" = "" ]; then

if type -p curl >/dev/null 2>&1; then

if [ "$https_proxy" != "" ]; then

CURL_PROXY="-x $https_proxy"

fi

HTTP_CLIENT="curl $CURL_PROXY -f -L -o"

else

HTTP_CLIENT="wget -O"

fi

fi

function download_failed_message{echo "Failed to download $1"

echo "It's possible your HTTP client's certificate store does not have the"

echo "correct certificate authority needed. This is often caused by an"

echo "out-of-date version of libssl. Either upgrade it or set HTTP_CLIENT"

echo "to turn off certificate checks:"

echo "  export HTTP_CLIENT=\"wget --no-check-certificate -O\" # or"

echo "  export HTTP_CLIENT=\"curl --insecure -f -L -o\""

echo "It's also possible that you're behind a firewall haven't yet"

echo "set HTTP_PROXY and HTTPS_PROXY."}function download{$HTTP_CLIENT "$2.pending" "$1"

if [ $? == 0 ]; then

# TODO:checksum

mv -f "$2.pending" "$2"

else

rm "$2.pending" 2> /dev/null

download_failed_message "$1"

exit 1

fi}function parse_tag{tag_value=`grep ".*<.>" $1 | sed -e "s/^.*"| cut -f1 -d"

MOCO_METADATA="/tmp/maven-metadata.xml"

download $MOCO_METADATA_URL $MOCO_METADATA

parse_tag $MOCO_METADATA latest

LATEST_VERSION=$tag_value}function parse_standalone_latest_url{parse_maven_metadata

VERSION=${LATEST_VERSION%}LATEST_MOCO_STANDALONE_JAR="moco-runner-$VERSION-standalone.jar"

MOCO_STANDLONE_URL="http://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/$LATEST_VERSION/$LATEST_MOCO_STANDALONE_JAR"

}

function install{echo "Install moco"

echo "Parse the latest version of moco"

parse_standalone_latest_url

echo "Download the latest moco:$LATEST_VERSION"

MOCO_STANDALONE="$MOCO_HOME/$LATEST_MOCO_STANDALONE_JAR"

echo "$MOCO_STANDALONE $LATEST_VERSION" >> $VERSION_LOG_FILE

download $MOCO_STANDLONE_URL $MOCO_STANDALONE}function load_current_version{read MOCO_STANDALONE CURRENT_VERSION 

if [[ "$(uname)" -ne "Darwin" && "$(expr substr $(uname -s) 2 6)" == "CYGWIN"   ]];then

MOCO_STANDALONE=`cygpath -m "$MOCO_STANDALONE"`

fi}function usage{printf "

options:help      show help

start     start server, e.g. moco start -p 12306 -c configfile.json

shutdown  shutdown moco server

upgrade   upgrade moco

"}if [ ! -e "$MOCO_HOME" ]

then

mkdir "$MOCO_HOME"

install

fi

if [ "$1" = "start" ]; then

echo "Starting

9b8a8a44dd1c74ae49c20a7cd451974e.png"

load_current_version

exec "$JAVACMD" -jar "$MOCO_STANDALONE" $*

elif [ "$1" = "http" ]; then

echo "Starting HTTP server

9b8a8a44dd1c74ae49c20a7cd451974e.png"

load_current_version

exec "$JAVACMD" -jar "$MOCO_STANDALONE" $*

elif [ "$1" = "https" ]; then

echo "Starting HTTPS server

9b8a8a44dd1c74ae49c20a7cd451974e.png"

load_current_version

exec "$JAVACMD" -jar "$MOCO_STANDALONE" $*

elif [ "$1" = "socket" ]; then

echo "Starting Socket server

9b8a8a44dd1c74ae49c20a7cd451974e.png"

load_current_version

exec "$JAVACMD" -jar "$MOCO_STANDALONE" $*

elif [ "$1" = "shutdown" ]; then

echo "Shutting down server

9b8a8a44dd1c74ae49c20a7cd451974e.png"

load_current_version

exec "$JAVACMD" -jar "$MOCO_STANDALONE" $*

elif [ "$1" = "upgrade" ]; then

echo "Check the new version"

parse_maven_metadata

load_current_version

if [ "$LATEST_VERSION" = "$CURRENT_VERSION" ]; then

echo "The current version of moco is the latest"

else

echo "Upgrading

9b8a8a44dd1c74ae49c20a7cd451974e.png"

rm $VERSION_LOG_FILE

install

fi

elif [ "$1" = "version" ]; then

load_current_version

echo "Moco version: $CURRENT_VERSION"

elif [ "$1" = "help" ]; then

usage

else

usage

fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值