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.controller.config.util.jolokia;
10 import static org.hamcrest.core.Is.is;
11 import static org.junit.Assert.assertThat;
13 import java.util.HashMap;
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;
23 public class ListableJolokiaClientTest {
25 private Map<String, Map<String, ExceptionMessageWithStackTrace>> failedValidations;
27 private ValidationException val;
29 private final static String ex = "{\"message\":null,"
30 + "\"failedValidations\":"
31 + "{\"ifc2\":{\"impl1\":{\"message\":\"abc\",\"trace\":\"vvv\"},"
32 + "\"impl2\":{\"message\":\"abc2\",\"trace\":\"vvv2\"}},"
34 + "{\"impl1\":{\"message\":\"abc\",\"trace\":\"vvv\"},"
35 + "\"impl2\":{\"message\":\"abc2\",\"trace\":\"vvv2\"}}},"
36 + "\"localizedMessage\":null," + "\"cause\":null}";
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);
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()));