Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / client / aai / AAIClientResponseExceptionMapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.client.aai;
22
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;
33
34 public class AAIClientResponseExceptionMapperTest {
35
36     AAIClientResponseExceptionMapper mapper;
37     String errorMsg;
38
39     @Before
40     public void before() {
41         mapper = new AAIClientResponseExceptionMapper();
42         errorMsg = "Error calling A&AI. Request-Id=" + mapper.getRequestId() + " ";
43     }
44
45     @Test
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"));
50
51         RequestError requestError = new RequestError();
52         requestError.setServiceException(svcException);
53
54         AAIError error = new AAIError();
55         error.setRequestError(requestError);
56
57         ObjectMapper objMapper = new ObjectMapper();
58         String strRequestError = objMapper.writeValueAsString(error);
59
60         assertEquals(errorMsg + "test error message - service exception error test",
61                 mapper.extractMessage(strRequestError).get());
62     }
63
64     @Test
65     public void testExtractMessageWithoutEntity() {
66         assertEquals(errorMsg, mapper.extractMessage("").get());
67     }
68 }