[SEBA-144] Operational Status DHCP L2 Relay.
Cherry-picked from dhcpl2relay-1.6
Change-Id: I58aab083152793af36dfd34fa91cd78385fd2ed7
Signed-off-by: Marcos Aurelio Carrero <mcarrero@furukawalatam.com>
diff --git a/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayConfigTest.java b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayConfigTest.java
new file mode 100644
index 0000000..94a90c8
--- /dev/null
+++ b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayConfigTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.opencord.dhcpl2relay.impl;
+
+import com.google.common.collect.ImmutableSet;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+
+import org.onlab.junit.TestUtils;
+import org.onlab.osgi.ComponentContextAdapter;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.common.event.impl.TestEventDispatcher;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.NetworkConfigRegistryAdapter;
+import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter;
+
+import java.util.Set;
+
+/**
+ * Tests for DHCP relay app configuration.
+ */
+public class DhcpL2RelayConfigTest extends DhcpL2RelayTestBase {
+
+ static final boolean USE_OLT_ULPORT_FOR_PKT_INOUT = true;
+ static final boolean MODIFY_SRC_DST_MAC = true;
+
+ private DhcpL2Relay dhcpL2Relay;
+
+ ComponentConfigService mockConfigService =
+ EasyMock.createMock(ComponentConfigService.class);
+
+ /**
+ * Sets up the services required by the dhcpl2relay app.
+ */
+ @Before
+ public void setUp() {
+ dhcpL2Relay = new DhcpL2Relay();
+ dhcpL2Relay.cfgService = new TestNetworkConfigRegistry();
+ dhcpL2Relay.coreService = new MockCoreServiceAdapter();
+ dhcpL2Relay.flowObjectiveService = new FlowObjectiveServiceAdapter();
+ dhcpL2Relay.packetService = new MockPacketService();
+ dhcpL2Relay.componentConfigService = mockConfigService;
+ dhcpL2Relay.deviceService = new MockDeviceService();
+ dhcpL2Relay.sadisService = new MockSadisService();
+ dhcpL2Relay.hostService = new MockHostService();
+ dhcpL2Relay.mastershipService = new MockMastershipService();
+ TestUtils.setField(dhcpL2Relay, "eventDispatcher", new TestEventDispatcher());
+ dhcpL2Relay.activate(new ComponentContextAdapter());
+ }
+
+ /**
+ * Mocks the network config registry.
+ */
+ static class MockDhcpL2RelayConfig extends DhcpL2RelayConfig {
+ @Override
+ public Set<ConnectPoint> getDhcpServerConnectPoint() {
+ return ImmutableSet.of(SERVER_CONNECT_POINT);
+ }
+
+ @Override
+ public boolean getModifySrcDstMacAddresses() {
+ return true;
+ }
+
+ @Override
+ public boolean getUseOltUplinkForServerPktInOut() {
+ return true;
+ }
+ }
+
+ /**
+ * Tests the default configuration.
+ */
+ @Test
+ public void testConfig() {
+ assertThat(dhcpL2Relay.useOltUplink, is(USE_OLT_ULPORT_FOR_PKT_INOUT));
+ assertThat(dhcpL2Relay.modifyClientPktsSrcDstMac, is(MODIFY_SRC_DST_MAC));
+ assertNull(dhcpL2Relay.dhcpServerConnectPoint.get());
+ }
+
+ /**
+ * Tests if dhcpl2relay app has been configured.
+ */
+ @Test
+ public void testDhcpL2RelayConfigured() {
+ assertTrue(dhcpL2Relay.configured());
+ }
+
+ /**
+ * Mocks the network config registry.
+ */
+ @SuppressWarnings("unchecked")
+ static final class TestNetworkConfigRegistry
+ extends NetworkConfigRegistryAdapter {
+ @Override
+ public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
+ DhcpL2RelayConfig dhcpConfig = new MockDhcpL2RelayConfig();
+ return (C) dhcpConfig;
+ }
+ }
+}
\ No newline at end of file