Merge "Include IkeTunnelConnectionParams in #hashCode and #equals"
This commit is contained in:
@@ -352,6 +352,7 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(
|
return Objects.hash(
|
||||||
mGatewayConnectionName,
|
mGatewayConnectionName,
|
||||||
|
mTunnelConnectionParams,
|
||||||
mExposedCapabilities,
|
mExposedCapabilities,
|
||||||
Arrays.hashCode(mRetryIntervalsMs),
|
Arrays.hashCode(mRetryIntervalsMs),
|
||||||
mMaxMtu);
|
mMaxMtu);
|
||||||
@@ -365,6 +366,7 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
|
|
||||||
final VcnGatewayConnectionConfig rhs = (VcnGatewayConnectionConfig) other;
|
final VcnGatewayConnectionConfig rhs = (VcnGatewayConnectionConfig) other;
|
||||||
return mGatewayConnectionName.equals(rhs.mGatewayConnectionName)
|
return mGatewayConnectionName.equals(rhs.mGatewayConnectionName)
|
||||||
|
&& mTunnelConnectionParams.equals(rhs.mTunnelConnectionParams)
|
||||||
&& mExposedCapabilities.equals(rhs.mExposedCapabilities)
|
&& mExposedCapabilities.equals(rhs.mExposedCapabilities)
|
||||||
&& Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs)
|
&& Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs)
|
||||||
&& mMaxMtu == rhs.mMaxMtu;
|
&& mMaxMtu == rhs.mMaxMtu;
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@@ -70,6 +72,14 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
public static final String GATEWAY_CONNECTION_NAME_PREFIX = "gatewayConnectionName-";
|
public static final String GATEWAY_CONNECTION_NAME_PREFIX = "gatewayConnectionName-";
|
||||||
private static int sGatewayConnectionConfigCount = 0;
|
private static int sGatewayConnectionConfigCount = 0;
|
||||||
|
|
||||||
|
private static VcnGatewayConnectionConfig buildTestConfig(
|
||||||
|
String gatewayConnectionName, IkeTunnelConnectionParams tunnelConnectionParams) {
|
||||||
|
return buildTestConfigWithExposedCaps(
|
||||||
|
new VcnGatewayConnectionConfig.Builder(
|
||||||
|
gatewayConnectionName, tunnelConnectionParams),
|
||||||
|
EXPOSED_CAPS);
|
||||||
|
}
|
||||||
|
|
||||||
// Public for use in VcnGatewayConnectionTest
|
// Public for use in VcnGatewayConnectionTest
|
||||||
public static VcnGatewayConnectionConfig buildTestConfig() {
|
public static VcnGatewayConnectionConfig buildTestConfig() {
|
||||||
return buildTestConfigWithExposedCaps(EXPOSED_CAPS);
|
return buildTestConfigWithExposedCaps(EXPOSED_CAPS);
|
||||||
@@ -83,10 +93,9 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
TUNNEL_CONNECTION_PARAMS);
|
TUNNEL_CONNECTION_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public for use in VcnGatewayConnectionTest
|
private static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(
|
||||||
public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
|
VcnGatewayConnectionConfig.Builder builder, int... exposedCaps) {
|
||||||
final VcnGatewayConnectionConfig.Builder builder =
|
builder.setRetryIntervalsMillis(RETRY_INTERVALS_MS).setMaxMtu(MAX_MTU);
|
||||||
newBuilder().setRetryIntervalsMillis(RETRY_INTERVALS_MS).setMaxMtu(MAX_MTU);
|
|
||||||
|
|
||||||
for (int caps : exposedCaps) {
|
for (int caps : exposedCaps) {
|
||||||
builder.addExposedCapability(caps);
|
builder.addExposedCapability(caps);
|
||||||
@@ -95,6 +104,11 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Public for use in VcnGatewayConnectionTest
|
||||||
|
public static VcnGatewayConnectionConfig buildTestConfigWithExposedCaps(int... exposedCaps) {
|
||||||
|
return buildTestConfigWithExposedCaps(newBuilder(), exposedCaps);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuilderRequiresNonNullGatewayConnectionName() {
|
public void testBuilderRequiresNonNullGatewayConnectionName() {
|
||||||
try {
|
try {
|
||||||
@@ -193,4 +207,46 @@ public class VcnGatewayConnectionConfigTest {
|
|||||||
|
|
||||||
assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
|
assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IkeTunnelConnectionParams buildTunnelConnectionParams(String ikePsk) {
|
||||||
|
final IkeSessionParams ikeParams =
|
||||||
|
IkeSessionParamsUtilsTest.createBuilderMinimum()
|
||||||
|
.setAuthPsk(ikePsk.getBytes())
|
||||||
|
.build();
|
||||||
|
return TunnelConnectionParamsUtilsTest.buildTestParams(ikeParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTunnelConnectionParamsEquals() throws Exception {
|
||||||
|
final String connectionName = "testTunnelConnectionParamsEquals.connectionName";
|
||||||
|
final String psk = "testTunnelConnectionParamsEquals.psk";
|
||||||
|
|
||||||
|
final IkeTunnelConnectionParams tunnelParams = buildTunnelConnectionParams(psk);
|
||||||
|
final VcnGatewayConnectionConfig config = buildTestConfig(connectionName, tunnelParams);
|
||||||
|
|
||||||
|
final IkeTunnelConnectionParams anotherTunnelParams = buildTunnelConnectionParams(psk);
|
||||||
|
final VcnGatewayConnectionConfig anotherConfig =
|
||||||
|
buildTestConfig(connectionName, anotherTunnelParams);
|
||||||
|
|
||||||
|
assertNotSame(tunnelParams, anotherTunnelParams);
|
||||||
|
assertEquals(tunnelParams, anotherTunnelParams);
|
||||||
|
assertEquals(config, anotherConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTunnelConnectionParamsNotEquals() throws Exception {
|
||||||
|
final String connectionName = "testTunnelConnectionParamsNotEquals.connectionName";
|
||||||
|
|
||||||
|
final IkeTunnelConnectionParams tunnelParams =
|
||||||
|
buildTunnelConnectionParams("testTunnelConnectionParamsNotEquals.pskA");
|
||||||
|
final VcnGatewayConnectionConfig config = buildTestConfig(connectionName, tunnelParams);
|
||||||
|
|
||||||
|
final IkeTunnelConnectionParams anotherTunnelParams =
|
||||||
|
buildTunnelConnectionParams("testTunnelConnectionParamsNotEquals.pskB");
|
||||||
|
final VcnGatewayConnectionConfig anotherConfig =
|
||||||
|
buildTestConfig(connectionName, anotherTunnelParams);
|
||||||
|
|
||||||
|
assertNotEquals(tunnelParams, anotherTunnelParams);
|
||||||
|
assertNotEquals(config, anotherConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user