hoverfly-java icon indicating copy to clipboard operation
hoverfly-java copied to clipboard

Supporting using different json files in Class/SubClass

Open patown opened this issue 5 years ago • 3 comments

A TestBase class is commonly useful to setup shared test context . Hope Hoverfly could support this scenario below,

Public class TestBase() { @ClassRule public static HoverflyRule logonRule = HoverflyRule.inCaptureOrSimulationMode("logon.json"); }

public class TestA extends TestBase { @ClassRule public static HoverflyRule TestARule = HoverflyRule.inCaptureOrSimulationMode("TestA.json"); // }

public class TestB extends TestBase { @ClassRule public static HoverflyRule TestBRule = HoverflyRule.inCaptureOrSimulationMode("TestB.json"); // }

patown avatar Nov 02 '20 01:11 patown

Hi @patown, that's a very useful scenario which I haven't thought of. I guess you want logonRule to be invoked on all the subclasses, and then every subclass has a specific simulation too.

The current hoverfly-java doesn't support it, but it's doable, as hoverfly already has a REST API for combining simulations (https://docs.hoverfly.io/en/latest/pages/reference/api/api.html#post-api-v2-simulation), that leaves us to make some tweaks in the library to support it.

It's not going to have multiple hoverfly rules though, one hoverfly per test is recommended to avoid conflicts in proxy config. So something like this:

Public class TestBase() {
@ClassRule
public static HoverflyRule baseRule = HoverflyRule.inCaptureOrSimulationMode("logon.json");
}

public class TestA extends TestBase {

// Setup
baseRule.captureOrSimulate("TestA.json", ImportMode.APPEND);

}

public class TestB extends TestBase {

// Setup
baseRule.captureOrSimulate("TestB.json", ImportMode.APPEND);
}

tommysitu avatar Nov 02 '20 22:11 tommysitu

Hi Tommy, Thank you for your mail. This is very helpful. Antony

At 2020-11-03 05:17:10, "Tommy Situ" [email protected] wrote:

Hi @patown, that's a very useful scenario which I haven't thought of. I guess you want logonRule to be invoked on all the subclasses, and then every subclass has a specific simulation too.

The current hoverfly-java doesn't support it, but it's doable, as hoverfly already has a REST API for combining simulations (https://docs.hoverfly.io/en/latest/pages/reference/api/api.html#post-api-v2-simulation), that leaves us to make some tweaks in the library to support it.

It's not going to have multiple hoverfly rules though, one hoverfly per test is recommended to avoid conflicts in proxy config. So something like this:

Public class TestBase() { @ClassRule public static HoverflyRule baseRule = HoverflyRule.inCaptureOrSimulationMode("logon.json"); }

public class TestA extends TestBase {

// Setup baseRule.captureOrSimulate("TestA.json", ImportMode.APPEND);

}

public class TestB extends TestBase {

// Setup baseRule.captureOrSimulate("TestB.json", ImportMode.APPEND); }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

patown avatar Nov 10 '20 12:11 patown

How can we do this in Junit5 ? baseRule.captureOrSimulate("TestA.json", ImportMode.APPEND);

patown avatar Feb 08 '21 03:02 patown