Replaced all tabs with spaces in java and pom.xml
[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.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;
31 import java.net.URI;
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;
44
45 @RunWith(MockitoJUnitRunner.class)
46 public class AAIRestClientTest {
47
48     @Mock
49     private AAIProperties props;
50
51     private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
52
53     @Rule
54     public ExpectedException thrown = ExpectedException.none();
55
56     @Test
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"));
61         client.patch(
62                 "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}");
63     }
64
65     @Test
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());
73         spy.patch(payload);
74         verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object) payload));
75     }
76 }