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.Matchers.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;
33 import java.net.URISyntaxException;
35 import javax.ws.rs.core.Response;
37 import org.junit.Rule;
38 import org.junit.Test;
39 import org.junit.rules.ExpectedException;
40 import org.junit.runner.RunWith;
41 import org.mockito.Mock;
42 import org.mockito.junit.MockitoJUnitRunner;
43 import org.onap.so.client.RestClientSSL;
44 import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException;
46 import com.fasterxml.jackson.databind.ObjectMapper;
48 @RunWith(MockitoJUnitRunner.class)
49 public class AAIRestClientTest {
52 private AAIProperties props;
54 private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
57 public ExpectedException thrown = ExpectedException.none();
60 public void failPatchOnComplexObject() throws URISyntaxException {
61 AAIRestClient client = new AAIRestClient(props, new URI(""));
62 this.thrown.expect(GraphInventoryPatchDepthExceededException.class);
63 this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action"));
64 client.patch("{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}");
68 public void verifyPatchValidation() throws URISyntaxException {
69 AAIRestClient client = new AAIRestClient(props, new URI(""));
70 AAIRestClient spy = spy(client);
71 AAIPatchConverter patchValidatorMock = mock(AAIPatchConverter.class);
72 doReturn(patchValidatorMock).when(spy).getPatchConverter();
73 String payload = "{}";
74 doReturn(Response.ok().build()).when(spy).method(eq("PATCH"), any());
76 verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object)payload));