1- package com .uid2 .admin .managers ;
1+ package com .uid2 .admin .cloudEncryption ;
22
3- import com .uid2 .admin .cloudEncryption .CloudSecretGenerator ;
43import com .uid2 .admin .store .writer .CloudEncryptionKeyStoreWriter ;
54import com .uid2 .shared .auth .OperatorKey ;
65import com .uid2 .shared .model .CloudEncryptionKey ;
@@ -99,33 +98,6 @@ void testGetNextKeyId() {
9998 assertEquals (2 , nextKeyId );
10099 }
101100
102- @ Test
103- void testGetCloudEncryptionKey () {
104- CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey (1 , siteId , 500L , 1500L , "existingSecret1" );
105- Map <Integer , CloudEncryptionKey > existingKeys = new HashMap <>();
106- existingKeys .put (1 , cloudEncryptionKey );
107- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (existingKeys );
108-
109- CloudEncryptionKey result = cloudEncryptionKeyManager .getCloudEncryptionKeyByKeyIdentifier (1 );
110-
111- assertEquals (cloudEncryptionKey , result );
112- }
113-
114- @ Test
115- void testGetAllCloudEncryptionKeys () {
116- Map <Integer , CloudEncryptionKey > existingKeys = new HashMap <>();
117- CloudEncryptionKey existingKey1 = new CloudEncryptionKey (1 , siteId , 500L , 1500L , "existingSecret1" );
118- CloudEncryptionKey existingKey2 = new CloudEncryptionKey (2 , siteId , 600L , 1600L , "existingSecret2" );
119- existingKeys .put (1 , existingKey1 );
120- existingKeys .put (2 , existingKey2 );
121-
122- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (existingKeys );
123-
124- Map <Integer , CloudEncryptionKey > result = cloudEncryptionKeyManager .getAllCloudEncryptionKeys ();
125-
126- assertEquals (existingKeys , result );
127- }
128-
129101 @ Test
130102 void testAddCloudEncryptionKey () throws Exception {
131103 CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey (1 , siteId , 1000L , 2000L , "randomKeyString" );
@@ -143,135 +115,6 @@ void testAddCloudEncryptionKey() throws Exception {
143115 assertEquals (cloudEncryptionKey , capturedKeys .get (1 ));
144116 }
145117
146- @ Test
147- void testGetCloudEncryptionKeyBySiteId () {
148- CloudEncryptionKey key1 = new CloudEncryptionKey (1 , 100 , 0 , 0 , "secret1" );
149- CloudEncryptionKey key2 = new CloudEncryptionKey (2 , 200 , 0 , 0 , "secret2" );
150- Map <Integer , CloudEncryptionKey > keys = new HashMap <>();
151- keys .put (1 , key1 );
152- keys .put (2 , key2 );
153-
154- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (keys );
155-
156- Optional <CloudEncryptionKey > result = cloudEncryptionKeyManager .getCloudEncryptionKeyBySiteId (100 );
157- assertTrue (result .isPresent ());
158- assertEquals (key1 , result .get ());
159- }
160-
161- @ Test
162- void testGetAllCloudEncryptionKeysBySiteId () {
163- CloudEncryptionKey key1 = new CloudEncryptionKey (1 , 100 , 0 , 0 , "secret1" );
164- CloudEncryptionKey key2 = new CloudEncryptionKey (2 , 100 , 0 , 0 , "secret2" );
165- CloudEncryptionKey key3 = new CloudEncryptionKey (3 , 200 , 0 , 0 , "secret3" );
166- Map <Integer , CloudEncryptionKey > keys = new HashMap <>();
167- keys .put (1 , key1 );
168- keys .put (2 , key2 );
169- keys .put (3 , key3 );
170-
171- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (keys );
172-
173- List <CloudEncryptionKey > result = cloudEncryptionKeyManager .getAllCloudEncryptionKeysBySiteId (100 );
174- assertEquals (2 , result .size ());
175- assertTrue (result .contains (key1 ));
176- assertTrue (result .contains (key2 ));
177- }
178-
179- @ Test
180- void testCreateAndAddImmediateCloudEncryptionKey () throws Exception {
181- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (new HashMap <>());
182- when (keyGenerator .generate ()).thenReturn ("generatedSecret" );
183-
184- CloudEncryptionKey newKey = cloudEncryptionKeyManager .createAndAddImmediateCloudEncryptionKey (100 );
185-
186- assertNotNull (newKey );
187- assertEquals (100 , newKey .getSiteId ());
188- assertEquals ("generatedSecret" , newKey .getSecret ());
189-
190- verify (cloudEncryptionKeyStoreWriter , times (1 )).upload (any (Map .class ), eq (null ));
191- }
192-
193- @ Test
194- public void testDoesSiteHaveKeys_SiteHasKeys () {
195- CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey (siteId , siteId , 0L , 0L , "key" );
196- Map <Integer , CloudEncryptionKey > allKeys = new HashMap <>();
197- allKeys .put (1 , cloudEncryptionKey );
198-
199- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (allKeys );
200-
201- boolean result = cloudEncryptionKeyManager .doesSiteHaveKeys (siteId );
202- assertTrue (result );
203- }
204-
205- @ Test
206- public void testDoesSiteHaveKeys_SiteDoesNotHaveKeys () {
207- Map <Integer , CloudEncryptionKey > allKeys = new HashMap <>();
208-
209- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (allKeys );
210-
211- boolean result = cloudEncryptionKeyManager .doesSiteHaveKeys (siteId );
212- assertFalse (result );
213- }
214-
215- @ Test
216- public void testDoesSiteHaveKeys_AllKeysNull () {
217- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (null );
218-
219- boolean result = cloudEncryptionKeyManager .doesSiteHaveKeys (siteId );
220- assertFalse (result );
221- }
222-
223- @ Test
224- public void testDoesSiteHaveKeys_MultipleKeysDifferentSiteIds () {
225- CloudEncryptionKey cloudEncryptionKey1 = new CloudEncryptionKey (1 , 1 , 0L , 0L , "key1" );
226- CloudEncryptionKey cloudEncryptionKey2 = new CloudEncryptionKey (2 , 2 , 0L , 0L , "key2" );
227- Map <Integer , CloudEncryptionKey > allKeys = new HashMap <>();
228- allKeys .put (1 , cloudEncryptionKey1 );
229- allKeys .put (2 , cloudEncryptionKey2 );
230-
231- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (allKeys );
232-
233- assertTrue (cloudEncryptionKeyManager .doesSiteHaveKeys (1 ));
234- assertTrue (cloudEncryptionKeyManager .doesSiteHaveKeys (2 ));
235- assertFalse (cloudEncryptionKeyManager .doesSiteHaveKeys (3 )); // Site ID 3 does not exist
236- }
237-
238- @ Test
239- public void testDoesSiteHaveKeys_SameSiteIdMultipleKeys () {
240- CloudEncryptionKey cloudEncryptionKey1 = new CloudEncryptionKey (siteId , siteId , 0L , 0L , "key1" );
241- CloudEncryptionKey cloudEncryptionKey2 = new CloudEncryptionKey (siteId , siteId , 0L , 0L , "key2" );
242- Map <Integer , CloudEncryptionKey > allKeys = new HashMap <>();
243- allKeys .put (1 , cloudEncryptionKey1 );
244- allKeys .put (2 , cloudEncryptionKey2 );
245-
246- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (allKeys );
247-
248- boolean result = cloudEncryptionKeyManager .doesSiteHaveKeys (siteId );
249- assertTrue (result );
250- }
251-
252- @ Test
253- public void testDoesSiteHaveKeys_LargeNumberOfKeys () {
254- Map <Integer , CloudEncryptionKey > allKeys = new HashMap <>();
255- for (int i = 1 ; i <= 1000 ; i ++) {
256- CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey (i , i , 0L , 0L , "key" + i );
257- allKeys .put (i , cloudEncryptionKey );
258- }
259-
260- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (allKeys );
261-
262- for (int i = 1 ; i <= 1000 ; i ++) {
263- assertTrue (cloudEncryptionKeyManager .doesSiteHaveKeys (i ));
264- }
265- assertFalse (cloudEncryptionKeyManager .doesSiteHaveKeys (1001 )); // Site ID 1001 does not exist
266- }
267-
268- @ Test
269- public void testDoesSiteHaveKeys_EmptyKeys () {
270- when (cloudEncryptionKeyProvider .getAll ()).thenReturn (new HashMap <>());
271-
272- assertFalse (cloudEncryptionKeyManager .doesSiteHaveKeys (1 ));
273- }
274-
275118 @ Test
276119 void testCountKeysForSite () {
277120 Map <Integer , CloudEncryptionKey > testKeys = new HashMap <>();
0 commit comments