Committed by
Gerrit Code Review
Unit tests for ModTunnelIdInstruction and ModTransportPortInstruction
Change-Id: Id0186affac32b0286d0e2fd782395253a8908101
Showing
1 changed file
with
123 additions
and
0 deletions
... | @@ -597,4 +597,127 @@ public class InstructionsTest { | ... | @@ -597,4 +597,127 @@ public class InstructionsTest { |
597 | modMplsLabelInstruction2); | 597 | modMplsLabelInstruction2); |
598 | } | 598 | } |
599 | 599 | ||
600 | + // ModTunnelIdInstruction | ||
601 | + | ||
602 | + private final long tunnelId1 = 1L; | ||
603 | + private final long tunnelId2 = 2L; | ||
604 | + private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1); | ||
605 | + private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1); | ||
606 | + private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2); | ||
607 | + | ||
608 | + /** | ||
609 | + * Test the modTunnelId method. | ||
610 | + */ | ||
611 | + @Test | ||
612 | + public void testModTunnelIdMethod() { | ||
613 | + final Instruction instruction = Instructions.modTunnelId(tunnelId1); | ||
614 | + final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction = | ||
615 | + checkAndConvert(instruction, Instruction.Type.L2MODIFICATION, | ||
616 | + L2ModificationInstruction.ModTunnelIdInstruction.class); | ||
617 | + assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1))); | ||
618 | + assertThat(modTunnelIdInstruction.subtype(), | ||
619 | + is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID))); | ||
620 | + } | ||
621 | + | ||
622 | + /*** | ||
623 | + * Test the equals() method of the ModTunnelIdInstruction class. | ||
624 | + */ | ||
625 | + @Test | ||
626 | + public void testModTunnelIdInstructionEquals() throws Exception { | ||
627 | + checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2); | ||
628 | + } | ||
629 | + | ||
630 | + /** | ||
631 | + * Test the hashCode() method of the ModTunnelIdInstruction class. | ||
632 | + */ | ||
633 | + @Test | ||
634 | + public void testModTunnelIdInstructionHashCode() { | ||
635 | + assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode()))); | ||
636 | + assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode())))); | ||
637 | + } | ||
638 | + | ||
639 | + // ModTransportPortInstruction | ||
640 | + | ||
641 | + private final short l4port1 = 1; | ||
642 | + private final short l4port2 = 2; | ||
643 | + private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(l4port1); | ||
644 | + private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(l4port1); | ||
645 | + private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(l4port2); | ||
646 | + | ||
647 | + /** | ||
648 | + * Test the modTcpSrc() method. | ||
649 | + */ | ||
650 | + @Test | ||
651 | + public void testModTcpSrcMethod() { | ||
652 | + final Instruction instruction = Instructions.modTcpSrc(l4port1); | ||
653 | + final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = | ||
654 | + checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, | ||
655 | + L4ModificationInstruction.ModTransportPortInstruction.class); | ||
656 | + assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1))); | ||
657 | + assertThat(modTransportPortInstruction.subtype(), | ||
658 | + is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC))); | ||
659 | + } | ||
660 | + | ||
661 | + /** | ||
662 | + * Test the modTcpDst() method. | ||
663 | + */ | ||
664 | + @Test | ||
665 | + public void testModTcpDstMethod() { | ||
666 | + final Instruction instruction = Instructions.modTcpDst(l4port1); | ||
667 | + final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = | ||
668 | + checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, | ||
669 | + L4ModificationInstruction.ModTransportPortInstruction.class); | ||
670 | + assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1))); | ||
671 | + assertThat(modTransportPortInstruction.subtype(), | ||
672 | + is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST))); | ||
673 | + } | ||
674 | + | ||
675 | + /** | ||
676 | + * Test the modUdpSrc() method. | ||
677 | + */ | ||
678 | + @Test | ||
679 | + public void testModUdpSrcMethod() { | ||
680 | + final Instruction instruction = Instructions.modUdpSrc(l4port1); | ||
681 | + final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = | ||
682 | + checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, | ||
683 | + L4ModificationInstruction.ModTransportPortInstruction.class); | ||
684 | + assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1))); | ||
685 | + assertThat(modTransportPortInstruction.subtype(), | ||
686 | + is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC))); | ||
687 | + } | ||
688 | + | ||
689 | + /** | ||
690 | + * Test the modUdpDst() method. | ||
691 | + */ | ||
692 | + @Test | ||
693 | + public void testModUdpDstMethod() { | ||
694 | + final Instruction instruction = Instructions.modUdpDst(l4port1); | ||
695 | + final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction = | ||
696 | + checkAndConvert(instruction, Instruction.Type.L4MODIFICATION, | ||
697 | + L4ModificationInstruction.ModTransportPortInstruction.class); | ||
698 | + assertThat(modTransportPortInstruction.port(), is(equalTo(l4port1))); | ||
699 | + assertThat(modTransportPortInstruction.subtype(), | ||
700 | + is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST))); | ||
701 | + } | ||
702 | + | ||
703 | + /** | ||
704 | + * Test the equals() method of the ModTransportPortInstruction class. | ||
705 | + */ | ||
706 | + @Test | ||
707 | + public void testModTransportPortInstructionEquals() throws Exception { | ||
708 | + checkEqualsAndToString(modTransportPortInstruction1, | ||
709 | + sameAsModTransportPortInstruction1, | ||
710 | + modTransportPortInstruction2); | ||
711 | + } | ||
712 | + | ||
713 | + /** | ||
714 | + * Test the hashCode() method of the ModTransportPortInstruction class. | ||
715 | + */ | ||
716 | + @Test | ||
717 | + public void testModTransportPortInstructionHashCode() { | ||
718 | + assertThat(modTransportPortInstruction1.hashCode(), | ||
719 | + is(equalTo(sameAsModTransportPortInstruction1.hashCode()))); | ||
720 | + assertThat(modTransportPortInstruction1.hashCode(), | ||
721 | + is(not(equalTo(modTransportPortInstruction2.hashCode())))); | ||
722 | + } | ||
600 | } | 723 | } | ... | ... |
-
Please register or login to post a comment