@Test
public void testApplyWithGateway() {
final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
final NetworkApi nwApi = createMock(NetworkApi.class);
final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
Network network = Network.builder().IPv4Range("0.0.0.0/0")
.id("abcd").name("this-network").gatewayIPv4("1.2.3.4")
.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network"))
.build();
Operation createOp = createMock(Operation.class);
final Supplier<String> userProject = new Supplier<String>() {
@Override
public String get() {
return "myproject";
}
};
expect(api.getNetworkApiForProject(userProject.get())).andReturn(nwApi).atLeastOnce();
expect(api.getGlobalOperationApiForProject(userProject.get())).andReturn(globalApi).atLeastOnce();
expect(nwApi.createInIPv4RangeWithGateway("this-network", "0.0.0.0/0", "1.2.3.4"))
.andReturn(createOp);
expect(globalApi.get("create-op")).andReturn(createOp);
expect(nwApi.get("this-network")).andReturn(null);
expect(nwApi.get("this-network")).andReturn(network);
expect(createOp.getName()).andReturn("create-op");
expect(createOp.getStatus()).andReturn(Operation.Status.DONE);