Copilot commented on code in PR #14368:
URL: https://github.com/apache/cloudstack/pull/14368#discussion_r4221226938


##########
server/src/test/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImplTest.java:
##########
@@ -787,4 +788,45 @@ public void 
composeConsoleAccessEndpointReturnsWithoutPersistWhenConsoleConnecti
         Assert.assertNull(endpoint.getWebsocketExtra());
         Assert.assertNull(endpoint.getWebsocketHost());
     }
+
+    @Test
+    public void 
composeConsoleAccessEndpointReturnsDirectUrlWhenNoConsoleProxyIsAvailable() {
+        String url = "url";
+        long vmId = 100L;
+        long hostId = 1L;
+        String sessionUuid = UUID.randomUUID().toString();
+        String addr = "addr";
+        ConsoleConnectionDetails details = new 
ConsoleConnectionDetails("password", "en", "tag", null);
+        details.setDirectUrl(url);
+        details.setModeFromExternalProtocol("direct");
+        VirtualMachine vm = Mockito.mock(VirtualMachine.class);
+        Mockito.when(vm.getId()).thenReturn(vmId);
+        HostVO host = Mockito.mock(HostVO.class);
+        Mockito.when(host.getId()).thenReturn(hostId);
+        
Mockito.doReturn(details).when(consoleAccessManager).getConsoleConnectionDetails(vm,
 host);
+        
Mockito.doNothing().when(consoleAccessManager).persistConsoleSession(sessionUuid,
 vmId, hostId, addr);
+
+        ConsoleEndpoint endpoint = 
consoleAccessManager.composeConsoleAccessEndpoint(null, vm, host, addr, 
sessionUuid, "");
+
+        Assert.assertTrue(endpoint.isResult());
+        Assert.assertEquals(url, endpoint.getUrl());
+        
Mockito.verify(consoleAccessManager).persistConsoleSession(sessionUuid, vmId, 
hostId, addr);
+    }
+
+    @Test
+    public void 
composeConsoleAccessEndpointThrowsWhenProxiedConsoleHasNoConsoleProxy() {
+        VirtualMachine vm = Mockito.mock(VirtualMachine.class);
+        HostVO host = Mockito.mock(HostVO.class);
+        ConsoleConnectionDetails details = new 
ConsoleConnectionDetails("password", "en", "tag", null);
+        details.setHost("192.168.1.100");
+        details.setPort(5900);
+        
Mockito.doReturn(details).when(consoleAccessManager).getConsoleConnectionDetails(vm,
 host);
+
+        CloudRuntimeException exception = 
Assert.assertThrows(CloudRuntimeException.class,
+                () -> consoleAccessManager.composeConsoleAccessEndpoint(null, 
vm, host, "addr", "sessionUuid", ""));
+
+        Assert.assertEquals("Console access will be ready in a few minutes. 
Please try it again later.", exception.getMessage());

Review Comment:
   This assertion tightly couples the test to an exact exception message 
string, which can make the test brittle if the message is reworded or 
localized. Prefer asserting on exception type only, or comparing against a 
shared constant (if one exists), or using a looser assertion (e.g., contains a 
stable substring) to keep the test focused on behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to