InstructionInfo redesign
[genius.git] / mdsalutil / mdsalutil-api / src / test / java / org / opendaylight / genius / mdsalutil / instructions / InstructionWriteMetadataTest.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.instructions;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import java.math.BigInteger;
14 import org.junit.Test;
15 import org.opendaylight.genius.mdsalutil.InstructionInfo;
16 import org.opendaylight.genius.mdsalutil.InstructionType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
20
21 /**
22  * Test for {@link InstructionWriteMetadata}.
23  */
24 public class InstructionWriteMetadataTest {
25     @Test
26     public void backwardsCompatibleInstruction() {
27         verifyInstructionInfo(
28                 new InstructionInfo(InstructionType.write_metadata, new BigInteger[] {BigInteger.ONE, BigInteger.TEN}));
29     }
30
31     @Test
32     public void newInstruction() {
33         verifyInstructionInfo(new InstructionWriteMetadata(BigInteger.ONE, BigInteger.TEN));
34     }
35
36     private void verifyInstructionInfo(InstructionInfo instructionInfo) {
37         Instruction instruction = instructionInfo.buildInstruction(2);
38         assertEquals(2, instruction.getKey().getOrder().intValue());
39         assertTrue(instruction.getInstruction() instanceof WriteMetadataCase);
40         WriteMetadataCase writeMetadataCase = (WriteMetadataCase) instruction.getInstruction();
41         WriteMetadata writeMetadata = writeMetadataCase.getWriteMetadata();
42         assertEquals(BigInteger.ONE, writeMetadata.getMetadata());
43         assertEquals(BigInteger.TEN, writeMetadata.getMetadataMask());
44     }
45 }