blob: 1a3447396aa6186d6d88ff317dd0c0b9087123b6 [file] [log] [blame]
Ray Milkeyafa00d22014-11-13 19:25:15 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
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 */
16package org.onlab.onos.net.packet;
17
18import java.nio.ByteBuffer;
19
20import org.junit.Test;
21import org.onlab.onos.net.flow.TrafficTreatment;
22import org.onlab.onos.net.intent.IntentTestsMocks;
23import 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;
31import static org.onlab.onos.net.NetTestTools.did;
32
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}