9927a0c59aa5cf0bfdbee6365d9b5f3aca9ac94b
[genius.git] / mdsalutil / mdsalutil-api / src / test / java / org / opendaylight / genius / mdsalutil / actions / ActionSetFieldEthernetSourceTest.java
1 /*
2  * Copyright © 2016, 2017 Red Hat, Inc. and others.
3  *
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
7  */
8 package org.opendaylight.genius.mdsalutil.actions;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
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.yang.types.rev130715.MacAddress;
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
21 /**
22  * Test class for {@link ActionSetFieldEthernetSource}.
23  */
24 public class ActionSetFieldEthernetSourceTest {
25     private static final String MAC_ADDRESS = "11:22:33:44:55:66";
26
27     private XtendBeanGenerator generator = new XtendBeanGenerator();
28
29     @Test
30     public void actionInfoTest() {
31         verifyAction(new ActionSetFieldEthernetSource(new MacAddress(MAC_ADDRESS)).buildAction());
32     }
33
34     private void verifyAction(Action action) {
35         assertTrue(action.getAction() instanceof SetFieldCase);
36         SetFieldCase actionCase = (SetFieldCase) action.getAction();
37         assertNotNull(actionCase.getSetField().getEthernetMatch());
38         assertNotNull(actionCase.getSetField().getEthernetMatch().getEthernetSource());
39         assertEquals(MAC_ADDRESS,
40             actionCase.getSetField().getEthernetMatch().getEthernetSource().getAddress().getValue());
41     }
42
43     @Test
44     public void generateAction() {
45         ActionInfo actionInfo = new ActionSetFieldEthernetSource(new MacAddress(MAC_ADDRESS));
46         actionInfo.buildAction();
47         assertEquals("new ActionSetFieldEthernetSource(0, new MacAddress(\"" + MAC_ADDRESS + "\"))",
48                 generator.getExpression(actionInfo));
49     }
50 }