2 * Copyright © 2016, 2017 Red Hat, Inc. and others.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.genius.mdsalutil.actions;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import ch.vorburger.xtendbeans.XtendBeanGenerator;
15 import org.junit.Test;
16 import org.opendaylight.genius.mdsalutil.ActionInfo;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Action;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
23 * Test class for {@link ActionSetSourceIp}.
25 public class ActionSetSourceIpTest {
26 private static final String IP_ADDRESS = "1.2.3.4";
27 private static final String IP_MASK = "32";
29 private final XtendBeanGenerator generator = new XtendBeanGenerator();
32 public void actionInfoTest() {
33 verifyAction(new ActionSetSourceIp(IP_ADDRESS).buildAction());
34 verifyAction(new ActionSetSourceIp(IP_ADDRESS, IP_MASK).buildAction());
35 verifyAction(new ActionSetSourceIp(new Ipv4Prefix(IP_ADDRESS + "/" + IP_MASK)).buildAction());
38 private static void verifyAction(Action action) {
39 assertTrue(action.getAction() instanceof SetFieldCase);
40 SetFieldCase actionCase = (SetFieldCase) action.getAction();
41 assertNotNull(actionCase.getSetField().getLayer3Match());
42 assertTrue(actionCase.getSetField().getLayer3Match() instanceof Ipv4Match);
43 Ipv4Match ipv4Match = (Ipv4Match) actionCase.getSetField().getLayer3Match();
44 assertEquals(new Ipv4Prefix(IP_ADDRESS + "/" + IP_MASK), ipv4Match.getIpv4Source());
48 public void generateAction() {
49 ActionInfo actionInfo = new ActionSetSourceIp(IP_ADDRESS);
50 assertEquals("Ipv4Prefix{_value=" + IP_ADDRESS + "/" + IP_MASK + "}",
51 ((ActionSetSourceIp) actionInfo).getSource().toString());