f9fa679790417a921728d3e42d6ad09bfa3b9760
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.sdnc.lcm.beans.payload;
22
23 import java.util.Collections;
24 import org.junit.Test;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.fail;
27
28 public class DownloadNESwPayloadTest extends LcmBasePayloadTest {
29     private static String expectedSwToBeDownloadedElement = "{" + "\"swLocation\":\"http://192.168.1.20/test.zip\","
30             + "\"swFileSize\":123456," + "\"swFileCompression\":\"ZIP\"," + "\"swFileFormat\":\"binary\"" + "}";
31
32     private static String expectedDownloadNESwPayload =
33             "{" + "\"ipaddress-v4-oam\":\"192.168.1.10\"," + "\"playbook-name\":\"test_playbook\","
34                     + "\"swToBeDownloaded\":[" + expectedSwToBeDownloadedElement + "]" + "}";
35
36     public SwToBeDownloadedElement buildSwToBeDownloadedElement() {
37         SwToBeDownloadedElement swToBeDownloadedElement = new SwToBeDownloadedElement();
38
39         swToBeDownloadedElement.setSwLocation("http://192.168.1.20/test.zip");
40         swToBeDownloadedElement.setSwFileSize(123456);
41         swToBeDownloadedElement.setSwFileCompression("ZIP");
42         swToBeDownloadedElement.setSwFileFormat("binary");
43
44         return swToBeDownloadedElement;
45     }
46
47     public DownloadNESwPayload buildDownloadNESwPayload() {
48         DownloadNESwPayload downloadNESwPayload = new DownloadNESwPayload();
49
50         downloadNESwPayload.setIpaddressV4Oam(ipaddressV4Oam);
51         downloadNESwPayload.setPlaybookName(playbookName);
52
53         SwToBeDownloadedElement swToBeDownloadedElement = buildSwToBeDownloadedElement();
54         downloadNESwPayload.setSwToBeDownloaded(Collections.singletonList(swToBeDownloadedElement));
55
56         return downloadNESwPayload;
57     }
58
59     @Test
60     public final void testSwToBeDownloadedElement() {
61         SwToBeDownloadedElement swToBeDownloadedElement = buildSwToBeDownloadedElement();
62
63         try {
64             String swToBeDownloadedElementString = convertToSting(swToBeDownloadedElement);
65             assertEquals(expectedSwToBeDownloadedElement, swToBeDownloadedElementString);
66         } catch (Exception e) {
67             fail("Convert SwToBeDownloadedElement to String error: " + e.toString());
68         }
69     }
70
71     @Test
72     public final void testDownloadNESwPayload() {
73         DownloadNESwPayload downloadNESwPayload = buildDownloadNESwPayload();
74
75         try {
76             String downloadNESwPayloadString = convertToSting(downloadNESwPayload);
77             assertEquals(expectedDownloadNESwPayload, downloadNESwPayloadString);
78         } catch (Exception e) {
79             fail("Convert DownloadNESwPayload to String error: " + e.toString());
80         }
81     }
82 }