Remove Multiplicity feature
[aai/gizmo.git] / src / test / java / org / onap / crud / util / CrudServiceUtilTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.crud.util;
22
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.onap.crud.service.VertexPayload;
26 import org.onap.crud.service.util.TestHeaders;
27 import com.google.gson.JsonElement;
28
29 public class CrudServiceUtilTest {
30
31     private final String putVertexPayload = "{" + "\"id\": \"test-uuid\"," + "\"type\": \"pserver\","
32             + "\"properties\": {" + "fqdn: myhost.onap.com," + "hostname: myhost } }";
33
34     @Test
35     public void testMergeHeaderInFoToPayload() throws Exception {
36         TestHeaders headers = new TestHeaders();
37         // X-FromAppId is used to set the source of truth
38         VertexPayload payload = VertexPayload.fromJson(putVertexPayload);
39
40         JsonElement properties = CrudServiceUtil.mergeHeaderInFoToPayload(payload.getProperties(), headers, false);
41         Assert.assertEquals("myhost.onap.com", properties.getAsJsonObject().get("fqdn").getAsString());
42         Assert.assertEquals("myhost", properties.getAsJsonObject().get("hostname").getAsString());
43         Assert.assertEquals("source-of-truth",
44                 properties.getAsJsonObject().get("last-mod-source-of-truth").getAsString());
45
46         properties = CrudServiceUtil.mergeHeaderInFoToPayload(payload.getProperties(), headers, true);
47         Assert.assertEquals("myhost.onap.com", properties.getAsJsonObject().get("fqdn").getAsString());
48         Assert.assertEquals("myhost", properties.getAsJsonObject().get("hostname").getAsString());
49         Assert.assertEquals("source-of-truth",
50                 properties.getAsJsonObject().get("last-mod-source-of-truth").getAsString());
51         Assert.assertEquals("source-of-truth", properties.getAsJsonObject().get("source-of-truth").getAsString());
52     }
53
54 }