Springboot 2.0 upgrade
[so.git] / common / src / test / java / org / onap / so / client / aai / AAIRestClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.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;
31
32 import java.net.URI;
33 import java.net.URISyntaxException;
34
35 import javax.ws.rs.core.Response;
36
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;
45
46 import com.fasterxml.jackson.databind.ObjectMapper;
47
48 @RunWith(MockitoJUnitRunner.class)
49 public class AAIRestClientTest {
50
51         @Mock
52         private AAIProperties props;
53         
54         private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
55         
56         @Rule
57         public ExpectedException thrown = ExpectedException.none();
58         
59         @Test
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\" }}");
65         }
66         
67         @Test
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());
75                 spy.patch(payload);
76                 verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object)payload));
77         }
78 }