MRI version bump for Aluminium
[genius.git] / mdsalutil / mdsalutil-api / src / test / java / org / opendaylight / genius / mdsalutil / actions / ActionSetSourceIpv6Test.java
1 /*
2  * Copyright © 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.inet.types.rev130715.Ipv6Prefix;
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.Ipv6Match;
21
22 /**
23  * Test class for {@link ActionSetSourceIpv6}.
24  */
25 public class ActionSetSourceIpv6Test {
26     private static final String IP_ADDRESS = "2001:db8::1";
27     private static final String IP_MASK = "128";
28
29     private XtendBeanGenerator generator = new XtendBeanGenerator();
30
31     @Test
32     public void actionInfoTest() {
33         verifyAction(new ActionSetSourceIpv6(IP_ADDRESS).buildAction());
34         verifyAction(new ActionSetSourceIpv6(IP_ADDRESS, IP_MASK).buildAction());
35         verifyAction(new ActionSetSourceIpv6(new Ipv6Prefix(IP_ADDRESS + "/" + IP_MASK)).buildAction());
36     }
37
38     private 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 Ipv6Match);
43         Ipv6Match ipv6Match = (Ipv6Match) actionCase.getSetField().getLayer3Match();
44         assertEquals(new Ipv6Prefix(IP_ADDRESS + "/" + IP_MASK), ipv6Match.getIpv6Source());
45     }
46
47     @Test
48     public void generateAction() {
49         ActionInfo actionInfo = new ActionSetSourceIpv6(IP_ADDRESS);
50         assertEquals(("Ipv6Prefix{_value=" + IP_ADDRESS + "/" + IP_MASK + "}"),
51                 ((ActionSetSourceIpv6) actionInfo).getSource().toString());
52     }
53 }