diff --git a/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/AbstractEntityRestClient.java b/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/AbstractEntityRestClient.java index 9336a99..7d10ff5 100644 --- a/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/AbstractEntityRestClient.java +++ b/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/AbstractEntityRestClient.java @@ -47,16 +47,21 @@ public AbstractEntityRestClient(String resourcePath, Class clazz) { @Override public EntityRestClient fetch(String idOrVersion) { - this.bean = withManager().get(getResourcePath(idOrVersion)) .as(clazz); + this.bean = withManager().get(getResourcePath(idOrVersion)).as(clazz); return this; } @Override public EntityRestClient create(NewEntity newBean) { - this.bean = withManager().content(newBean).post(resourcePath).as(clazz);; + this.bean = withManager().content(newBean).post(resourcePath).as(clazz); return this; } + @Override + public void delete(String idOrVersion, ResponseSpecification spec){ + givenManager().delete(getResourcePath(idOrVersion)).then().specification(spec); + } + @Override public void peek(String idOrVersion) { ResponseSpecification spec = new ResponseSpecBuilder().expectStatusCode(200).build(); diff --git a/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/EntityRestClient.java b/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/EntityRestClient.java index acc78c2..d5de066 100644 --- a/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/EntityRestClient.java +++ b/apiman-it-commons/src/main/java/io/apiman/test/integration/runner/restclients/EntityRestClient.java @@ -39,6 +39,13 @@ public interface EntityRestClient { */ EntityRestClient create(NewEntity newBean); + /** + * Perform DELETE request via REST API by id or version + * @param idOrVersion id or version + * @param spec specification to be used for response verification + */ + void delete(String idOrVersion, ResponseSpecification spec); + /** * Perform GET request and verify the response * @param idOrVersion id or version diff --git a/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/entity/DeleteOrg.java b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/entity/DeleteOrg.java new file mode 100644 index 0000000..a699c44 --- /dev/null +++ b/apiman-it-rest/src/test/java/io/apiman/test/integration/rest/entity/DeleteOrg.java @@ -0,0 +1,115 @@ +/* + * Copyright 2016 Red Hat Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.apiman.test.integration.rest.entity; + +import io.apiman.test.integration.runner.ApimanRunner; +import io.apiman.test.integration.runner.annotations.entity.Api; +import io.apiman.test.integration.runner.annotations.entity.Client; +import io.apiman.test.integration.runner.annotations.entity.Organization; +import io.apiman.test.integration.runner.annotations.entity.Plan; +import io.apiman.test.integration.runner.annotations.misc.ApiKey; +import io.apiman.test.integration.runner.annotations.misc.Contract; +import io.apiman.test.integration.runner.annotations.misc.ManagedEndpoint; +import io.apiman.test.integration.runner.annotations.version.ApiVersion; +import io.apiman.test.integration.runner.annotations.version.ClientVersion; +import io.apiman.test.integration.runner.annotations.version.PlanVersion; +import io.apiman.test.integration.runner.restclients.entity.Organizations; +import io.apiman.manager.api.beans.apis.ApiBean; +import io.apiman.manager.api.beans.apis.ApiVersionBean; +import io.apiman.manager.api.beans.clients.ClientBean; +import io.apiman.manager.api.beans.orgs.OrganizationBean; +import io.apiman.manager.api.beans.plans.PlanBean; + +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.ResponseSpecification; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Created by jsmolar. + * + * Rules for organization entity deletion. + * -cannot have any published APIs + * -cannot have any registered client apps + */ +@RunWith(ApimanRunner.class) +public class DeleteOrg { + + //Empty Organization + @Organization + public static OrganizationBean org1; + + //Organization with registered client app + @Organization + public static OrganizationBean org2; + + @Api(organization = "org2") + public static ApiBean api2; + + @ApiVersion(api = "api2", vPlans = {"plan"}) + @ManagedEndpoint + private static String endpoint; + + @Plan(organization = "org2") + @PlanVersion + private static PlanBean plan; + + @Client(organization = "org2") + private static ClientBean client; + + @ClientVersion(client = "client", contracts = @Contract(vPlan = "plan", vApi = "endpoint")) + @ApiKey(vPlan = "plan", vApi = "endpoint") + private static String apikey; + + //Organization with published API + @Organization() + public static OrganizationBean org3; + + @Api(organization = "org3") + public static ApiBean api3; + + @ApiVersion(api = "api3") + private static ApiVersionBean apiVersion3; + + private Organizations organizations; + private ResponseSpecification specOK; + private ResponseSpecification specConflict; + + @Before + public void setUp() { + organizations = new Organizations(); + specOK = new ResponseSpecBuilder().expectStatusCode(204).build(); + specConflict = new ResponseSpecBuilder().expectStatusCode(409).build(); + } + + @Test + public void shouldDeleteEmptyOrganization() { + organizations.delete(org1.getId(), specOK); + } + + @Test + public void shouldNotDeleteOrgWithRegisteredClientApp() { + organizations.delete(org2.getId(), specConflict); + } + + @Test + public void shouldNotDeleteOrgWithPublishedApi() { + organizations.delete(org3.getId(), specConflict); + } + +} diff --git a/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/assertion/BeanAssert.java b/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/assertion/BeanAssert.java index 089ee5a..8cf8c7c 100644 --- a/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/assertion/BeanAssert.java +++ b/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/assertion/BeanAssert.java @@ -19,9 +19,10 @@ import static io.apiman.test.integration.runner.RestAssuredUtils.givenManager; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isEmptyOrNullString; import io.apiman.test.integration.Suite; -import io.apiman.test.integration.SuiteProperties; import io.apiman.test.integration.runner.restclients.VersionRestClient; import io.apiman.manager.api.beans.apis.ApiBean; import io.apiman.manager.api.beans.apis.ApiVersionBean; @@ -32,7 +33,6 @@ import java.util.List; -import com.codeborne.selenide.Selenide; import com.jayway.restassured.builder.ResponseSpecBuilder; import com.jayway.restassured.specification.ResponseSpecification; import org.hamcrest.Matchers; @@ -60,6 +60,23 @@ public static void assertOrganization(OrganizationBean expected) { body("description", equalTo(expected.getDescription())); } + /** + * Asserts that the given bean does not matches one inside apiman. + * This method does not have to cross check all fields. + * + * Currently checked fields: name, description + * + * @param expected expected bean + */ + public static void assertOrganizationNotPresent(OrganizationBean expected){ + final String path = "/organizations/{org}"; + givenManager(). + get(path, expected.getName()). + then(). + body("name", is(isEmptyOrNullString())). + body("description", is(isEmptyOrNullString())); + } + /** * Asserts that the given bean matches one inside apiman. * This method does not have to cross check all fields. diff --git a/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/selenide/layouts/OrgEntitiesListPage.java b/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/selenide/layouts/OrgEntitiesListPage.java index 386a040..efb4975 100644 --- a/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/selenide/layouts/OrgEntitiesListPage.java +++ b/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/support/selenide/layouts/OrgEntitiesListPage.java @@ -42,6 +42,20 @@ public SelenideElement orgDescription() { return $("#descriptionWrapper"); } + public SelenideElement deleteButton() { + SelenideElement orgMenu = $("[class='org-menu pull-right']"); + orgMenu.find("[class='dropdown']").click(); + return $("[class='org-delete']"); + } + + public void confirmOrgName(String name){ + $("[ng-model='confirmOrgName']").setValue(name); + } + + public SelenideElement confirmOrgNameButton(){ + return $("[apiman-i18n-key='org-delete-modal-confirmation-button']"); + } + // Tabs /** @@ -79,7 +93,7 @@ public OrgMembersListPage members() { $("#tab-members").click(); return page(OrgMembersListPage.class); } - + /** * Activates activity tab * @return OrgPlansListPage page object diff --git a/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/tests/organizations/DeleteOrganizationIT.java b/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/tests/organizations/DeleteOrganizationIT.java new file mode 100644 index 0000000..22c44ac --- /dev/null +++ b/apiman-it-ui/src/test/java/io/apiman/test/integration/ui/tests/organizations/DeleteOrganizationIT.java @@ -0,0 +1,80 @@ +/* + * Copyright 2016 Red Hat Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.apiman.test.integration.ui.tests.organizations; + +import static io.apiman.test.integration.ui.support.selenide.SelenideUtils.open; + +import io.apiman.test.integration.runner.annotations.entity.Api; +import io.apiman.test.integration.runner.annotations.entity.Organization; +import io.apiman.test.integration.runner.annotations.version.ApiVersion; +import io.apiman.test.integration.ui.support.assertion.BeanAssert; +import io.apiman.test.integration.ui.support.selenide.base.AbstractSimpleUITest; +import io.apiman.test.integration.ui.support.selenide.pages.organizations.OrgPlansListPage; + +import io.apiman.manager.api.beans.apis.ApiBean; +import io.apiman.manager.api.beans.apis.ApiVersionBean; +import io.apiman.manager.api.beans.orgs.OrganizationBean; + +import com.codeborne.selenide.Condition; +import org.junit.Before; +import org.junit.Test; + +/** + * Created by jsmolar. + */ +public class DeleteOrganizationIT extends AbstractSimpleUITest { + + @Organization + private OrganizationBean organization; + + @Organization() + public static OrganizationBean orgWithApi; + + @Api(organization = "orgWithApi") + public static ApiBean api; + + @ApiVersion(api = "api") + private static ApiVersionBean apiVersion; + + private OrgPlansListPage thePlansPage; + + @Before + public void setUp() { + thePlansPage = open(OrgPlansListPage.class, organization.getName()); + thePlansPage.deleteButton().click(); + } + + @Test + public void shouldDeleteOrganization() { + thePlansPage.confirmOrgName(organization.getName()); + thePlansPage.confirmOrgNameButton().click(); + BeanAssert.assertOrganizationNotPresent(organization); + } + + @Test + public void couldNotDeleteWithWrongName() { + thePlansPage.confirmOrgName("WrongOrgName"); + thePlansPage.confirmOrgNameButton().shouldBe(Condition.disabled); + } + + @Test + public void shouldNotDeleteOrgWithPublishedApi() { + thePlansPage.confirmOrgName(orgWithApi.getName()); + thePlansPage.confirmOrgNameButton().click(); + BeanAssert.assertOrganization(organization); + } +}