|
22 | 22 | import static org.mockito.Mockito.verify; |
23 | 23 | import static org.mockito.Mockito.when; |
24 | 24 |
|
| 25 | +import java.net.URI; |
25 | 26 | import java.util.ArrayList; |
26 | 27 | import java.util.Arrays; |
27 | 28 | import java.util.HashMap; |
28 | 29 | import java.util.List; |
29 | 30 | import java.util.Map; |
30 | 31 |
|
| 32 | +import com.cloud.network.dao.PhysicalNetworkVO; |
| 33 | +import com.cloud.utils.exception.CloudRuntimeException; |
31 | 34 | import org.apache.log4j.Logger; |
32 | 35 | import org.junit.Assert; |
33 | 36 | import org.junit.Before; |
@@ -463,4 +466,75 @@ public void validateLockedRequestedIpTestFreeAndNotNullIp() { |
463 | 466 | testOrchastrator.validateLockedRequestedIp(ipVoSpy, lockedIp); |
464 | 467 | } |
465 | 468 |
|
| 469 | + @Test |
| 470 | + public void encodeVlanIdIntoBroadcastUriTestVxlan() { |
| 471 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", "VXLAN", "vxlan", "vxlan://123"); |
| 472 | + } |
| 473 | + |
| 474 | + @Test |
| 475 | + public void encodeVlanIdIntoBroadcastUriTestVlan() { |
| 476 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", "VLAN", "vlan", "vlan://123"); |
| 477 | + } |
| 478 | + |
| 479 | + @Test |
| 480 | + public void encodeVlanIdIntoBroadcastUriTestEmpty() { |
| 481 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", "", "vlan", "vlan://123"); |
| 482 | + } |
| 483 | + |
| 484 | + @Test |
| 485 | + public void encodeVlanIdIntoBroadcastUriTestNull() { |
| 486 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", null, "vlan", "vlan://123"); |
| 487 | + } |
| 488 | + |
| 489 | + @Test(expected = CloudRuntimeException.class) |
| 490 | + public void encodeVlanIdIntoBroadcastUriTestEmptyVlanId() { |
| 491 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("", "vxlan", "vlan", "vlan://123"); |
| 492 | + } |
| 493 | + |
| 494 | + @Test(expected = CloudRuntimeException.class) |
| 495 | + public void encodeVlanIdIntoBroadcastUriTestNullVlanId() { |
| 496 | + encodeVlanIdIntoBroadcastUriPrepareAndTest(null, "vlan", "vlan", "vlan://123"); |
| 497 | + } |
| 498 | + |
| 499 | + @Test(expected = CloudRuntimeException.class) |
| 500 | + public void encodeVlanIdIntoBroadcastUriTestBlankVlanId() { |
| 501 | + encodeVlanIdIntoBroadcastUriPrepareAndTest(" ", "vlan", "vlan", "vlan://123"); |
| 502 | + } |
| 503 | + |
| 504 | + @Test |
| 505 | + public void encodeVlanIdIntoBroadcastUriTestNullVlanIdWithSchema() { |
| 506 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vlan://123", "vlan", "vlan", "vlan://123"); |
| 507 | + } |
| 508 | + |
| 509 | + @Test |
| 510 | + public void encodeVlanIdIntoBroadcastUriTestNullVlanIdWithSchemaIsolationVxlan() { |
| 511 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vlan://123", "vxlan", "vlan", "vlan://123"); |
| 512 | + } |
| 513 | + |
| 514 | + @Test |
| 515 | + public void encodeVlanIdIntoBroadcastUriTestNullVxlanIdWithSchema() { |
| 516 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vxlan://123", "vxlan", "vxlan", "vxlan://123"); |
| 517 | + } |
| 518 | + |
| 519 | + @Test |
| 520 | + public void encodeVlanIdIntoBroadcastUriTestNullVxlanIdWithSchemaIsolationVlan() { |
| 521 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vxlan://123", "vlan", "vxlan", "vxlan://123"); |
| 522 | + } |
| 523 | + |
| 524 | + @Test(expected = InvalidParameterValueException.class) |
| 525 | + public void encodeVlanIdIntoBroadcastUriTestNullNetwork() { |
| 526 | + URI resultUri = testOrchastrator.encodeVlanIdIntoBroadcastUri("vxlan://123", null); |
| 527 | + } |
| 528 | + |
| 529 | + private void encodeVlanIdIntoBroadcastUriPrepareAndTest(String vlanId, String isolationMethod, String expectedIsolation, String expectedUri) { |
| 530 | + PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(); |
| 531 | + List<String> isolationMethods = new ArrayList<>(); |
| 532 | + isolationMethods.add(isolationMethod); |
| 533 | + physicalNetwork.setIsolationMethods(isolationMethods); |
| 534 | + |
| 535 | + URI resultUri = testOrchastrator.encodeVlanIdIntoBroadcastUri(vlanId, physicalNetwork); |
| 536 | + |
| 537 | + Assert.assertEquals(expectedIsolation, resultUri.getScheme()); |
| 538 | + Assert.assertEquals(expectedUri, resultUri.toString()); |
| 539 | + } |
466 | 540 | } |
0 commit comments