AT&T 1712 and 1802 release code
[so.git] / common / src / test / java / org / openecomp / mso / client / sdno / SDNOHealthCheckClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.mso.client.sdno;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.Optional;
29
30 import org.junit.Test;
31 import org.openecomp.mso.client.sdno.beans.SDNO;
32
33 import com.fasterxml.jackson.databind.ObjectMapper;
34
35 public class SDNOHealthCheckClientTest {
36
37         
38         
39         private final String fileLocation = "src/test/resources/org/openecomp/mso/client/sdno/health-check/";
40         private static final String userId = "test-user";
41         private static final Optional<String> clliCode = Optional.of("test-clli");
42         private static final String requestId = "test-request-id";
43         private static final String configurationId = "test-configuration-id";
44         private static final String interfaceId = "test-interface-id";
45         
46         @Test
47         public void verfyLPortMirrorPreCheckRequest() throws IOException{
48                 String content = this.getJson("custom-lport-mirror-pre-check-request.json");
49                 ObjectMapper mapper = new ObjectMapper();
50                 SDNO expected = mapper.readValue(content, SDNO.class);
51                 SDNOHealthCheckClient client = new SDNOHealthCheckClient();
52                 String actual = client.buildLPortMirrorCheckPreRequest(userId, requestId, clliCode, configurationId, interfaceId);
53                 assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
54         }
55         
56         @Test
57         public void verfyLPortMirrorPostCheckRequest() throws IOException{
58                 String content = this.getJson("custom-lport-mirror-post-check-request.json");
59                 ObjectMapper mapper = new ObjectMapper();
60                 SDNO expected = mapper.readValue(content, SDNO.class);
61                 SDNOHealthCheckClient client = new SDNOHealthCheckClient();
62                 String actual = client.buildLPortMirrorCheckPostRequest(userId, requestId, clliCode, configurationId, interfaceId);
63                 assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
64         }
65         
66         
67         @Test
68         public void verifyPortMirrorPostCheckRequest() throws IOException{
69                 String content = this.getJson("custom-port-mirror-post-check-request.json");
70                 ObjectMapper mapper = new ObjectMapper();
71                 SDNO expected = mapper.readValue(content, SDNO.class);
72                 SDNOHealthCheckClient client = new SDNOHealthCheckClient();
73                 String actual = client.buildPortMirrorPostCheckRequest(userId, requestId, clliCode, configurationId);
74                 
75                 assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
76
77         }
78         @Test
79         public void verifyPortMirrorPreCheckRequest() throws IOException {
80                 String content = this.getJson("custom-port-mirror-pre-check-request.json");
81                 ObjectMapper mapper = new ObjectMapper();
82                 SDNO expected = mapper.readValue(content, SDNO.class);
83                 SDNOHealthCheckClient client = new SDNOHealthCheckClient();
84                 String actual = client.buildPortMirrorPreCheckRequest(userId, requestId, clliCode, configurationId);
85                 
86                 assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual);
87                 
88         }
89         
90         private String getJson(String filename) throws IOException {
91                 return new String(Files.readAllBytes(Paths.get(fileLocation + filename)));
92         }
93         
94 }