JulioHM
JulioHM

Reputation: 1309

Maven plugin that runs a "web proxy" for integration tests

This might be confusing, so bear with me.

I am not interested in running maven behind a proxy. I understand how to configure maven, eclipse or the JVM itself to get web access via proxies.

However, in my project, I have a component that will retrieve the contents of a given URL and analyze it. It uses Apache Http Components underneath, coated with a little predefined configuration and error handling (really just a wrapper to hide boiler plate code). Since apache-httpcomponents itself can make use of proxies, my component will accept a proxy configuration that can be passed to apache-httpcomponents.

Does anyone know of any proxy plugin that allows this type of integration test, like "maven-simpleproxy-plugin" or anything like that?

I want to test the ability of my component to run well behind a proxy. I imagine that I would need to run some sort of plugin which will start up a dummy proxy server along with maven-embedded-glassfish-plugin. I can host a dummy content inside glassfish and make my component try to access it via this "maven-simpleproxy-plugin" instance... thus allowing me to test the component's ability to handle its proxy configuration correctly.

Does anything like that exist?

Upvotes: 1

Views: 692

Answers (2)

Kostas Filios
Kostas Filios

Reputation: 780

I think you are looking for MockServer. It looks pretty active on github with 1.000+ stars and 25+ contributors and can do the following, as explained on their website:

MockServer Proxy can:

  • proxy all requests using any of the following proxying methods:
    • Port Forwarding
    • Web Proxying (i.e. HTTP proxy)
    • HTTPS Tunneling Proxying (using HTTP CONNECT)
    • SOCKS Proxying (i.e. dynamic port forwarding)
  • verify requests have been sent (i.e. in a test assertion)
  • record requests and responses to analyse how a system behaves

Regarding the different deployment/usage options you've been asking for, let me again copy from their website:

The MockServer and MockServer Proxy can be run:

  • via a Maven Plugin as part of a Maven build cycle
  • programmatically via a Java API in an @Before or @After method
  • using a JUnit @Rule via a @Rule annotated field in a JUnit test
  • from the command line as a stand-alone process in a test environment
  • as a deployable WAR to an existing application server
  • as a Grunt plugin as part of a Grunt build cycle
  • as a Node.js (npm) module from any Node.js code
  • as a Docker container in any Docker enabled environment

ps: I'm not affiliated in any way with the project

Upvotes: 0

James Gustard
James Gustard

Reputation: 61

I would use maven exec plugin to start up the proxy server you want to test. Then write a script which is called at the post-integration-test phase that shuts the proxy server down. Then you are testing through the same proxy server type as your production environment.

Upvotes: 1

Related Questions