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 static org.mockito.Mockito.doReturn;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.so.client.aai.entities.AAIError;
35 import org.onap.so.client.aai.entities.RequestError;
36 import org.onap.so.client.aai.entities.ServiceException;
38 public class AAIErrorFormatterTest {
40 @Mock private AAIError errorObj;
44 MockitoAnnotations.initMocks(this);
47 public void testFillInTemplateWithReplace() {
48 String error = "Error %1 on %2";
49 List<String> list = Arrays.asList("PUT", "hello %1");
50 AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
51 String result = formatter.fillInTemplate(error, list);
52 assertEquals("equal", "Error PUT on hello PUT", result);
57 public void testFillInTemplateWithoutReplace() {
58 String error = "Error";
59 List<String> list = new ArrayList<>();
60 AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
61 String result = formatter.fillInTemplate(error, list);
62 assertEquals("equal", "Error", result);
66 public void testGetMessage() {
67 ServiceException svcException = new ServiceException();
68 svcException.setText("test %1 message - %2");
69 svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
71 RequestError requestError = new RequestError();
72 requestError.setServiceException(svcException);
74 doReturn(requestError).when(errorObj).getRequestError();
76 AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
77 String result = formatter.getMessage();
78 assertEquals("equal", "test error message - service exception error test", result);
82 public void testGetMessageNoParsable() {
83 errorObj.setRequestError(null);
84 AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
85 String result = formatter.getMessage();
86 assertEquals("equal", "no parsable error message found", result);