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

Rest and UI tests for organization entity deletion #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ public AbstractEntityRestClient(String resourcePath, Class<Entity> clazz) {

@Override
public EntityRestClient<Entity, NewEntity> fetch(String idOrVersion) {
this.bean = withManager().get(getResourcePath(idOrVersion)) .as(clazz);
this.bean = withManager().get(getResourcePath(idOrVersion)).as(clazz);
return this;
}

@Override
public EntityRestClient<Entity, NewEntity> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public interface EntityRestClient<Entity, NewEntity> {
*/
EntityRestClient<Entity, NewEntity> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -79,7 +93,7 @@ public OrgMembersListPage members() {
$("#tab-members").click();
return page(OrgMembersListPage.class);
}

/**
* Activates activity tab
* @return OrgPlansListPage page object
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}