From 864543c3f1eaa76b35438aee9e275cd892b2ba5c Mon Sep 17 00:00:00 2001 From: David Date: Thu, 26 Feb 2026 12:01:02 -0600 Subject: [PATCH] (feat Account Management) add v4 api Signed-off-by: David --- README.md | 1 + modules/account-management/pom.xml | 54 +++++++ .../v4/AccountManagement.java | 111 ++++++++++++++ .../v4/model/AccountResponse.java | 131 +++++++++++++++++ .../v4/model/AccountResponseTraits.java | 58 ++++++++ .../v4/model/GetAccountOptions.java | 104 +++++++++++++ .../account_management/v4/package-info.java | 17 +++ .../v4/AccountManagementIT.java | 102 +++++++++++++ .../v4/AccountManagementTest.java | 138 ++++++++++++++++++ .../v4/model/AccountResponseTest.java | 47 ++++++ .../v4/model/AccountResponseTraitsTest.java | 39 +++++ .../v4/model/GetAccountOptionsTest.java | 45 ++++++ .../v4/utils/TestUtilities.java | 131 +++++++++++++++++ modules/coverage-reports/pom.xml | 5 + modules/examples/pom.xml | 5 + .../v4/AccountManagementExamples.java | 77 ++++++++++ pom.xml | 1 + 17 files changed, 1066 insertions(+) create mode 100644 modules/account-management/pom.xml create mode 100644 modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagement.java create mode 100644 modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponse.java create mode 100644 modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraits.java create mode 100644 modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptions.java create mode 100644 modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/package-info.java create mode 100644 modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementIT.java create mode 100644 modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementTest.java create mode 100644 modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTest.java create mode 100644 modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraitsTest.java create mode 100644 modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptionsTest.java create mode 100644 modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/utils/TestUtilities.java create mode 100644 modules/examples/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementExamples.java diff --git a/README.md b/README.md index cb64fe39f47..9fca5da9d4f 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ The IBM Cloud Platform Services Java SDK allows developers to programmatically i Service Name | Artifact Coordinates --- | --- +[Account Management](https://test.cloud.ibm.com/apidocs/account-management) | com.ibm.cloud:account-management:0.73.2 [Case Management](https://cloud.ibm.com/apidocs/case-management?code=java) | com.ibm.cloud:case-management:0.73.2 [Catalog Management](https://cloud.ibm.com/apidocs/resource-catalog/private-catalog?code=java) | com.ibm.cloud:catalog-management:0.73.2 [Context Based Restrictions](https://cloud.ibm.com/apidocs/context-based-restrictions?code=java) | com.ibm.cloud:context-based-restrictions:0.73.2 diff --git a/modules/account-management/pom.xml b/modules/account-management/pom.xml new file mode 100644 index 00000000000..6b17fe5f555 --- /dev/null +++ b/modules/account-management/pom.xml @@ -0,0 +1,54 @@ + + 4.0.0 + + + + platform-services + com.ibm.cloud + 99-SNAPSHOT + ../.. + + + + account-management + + + IBM Cloud Account Management API + jar + + + + com.ibm.cloud + sdk-core + + + + platform-services-common + com.ibm.cloud + + + + platform-services-common + ${project.groupId} + test-jar + tests + test + + + org.testng + testng + test + + + com.squareup.okhttp3 + mockwebserver + test + + + org.slf4j + slf4j-jdk14 + test + + + diff --git a/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagement.java b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagement.java new file mode 100644 index 00000000000..081d21cb2ec --- /dev/null +++ b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagement.java @@ -0,0 +1,111 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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. + */ + +/* + * IBM OpenAPI SDK Code Generator Version: 3.111.0-1bfb72c2-20260206-185521 + */ + +package com.ibm.cloud.platform_services.account_management.v4; + +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponse; +import com.ibm.cloud.platform_services.account_management.v4.model.GetAccountOptions; +import com.ibm.cloud.platform_services.common.SdkCommon; +import com.ibm.cloud.sdk.core.http.RequestBuilder; +import com.ibm.cloud.sdk.core.http.ResponseConverter; +import com.ibm.cloud.sdk.core.http.ServiceCall; +import com.ibm.cloud.sdk.core.security.Authenticator; +import com.ibm.cloud.sdk.core.security.ConfigBasedAuthenticatorFactory; +import com.ibm.cloud.sdk.core.service.BaseService; +import com.ibm.cloud.sdk.core.util.ResponseConverterUtils; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +/** + * The Account Management API allows for the management of Account. + * + * API Version: 4.0.0 + */ +public class AccountManagement extends BaseService { + + /** + * Default service name used when configuring the `AccountManagement` client. + */ + public static final String DEFAULT_SERVICE_NAME = "account_management"; + + /** + * Default service endpoint URL. + */ + public static final String DEFAULT_SERVICE_URL = "https://accounts.test.cloud.ibm.com"; + + /** + * Class method which constructs an instance of the `AccountManagement` client. + * The default service name is used to configure the client instance. + * + * @return an instance of the `AccountManagement` client using external configuration + */ + public static AccountManagement newInstance() { + return newInstance(DEFAULT_SERVICE_NAME); + } + + /** + * Class method which constructs an instance of the `AccountManagement` client. + * The specified service name is used to configure the client instance. + * + * @param serviceName the service name to be used when configuring the client instance + * @return an instance of the `AccountManagement` client using external configuration + */ + public static AccountManagement newInstance(String serviceName) { + Authenticator authenticator = ConfigBasedAuthenticatorFactory.getAuthenticator(serviceName); + AccountManagement service = new AccountManagement(serviceName, authenticator); + service.configureService(serviceName); + return service; + } + + /** + * Constructs an instance of the `AccountManagement` client. + * The specified service name and authenticator are used to configure the client instance. + * + * @param serviceName the service name to be used when configuring the client instance + * @param authenticator the {@link Authenticator} instance to be configured for this client + */ + public AccountManagement(String serviceName, Authenticator authenticator) { + super(serviceName, authenticator); + setServiceUrl(DEFAULT_SERVICE_URL); + } + + /** + * Get Account by Account ID. + * + * Returns the details of an account. + * + * @param getAccountOptions the {@link GetAccountOptions} containing the options for the call + * @return a {@link ServiceCall} with a result of type {@link AccountResponse} + */ + public ServiceCall getAccount(GetAccountOptions getAccountOptions) { + com.ibm.cloud.sdk.core.util.Validator.notNull(getAccountOptions, + "getAccountOptions cannot be null"); + Map pathParamsMap = new HashMap(); + pathParamsMap.put("account_id", getAccountOptions.accountId()); + RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/accounts/{account_id}", pathParamsMap)); + Map sdkHeaders = SdkCommon.getSdkHeaders("account_management", "v4", "getAccount"); + for (Entry header : sdkHeaders.entrySet()) { + builder.header(header.getKey(), header.getValue()); + } + builder.header("Accept", "application/json"); + ResponseConverter responseConverter = + ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType()); + return createServiceCall(builder.build(), responseConverter); + } + +} diff --git a/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponse.java b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponse.java new file mode 100644 index 00000000000..535fa975034 --- /dev/null +++ b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponse.java @@ -0,0 +1,131 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4.model; + +import com.google.gson.annotations.SerializedName; +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * AccountResponse. + */ +public class AccountResponse extends GenericModel { + + protected String name; + protected String id; + protected String owner; + @SerializedName("owner_userid") + protected String ownerUserid; + @SerializedName("owner_iamid") + protected String ownerIamid; + protected String type; + protected String status; + @SerializedName("linked_softlayer_account") + protected String linkedSoftlayerAccount; + @SerializedName("team_directory_enabled") + protected Boolean teamDirectoryEnabled; + protected AccountResponseTraits traits; + + protected AccountResponse() { } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Gets the owner. + * + * @return the owner + */ + public String getOwner() { + return owner; + } + + /** + * Gets the ownerUserid. + * + * @return the ownerUserid + */ + public String getOwnerUserid() { + return ownerUserid; + } + + /** + * Gets the ownerIamid. + * + * @return the ownerIamid + */ + public String getOwnerIamid() { + return ownerIamid; + } + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Gets the status. + * + * @return the status + */ + public String getStatus() { + return status; + } + + /** + * Gets the linkedSoftlayerAccount. + * + * @return the linkedSoftlayerAccount + */ + public String getLinkedSoftlayerAccount() { + return linkedSoftlayerAccount; + } + + /** + * Gets the teamDirectoryEnabled. + * + * @return the teamDirectoryEnabled + */ + public Boolean isTeamDirectoryEnabled() { + return teamDirectoryEnabled; + } + + /** + * Gets the traits. + * + * @return the traits + */ + public AccountResponseTraits getTraits() { + return traits; + } +} + diff --git a/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraits.java b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraits.java new file mode 100644 index 00000000000..56dd1b44e0c --- /dev/null +++ b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraits.java @@ -0,0 +1,58 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4.model; + +import com.google.gson.annotations.SerializedName; +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * AccountResponseTraits. + */ +public class AccountResponseTraits extends GenericModel { + + @SerializedName("eu_supported") + protected Boolean euSupported; + protected Boolean poc; + protected Boolean hippa; + + protected AccountResponseTraits() { } + + /** + * Gets the euSupported. + * + * @return the euSupported + */ + public Boolean isEuSupported() { + return euSupported; + } + + /** + * Gets the poc. + * + * @return the poc + */ + public Boolean isPoc() { + return poc; + } + + /** + * Gets the hippa. + * + * @return the hippa + */ + public Boolean isHippa() { + return hippa; + } +} + diff --git a/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptions.java b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptions.java new file mode 100644 index 00000000000..abd8337c32d --- /dev/null +++ b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptions.java @@ -0,0 +1,104 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4.model; + +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * The getAccount options. + */ +public class GetAccountOptions extends GenericModel { + + protected String accountId; + + /** + * Builder. + */ + public static class Builder { + private String accountId; + + /** + * Instantiates a new Builder from an existing GetAccountOptions instance. + * + * @param getAccountOptions the instance to initialize the Builder with + */ + private Builder(GetAccountOptions getAccountOptions) { + this.accountId = getAccountOptions.accountId; + } + + /** + * Instantiates a new builder. + */ + public Builder() { + } + + /** + * Instantiates a new builder with required properties. + * + * @param accountId the accountId + */ + public Builder(String accountId) { + this.accountId = accountId; + } + + /** + * Builds a GetAccountOptions. + * + * @return the new GetAccountOptions instance + */ + public GetAccountOptions build() { + return new GetAccountOptions(this); + } + + /** + * Set the accountId. + * + * @param accountId the accountId + * @return the GetAccountOptions builder + */ + public Builder accountId(String accountId) { + this.accountId = accountId; + return this; + } + } + + protected GetAccountOptions() { } + + protected GetAccountOptions(Builder builder) { + com.ibm.cloud.sdk.core.util.Validator.notEmpty(builder.accountId, + "accountId cannot be empty"); + accountId = builder.accountId; + } + + /** + * New builder. + * + * @return a GetAccountOptions builder + */ + public Builder newBuilder() { + return new Builder(this); + } + + /** + * Gets the accountId. + * + * The unique identifier of the account you want to retrieve. + * + * @return the accountId + */ + public String accountId() { + return accountId; + } +} + diff --git a/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/package-info.java b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/package-info.java new file mode 100644 index 00000000000..13e712c8c9b --- /dev/null +++ b/modules/account-management/src/main/java/com/ibm/cloud/platform_services/account_management/v4/package-info.java @@ -0,0 +1,17 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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. + */ + +/** + * Account Management v4. + */ +package com.ibm.cloud.platform_services.account_management.v4; diff --git a/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementIT.java b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementIT.java new file mode 100644 index 00000000000..895ed87c4a8 --- /dev/null +++ b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementIT.java @@ -0,0 +1,102 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4; + +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponse; +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponseTraits; +import com.ibm.cloud.platform_services.account_management.v4.model.GetAccountOptions; +import com.ibm.cloud.platform_services.account_management.v4.utils.TestUtilities; +import com.ibm.cloud.sdk.core.http.Response; +import com.ibm.cloud.sdk.core.service.exception.ServiceResponseException; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import com.ibm.cloud.sdk.core.util.CredentialUtils; +import com.ibm.cloud.platform_services.test.SdkIntegrationTestBase; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Integration test class for the AccountManagement service. + */ +public class AccountManagementIT extends SdkIntegrationTestBase { + public AccountManagement service = null; + public static Map config = null; + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + /** + * This method provides our config filename to the base class. + */ + + public String getConfigFilename() { + return "../../account_management_v4.env"; + } + private String accountId = null; + + @BeforeClass + public void constructService() { + // Ask super if we should skip the tests. + if (skipTests()) { + return; + } + + service = AccountManagement.newInstance(); + assertNotNull(service); + assertNotNull(service.getServiceUrl()); + + // Load up our test-specific config properties. + config = CredentialUtils.getServiceProperties(AccountManagement.DEFAULT_SERVICE_NAME); + assertNotNull(config); + assertFalse(config.isEmpty()); + assertEquals(service.getServiceUrl(), config.get("URL")); + accountId = config.get("ACCOUNT_ID"); + assertNotNull(accountId); + + service.enableRetries(4, 30); + + System.out.println("Setup complete."); + } + + @Test + public void testGetAccount() throws Exception { + try { + GetAccountOptions getAccountOptions = new GetAccountOptions.Builder() + .accountId(accountId) + .build(); + + // Invoke operation + Response response = service.getAccount(getAccountOptions).execute(); + // Validate response + assertNotNull(response); + assertEquals(response.getStatusCode(), 200); + + AccountResponse accountResponseResult = response.getResult(); + assertNotNull(accountResponseResult); + + } catch (ServiceResponseException e) { + fail(String.format("Service returned status code %d: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo())); + } + } + + @AfterClass + public void tearDown() { + // Add any clean up logic here + System.out.println("Clean up complete."); + } + } diff --git a/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementTest.java b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementTest.java new file mode 100644 index 00000000000..a7b29b47bcc --- /dev/null +++ b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementTest.java @@ -0,0 +1,138 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4; + +import com.ibm.cloud.platform_services.account_management.v4.AccountManagement; +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponse; +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponseTraits; +import com.ibm.cloud.platform_services.account_management.v4.model.GetAccountOptions; +import com.ibm.cloud.platform_services.account_management.v4.utils.TestUtilities; +import com.ibm.cloud.sdk.core.http.Response; +import com.ibm.cloud.sdk.core.security.Authenticator; +import com.ibm.cloud.sdk.core.security.NoAuthAuthenticator; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the AccountManagement service. + */ +public class AccountManagementTest { + + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + protected MockWebServer server; + protected AccountManagement accountManagementService; + + // Construct the service with a null authenticator (negative test) + @Test(expectedExceptions = IllegalArgumentException.class) + public void testConstructorWithNullAuthenticator() throws Throwable { + final String serviceName = "testService"; + new AccountManagement(serviceName, null); + } + + // Test the getAccount operation with a valid options model parameter + @Test + public void testGetAccountWOptions() throws Throwable { + // Register a mock response + String mockResponseBody = "{\"name\": \"name\", \"id\": \"id\", \"owner\": \"owner\", \"owner_userid\": \"ownerUserid\", \"owner_iamid\": \"ownerIamid\", \"type\": \"type\", \"status\": \"status\", \"linked_softlayer_account\": \"linkedSoftlayerAccount\", \"team_directory_enabled\": true, \"traits\": {\"eu_supported\": false, \"poc\": false, \"hippa\": false}}"; + String getAccountPath = "/v4/accounts/testString"; + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponseBody)); + + // Construct an instance of the GetAccountOptions model + GetAccountOptions getAccountOptionsModel = new GetAccountOptions.Builder() + .accountId("testString") + .build(); + + // Invoke getAccount() with a valid options model and verify the result + Response response = accountManagementService.getAccount(getAccountOptionsModel).execute(); + assertNotNull(response); + AccountResponse responseObj = response.getResult(); + assertNotNull(responseObj); + + // Verify the contents of the request sent to the mock server + RecordedRequest request = server.takeRequest(); + assertNotNull(request); + assertEquals(request.getMethod(), "GET"); + // Verify request path + String parsedPath = TestUtilities.parseReqPath(request); + assertEquals(parsedPath, getAccountPath); + // Verify that there is no query string + Map query = TestUtilities.parseQueryString(request); + assertNull(query); + } + + // Test the getAccount operation with and without retries enabled + @Test + public void testGetAccountWRetries() throws Throwable { + accountManagementService.enableRetries(4, 30); + testGetAccountWOptions(); + + accountManagementService.disableRetries(); + testGetAccountWOptions(); + } + + // Test the getAccount operation with a null options model (negative test) + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetAccountNoOptions() throws Throwable { + server.enqueue(new MockResponse()); + accountManagementService.getAccount(null).execute(); + } + + // Perform setup needed before each test method + @BeforeMethod + public void beforeEachTest() { + // Start the mock server. + try { + server = new MockWebServer(); + server.start(); + } catch (IOException err) { + fail("Failed to instantiate mock web server"); + } + + // Construct an instance of the service + constructClientService(); + } + + // Perform tear down after each test method + @AfterMethod + public void afterEachTest() throws IOException { + server.shutdown(); + accountManagementService = null; + } + + // Constructs an instance of the service to be used by the tests + public void constructClientService() { + System.setProperty("TESTSERVICE_AUTH_TYPE", "noAuth"); + final String serviceName = "testService"; + + accountManagementService = AccountManagement.newInstance(serviceName); + String url = server.url("/").toString(); + accountManagementService.setServiceUrl(url); + } +} \ No newline at end of file diff --git a/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTest.java b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTest.java new file mode 100644 index 00000000000..ebb59093140 --- /dev/null +++ b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTest.java @@ -0,0 +1,47 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4.model; + +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponse; +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponseTraits; +import com.ibm.cloud.platform_services.account_management.v4.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the AccountResponse model. + */ +public class AccountResponseTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testAccountResponse() throws Throwable { + AccountResponse accountResponseModel = new AccountResponse(); + assertNull(accountResponseModel.getName()); + assertNull(accountResponseModel.getId()); + assertNull(accountResponseModel.getOwner()); + assertNull(accountResponseModel.getOwnerUserid()); + assertNull(accountResponseModel.getOwnerIamid()); + assertNull(accountResponseModel.getType()); + assertNull(accountResponseModel.getStatus()); + assertNull(accountResponseModel.getLinkedSoftlayerAccount()); + assertNull(accountResponseModel.isTeamDirectoryEnabled()); + assertNull(accountResponseModel.getTraits()); + } +} \ No newline at end of file diff --git a/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraitsTest.java b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraitsTest.java new file mode 100644 index 00000000000..d8a38a19ec3 --- /dev/null +++ b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/AccountResponseTraitsTest.java @@ -0,0 +1,39 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4.model; + +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponseTraits; +import com.ibm.cloud.platform_services.account_management.v4.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the AccountResponseTraits model. + */ +public class AccountResponseTraitsTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testAccountResponseTraits() throws Throwable { + AccountResponseTraits accountResponseTraitsModel = new AccountResponseTraits(); + assertNull(accountResponseTraitsModel.isEuSupported()); + assertNull(accountResponseTraitsModel.isPoc()); + assertNull(accountResponseTraitsModel.isHippa()); + } +} \ No newline at end of file diff --git a/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptionsTest.java b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptionsTest.java new file mode 100644 index 00000000000..ac8046aeb7f --- /dev/null +++ b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/model/GetAccountOptionsTest.java @@ -0,0 +1,45 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.ccount_management.v4.model; + +import com.ibm.cloud.platform_services.account_management.v4.model.GetAccountOptions; +import com.ibm.cloud.platform_services.account_management.v4.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the GetAccountOptions model. + */ +public class GetAccountOptionsTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testGetAccountOptions() throws Throwable { + GetAccountOptions getAccountOptionsModel = new GetAccountOptions.Builder() + .accountId("testString") + .build(); + assertEquals(getAccountOptionsModel.accountId(), "testString"); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetAccountOptionsError() throws Throwable { + new GetAccountOptions.Builder().build(); + } + +} \ No newline at end of file diff --git a/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/utils/TestUtilities.java b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/utils/TestUtilities.java new file mode 100644 index 00000000000..06a58bc8dc1 --- /dev/null +++ b/modules/account-management/src/test/java/com/ibm/cloud/platform_services/account_management/v4/utils/TestUtilities.java @@ -0,0 +1,131 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4.utils; + +import java.util.Base64; +import java.util.Map; +import java.util.Set; +import java.util.List; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.io.InputStream; +import java.io.ByteArrayInputStream; + +import okhttp3.mockwebserver.RecordedRequest; +import okhttp3.HttpUrl; +import com.ibm.cloud.sdk.core.util.DateUtils; +import com.ibm.cloud.sdk.core.util.GsonSingleton; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; + +/** + * A class used by the unit tests containing utility functions. + */ +public class TestUtilities { + public static Map createMockMap() { + Map mockMap = new HashMap<>(); + mockMap.put("foo", "bar"); + return mockMap; + } + + public static HashMap createMockStreamMap() { + return new HashMap() { + { put("key1", createMockStream("This is a mock file.")); } + }; + } + + public static Map parseQueryString(RecordedRequest req) { + Map queryMap = new HashMap<>(); + + try { + HttpUrl requestUrl = req.getRequestUrl(); + + if (requestUrl != null) { + Set queryParamsNames = requestUrl.queryParameterNames(); + // map the parameter name to its corresponding value + for (String p : queryParamsNames) { + // get the corresponding value for the parameter (p) + List val = requestUrl.queryParameterValues(p); + if (val != null && !val.isEmpty()) { + String joinedQuery = String.join(",", val); + queryMap.put(p, joinedQuery); + } + } + } + if (queryMap.isEmpty()) { + return null; + } + } catch (Exception e) { + return null; + } + + return queryMap; + } + + public static String parseReqPath(RecordedRequest req) { + String parsedPath = null; + + try { + String fullPath = req.getPath(); + if (fullPath != null && !fullPath.isEmpty()) { + // retrieve the path segment before the query parameter + parsedPath = fullPath.split("\\?", 2)[0]; + } + if (parsedPath.isEmpty() || parsedPath == null) { + return null; + } + + } catch (Exception e) { + return null; + } + + return parsedPath; + } + + public static String serialize(Object obj) { + return GsonSingleton.getGson().toJson(obj); + } + + public static T deserialize(String json, Class clazz) { + return GsonSingleton.getGson().fromJson(json, clazz); + } + + public static InputStream createMockStream(String s) { + return new ByteArrayInputStream(s.getBytes()); + } + + public static List creatMockListFileWithMetadata() { + List list = new ArrayList(); + byte[] fileBytes = {(byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef}; + InputStream inputStream = new ByteArrayInputStream(fileBytes); + FileWithMetadata.Builder builder = new FileWithMetadata.Builder(); + builder.data(inputStream); + FileWithMetadata fileWithMetadata = builder.build(); + list.add(fileWithMetadata); + + return list; + } + + public static byte[] createMockByteArray(String encodedString) throws Exception { + return Base64.getDecoder().decode(encodedString); + } + + public static Date createMockDate(String date) throws Exception { + return DateUtils.parseAsDate(date); + } + + public static Date createMockDateTime(String date) throws Exception { + return DateUtils.parseAsDateTime(date); + } +} \ No newline at end of file diff --git a/modules/coverage-reports/pom.xml b/modules/coverage-reports/pom.xml index 862224bbb0b..972ff34dc81 100644 --- a/modules/coverage-reports/pom.xml +++ b/modules/coverage-reports/pom.xml @@ -28,6 +28,11 @@ platform-services-common ${project.version} + + ${project.groupId} + account-management + ${project.version} + ${project.groupId} case-management diff --git a/modules/examples/pom.xml b/modules/examples/pom.xml index 6c23704a500..8381ddda8f5 100644 --- a/modules/examples/pom.xml +++ b/modules/examples/pom.xml @@ -17,6 +17,11 @@ + + ${project.groupId} + account-management + ${project.version} + ${project.groupId} case-management diff --git a/modules/examples/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementExamples.java b/modules/examples/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementExamples.java new file mode 100644 index 00000000000..71c3f735ece --- /dev/null +++ b/modules/examples/src/main/java/com/ibm/cloud/platform_services/account_management/v4/AccountManagementExamples.java @@ -0,0 +1,77 @@ +/* + * (C) Copyright IBM Corp. 2026. + * + * 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 com.ibm.cloud.platform_services.account_management.v4; + +import com.ibm.cloud.platform_services.account_management.v4.model.AccountResponse; +import com.ibm.cloud.platform_services.account_management.v4.model.GetAccountOptions; +import com.ibm.cloud.sdk.core.http.Response; +import com.ibm.cloud.sdk.core.service.exception.ServiceResponseException; +import com.ibm.cloud.sdk.core.util.CredentialUtils; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class contains examples of how to use the account_management service. + * + * The following configuration properties are assumed to be defined: + * ACCOUNT_MANAGEMENT_URL=<service base url> + * ACCOUNT_MANAGEMENT_AUTH_TYPE=iam + * ACCOUNT_MANAGEMENT_APIKEY=<IAM apikey> + * ACCOUNT_MANAGEMENT_AUTH_URL=<IAM token service base URL - omit this if using the production environment> + * + * These configuration properties can be exported as environment variables, or stored + * in a configuration file and then: + * export IBM_CREDENTIALS_FILE=<name of configuration file> + */ +public class AccountManagementExamples { + private static final Logger logger = LoggerFactory.getLogger(AccountManagementExamples.class); + protected AccountManagementExamples() { } + private static String accountId; + + static { + System.setProperty("IBM_CREDENTIALS_FILE", "../../account_management_v4.env"); + } + + /** + * The main() function invokes operations of the account_management service. + * @param args command-line arguments + * @throws Exception an error occurred + */ + @SuppressWarnings("checkstyle:methodlength") + public static void main(String[] args) throws Exception { + AccountManagement accountManagementService = AccountManagement.newInstance(); + + // Load up our test-specific config properties. + Map testConfigProperties = CredentialUtils.getServiceProperties(AccountManagement.DEFAULT_SERVICE_NAME); + accountId = testConfigProperties.get("ACCOUNT_ID"); + + try { + System.out.println("getAccount() result:"); + // begin-getAccount + GetAccountOptions getAccountOptions = new GetAccountOptions.Builder() + .accountId(accountId) + .build(); + + Response response = accountManagementService.getAccount(getAccountOptions).execute(); + AccountResponse accountResponse = response.getResult(); + + System.out.println(accountResponse); + // end-getAccount + } catch (ServiceResponseException e) { + logger.error(String.format("Service returned status code %s: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); + } + } +} diff --git a/pom.xml b/pom.xml index 9139406c1fa..2ef205466c4 100644 --- a/pom.xml +++ b/pom.xml @@ -60,6 +60,7 @@ modules/common + modules/account-management modules/case-management modules/catalog-management modules/context-based-restrictions