Skip to content

Commit 831dc98

Browse files
committed
Fixing tests for SDK
1 parent 27ca7bf commit 831dc98

21 files changed

+675
-379
lines changed

astra-sdk-devops/src/main/java/com/dtsx/astra/sdk/org/TokensClient.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.dtsx.astra.sdk.org;
22

33
import com.dtsx.astra.sdk.AbstractApiClient;
4-
import com.dtsx.astra.sdk.org.domain.CreateTokenResponse;
5-
import com.dtsx.astra.sdk.org.domain.IamToken;
6-
import com.dtsx.astra.sdk.org.domain.ResponseAllIamTokens;
4+
import com.dtsx.astra.sdk.org.domain.*;
75
import com.dtsx.astra.sdk.utils.ApiLocator;
86
import com.dtsx.astra.sdk.utils.ApiResponseHttp;
97
import com.dtsx.astra.sdk.utils.Assert;
@@ -17,6 +15,9 @@
1715
*/
1816
public class TokensClient extends AbstractApiClient {
1917

18+
/** useful with tokens interactions. */
19+
private RolesClient rolesClient;
20+
2021
/**
2122
* Constructor.
2223
*
@@ -25,6 +26,7 @@ public class TokensClient extends AbstractApiClient {
2526
*/
2627
public TokensClient(String token) {
2728
super(token);
29+
this.rolesClient = new RolesClient(token);
2830
}
2931

3032
/**
@@ -89,14 +91,34 @@ public void delete(String tokenId) {
8991
*/
9092
public CreateTokenResponse create(String role) {
9193
Assert.hasLength(role, "role");
94+
// Role should exist
95+
Optional<Role> optRole = rolesClient.findByName(role);
96+
String roleId = role;
97+
if (optRole.isPresent()) {
98+
roleId = optRole.get().getId();
99+
} else {
100+
roleId = rolesClient.get(role).getId();
101+
}
92102
// Building request
93-
String body = "{ \"roles\": [ \"" + JsonUtils.escapeJson(role) + "\"]}";
103+
String body = "{ \"roles\": [ \"" + JsonUtils.escapeJson(roleId) + "\"]}";
94104
// Invoke endpoint
95105
ApiResponseHttp res = POST(getEndpointTokens(), body);
96106
// Marshall response
97107
return JsonUtils.unmarshallBean(res.getBody(), CreateTokenResponse.class);
98108
}
99109

110+
/**
111+
* Create token
112+
*
113+
* @param role
114+
* create a token with dedicated role
115+
* @return
116+
* created token
117+
*/
118+
public CreateTokenResponse create(DefaultRoles role) {
119+
return create(role.getName());
120+
}
121+
100122
/**
101123
* Endpoint to access schema for namespace.
102124
*

astra-sdk-devops/src/main/java/com/dtsx/astra/sdk/org/UsersClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.dtsx.astra.sdk.org.domain.ResponseAllUsers;
77
import com.dtsx.astra.sdk.org.domain.Role;
88
import com.dtsx.astra.sdk.org.domain.User;
9+
import com.dtsx.astra.sdk.org.exception.UserNotFoundException;
910
import com.dtsx.astra.sdk.utils.*;
1011

1112
import java.net.HttpURLConnection;
@@ -102,7 +103,7 @@ public boolean existByEmail(String userEmail) {
102103
*/
103104
public void delete(String userId) {
104105
if (!exist(userId)) {
105-
throw new RuntimeException("User '"+ userId + "' has not been found");
106+
throw new UserNotFoundException(userId);
106107
}
107108
DELETE(getEndpointUser(userId));
108109
}

astra-sdk-devops/src/main/java/com/dtsx/astra/sdk/streaming/domain/CreateTenant.java

Lines changed: 154 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,126 +4,206 @@
44
* Tenant Request Creation.
55
*/
66
public class CreateTenant {
7-
7+
8+
/** cloud provider. */
89
private String cloudProvider = "aws";
9-
private String cloudRegion = "useast2";
10-
private String plan = "free";
10+
11+
/** cloud region. */
12+
private String cloudRegion = "useast2";
13+
14+
/** pan. */
15+
private String plan = "free";
16+
17+
/** tenant name. */
1118
private String tenantName;
19+
20+
/** user email. */
1221
private String userEmail;
22+
23+
/** cluster name for DEDICATED clusters. */
1324
private String clusterName;
1425

1526
/**
16-
* Default Constructor.
17-
*/
18-
public CreateTenant() {}
19-
20-
/**
21-
* Provide tenant Name and email.
22-
* @param tenantName
23-
* tenant identifier
24-
* @param email
25-
* email
27+
* Default constructor.
2628
*/
27-
public CreateTenant(String tenantName, String email) {
28-
this.userEmail = email;
29-
this.tenantName = tenantName;
30-
}
31-
29+
private CreateTenant() {}
30+
3231
/**
33-
* Getter accessor for attribute 'cloudProvider'.
34-
*
32+
* Work with builder.
3533
* @return
36-
* current value of 'cloudProvider'
34+
* builder
3735
*/
38-
public String getCloudProvider() {
39-
return cloudProvider;
36+
public static Builder builder() {
37+
return new Builder();
4038
}
4139

4240
/**
43-
* Setter accessor for attribute 'cloudProvider'.
44-
* @param cloudProvider
45-
* new value for 'cloudProvider '
41+
* Builder
4642
*/
47-
public void setCloudProvider(String cloudProvider) {
48-
this.cloudProvider = cloudProvider;
43+
public static class Builder {
44+
45+
/** cloud provider. */
46+
private String cloudProvider = "aws";
47+
48+
/** cloud region. */
49+
private String cloudRegion = "useast2";
50+
51+
/** pan. */
52+
private String plan = "free";
53+
54+
/** tenant name. */
55+
private String tenantName;
56+
57+
/** user email. */
58+
private String userEmail;
59+
60+
/** cluster name for DEDICATED clusters. */
61+
private String clusterName;
62+
63+
/** default/ */
64+
public Builder() {}
65+
66+
/**
67+
* Builder.
68+
*
69+
* @param tenantName
70+
* current param.
71+
* @return
72+
* current reference.
73+
*/
74+
public Builder tenantName(String tenantName) {
75+
this.tenantName = tenantName;
76+
return this;
77+
}
78+
79+
/**
80+
* Builder.
81+
*
82+
* @param email
83+
* current param.
84+
* @return
85+
* current reference.
86+
*/
87+
public Builder userEmail(String email) {
88+
this.userEmail = email;
89+
return this;
90+
}
91+
92+
/**
93+
* Builder.
94+
*
95+
* @param cloudProvider
96+
* current param.
97+
* @return
98+
* current reference.
99+
*/
100+
public Builder cloudProvider(String cloudProvider) {
101+
this.cloudProvider = cloudProvider;
102+
return this;
103+
}
104+
105+
/**
106+
* Builder.
107+
*
108+
* @param cloudRegion
109+
* current param.
110+
* @return
111+
* current reference.
112+
*/
113+
public Builder cloudRegion(String cloudRegion) {
114+
this.cloudRegion = cloudRegion;
115+
return this;
116+
}
117+
118+
/**
119+
* Builder.
120+
*
121+
* @param plan
122+
* current param.
123+
* @return
124+
* current reference.
125+
*/
126+
public Builder plan(String plan) {
127+
this.plan = plan;
128+
return this;
129+
}
130+
131+
/**
132+
* Builder.
133+
*
134+
* @param clusterName
135+
* current param.
136+
* @return
137+
* current reference.
138+
*/
139+
public Builder clusterName(String clusterName) {
140+
this.clusterName = clusterName;
141+
return this;
142+
}
143+
144+
/**
145+
* Builder.
146+
*
147+
* @return
148+
* target object
149+
*/
150+
public CreateTenant build() {
151+
CreateTenant tenant = new CreateTenant();
152+
tenant.cloudProvider = this.cloudProvider;
153+
tenant.cloudRegion = this.cloudRegion;
154+
tenant.plan = this.plan;
155+
tenant.tenantName = this.tenantName;
156+
tenant.userEmail = this.userEmail;
157+
tenant.clusterName = this.clusterName;
158+
return tenant;
159+
}
49160
}
50161

51162
/**
52-
* Getter accessor for attribute 'cloudRegion'.
163+
* Gets cloudProvider
53164
*
54-
* @return
55-
* current value of 'cloudRegion'
165+
* @return value of cloudProvider
56166
*/
57-
public String getCloudRegion() {
58-
return cloudRegion;
167+
public String getCloudProvider() {
168+
return cloudProvider;
59169
}
60170

61171
/**
62-
* Setter accessor for attribute 'cloudRegion'.
63-
* @param cloudRegion
64-
* new value for 'cloudRegion '
172+
* Gets cloudRegion
173+
*
174+
* @return value of cloudRegion
65175
*/
66-
public void setCloudRegion(String cloudRegion) {
67-
this.cloudRegion = cloudRegion;
176+
public String getCloudRegion() {
177+
return cloudRegion;
68178
}
69179

70180
/**
71-
* Getter accessor for attribute 'plan'.
181+
* Gets plan
72182
*
73-
* @return
74-
* current value of 'plan'
183+
* @return value of plan
75184
*/
76185
public String getPlan() {
77186
return plan;
78187
}
79188

80189
/**
81-
* Setter accessor for attribute 'plan'.
82-
* @param plan
83-
* new value for 'plan '
84-
*/
85-
public void setPlan(String plan) {
86-
this.plan = plan;
87-
}
88-
89-
/**
90-
* Getter accessor for attribute 'tenantName'.
190+
* Gets tenantName
91191
*
92-
* @return
93-
* current value of 'tenantName'
192+
* @return value of tenantName
94193
*/
95194
public String getTenantName() {
96195
return tenantName;
97196
}
98197

99198
/**
100-
* Setter accessor for attribute 'tenantName'.
101-
* @param tenantName
102-
* new value for 'tenantName '
103-
*/
104-
public void setTenantName(String tenantName) {
105-
this.tenantName = tenantName;
106-
}
107-
108-
/**
109-
* Getter accessor for attribute 'userEmail'.
199+
* Gets userEmail
110200
*
111-
* @return
112-
* current value of 'userEmail'
201+
* @return value of userEmail
113202
*/
114203
public String getUserEmail() {
115204
return userEmail;
116205
}
117206

118-
/**
119-
* Setter accessor for attribute 'userEmail'.
120-
* @param userEmail
121-
* new value for 'userEmail '
122-
*/
123-
public void setUserEmail(String userEmail) {
124-
this.userEmail = userEmail;
125-
}
126-
127207
/**
128208
* Gets clusterName
129209
*
@@ -132,14 +212,4 @@ public void setUserEmail(String userEmail) {
132212
public String getClusterName() {
133213
return clusterName;
134214
}
135-
136-
/**
137-
* Set value for clusterName
138-
*
139-
* @param clusterName
140-
* new value for clusterName
141-
*/
142-
public void setClusterName(String clusterName) {
143-
this.clusterName = clusterName;
144-
}
145215
}

astra-sdk-devops/src/test/java/com/datastax/astra/sdk/devops/AbstractDevopsApiTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public abstract class AbstractDevopsApiTest {
2121
static final String SDK_TEST_DB_REGION = "us-east1";
2222

2323
/** Test Constants. */
24-
static final String SDK_TEST_KEYSPACE = "java";
24+
static final String SDK_TEST_KEYSPACE = "sdk_java";
2525

2626
/** Test Constants. */
27-
static final String SDK_TEST_KEYSPACE2 = "java2";
27+
static final String SDK_TEST_KEYSPACE2 = "sdk_java2";
2828

2929
/**
3030
* Hold reference to token

0 commit comments

Comments
 (0)