Skip to content

Commit 1d6087b

Browse files
committed
working on intial impl and tests
Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com>
1 parent 984a7bb commit 1d6087b

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

spring-cloud-oci-adb/src/main/java/com/oracle/cloud/spring/adb/AutonomousDatabase.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,52 @@
33

44
package com.oracle.cloud.spring.adb;
55

6+
import com.oracle.bmc.database.DatabaseClient;
7+
import com.oracle.bmc.database.responses.*;
8+
69
/**
710
* Interface for OCI Autonomous Database module.
811
*/
912
public interface AutonomousDatabase {
1013

14+
/**
15+
* Direct instance of OCI Java SDK DatabaseClient.
16+
* @return DatabaseClient
17+
*/
18+
DatabaseClient getDatatbaseClient();
19+
20+
/**
21+
* Create an Autonomous Database.
22+
*
23+
* @param databaseName Name of the Autonomous Database to be created
24+
* @param compartmentId Compartment OCID where the Autonomous Database needs to be created
25+
* @return CreateAutonomousDatabaseResponse
26+
*/
27+
CreateAutonomousDatabaseResponse createAutonomousDatabase(String databaseName, String compartmentId);
28+
29+
/**
30+
* Get details of an Autonomous Database.
31+
*
32+
* @param databaseId OCID of the Autonomous Database to get details of
33+
* @return GetAutonomousDatabaseResponse
34+
*/
35+
GetAutonomousDatabaseResponse getAutonomousDatabase(String databaseId);
36+
37+
/**
38+
* Generate a wallet for an Autonomous Database.
39+
*
40+
* @param databaseId OCID of the Autonomous Database to get generate a wallet for
41+
* @param password Password for the wallet
42+
* @return GenerateAutonomousDatabaseWalletResponse
43+
*/
44+
GenerateAutonomousDatabaseWalletResponse generateAutonomousDatabaseWallet(String databaseId, String password);
45+
46+
/**
47+
* Delete an Autonomous Database.
48+
*
49+
* @param databaseId OCID of the Autonomous Database to be deleted
50+
* @return DeleteAutonomousDatabaseResponse
51+
*/
52+
DeleteAutonomousDatabaseResponse deleteAutonomousDatabase(String databaseId);
53+
1154
}

spring-cloud-oci-adb/src/main/java/com/oracle/cloud/spring/adb/AutonomousDatabaseImpl.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
package com.oracle.cloud.spring.adb;
55

66
import com.oracle.bmc.database.DatabaseClient;
7+
import com.oracle.bmc.database.model.*;
8+
import com.oracle.bmc.database.responses.*;
9+
import com.oracle.bmc.database.requests.*;
710

811
/**
912
* Implementation for the OCI Autonomous Database module.
@@ -16,4 +19,78 @@ public AutonomousDatabaseImpl(DatabaseClient client) {
1619
this.client = client;
1720
}
1821

22+
/**
23+
* Direct instance of OCI Java SDK DatabaseClient.
24+
* @return DatabaseClient
25+
*/
26+
public DatabaseClient getDatatbaseClient() {
27+
return client;
28+
}
29+
30+
/**
31+
* Create an Autonomous Database.
32+
*
33+
* @param databaseName Name of the Autonomous Database to be created
34+
* @param compartmentId Compartment OCID where the Autonomous Database needs to be created
35+
* @return CreateAutonomousDatabaseResponse
36+
*/
37+
public CreateAutonomousDatabaseResponse createAutonomousDatabase(String databaseName, String compartmentId) {
38+
return null;
39+
}
40+
41+
/**
42+
* Get details of an Autonomous Database.
43+
*
44+
* @param databaseId OCID of the Autonomous Database to get details of
45+
* @return GetAutonomousDatabaseResponse
46+
*/
47+
public GetAutonomousDatabaseResponse getAutonomousDatabase(String databaseId) {
48+
GetAutonomousDatabaseRequest getAutonomousDatabaseRequest = GetAutonomousDatabaseRequest.builder()
49+
.autonomousDatabaseId(databaseId)
50+
.build();
51+
52+
GetAutonomousDatabaseResponse response = client.getAutonomousDatabase(getAutonomousDatabaseRequest);
53+
54+
return response;
55+
}
56+
57+
/**
58+
* Generate a wallet for an Autonomous Database.
59+
*
60+
* @param databaseId OCID of the Autonomous Database to get generate a wallet for
61+
* @param password Password for the wallet
62+
* @return GenerateAutonomousDatabaseWalletResponse
63+
*/
64+
public GenerateAutonomousDatabaseWalletResponse generateAutonomousDatabaseWallet(String databaseId, String password) {
65+
GenerateAutonomousDatabaseWalletDetails generateAutonomousDatabaseWalletDetails = GenerateAutonomousDatabaseWalletDetails.builder()
66+
.generateType(GenerateAutonomousDatabaseWalletDetails.GenerateType.All)
67+
.password(password)
68+
.isRegional(true).build();
69+
70+
GenerateAutonomousDatabaseWalletRequest generateAutonomousDatabaseWalletRequest = GenerateAutonomousDatabaseWalletRequest.builder()
71+
.autonomousDatabaseId(databaseId)
72+
.generateAutonomousDatabaseWalletDetails(generateAutonomousDatabaseWalletDetails)
73+
.build();
74+
75+
GenerateAutonomousDatabaseWalletResponse response = client.generateAutonomousDatabaseWallet(generateAutonomousDatabaseWalletRequest);
76+
77+
return response;
78+
}
79+
80+
/**
81+
* Delete an Autonomous Database.
82+
*
83+
* @param databaseId OCID of the Autonomous Database to be deleted
84+
* @return DeleteAutonomousDatabaseResponse
85+
*/
86+
public DeleteAutonomousDatabaseResponse deleteAutonomousDatabase(String databaseId) {
87+
DeleteAutonomousDatabaseRequest deleteAutonomousDatabaseRequest = DeleteAutonomousDatabaseRequest.builder()
88+
.autonomousDatabaseId(databaseId)
89+
.build();
90+
91+
DeleteAutonomousDatabaseResponse response = client.deleteAutonomousDatabase(deleteAutonomousDatabaseRequest);
92+
93+
return response;
94+
}
95+
1996
}

spring-cloud-oci-adb/src/test/java/com/oracle/cloud/spring/adb/AutonomousDatabaseImplTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import static org.mockito.Mockito.*;
1111
import static org.junit.jupiter.api.Assertions.*;
12+
import static org.mockito.ArgumentMatchers.any;
1213

1314

1415
public class AutonomousDatabaseImplTests {
@@ -22,4 +23,25 @@ void testDatabaseClient() {
2223
when(client.createAutonomousDatabase(any())).thenReturn(mock(CreateAutonomousDatabaseResponse.class));
2324
}
2425

26+
@Test
27+
void testDatbaseImpl() {
28+
when(autonomousDatabase.createAutonomousDatabase(any())).thenReturn(mock(CreateAutonomousDatabaseResponse.class));
29+
when(autonomousDatabase.getAutonomousDatabase(any())).thenReturn(mock(GetAutonomousDatabaseResponse.class));
30+
when(autonomousDatabase.generateAutonomousDatabaseWallet(any())).thenReturn(mock(GenerateAutonomousDatabaseWalletResponse.class));
31+
when(autonomousDatabase.deleteAutonomousDatabase(any())).thenReturn(mock(DeleteAutonomousDatabaseResponse.class));
32+
33+
CreateAutonomousDatabaseResponse cadr = autonomousDatabase.createAutonomousDatabase("name", "compartment");
34+
// NYI - assertNotNull(cadr);
35+
36+
GetAutonomousDatabaseResponse gadr = autonomousDatabase.getAutonomousDatabase("ocid");
37+
assertNotNull(gadr);
38+
39+
GenerateAutonomousDatabaseWalletResponse gadwr = autonomousDatabase.generateAutonomousDatabaseWallet("ocid", "password");
40+
assertNotNull(gadwr);
41+
42+
DeleteAutonomousDatabaseResponse dadr = autonomousDatabase.deleteAutonomousDatabase("ocid");
43+
assertNotNull(dadr);
44+
45+
}
46+
2547
}

0 commit comments

Comments
 (0)