2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.openflow.md.core.translator;
10 import java.lang.reflect.Method;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorMessage;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
25 public class ErrorTranslatorTest {
27 private ErrorTranslator errorTranslator;
28 private static Logger LOG = LoggerFactory
29 .getLogger(ErrorTranslatorTest.class);
36 errorTranslator = new ErrorTranslator();
40 * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.translator.ErrorTranslator#getGranularNodeErrors(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorType)}.
44 public void testGetGranularNodeErrors() throws Exception {
45 for (ErrorType eType : ErrorType.values()) {
46 ErrorMessageBuilder builder = new ErrorMessageBuilder();
47 builder.setType(eType.getIntValue());
50 builder.setData(new byte[]{42});
52 ErrorMessage errorMessage = errorTranslator.getGranularNodeErrors(builder.build(), eType);
53 LOG.debug("translating errorMessage of type {}", eType);
54 Assert.assertNotNull("translated error is null", errorMessage);
55 Assert.assertEquals(21, errorMessage.getCode().intValue());
56 Assert.assertEquals(eType, errorMessage.getType());
57 Method getXid = errorMessage.getClass().getMethod("getTransactionId", new Class[0]);
58 getXid.setAccessible(true);
59 TransactionId xid = (TransactionId) getXid.invoke(errorMessage, new Object[0]);
60 Assert.assertEquals(42L, xid.getValue().longValue());
61 Assert.assertNotNull("data is null", errorMessage.getData());
66 * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.translator.ErrorTranslator#decodeErrorType(int)}.
69 public void testDecodeErrorType() {
70 for (ErrorType eType : ErrorType.values()) {
71 ErrorType result = errorTranslator.decodeErrorType(eType.getIntValue());
72 Assert.assertEquals(eType, result);