2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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.hamcrest.CoreMatchers.containsString;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.spy;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
32 import java.net.URISyntaxException;
33 import javax.ws.rs.core.Response;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 import org.mockito.junit.MockitoJUnitRunner;
40 import org.onap.so.client.RestClientSSL;
41 import org.onap.so.client.graphinventory.GraphInventoryPatchConverter;
42 import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException;
43 import com.fasterxml.jackson.databind.ObjectMapper;
45 @RunWith(MockitoJUnitRunner.class)
46 public class AAIRestClientTest {
49 private AAIProperties props;
51 private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
54 public ExpectedException thrown = ExpectedException.none();
57 public void failPatchOnComplexObject() throws URISyntaxException {
58 AAIRestClient client = new AAIRestClient(props, new URI(""));
59 this.thrown.expect(GraphInventoryPatchDepthExceededException.class);
60 this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action"));
62 "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}");
66 public void verifyPatchValidation() throws URISyntaxException {
67 AAIRestClient client = new AAIRestClient(props, new URI(""));
68 AAIRestClient spy = spy(client);
69 GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class);
70 doReturn(patchValidatorMock).when(spy).getPatchConverter();
71 String payload = "{}";
72 doReturn(Response.ok().build()).when(spy).method(eq("PATCH"), any());
74 verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object) payload));