fix(manager): add test for delete (clients, apis, plans)
Fixes
MODIFY
manager/api/es/src/main/java/io/apiman/manager/api/es/EsStorage.java
manager/api/es/src/main/java/io/apiman/manager/api/es/EsStorage.java
@@ -659,30 +659,29 @@ public class EsStorage extends AbstractEsComponent implements IStorage, IStorage
BoolQueryBuilder qb = QueryBuilders.boolQuery();
List<QueryBuilder> filter = qb.filter();
- // part 1.1
- BoolQueryBuilder subBoolQuery1 = QueryBuilders.boolQuery();
- List<QueryBuilder> subShouldQuery1 = subBoolQuery1.should();
- subShouldQuery1.add(QueryBuilders.termQuery("clientOrganizationId", orgId));
- subShouldQuery1.add(QueryBuilders.termQuery("organizationId", orgId));
- filter.add(subBoolQuery1);
+ // contract
+ BoolQueryBuilder shouldMatchClientOrgAndOrgId = QueryBuilders.boolQuery();
+ shouldMatchClientOrgAndOrgId.should().add(QueryBuilders.termQuery("clientOrganizationId", orgId));
+ shouldMatchClientOrgAndOrgId.should().add(QueryBuilders.termQuery("organizationId", orgId));
- BoolQueryBuilder subBoolQuery2 = QueryBuilders.boolQuery();
- List<QueryBuilder> shouldQuery2 = qb.should();
-
- // part 2.1
- BoolQueryBuilder part1 = QueryBuilders.boolQuery();
- List<QueryBuilder> part1filter = part1.filter();
- part1filter.add(QueryBuilders.termQuery("entityId", clientId));
- part1filter.add(QueryBuilders.termQuery("entityType", AuditEntityType.Client.name()));
- // part 2.2
- BoolQueryBuilder part2 = QueryBuilders.boolQuery();
- List<QueryBuilder> part2filter = part2.filter();
- part2filter.add(QueryBuilders.termQuery("entityId", clientId));
- part2filter.add(QueryBuilders.termQuery("type", AuditEntityType.Client.name()));
- // part 2.3
- shouldQuery2.add(QueryBuilders.termQuery("clientId", clientId));
-
- filter.add(subBoolQuery2);
+ BoolQueryBuilder shouldMatchTypesAndEntityIds = QueryBuilders.boolQuery();
+ List<QueryBuilder> shouldMatchCombination = shouldMatchTypesAndEntityIds.should();
+
+ // all audit entries with given clientId
+ BoolQueryBuilder shouldMatchEntityIdAndEntityType = QueryBuilders.boolQuery();
+ shouldMatchEntityIdAndEntityType.filter().add(QueryBuilders.termQuery("entityId", clientId));
+ shouldMatchEntityIdAndEntityType.filter().add(QueryBuilders.termQuery("entityType", AuditEntityType.Client.name()));
+ shouldMatchCombination.add(shouldMatchEntityIdAndEntityType);
+
+ BoolQueryBuilder shouldMatchEntityIdAndType = QueryBuilders.boolQuery();
+ shouldMatchEntityIdAndType.filter().add(QueryBuilders.termQuery("entityId", clientId));
+ shouldMatchEntityIdAndType.filter().add(QueryBuilders.termQuery("type", AuditEntityType.Client.name()));
+ shouldMatchCombination.add(shouldMatchEntityIdAndType);
+
+ shouldMatchCombination.add(QueryBuilders.termQuery("clientId", clientId));
+
+ filter.add(shouldMatchClientOrgAndOrgId);
+ filter.add(shouldMatchTypesAndEntityIds);
try {
@@ -807,13 +806,13 @@ public class EsStorage extends AbstractEsComponent implements IStorage, IStorage
shouldFilters.add(subBoolQuery1);
BoolQueryBuilder subBoolQuery2 = QueryBuilders.boolQuery();
- List<QueryBuilder> subBoolQuery2Filter = subBoolQuery1.filter();
+ List<QueryBuilder> subBoolQuery2Filter = subBoolQuery2.filter();
subBoolQuery2Filter.add(QueryBuilders.termQuery("planId", planId));
subBoolQuery2Filter.add(QueryBuilders.termQuery("organizationId", orgId));
shouldFilters.add(subBoolQuery2);
BoolQueryBuilder subBoolQuery3 = QueryBuilders.boolQuery();
- List<QueryBuilder> subBoolQuery3Filter = subBoolQuery1.filter();
+ List<QueryBuilder> subBoolQuery3Filter = subBoolQuery3.filter();
subBoolQuery3Filter.add(QueryBuilders.termQuery("entityId", planId));
subBoolQuery3Filter.add(QueryBuilders.termQuery("type", AuditEntityType.Plan.name()));
shouldFilters.add(subBoolQuery3);

ADD
manager/test/api/src/test/resources/test-plan-data/apis/delete_unpublished/005_get-api-5-version-7.0.resttest
+GET /organizations/Organization1/apis/API5/versions/7.0 admin/admin
+----
+200
+Content-Type: application/json
+
+{
+ "api" : {
+ "organization" : {
+ "id" : "Organization1"
+ },
+ "id" : "API5",
+ "name" : "API 5",
+ "description" : "This is the description of API 5.",
+ "createdBy":"admin"
+ },
+ "status" : "Ready",
+ "version" : "7.0",
+ "createdBy" : "admin",
+ "endpoint" : "http://localhost:9000/api-5",
+ "endpointType" : "rest",
+ "publicAPI" : true
+}

ADD
manager/test/api/src/test/resources/test-plan-data/clients/delete/001_delete-client-2.resttest
+DELETE /organizations/Organization1/clients/Client2 admin/admin
+----
+204

DELETE
manager/test/api/src/test/resources/test-plan-data/clients/delete/002_delete-client-1.resttest
-DELETE /organizations/Organization1/clients/Client1 admin/admin
-----
-204

RENAME
manager/test/api/src/test/resources/test-plan-data/clients/delete/003_get-client-1.resttest
manager/test/api/src/test/resources/test-plan-data/clients/delete/002_get-client-2.resttest
-GET /organizations/Organization1/clients/Client1 admin/admin
+GET /organizations/Organization1/clients/Client2 admin/admin
----
404
Content-Type: application/json
X-Apiman-Error: true
-{"type":"ClientNotFoundException","errorCode":4002,"message":"Client does not exist: Client1","moreInfoUrl":null}
+{"type":"ClientNotFoundException","errorCode":4002,"message":"Client does not exist: Client2","moreInfoUrl":null}

ADD
manager/test/api/src/test/resources/test-plan-data/clients/delete/003_get-client-1-version-1.0.resttest
+GET /organizations/Organization1/clients/Client1/versions/1.0 admin/admin
+----
+200
+Content-Type: application/json
+
+{
+ "client" : {
+ "organization" : {
+ "id" : "Organization1"
+ },
+ "id" : "Client1",
+ "name" : "Client 1",
+ "description" : "[UPDATED] This is the description of Client 1!",
+ "createdBy":"admin"
+ },
+ "status" : "Created",
+ "version" : "1.0",
+ "createdBy" : "admin"
+}

ADD
manager/test/api/src/test/resources/test-plan-data/plans/delete/007_get-plan1-version-1.0.resttest
+GET /organizations/Organization1/plans/Plan1/versions/1.0 admin/admin
+----
+200
+Content-Type: application/json
+
+{
+ "plan" : {
+ "organization" : {
+ "id" : "Organization1"
+ },
+ "id" : "Plan1",
+ "name" : "Plan 1",
+ "description" : "[UPDATED] This is the description of Plan 1!",
+ "createdBy":"admin"
+ },
+ "status" : "Locked",
+ "version" : "1.0",
+ "createdBy" : "admin"
+}

MODIFY
manager/test/api/src/test/resources/test-plans/apis-testPlan.xml
manager/test/api/src/test/resources/test-plans/apis-testPlan.xml
<test name="Retire API 1">test-plan-data/apis/publish/005_retire-api-1.resttest</test>
<test name="Delete API 1">test-plan-data/apis/publish/006_delete-api-1.resttest</test>
<test name="Delete API 1 (404)">test-plan-data/apis/delete_unpublished/004_get-unpublished-api1-404.resttest</test>
+ <test name="Check delete do not affect other APIs">test-plan-data/apis/versions/011_get-api-5-version-7.0.resttest</test>
</testGroup>
</testPlan>

MODIFY
manager/test/api/src/test/resources/test-plans/clients-testPlan.xml
manager/test/api/src/test/resources/test-plans/clients-testPlan.xml
<!-- Deleting -->
<testGroup name="Deleting Clients (With subordinate elements)">
- <test name="Delete Client 1">test-plan-data/clients/delete/002_delete-client-1.resttest</test>
- <test name="Get Client 1 (404)">test-plan-data/clients/delete/003_get-client-1.resttest</test>
+ <test name="Delete Client 2">test-plan-data/clients/delete/001_delete-client-2.resttest</test>
+ <test name="Get Client 2 (404)">test-plan-data/clients/delete/002_get-client-2.resttest</test>
+ <test name="Check delete do not affect other clients">test-plan-data/clients/delete/003_get-client-1-version-1.0.resttest</test>
</testGroup>
</testPlan>

MODIFY
manager/test/api/src/test/resources/test-plans/plans-testPlan.xml
manager/test/api/src/test/resources/test-plans/plans-testPlan.xml
<test name="Get Plan 2 (not found)">test-plan-data/plans/delete/004_get-plan2-not-found.resttest</test>
<test name="Get Plan 2 activity (empty) ">test-plan-data/plans/delete/005_activity.resttest</test>
<test name="Get Plan 2 version activity (empty)">test-plan-data/plans/delete/006_version-activity.resttest</test>
+ <test name="Check delete do not affect other plans">test-plan-data/plans/delete/007_get-plan1-version-1.0.resttest</test>
</testGroup>
</testPlan>

fix(manager): add test for delete (clients, apis, plans)

Fixes #1031