2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.client.aai;
23 import static org.junit.Assert.assertEquals;
24 import java.util.Arrays;
25 import java.util.List;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.so.client.aai.entities.AAIError;
29 import org.onap.so.client.aai.entities.RequestError;
30 import org.onap.so.client.aai.entities.ServiceException;
31 import com.fasterxml.jackson.core.JsonProcessingException;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 public class AAIClientResponseExceptionMapperTest {
36 AAIClientResponseExceptionMapper mapper;
40 public void before() {
41 mapper = new AAIClientResponseExceptionMapper();
42 errorMsg = "Error calling A&AI. Request-Id=" + mapper.getRequestId() + " ";
46 public void testExtractMessageWithEntity() throws JsonProcessingException {
47 ServiceException svcException = new ServiceException();
48 svcException.setText("test %1 message - %2");
49 svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
51 RequestError requestError = new RequestError();
52 requestError.setServiceException(svcException);
54 AAIError error = new AAIError();
55 error.setRequestError(requestError);
57 ObjectMapper objMapper = new ObjectMapper();
58 String strRequestError = objMapper.writeValueAsString(error);
60 assertEquals(errorMsg + "test error message - service exception error test",
61 mapper.extractMessage(strRequestError).get());
65 public void testExtractMessageWithoutEntity() {
66 assertEquals(errorMsg, mapper.extractMessage("").get());