-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to get all entries from push conn registry
- Loading branch information
Karthik Yagna
committed
Oct 20, 2023
1 parent
8eeb23e
commit e546809
Showing
2 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
zuul-core/src/test/java/com/netflix/zuul/netty/server/push/PushConnectionRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.netflix.zuul.netty.server.push; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PushConnectionRegistryTest { | ||
private PushConnectionRegistry pushConnectionRegistry; | ||
|
||
private PushConnection pushConnection; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
pushConnectionRegistry = new PushConnectionRegistry(); | ||
pushConnection = mock(PushConnection.class); | ||
} | ||
|
||
@Test | ||
void testPutAndGet() { | ||
assertNull(pushConnectionRegistry.get("clientId1")); | ||
|
||
pushConnectionRegistry.put("clientId1", pushConnection); | ||
|
||
assertEquals(pushConnection, pushConnectionRegistry.get("clientId1")); | ||
} | ||
|
||
@Test | ||
void testGetAll() { | ||
pushConnectionRegistry.put("clientId1", pushConnection); | ||
pushConnectionRegistry.put("clientId2", pushConnection); | ||
|
||
List<PushConnection> connections = pushConnectionRegistry.getAll(); | ||
|
||
assertEquals(2, connections.size()); | ||
} | ||
|
||
@Test | ||
void testMintNewSecureToken() { | ||
String token = pushConnectionRegistry.mintNewSecureToken(); | ||
|
||
assertNotNull(token); | ||
assertEquals(20, token.length()); // 15 bytes become 20 characters when Base64-encoded | ||
} | ||
|
||
@Test | ||
void testPutAssignsTokenToConnection() { | ||
pushConnectionRegistry.put("clientId1", pushConnection); | ||
|
||
verify(pushConnection).setSecureToken(anyString()); | ||
} | ||
|
||
@Test | ||
void testRemove() { | ||
pushConnectionRegistry.put("clientId1", pushConnection); | ||
|
||
assertEquals(pushConnection, pushConnectionRegistry.remove("clientId1")); | ||
assertNull(pushConnectionRegistry.get("clientId1")); | ||
} | ||
|
||
@Test | ||
void testSize() { | ||
assertEquals(0, pushConnectionRegistry.size()); | ||
|
||
pushConnectionRegistry.put("clientId1", pushConnection); | ||
|
||
assertEquals(1, pushConnectionRegistry.size()); | ||
} | ||
} |