Jian Li
Committed by Gerrit Code Review

Add unit test for LISP msg to check object equality and construction

Change-Id: I5365f7654df10f4cf157c79f098c7ce26c29a300
......@@ -15,8 +15,11 @@
*/
package org.onosproject.lisp.msg.protocols;
import com.google.common.base.Objects;
import org.onosproject.lisp.msg.types.LispAfiAddress;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Default implementation of LispMapRecord.
*/
......@@ -88,6 +91,42 @@ public final class DefaultLispMapRecord implements LispMapRecord {
return eidPrefixAfi;
}
@Override
public String toString() {
return toStringHelper(this)
.add("record TTL", recordTtl)
.add("locatorCount", locatorCount)
.add("maskLength", maskLength)
.add("action", action)
.add("authoritative", authoritative)
.add("mapVersionNumber", mapVersionNumber)
.add("EID prefix AFI address", eidPrefixAfi).toString();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DefaultLispMapRecord that = (DefaultLispMapRecord) o;
return Objects.equal(recordTtl, that.recordTtl) &&
Objects.equal(locatorCount, that.locatorCount) &&
Objects.equal(maskLength, that.maskLength) &&
Objects.equal(action, that.action) &&
Objects.equal(authoritative, that.authoritative) &&
Objects.equal(mapVersionNumber, that.mapVersionNumber) &&
Objects.equal(eidPrefixAfi, that.eidPrefixAfi);
}
@Override
public int hashCode() {
return Objects.hashCode(recordTtl, locatorCount, maskLength, action,
authoritative, mapVersionNumber, eidPrefixAfi);
}
public static final class DefaultMapRecordBuilder implements MapRecordBuilder {
private int recordTtl;
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.lisp.msg.protocols;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Unit tests for DefaultLispMapNotify class.
*/
public class DefaultLispMapNotifyTest {
private LispMapNotify notify1;
private LispMapNotify sameAsNotify1;
private LispMapNotify notify2;
@Before
public void setup() {
LispMapNotify.NotifyBuilder builder1 =
new DefaultLispMapNotify.DefaultNotifyBuilder();
notify1 = builder1
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapNotify.NotifyBuilder builder2 =
new DefaultLispMapNotify.DefaultNotifyBuilder();
sameAsNotify1 = builder2
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapNotify.NotifyBuilder builder3 =
new DefaultLispMapNotify.DefaultNotifyBuilder();
notify2 = builder3
.withKeyId((short) 2)
.withNonce(2L)
.withRecordCount((byte) 0x02)
.build();
}
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(notify1, sameAsNotify1)
.addEqualityGroup(notify2).testEquals();
}
@Test
public void testConstruction() {
DefaultLispMapNotify notify = (DefaultLispMapNotify) notify1;
assertThat(notify.getKeyId(), is((short) 1));
assertThat(notify.getNonce(), is(1L));
assertThat(notify.getRecordCount(), is((byte) 0x01));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.lisp.msg.protocols;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Unit tests for DefaultLispMapRecord class.
*/
public class DefaultLispMapRecordTest {
private LispMapRecord record1;
private LispMapRecord sameAsRecord1;
private LispMapRecord record2;
@Before
public void setup() {
LispMapRecord.MapRecordBuilder builder1 =
new DefaultLispMapRecord.DefaultMapRecordBuilder();
record1 = builder1
.withRecordTtl(100)
.withAuthoritative(true)
.withLocatorCount(100)
.withMapVersionNumber((short) 1)
.withMaskLength((byte) 0x01)
.build();
LispMapRecord.MapRecordBuilder builder2 =
new DefaultLispMapRecord.DefaultMapRecordBuilder();
sameAsRecord1 = builder2
.withRecordTtl(100)
.withAuthoritative(true)
.withLocatorCount(100)
.withMapVersionNumber((short) 1)
.withMaskLength((byte) 0x01)
.build();
LispMapRecord.MapRecordBuilder builder3 =
new DefaultLispMapRecord.DefaultMapRecordBuilder();
record2 = builder3
.withRecordTtl(200)
.withAuthoritative(false)
.withLocatorCount(200)
.withMapVersionNumber((short) 2)
.withMaskLength((byte) 0x02)
.build();
}
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(record1, sameAsRecord1)
.addEqualityGroup(record2).testEquals();
}
@Test
public void testConstruction() {
DefaultLispMapRecord record = (DefaultLispMapRecord) record1;
assertThat(record.getRecordTtl(), is(100));
assertThat(record.isAuthoritative(), is(true));
assertThat(record.getLocatorCount(), is(100));
assertThat(record.getMapVersionNumber(), is((short) 1));
assertThat(record.getMaskLength(), is((byte) 0x01));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.lisp.msg.protocols;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Unit tests for DefaultLispMapRegister class.
*/
public class DefaultLispMapRegisterTest {
private LispMapRegister register1;
private LispMapRegister sameAsRegister1;
private LispMapRegister register2;
@Before
public void setup() {
LispMapRegister.RegisterBuilder builder1 =
new DefaultLispMapRegister.DefaultRegisterBuilder();
register1 = builder1
.withIsProxyMapReply(true)
.withIsWantMapNotify(false)
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapRegister.RegisterBuilder builder2 =
new DefaultLispMapRegister.DefaultRegisterBuilder();
sameAsRegister1 = builder2
.withIsProxyMapReply(true)
.withIsWantMapNotify(false)
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapRegister.RegisterBuilder builder3 =
new DefaultLispMapRegister.DefaultRegisterBuilder();
register2 = builder3
.withIsProxyMapReply(true)
.withIsWantMapNotify(false)
.withKeyId((short) 2)
.withNonce(2L)
.withRecordCount((byte) 0x02)
.build();
}
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(register1, sameAsRegister1)
.addEqualityGroup(register2).testEquals();
}
@Test
public void testConstruction() {
DefaultLispMapRegister register = (DefaultLispMapRegister) register1;
assertThat(register.isProxyMapReply(), is(true));
assertThat(register.isWantMapNotify(), is(false));
assertThat(register.getKeyId(), is((short) 1));
assertThat(register.getNonce(), is(1L));
assertThat(register.getRecordCount(), is((byte) 0x01));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.lisp.msg.protocols;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Unit tests for DefaultLispMapReply class.
*/
public class DefaultLispMapReplyTest {
private LispMapReply reply1;
private LispMapReply sameAsReply1;
private LispMapReply reply2;
@Before
public void setup() {
LispMapReply.ReplyBuilder builder1 =
new DefaultLispMapReply.DefaultReplyBuilder();
reply1 = builder1
.withIsEtr(true)
.withIsProbe(false)
.withIsSecurity(true)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapReply.ReplyBuilder builder2 =
new DefaultLispMapReply.DefaultReplyBuilder();
sameAsReply1 = builder2
.withIsEtr(true)
.withIsProbe(false)
.withIsSecurity(true)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapReply.ReplyBuilder builder3 =
new DefaultLispMapReply.DefaultReplyBuilder();
reply2 = builder3
.withIsEtr(false)
.withIsProbe(true)
.withIsSecurity(false)
.withNonce(2L)
.withRecordCount((byte) 0x02)
.build();
}
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(reply1, sameAsReply1)
.addEqualityGroup(reply2).testEquals();
}
@Test
public void testConstruction() {
DefaultLispMapReply reply = (DefaultLispMapReply) reply1;
assertThat(reply.isEtr(), is(true));
assertThat(reply.isProbe(), is(false));
assertThat(reply.isSecurity(), is(true));
assertThat(reply.getNonce(), is(1L));
assertThat(reply.getRecordCount(), is((byte) 0x01));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.lisp.msg.protocols;
import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Unit tests for DefaultLispMapRequest class.
*/
public class DefaultLispMapRequestTest {
private LispMapRequest request1;
private LispMapRequest sameAsRequest1;
private LispMapRequest request2;
@Before
public void setup() {
LispMapRequest.RequestBuilder builder1 =
new DefaultLispMapRequest.DefaultRequestBuilder();
request1 = builder1
.withIsAuthoritative(true)
.withIsMapDataPresent(true)
.withIsPitr(false)
.withIsProbe(false)
.withIsSmr(true)
.withIsSmrInvoked(false)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapRequest.RequestBuilder builder2 =
new DefaultLispMapRequest.DefaultRequestBuilder();
sameAsRequest1 = builder2
.withIsAuthoritative(true)
.withIsMapDataPresent(true)
.withIsPitr(false)
.withIsProbe(false)
.withIsSmr(true)
.withIsSmrInvoked(false)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.build();
LispMapRequest.RequestBuilder builder3 =
new DefaultLispMapRequest.DefaultRequestBuilder();
request2 = builder3
.withIsAuthoritative(false)
.withIsMapDataPresent(false)
.withIsPitr(true)
.withIsProbe(true)
.withIsSmr(false)
.withIsSmrInvoked(true)
.withNonce(2L)
.withRecordCount((byte) 0x02)
.build();
}
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(request1, sameAsRequest1)
.addEqualityGroup(request2).testEquals();
}
@Test
public void testConstruction() {
DefaultLispMapRequest request = (DefaultLispMapRequest) request1;
assertThat(request.isAuthoritative(), is(true));
assertThat(request.isMapDataPresent(), is(true));
assertThat(request.isPitr(), is(false));
assertThat(request.isProbe(), is(false));
assertThat(request.isSmr(), is(true));
assertThat(request.isSmrInvoked(), is(false));
assertThat(request.getNonce(), is(1L));
assertThat(request.getRecordCount(), is((byte) 0x01));
}
}