1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 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 ******************************************************************************/
22 package org.onap.aaf.cadi.aaf.client;
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Mockito.when;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Answers;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.aaf.cadi.CadiException;
33 import org.onap.aaf.cadi.aaf.client.ErrMessage;
34 import org.onap.aaf.cadi.client.Future;
35 import org.onap.aaf.misc.env.APIException;
36 import org.onap.aaf.misc.env.Data.TYPE;
37 import org.onap.aaf.misc.rosetta.env.RosettaDF;
38 import org.onap.aaf.misc.rosetta.env.RosettaEnv;
40 import aaf.v2_0.Error;
42 public class JU_ErrMessageTest {
45 private RosettaEnv env;
47 @Mock(answer=Answers.RETURNS_DEEP_STUBS)
48 private RosettaDF<Object> errDF;
50 private ErrMessage errMessage;
52 private String attErrJson = "key:value";
56 private Future<?> future;
59 public void setUp() throws Exception {
60 MockitoAnnotations.initMocks(this);
62 when(env.newDataFactory(Error.class)).thenReturn(errDF);
64 future = new Future<Error>() {
67 public boolean get(int timeout) throws CadiException {
77 public String body() {
82 public String header(String tag) {
88 error.setMessageId("Error Message Id");
89 error.setText("Error Text");
90 errMessage = new ErrMessage(env);
96 public void testPrintErrMessage() throws APIException {
97 when(errDF.newData().in(TYPE.JSON).load(attErrJson).asObject()).thenReturn(error);
99 errMessage.printErr(System.out, attErrJson);
103 public void testToMsgJsonErrAttribute() throws APIException {
104 when(errDF.newData().in(TYPE.JSON).load(attErrJson).asObject()).thenReturn(error);
106 StringBuilder sb = new StringBuilder();
107 errMessage.toMsg(sb,attErrJson);
109 assertEquals(sb.toString(),"Error Message Id Error Text");
113 public void testToMsgFuture() {
114 StringBuilder sb = errMessage.toMsg(future);
116 assertEquals(sb.toString(), "0: Body");
121 public void testToMsgFutureWithoutException() throws APIException {
122 when(errDF.newData().in(TYPE.JSON).load(future.body()).asObject()).thenReturn(error);
124 StringBuilder sb = errMessage.toMsg(future);
126 assertEquals(sb.toString(), "Error Message Id Error Text");