Skip to content

Commit 52a0557

Browse files
committed
Polishing
This commit tweaks some formatting, adds a missing unit test, and adds integration tests. [resolves #1079] Signed-off-by: Paul Harris <harrisp@vmware.com>
1 parent d946cec commit 52a0557

File tree

8 files changed

+276
-57
lines changed

8 files changed

+276
-57
lines changed

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/roles/Role.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,24 @@
1717
package org.cloudfoundry.client.v3.roles;
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import org.cloudfoundry.Nullable;
2021
import org.cloudfoundry.client.v3.Resource;
2122

2223
/**
2324
* Base class for responses that are roles
2425
*/
2526
public abstract class Role extends Resource {
2627

27-
/**
28-
* The type
29-
*/
30-
@JsonProperty("type")
31-
public abstract RoleType getType();
32-
3328
/**
3429
* Relationships of the role
3530
*/
3631
@JsonProperty("relationships")
3732
public abstract RoleRelationships getRelationships();
3833

34+
/**
35+
* The type
36+
*/
37+
@JsonProperty("type")
38+
public abstract RoleType getType();
39+
3940
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/roles/RoleType.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@
3131
public enum RoleType {
3232

3333
/**
34-
* organization_user role type
34+
* organization_auditor role type
3535
*/
36-
ORGANIZATION_USER,
36+
ORGANIZATION_AUDITOR,
3737

3838
/**
39-
* organization_auditor role type
39+
* organization_billing_manager role type
4040
*/
41-
ORGANIZATION_AUDITOR,
41+
ORGANIZATION_BILLING_MANAGER,
4242

4343
/**
4444
* organization_manager role type
4545
*/
4646
ORGANIZATION_MANAGER,
4747

4848
/**
49-
* organization_billing_manager role type
49+
* organization_user role type
5050
*/
51-
ORGANIZATION_BILLING_MANAGER,
51+
ORGANIZATION_USER,
5252

5353
/**
5454
* space_auditor role type
@@ -65,8 +65,8 @@ public enum RoleType {
6565
*/
6666
SPACE_MANAGER;
6767

68-
public static final Set<RoleType> ORGANIZATION_ROLE_TYPES = EnumSet.of(ORGANIZATION_USER, ORGANIZATION_AUDITOR,
69-
ORGANIZATION_MANAGER, ORGANIZATION_BILLING_MANAGER);
68+
public static final Set<RoleType> ORGANIZATION_ROLE_TYPES = EnumSet.of(ORGANIZATION_AUDITOR, ORGANIZATION_BILLING_MANAGER, ORGANIZATION_MANAGER, ORGANIZATION_USER);
69+
7070
public static final Set<RoleType> SPACE_ROLE_TYPES = EnumSet.of(SPACE_AUDITOR, SPACE_DEVELOPER, SPACE_MANAGER);
7171

7272
private static final Map<String, RoleType> NAMES_TO_VALUES = Arrays.stream(RoleType.values())

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/roles/_CreateRoleRequest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@
2727
@Value.Immutable
2828
abstract class _CreateRoleRequest {
2929

30-
/**
31-
* The type
32-
*/
33-
@JsonProperty("type")
34-
abstract RoleType getType();
35-
36-
/**
37-
* The relationships
38-
*/
39-
@JsonProperty("relationships")
40-
abstract RoleRelationships getRelationships();
41-
4230
@Value.Check
4331
protected void validateRelationships() {
4432
if (RoleType.ORGANIZATION_ROLE_TYPES.contains(getType()) && getRelationships().getOrganization() == null) {
@@ -49,4 +37,16 @@ protected void validateRelationships() {
4937
}
5038
}
5139

40+
/**
41+
* The relationships
42+
*/
43+
@JsonProperty("relationships")
44+
abstract RoleRelationships getRelationships();
45+
46+
/**
47+
* The type
48+
*/
49+
@JsonProperty("type")
50+
abstract RoleType getType();
51+
5252
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/roles/_ListRolesRequest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ abstract class _ListRolesRequest extends PaginatedRequest {
3232
* The role ids filter
3333
*/
3434
@FilterParameter("guids")
35-
abstract List<String> getIds();
35+
abstract List<String> getRoleIds();
3636

3737
/**
38-
* The types filter
38+
* The organization ids filter
3939
*/
40-
@FilterParameter("types")
41-
abstract List<RoleType> getTypes();
40+
@FilterParameter("organization_guids")
41+
abstract List<String> getOrganizationIds();
4242

4343
/**
4444
* The space ids filter
@@ -47,10 +47,10 @@ abstract class _ListRolesRequest extends PaginatedRequest {
4747
abstract List<String> getSpaceIds();
4848

4949
/**
50-
* The organization ids filter
50+
* The types filter
5151
*/
52-
@FilterParameter("organization_guids")
53-
abstract List<String> getOrganizationIds();
52+
@FilterParameter("types")
53+
abstract List<RoleType> getTypes();
5454

5555
/**
5656
* The user ids filter

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/roles/_RoleRelationships.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import org.cloudfoundry.AllowNulls;
2122
import org.cloudfoundry.Nullable;
2223
import org.cloudfoundry.client.v3.ToOneRelationship;
2324
import org.immutables.value.Value;
@@ -30,10 +31,11 @@
3031
abstract class _RoleRelationships {
3132

3233
/**
33-
* The user relationship
34+
* The organization relationship
3435
*/
35-
@JsonProperty("user")
36-
abstract ToOneRelationship getUser();
36+
@JsonProperty("organization")
37+
@Nullable
38+
abstract ToOneRelationship getOrganization();
3739

3840
/**
3941
* The space relationship
@@ -43,10 +45,9 @@ abstract class _RoleRelationships {
4345
abstract ToOneRelationship getSpace();
4446

4547
/**
46-
* The organization relationship
48+
* The user relationship
4749
*/
48-
@JsonProperty("organization")
49-
@Nullable
50-
abstract ToOneRelationship getOrganization();
50+
@JsonProperty("user")
51+
abstract ToOneRelationship getUser();
5152

5253
}

cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/roles/CreateRoleRequestTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,15 @@ public void invalidWithMissingOrgRelationship() {
3737
}
3838

3939
@Test(expected = IllegalStateException.class)
40-
public void invalidWithSpaceRelationship() {
40+
public void invalidWithMissingSpaceRelationship() {
4141
CreateRoleRequest.builder()
42-
.type(RoleType.ORGANIZATION_AUDITOR)
42+
.type(RoleType.SPACE_AUDITOR)
4343
.relationships(RoleRelationships.builder()
4444
.user(ToOneRelationship.builder()
4545
.data(Relationship.builder()
4646
.id("test-user-id")
4747
.build())
4848
.build())
49-
.space(ToOneRelationship.builder()
50-
.data(Relationship.builder()
51-
.id("test-space-id")
52-
.build())
53-
.build())
5449
.build())
5550
.build();
5651
}
@@ -63,47 +58,52 @@ public void invalidWithNoRelationships() {
6358
}
6459

6560
@Test(expected = IllegalStateException.class)
66-
public void invalidWithoutType() {
61+
public void invalidWithOrgRelationship() {
6762
CreateRoleRequest.builder()
63+
.type(RoleType.SPACE_AUDITOR)
6864
.relationships(RoleRelationships.builder()
6965
.user(ToOneRelationship.builder()
7066
.data(Relationship.builder()
7167
.id("test-user-id")
7268
.build())
7369
.build())
70+
.organization(ToOneRelationship.builder()
71+
.data(Relationship.builder()
72+
.id("test-org-id")
73+
.build())
74+
.build())
7475
.build())
7576
.build();
7677
}
7778

7879
@Test(expected = IllegalStateException.class)
79-
public void invalidWithMissingSpaceRelationship() {
80+
public void invalidWithSpaceRelationship() {
8081
CreateRoleRequest.builder()
81-
.type(RoleType.SPACE_AUDITOR)
82+
.type(RoleType.ORGANIZATION_AUDITOR)
8283
.relationships(RoleRelationships.builder()
8384
.user(ToOneRelationship.builder()
8485
.data(Relationship.builder()
8586
.id("test-user-id")
8687
.build())
8788
.build())
89+
.space(ToOneRelationship.builder()
90+
.data(Relationship.builder()
91+
.id("test-space-id")
92+
.build())
93+
.build())
8894
.build())
8995
.build();
9096
}
9197

9298
@Test(expected = IllegalStateException.class)
93-
public void invalidWithOrgRelationship() {
99+
public void invalidWithoutType() {
94100
CreateRoleRequest.builder()
95-
.type(RoleType.SPACE_AUDITOR)
96101
.relationships(RoleRelationships.builder()
97102
.user(ToOneRelationship.builder()
98103
.data(Relationship.builder()
99104
.id("test-user-id")
100105
.build())
101106
.build())
102-
.organization(ToOneRelationship.builder()
103-
.data(Relationship.builder()
104-
.id("test-org-id")
105-
.build())
106-
.build())
107107
.build())
108108
.build();
109109
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3.roles;
18+
19+
import org.junit.Test;
20+
21+
public class ListRolesRequestTest {
22+
23+
@Test
24+
public void valid() {
25+
ListRolesRequest.builder()
26+
.build();
27+
}
28+
29+
}

0 commit comments

Comments
 (0)