e06981853b00b1ccee04392b011bb55c73128103
[genius.git] / mdsalutil / mdsalutil-api / src / test / java / org / opendaylight / genius / mdsalutil / tests / FlowEntityAssertBeansTest.java
1 /*
2  * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
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.tests;
9
10 import static com.google.common.truth.Truth.assertThat;
11 import static org.opendaylight.mdsal.binding.testutils.AssertDataObjects.assertEqualBeans;
12
13 import ch.vorburger.xtendbeans.XtendBeanGenerator;
14 import org.junit.ComparisonFailure;
15 import org.junit.Test;
16 import org.opendaylight.genius.mdsalutil.FlowEntity;
17 import org.opendaylight.genius.mdsalutil.FlowEntityBuilder;
18 import org.opendaylight.genius.mdsalutil.matches.MatchIpv4Source;
19 import org.opendaylight.yangtools.yang.common.Uint64;
20
21 /**
22  * Tests non-regression of FlowEntity related assertions.
23  * See <a href="https://bugs.opendaylight.org/show_bug.cgi?id=8800">Bug 8800</a>.
24  * @author Michael Vorburger.ch
25  */
26 public class FlowEntityAssertBeansTest {
27
28     // FLOW1 & FLOW2 differ by a minor variance in their MatchIpv4Source (NB .1 vs .2)
29     private static final FlowEntity FLOW1 = new FlowEntityBuilder()
30             .addMatchInfoList(new MatchIpv4Source("10.0.0.1", "32")).setFlowId("A").setTableId((short) 1)
31             .setDpnId(Uint64.ONE).build();
32     private static final FlowEntity FLOW2 = new FlowEntityBuilder()
33             .addMatchInfoList(new MatchIpv4Source("10.0.0.2", "32")).setFlowId("A").setTableId((short) 1)
34             .setDpnId(Uint64.ONE).build();
35
36     @Test(expected = ComparisonFailure.class)
37     public void testFlowEntityAssertEqualBeans() {
38         assertEqualBeans(FLOW1, FLOW2);
39     }
40
41     @Test
42     public void testXtendBeanGenerator() {
43         XtendBeanGenerator generator = new UintXtendBeanGenerator();
44         assertThat(generator.getExpression(FLOW1)).isEqualTo("(new FlowEntityBuilder => [\n"
45                 + "    cookie = (u64)1114112\n"
46                 + "    dpnId = (u64)1\n"
47                 + "    flowId = \"A\"\n"
48                 + "    hardTimeOut = 0\n"
49                 + "    idleTimeOut = 0\n"
50                 + "    instructionInfoList = #[\n"
51                 + "    ]\n"
52                 + "    matchInfoList = #[\n"
53                 + "        new MatchIpv4Source(new Ipv4Prefix(\"10.0.0.1/32\"))\n"
54                 + "    ]\n"
55                 + "    priority = 0\n"
56                 + "    sendFlowRemFlag = false\n"
57                 + "    strictFlag = false\n"
58                 + "    tableId = 1 as short\n"
59                 + "]).build()");
60     }
61
62 }