Merge "Get rid of legacy ref_ prefixes in configuration"
[controller.git] / opendaylight / config / config-util / src / test / java / org / opendaylight / controller / config / util / jolokia / ListableJolokiaClientTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
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.controller.config.util.jolokia;
9
10 import static org.hamcrest.core.Is.is;
11 import static org.junit.Assert.assertThat;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.json.simple.JSONObject;
17 import org.json.simple.JSONValue;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.controller.config.api.ValidationException;
21 import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace;
22
23 public class ListableJolokiaClientTest {
24
25     private Map<String, Map<String, ExceptionMessageWithStackTrace>> failedValidations;
26
27     private ValidationException val;
28
29     private final static String ex = "{\"message\":null,"
30             + "\"failedValidations\":"
31             + "{\"ifc2\":{\"impl1\":{\"message\":\"abc\",\"trace\":\"vvv\"},"
32             + "\"impl2\":{\"message\":\"abc2\",\"trace\":\"vvv2\"}},"
33             + "\"ifc1\":"
34             + "{\"impl1\":{\"message\":\"abc\",\"trace\":\"vvv\"},"
35             + "\"impl2\":{\"message\":\"abc2\",\"trace\":\"vvv2\"}}},"
36             + "\"localizedMessage\":null," + "\"cause\":null}";
37
38     @Before
39     public void setUp() {
40         failedValidations = new HashMap<String, Map<String, ExceptionMessageWithStackTrace>>();
41         Map<String, ExceptionMessageWithStackTrace> map1 = new HashMap<String, ValidationException.ExceptionMessageWithStackTrace>();
42         map1.put("impl1", new ExceptionMessageWithStackTrace("abc", "vvv"));
43         map1.put("impl2", new ExceptionMessageWithStackTrace("abc2", "vvv2"));
44         failedValidations.put("ifc1", map1);
45         failedValidations.put("ifc2", map1);
46         val = new ValidationException(failedValidations);
47     }
48
49     @Test
50     public void testParsing() {
51         JSONObject e = (JSONObject) JSONValue.parse(ex);
52         ValidationException val2 = ListableJolokiaClient
53                 .createValidationExceptionFromJSONObject(e);
54         assertThat(val2.getMessage(), is(val.getMessage()));
55         assertThat(val2.getFailedValidations(), is(val.getFailedValidations()));
56     }
57
58 }