Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Add tests for creating contract with oldest/newest version of API int…
Browse files Browse the repository at this point in the history
…o CreateContractIT
  • Loading branch information
Ondrej Pontes committed Jun 15, 2016
1 parent 51aa4dd commit afd96ff
Showing 1 changed file with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static io.apiman.test.integration.ui.support.selenide.SelenideUtils.open;

import static com.codeborne.selenide.Condition.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;

import io.apiman.test.integration.runner.annotations.entity.Plan;
import io.apiman.test.integration.runner.annotations.misc.Contract;
Expand Down Expand Up @@ -52,18 +54,20 @@ public class CreateContractIT extends AbstractUITest {
@PlanVersion(plan = "secondPlan")
private static PlanVersionBean secondPlanVersion;

@ApiVersion(api = "api", unique = true, vPlans = {"planVersion", "secondPlanVersion"})
private static ApiVersionBean publishedApiVersion;
@ApiVersion(api = "api", unique = true, isPublic = false, vPlans = {"planVersion", "secondPlanVersion"})
private static ApiVersionBean firstAPI;

@ApiVersion(api = "api", unique = true, publish = false)
private static ApiVersionBean unpublishedApiVersion;
@ApiVersion(api = "api", unique = true, isPublic = false, vPlans = {"planVersion", "secondPlanVersion"})
private static ApiVersionBean secondAPI;

@ClientVersion(client = "client", unique = true,
contracts = @Contract(vPlan = "planVersion", vApi = "publishedApiVersion"))
private static ClientVersionBean registeredClientVersion;
@ApiVersion(api = "api", publish = false)
private static ApiVersionBean unpublishAPI;

@ClientVersion(client = "client", unique = true, publish = false)
private static ClientVersionBean nonRegisteredClientVersion;
@ClientVersion(client = "client", unique = true)
private static ClientVersionBean firstClientVersion;

@ClientVersion(client = "client", unique = true)
private static ClientVersionBean secondClientVersion;

CreateContractPage page;

Expand All @@ -78,13 +82,13 @@ public void shouldListAllAvailableVersionsForSelectedClient() throws Exception {

page.clientVersionSelect().open();

page.clientVersionSelect().options().findBy(text(nonRegisteredClientVersion.getVersion())).should(exist);
page.clientVersionSelect().options().findBy(text(registeredClientVersion.getVersion())).should(exist);
page.clientVersionSelect().options().findBy(text(firstClientVersion.getVersion())).should(exist);
page.clientVersionSelect().options().findBy(text(secondClientVersion.getVersion())).should(exist);
}

@Test
public void shouldListAllAvailablePlansForSelectedApi() throws Exception {
page.selectApiVersion(api.getName(), publishedApiVersion.getVersion());
page.selectApiVersion(api.getName(), firstAPI.getVersion());

page.planSelect().open();
page.planSelect().options().findBy(text(plan.getName())).should(exist);
Expand All @@ -96,32 +100,48 @@ public void shouldListOnlyPublishedApis() throws Exception {
page.selectApi(api.getName());
page.apiVersionSelect().open();
page.apiVersionSelect().options()
.findBy(text(publishedApiVersion.getVersion()))
.findBy(text(firstAPI.getVersion()))
.should(exist);
page.apiVersionSelect().options()
.findBy(text(secondAPI.getVersion()))
.should(exist);

page.apiVersionSelect().options().shouldHaveSize(1);
page.apiVersionSelect().options().shouldHaveSize(2);
}

@Test
public void shouldListCorrectApiVersionWhenSelected() throws Exception {
page.selectApiVersion(api.getName(), publishedApiVersion.getVersion());
page.selectedApiButton().shouldHave(
and("Selected api version button displays api name and api version",
text(api.getName()), text(publishedApiVersion.getVersion())));
selectAndCheckApiVersion(firstAPI.getVersion());
selectAndCheckApiVersion(secondAPI.getVersion());
}

@Test
public void canCreateContract() throws Exception {
page.selectClientVersion(client.getName(), nonRegisteredClientVersion.getVersion())
.selectApiVersion(api.getName(), publishedApiVersion.getVersion())
.selectPlan(plan.getName())
public void canCreateContractWithOldestVersionOfApi() throws Exception {
createContract(firstClientVersion, firstAPI);
}

@Test
public void canCreateContractWithNewestVersionOfApi(){
createContract(secondClientVersion, secondAPI);
}

private void createContract(ClientVersionBean clientVersion, ApiVersionBean apiVersion){
page.selectClientVersion(client.getName(), clientVersion.getVersion())
.selectApiVersion(api.getName(), apiVersion.getVersion())
.create();

ClientVersions clientVersions = new ClientVersions(client);
clientVersions.fetch(nonRegisteredClientVersion.getVersion());
clientVersions.fetch(clientVersion.getVersion());
Contracts contractClient = clientVersions.contracts();

contractClient.fetch(organization, publishedApiVersion, planVersion);
contractClient.fetch(organization, apiVersion, planVersion);
Assert.assertNotNull("Contract hasn't been created", contractClient.getBean());
}

private void selectAndCheckApiVersion(String version){
page.selectApiVersion(api.getName(), version);
page.selectedApiButton().shouldHave(
and("Selected api version button displays api name and api version",
text(api.getName()), text(version)));
}
}

0 comments on commit afd96ff

Please sign in to comment.