juju: fixed collector tests.

using a testing server to return badgateway to skip timeout.
juju: refactoring collector tests.

create a function to create a badGatewayServer.