Merge automation from ECOMP's repository
[vid.git] / vid-automation / src / main / java / org / onap / simulator / presetGenerator / presets / mso / PresetMSOBaseCreateInstancePost.java
1 package org.onap.simulator.presetGenerator.presets.mso;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset;
5 import org.springframework.http.HttpMethod;
6
7 public abstract class PresetMSOBaseCreateInstancePost extends BaseMSOPreset {
8
9     private final String requestId;
10     protected String responseInstanceId;
11     public static final String DEFAULT_REQUEST_ID = "c0011670-0e1a-4b74-945d-8bf5aede1d9c";
12     protected String msoTestApi;
13     protected boolean withTestApi;
14
15     public PresetMSOBaseCreateInstancePost() {
16         this(null);
17     }
18
19     public PresetMSOBaseCreateInstancePost(String requestId) {
20         this.requestId = requestId != null ? requestId : DEFAULT_REQUEST_ID;
21         this.responseInstanceId = DEFAULT_INSTANCE_ID;
22     }
23
24     public PresetMSOBaseCreateInstancePost(String requestId, String responseInstanceId) {
25         this.requestId = requestId != null ? requestId : DEFAULT_REQUEST_ID;
26         this.responseInstanceId = responseInstanceId;
27     }
28
29     public PresetMSOBaseCreateInstancePost(String requestId, String responseInstanceId, String msoTestApi) {
30         this(requestId, responseInstanceId, msoTestApi, true);
31     }
32
33     public PresetMSOBaseCreateInstancePost(String requestId, String responseInstanceId, String msoTestApi, boolean withTestApi) {
34        this(requestId, responseInstanceId);
35        this.msoTestApi = msoTestApi;
36        this.withTestApi= withTestApi;
37     }
38
39     public String addTestApi() {
40         if(this.withTestApi) {
41             return "\"testApi\": \"" + msoTestApi + "\",";
42         }
43         return "";
44     }
45
46     @Override
47     public HttpMethod getReqMethod() {
48         return HttpMethod.POST;
49     }
50
51     @Override
52     public int getResponseCode() {
53         return 202;
54     }
55
56     public String getRequestId() {
57         return requestId;
58     }
59
60     @Override
61     public Object getResponseBody() {
62         return "{\"requestReferences\":{\"instanceId\":\"" + responseInstanceId + "\",\"requestId\":\"" + requestId + "\"}}";
63     }
64
65     protected String formatSuffix(int suffix) {
66         return (suffix==0) ? StringUtils.EMPTY : "_" + String.format("%03d", suffix);
67     }
68 }