|
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; |
@@ -483,4 +486,74 @@ public void testDontReleaseNicWhenPreserveNicsSettingEnabled() { |
483 | 486 | verify(testOrchastrator._nicDao, never()).remove(nicId); |
484 | 487 | } |
485 | 488 |
|
| 489 | + public void encodeVlanIdIntoBroadcastUriTestVxlan() { |
| 490 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", "VXLAN", "vxlan", "vxlan://123"); |
| 491 | + } |
| 492 | + |
| 493 | + @Test |
| 494 | + public void encodeVlanIdIntoBroadcastUriTestVlan() { |
| 495 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", "VLAN", "vlan", "vlan://123"); |
| 496 | + } |
| 497 | + |
| 498 | + @Test |
| 499 | + public void encodeVlanIdIntoBroadcastUriTestEmpty() { |
| 500 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", "", "vlan", "vlan://123"); |
| 501 | + } |
| 502 | + |
| 503 | + @Test |
| 504 | + public void encodeVlanIdIntoBroadcastUriTestNull() { |
| 505 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("123", null, "vlan", "vlan://123"); |
| 506 | + } |
| 507 | + |
| 508 | + @Test(expected = CloudRuntimeException.class) |
| 509 | + public void encodeVlanIdIntoBroadcastUriTestEmptyVlanId() { |
| 510 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("", "vxlan", "vlan", "vlan://123"); |
| 511 | + } |
| 512 | + |
| 513 | + @Test(expected = CloudRuntimeException.class) |
| 514 | + public void encodeVlanIdIntoBroadcastUriTestNullVlanId() { |
| 515 | + encodeVlanIdIntoBroadcastUriPrepareAndTest(null, "vlan", "vlan", "vlan://123"); |
| 516 | + } |
| 517 | + |
| 518 | + @Test(expected = CloudRuntimeException.class) |
| 519 | + public void encodeVlanIdIntoBroadcastUriTestBlankVlanId() { |
| 520 | + encodeVlanIdIntoBroadcastUriPrepareAndTest(" ", "vlan", "vlan", "vlan://123"); |
| 521 | + } |
| 522 | + |
| 523 | + @Test |
| 524 | + public void encodeVlanIdIntoBroadcastUriTestNullVlanIdWithSchema() { |
| 525 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vlan://123", "vlan", "vlan", "vlan://123"); |
| 526 | + } |
| 527 | + |
| 528 | + @Test |
| 529 | + public void encodeVlanIdIntoBroadcastUriTestNullVlanIdWithSchemaIsolationVxlan() { |
| 530 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vlan://123", "vxlan", "vlan", "vlan://123"); |
| 531 | + } |
| 532 | + |
| 533 | + @Test |
| 534 | + public void encodeVlanIdIntoBroadcastUriTestNullVxlanIdWithSchema() { |
| 535 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vxlan://123", "vxlan", "vxlan", "vxlan://123"); |
| 536 | + } |
| 537 | + |
| 538 | + @Test |
| 539 | + public void encodeVlanIdIntoBroadcastUriTestNullVxlanIdWithSchemaIsolationVlan() { |
| 540 | + encodeVlanIdIntoBroadcastUriPrepareAndTest("vxlan://123", "vlan", "vxlan", "vxlan://123"); |
| 541 | + } |
| 542 | + |
| 543 | + @Test(expected = InvalidParameterValueException.class) |
| 544 | + public void encodeVlanIdIntoBroadcastUriTestNullNetwork() { |
| 545 | + URI resultUri = testOrchastrator.encodeVlanIdIntoBroadcastUri("vxlan://123", null); |
| 546 | + } |
| 547 | + |
| 548 | + private void encodeVlanIdIntoBroadcastUriPrepareAndTest(String vlanId, String isolationMethod, String expectedIsolation, String expectedUri) { |
| 549 | + PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(); |
| 550 | + List<String> isolationMethods = new ArrayList<>(); |
| 551 | + isolationMethods.add(isolationMethod); |
| 552 | + physicalNetwork.setIsolationMethods(isolationMethods); |
| 553 | + |
| 554 | + URI resultUri = testOrchastrator.encodeVlanIdIntoBroadcastUri(vlanId, physicalNetwork); |
| 555 | + |
| 556 | + Assert.assertEquals(expectedIsolation, resultUri.getScheme()); |
| 557 | + Assert.assertEquals(expectedUri, resultUri.toString()); |
| 558 | + } |
486 | 559 | } |
0 commit comments