184beceef02b62ba29f67b1fda287aa7557f8196
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.v3po.translate.v3po.util;
18
19 import java.util.Random;
20 import org.junit.Assert;
21 import org.junit.Test;
22
23 public class VppApiInvocationExceptionTest {
24
25     @Test
26     public void testInstantiation() {
27         final String apiMethodName = "methodName";
28         final int ctxId = 1;
29         final int code = -1;
30         VppApiInvocationException e = new VppApiInvocationException(apiMethodName, ctxId, code);
31         Assert.assertEquals(apiMethodName, e.getMethodName());
32         Assert.assertEquals(ctxId, e.getCtxId());
33         Assert.assertEquals(code, e.getErrorCode());
34         Assert.assertTrue(e.getMessage().contains(apiMethodName));
35         Assert.assertTrue(e.getMessage().contains(String.valueOf(code)));
36         Assert.assertTrue(e.getMessage().contains(String.valueOf(ctxId)));
37     }
38
39     @Test(expected = IllegalArgumentException.class)
40     public void testInstantiationFailed() {
41         final int code = new Random().nextInt(Integer.MAX_VALUE);
42         VppApiInvocationException e = new VppApiInvocationException("apiMethodName", 1, code);
43     }
44 }