blob: c56ef01da5bb98cbafad5e5e1d44e0cff3e8cc33 [file] [log] [blame]
Ray Milkeyafa00d22014-11-13 19:25:15 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Ray Milkeyafa00d22014-11-13 19:25:15 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.packet;
Ray Milkeyafa00d22014-11-13 19:25:15 -080017
18import java.nio.ByteBuffer;
19
20import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.flow.TrafficTreatment;
22import org.onosproject.net.intent.IntentTestsMocks;
Ray Milkeyafa00d22014-11-13 19:25:15 -080023import org.onlab.packet.Ethernet;
24import org.onlab.packet.MacAddress;
25
26import com.google.common.testing.EqualsTester;
27
28import static org.hamcrest.MatcherAssert.assertThat;
29import static org.hamcrest.Matchers.equalTo;
30import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import static org.onosproject.net.NetTestTools.did;
Ray Milkeyafa00d22014-11-13 19:25:15 -080032
33/**
34 * Unit tests for the DefaultOutboundPacketTest class.
35 */
36public class DefaultOutboundPacketTest {
37 final Ethernet eth = new Ethernet()
38 .setDestinationMACAddress(MacAddress.BROADCAST)
39 .setSourceMACAddress(MacAddress.BROADCAST);
40 final ByteBuffer byteBuffer = ByteBuffer.wrap(eth.serialize());
41 final TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
42 final DefaultOutboundPacket packet1 =
43 new DefaultOutboundPacket(did("d1"),
44 treatment,
45 byteBuffer);
46 final DefaultOutboundPacket sameAsPacket1 =
47 new DefaultOutboundPacket(did("d1"),
48 treatment,
49 byteBuffer);
50 final DefaultOutboundPacket packet2 =
51 new DefaultOutboundPacket(did("d2"),
52 treatment,
53 byteBuffer);
54 /**
55 * Checks that the DefaultOutboundPacket class is immutable.
56 */
57 @Test
58 public void testImmutability() {
59 assertThatClassIsImmutable(DefaultOutboundPacket.class);
60 }
61
62 /**
63 * Tests the equals(), hashCode() and toString() methods.
64 */
65 @Test
66 public void testEquals() {
67 new EqualsTester()
68 .addEqualityGroup(packet1, sameAsPacket1)
69 .addEqualityGroup(packet2)
70 .testEquals();
71 }
72
73 /**
74 * Tests the object creation through the constructor.
75 */
76 @Test
77 public void testConstruction() {
78 assertThat(packet1.sendThrough(), equalTo(did("d1")));
79 assertThat(packet1.data(), equalTo(byteBuffer));
80 assertThat(packet1.treatment(), equalTo(treatment));
81 }
82}