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 static org.junit.Assert.assertNotNull;
12 import java.lang.reflect.Method;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.MockitoAnnotations;
18 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
19 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.errors.rev131116.ErrorType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
31 public class ErrorTranslatorTest {
33 private final ErrorTranslator errorTranslator = new ErrorTranslator();
34 private final ErrorMessageBuilder builder = new ErrorMessageBuilder();;
35 private static Logger LOG = LoggerFactory
36 .getLogger(ErrorTranslatorTest.class);
38 @MockitoAnnotations.Mock
39 SwitchConnectionDistinguisher cookie;
40 @MockitoAnnotations.Mock
50 builder.setData(new byte[]{42});
56 public void testTranslate() {
58 List<DataObject> data = errorTranslator.translate(cookie, sc, builder.build());
63 * 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)}.
68 public void testGetGranularNodeErrors() throws Exception {
69 for (ErrorType eType : ErrorType.values()) {
70 builder.setType(eType.getIntValue());
71 ErrorMessage errorMessage = errorTranslator.getGranularNodeErrors(builder.build(), eType);
72 LOG.debug("translating errorMessage of type {}", eType);
73 assertNotNull("translated error is null", errorMessage);
74 Assert.assertEquals(21, errorMessage.getCode().intValue());
75 Assert.assertEquals(eType, errorMessage.getType());
76 Method getXid = errorMessage.getClass().getMethod("getTransactionId", new Class[0]);
77 getXid.setAccessible(true);
78 TransactionId xid = (TransactionId) getXid.invoke(errorMessage, new Object[0]);
79 Assert.assertEquals(42L, xid.getValue().longValue());
80 assertNotNull("data is null", errorMessage.getData());
85 * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.translator.ErrorTranslator#decodeErrorType(int)}.
88 public void testDecodeErrorType() {
89 for (ErrorType eType : ErrorType.values()) {
90 ErrorType result = errorTranslator.decodeErrorType(eType.getIntValue());
91 Assert.assertEquals(eType, result);