61386b44fcb108bf707125c1bdf82807cc84e425
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / FlowUtilTest.java
1 /*
2  *
3  *  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
4  *  *
5  *  * This program and the accompanying materials are made available under the
6  *  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  *
10  */
11
12 package org.opendaylight.openflowplugin.impl.util;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17
18 import org.junit.Test;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
20
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23
24 public class FlowUtilTest {
25
26     private static final short DUMMY_TABLE_ID = 1;
27     public static final Pattern INDEX_PATTERN = Pattern.compile("^#UF\\$TABLE\\*1-([0-9]+)$");
28
29     @Test
30     public void createAlienFlowIdTest() {
31         final String alienFlowId1 = FlowUtil.createAlienFlowId(DUMMY_TABLE_ID).getValue();
32         final Integer index1 = parseIndex(alienFlowId1);
33         final String alienFlowId2 = FlowUtil.createAlienFlowId(DUMMY_TABLE_ID).getValue();
34         final Integer index2 = parseIndex(alienFlowId2);
35
36         assertNotNull("index1 parsing failed: "+alienFlowId1, index1);
37         assertNotNull("index2 parsing failed: "+alienFlowId2, index2);
38         assertTrue(index1 < index2);
39     }
40
41     private static Integer parseIndex(String alienFlowIdValue) {
42         final Matcher mach = INDEX_PATTERN.matcher(alienFlowIdValue);
43         if (mach.find()) {
44             return Integer.valueOf(mach.group(1));
45         }
46         return null;
47     }
48
49 }