Merge "Refactor, fix code formatting and add unittests"
[dcaegen2/platform.git] / mod2 / catalog-service / src / test / java / org / onap / dcaegen2 / platform / mod / objectmothers / DeploymentArtifactObjectMother.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  org.onap.dcae
4  *  ================================================================================
5  *  Copyright (c) 2020 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.dcaegen2.platform.mod.objectmothers;
22
23 import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact;
24 import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus;
25 import org.onap.dcaegen2.platform.mod.model.deploymentartifact.MsInstanceInfo;
26
27 import java.util.*;
28
29 import static org.onap.dcaegen2.platform.mod.objectmothers.MsInstanceObjectMother.USER;
30
31 public class DeploymentArtifactObjectMother {
32
33
34     public static final String BLUEPRINT_FILENAME = "hello-world-k8s-blueprint.yaml";
35     public static final String BLUEPRINT_CONTENT = "\\n#Basic java app to print out at&t buzzwords\\n#1.0" +
36             ".0\\n#\\n---\\" + "ntosca_definitions_version: cloudify_dsl_1_3\\nimports:\\n- http://www.getcloudify" +
37             ".org/spec/cloudify/4.4/types" + ".yaml\\n- http://dockercentral.it.att" +
38             ".com:8093/nexus/repository/rawcentral/com.att.dcae.controller/type_files/" + "k8splugin/1.7.4/node-type" +
39             ".yaml\\n- http://dockercentral.it.att.com:8093/nexus/repository/rawcentral/com.att.d" + "cae.controller" +
40             "/type_files/relationship/2006001.1.0/types.yaml\\n- http://dockercentral.it.att.com:8093/nexus/" +
41             "repository/rawcentral/com.att.dcae.controller/type_files/cloudifydmaapplugin/1.4.10/node-type.yaml\\n- " +
42             "http:/" + "/dockercentral.it.att.com:8093/nexus/repository/rawcentral/com.att.dcae" +
43             ".controller/type_files/dcaepolicyplugi" + "n/2.3.3/node-type.yaml\\n- http://dockercentral.it.att" +
44             ".com:8093/nexus/repository/rawcentral/com.att.dcae.cont" + "roller/type_files/pgaas/0.3.2/pgaas_types" +
45             ".yaml\\ninputs:\\n  ConsulTest1:\\n    type: string\\n    description" + ": test description\\n    " +
46             "default: 'TEST1'\\n  ConsulTest2:\\n    type: string\\n    description: test description\\n    default: " +
47             "'TEST2'\\n  aaf_cert_directory:\\n    type: string\\n    default: '/opt/app/aafcertman'\\n    " +
48             "description: directory location for the aaf-tls certs\\n  additionalsans:\\n    type: string\\n    " +
49             "default: ''\\n    description: additional sans (string)\\n  annotations:\\n    default: {}\\n  " +
50             "app_name:\\n    type: string\\n    default: 'dcae'\\n    description: This is used to generateForRelease different" +
51             " secret code for DCAE or D2A based\\n      on Tosca or Helm based BP\\n  dcae_service_location:\\n    " +
52             "type: string\\n    description: Docker host override for docker bps (string)\\n  " +
53             "dti_sidecar_cpu_limit:\\n    type: string\\n    default: '250m'\\n    description: cpu limit for " +
54             "deployment (string)\\n  dti_sidecar_cpu_request:\\n    type: string\\n    default: '250m'\\n    " +
55             "description: cpu requested for deployment (string)\\n  dti_sidecar_image:\\n    type: string\\n    " +
56             "default: 'dockercentral.it.att.com:5100/com.att.dcae.controller/dcae-controller-sidecar:19.11-001'\\n   " +
57             " description: dti side car image for dti (string)\\n  dti_sidecar_memory_limit:\\n    type: string\\n   " +
58             " default: '128Mi'\\n    description: memory limit for deployment (string)\\n  " +
59             "dti_sidecar_memory_request:\\n    type: string\\n    default: '128Mi'\\n    description: memory " +
60             "requested for deployment (string)\\n  dti_sidecar_port:\\n    type: string\\n    default: ''\\n    " +
61             "description: Port for the side car (string)\\n  hello-buzzword_cpu_limit:\\n    type: string\\n    " +
62             "default: '250m'\\n    description: cpu limit for deployment (string)\\n  hello-buzzword_cpu_request:\\n " +
63             "   type: string\\n    default: '250m'\\n    description: cpu requested for deployment (string)\\n  " +
64             "hello-buzzword_memory_limit:\\n    type: string\\n    default: '128Mi'\\n    description: memory limit " +
65             "for deployment (string)\\n  hello-buzzword_memory_request:\\n    type: string\\n    default: '128Mi'\\n " +
66             "   description: memory requested for deployment (string)\\n  idns_fqdn:\\n    type: string\\n    " +
67             "default: ''\\n    description: The idns you will be using for your deployment (string)\\n  image:\\n    " +
68             "type: string\\n    default: 'test-image-uri'\\n    description: The docker image for your microservice " +
69             "(string)\\n  namespace:\\n    type: string\\n  replicas:\\n    type: integer\\n    default: 1\\n    " +
70             "description: The number of replicas for your kubernetes deployment (integer)\\n  " +
71             "service_component_name_override:\\n    type: string\\n    default: 'hello-buzzword'\\n    description: " +
72             "Unique identifier for your deployment (string)\\n  use_aaf_tls:\\n    type: boolean\\n    default: " +
73             "false\\n    description: To use or not use the aaf section (boolean)\\n  use_dti_info:\\n    type: " +
74             "boolean\\n    default: true\\n    description: Flag to use or not use dti (boolean)\\nnode_templates:\\n" +
75             "  hello-buzzword_hello-buzzword:\\n    type: dcae.nodes.ContainerizedServiceComponent\\n    " +
76             "properties:\\n      application_config:\\n        services_calls: []\\n        streams_publishes: {}\\n " +
77             "       streams_subscribes: {}\\n        ConsulTest1:\\n          get_input: ConsulTest1\\n        " +
78             "ConsulTest2:\\n          get_input: ConsulTest2\\n      docker_config:\\n        healthcheck:\\n        " +
79             "  interval: 180s\\n          timeout: 30s\\n          script: \\\"true\\\"\\n          type: docker\\n  " +
80             "      livehealthcheck:\\n          interval: 180s\\n          timeout: 30s\\n          script: " +
81             "\\\"true\\\"\\n          type: docker\\n        reconfigs:\\n          dti: dti/test-script\\n          " +
82             "app_reconfig: /app-reconfig/test-script\\n        env:\\n        - name: DTI_DATA_DIR\\n          value:" +
83             " /dtidata\\n        - name: KUBE_CLUSTER_FQDN\\n          value: {get_secret: " +
84             "kc-kubernetes_master_ip}\\n      image:\\n        get_input: image\\n      location_id:\\n        " +
85             "get_input: dcae_service_location\\n      service_component_type: hello-buzzword\\n      replicas:\\n    " +
86             "    get_input: replicas\\n      service_component_name_override:\\n        concat:\\n        - " +
87             "get_secret: location_id\\n        - '-'\\n        - get_input: service_component_name_override\\n      " +
88             "k8s_controller_type: statefulset\\n      configuration:\\n        file_content:\\n          apiVersion: " +
89             "v1\\n          clusters:\\n          - name: default-cluster\\n            cluster:\\n              " +
90             "server:\\n                concat:\\n                - https://\\n                - get_secret: " +
91             "kc-kubernetes_master_ip\\n                - ':'\\n                - get_secret: " +
92             "kc-kubernetes_master_port\\n              insecure-skip-tls-verify: true\\n          contexts:\\n       " +
93             "   - name: default-context\\n            context:\\n              cluster: default-cluster\\n           " +
94             "   namespace:\\n                get_input: namespace\\n              user: default-user\\n          " +
95             "kind: Config\\n          preferences: {}\\n          users:\\n          - name: default-user\\n         " +
96             "   user:\\n              token:\\n                get_secret:\\n                  concat:\\n            " +
97             "      - get_input: app_name\\n                  - -mechid-k8s-token\\n          current-context: " +
98             "default-context\\n      resource_config:\\n        limits:\\n          cpu:\\n            get_input: " +
99             "hello-buzzword_cpu_limit\\n          memory:\\n            get_input: hello-buzzword_memory_limit\\n    " +
100             "    requests:\\n          cpu:\\n            get_input: hello-buzzword_cpu_request\\n          " +
101             "memory:\\n            get_input: hello-buzzword_memory_request\\n      aaf_tls_info:\\n        " +
102             "use_aaf_tls:\\n          get_input: use_aaf_tls\\n        cert_directory:\\n          get_input: " +
103             "aaf_cert_directory\\n        image: dockercentral.it.att.com:5100/com.att.ecompcntr" +
104             ".public/ecompc-aaf-init-container:1.0.2\\n        env:\\n        - name: NAMESPACE\\n          " +
105             "valueFrom:\\n            fieldRef:\\n              fieldPath: metadata.namespace\\n        - name: " +
106             "deployer_id\\n          valueFrom:\\n            secretKeyRef:\\n              name:\\n                " +
107             "concat:\\n                - get_input: namespace\\n                - -cert-secret\\n              key: " +
108             "deployerid\\n        - name: deployer_pass\\n          valueFrom:\\n            secretKeyRef:\\n        " +
109             "      name:\\n                concat:\\n                - get_input: namespace\\n                - " +
110             "-cert-secret\\n              key: deployerpass\\n        - name: cert_id\\n          valueFrom:\\n      " +
111             "      secretKeyRef:\\n              name:\\n                concat:\\n                - get_input: " +
112             "namespace\\n                - -cert-secret\\n              key: certid\\n        - name: cm_url\\n      " +
113             "    valueFrom:\\n            secretKeyRef:\\n              name:\\n                concat:\\n           " +
114             "     - get_input: namespace\\n                - -cert-secret\\n              key: cmurl\\n        - " +
115             "name: idns_fqdn\\n          value:\\n            get_input: idns_fqdn\\n        - name: " +
116             "app_service_names\\n          value:\\n            concat:\\n            - get_secret: location_id\\n   " +
117             "         - '-'\\n            - get_input: service_component_name_override\\n        args:\\n        - " +
118             "place\\n        - cmtemplate\\n        - -idnsfqdn=$(idns_fqdn)\\n        - -cmurl=$(cm_url)\\n        -" +
119             " -deployerid=$(deployer_id)\\n        - -deployerpass=$(deployer_pass)\\n        - -certid=$(cert_id)\\n" +
120             "        - -namespace=$(NAMESPACE)\\n        - -services=$(app_service_names)\\n        - concat:\\n     " +
121             "     - -additionalsans=\\n          - get_input: additionalsans\\n        use_aaf_tls_renewal: true\\n  " +
122             "      renewal_args:\\n        - renew\\n        - -idnsfqdn=$(idns_fqdn)\\n        - -cmurl=$(cm_url)\\n" +
123             "        resource_config:\\n          limits:\\n            cpu: 250m\\n            memory: 256Mi\\n     " +
124             "     requests:\\n            cpu: 100m\\n            memory: 256Mi\\n      annotations:\\n        " +
125             "get_input: annotations\\n      dti_info:\\n        image:\\n          get_input: dti_sidecar_image\\n   " +
126             "     use_dti_info:\\n          get_input: use_dti_info\\n        healthcheck:\\n          interval: " +
127             "90s\\n          timeout: 60s\\n          type: https\\n          endpoint: /healthcheck\\n        " +
128             "livehealthcheck:\\n          interval: 90s\\n          timeout: 60s\\n          type: https\\n          " +
129             "endpoint: /healthcheck\\n        dtidata_directory: /dtidata\\n        resource_config:\\n          " +
130             "limits:\\n            cpu:\\n              get_input: dti_sidecar_cpu_limit\\n            memory:\\n    " +
131             "          get_input: dti_sidecar_memory_limit\\n          requests:\\n            cpu:\\n              " +
132             "get_input: dti_sidecar_cpu_request\\n            memory:\\n              get_input: " +
133             "dti_sidecar_memory_request\\n        env:\\n        - name: DTI_DATA_DIR\\n          value: /dtidata\\n " +
134             "       - name: KUBE_CLUSTER_FQDN\\n          value: {get_secret: kc-kubernetes_master_ip}\\n        - " +
135             "name: KUBE_PROXY_FQDN\\n          value: {get_secret: kube_proxy_fqdn}\\n        - name: POD_SVC_PORT\\n" +
136             "          value: '9999'\\n        ports:\\n        - concat:\\n          - '9999:'\\n          - " +
137             "get_input: dti_sidecar_port\\n    relationships: []";
138
139     public static final String SPEC_FILE_AS_STRING = String.format("{\r\n\t\"self\": {\r\n\t\t\"component_type\": " +
140             "\"docker\",\r\n\t\t\"description\": \"Basic java app to print out at&t buzzwords\",\r\n\t\t\"name\": " +
141             "\"hello-buzzword\",\r\n\t\t\"version\": \"1.0.0\"\r\n\t},\r\n\t\r\n\t\"services\": {\r\n\t\t\"calls\": " +
142             "[],\r\n\t\t\"provides\": []\r\n\t},\r\n\t\"streams\": {\r\n\t\t\"publishes\": [],\r\n\t\t\"subscribes\":" +
143             " []\r\n\t},\r\n\t\"parameters\": [\r\n\t\t{\r\n            \"name\": \"ConsulTest1\",\r\n            " +
144             "\"value\": \"TEST1\",\r\n            \"description\": \"Test consul output\"," +
145             "\r\n\t\t\t\"sourced_at_deployment\": true,\r\n\t\t\t\"designer_editable\": true," +
146             "\r\n\t\t\t\"policy_editable\": false,\r\n\t\t\t\"type\": \"string\" ,\r\n\t\t\t\"description\": \"test " +
147             "description\"        \r\n        },\r\n        {\r\n            \"name\": \"ConsulTest2\",\r\n          " +
148             "  \"value\": \"TEST2\",\r\n\t\t\t\"sourced_at_deployment\": true,\r\n\t\t\t\"designer_editable\": true," +
149             "\r\n\t\t\t\"policy_editable\": false,\r\n\t\t\t\"type\": \"string\",\r\n\t\t\t\"description\": \"test " +
150             "description\"    \r\n        }\r\n       \r\n\t],\r\n\r\n\t\"auxilary\": {\r\n\t\t\"healthcheck\": " +
151             "{\r\n\t\t\t\"type\": \"docker\",\r\n        \t\"script\": \"true\",\r\n        \t\"timeout\": \"30s\"," +
152             "\r\n        \t\"interval\": \"180s\"\r\n\t\t},\r\n\t\t\"livehealthcheck\": {\r\n\t\t\t\"type\": " +
153             "\"docker\",\r\n        \t\"script\": \"true\",\r\n        \t\"timeout\": \"30s\",\r\n        " +
154             "\t\"interval\": \"180s\"\r\n\t\t},\r\n\t\t\"reconfigs\": {\r\n\t\t\t\"app_reconfig\" : " +
155             "\"/app-reconfig/test-script\",\r\n\t\t\t\"dti\" : \"dti/test-script\"}}," +
156             "\r\n\t\"artifacts\": [{\r\n\t\t\"type\": \"docker image\",\r\n\t\t\"uri\": " +
157             "\"test-image-uri\"\r\n\t}]\r\n}");
158
159     public static DeploymentArtifact createDeploymentArtifactDAO(DeploymentArtifactStatus status) {
160         DeploymentArtifact artifact = new DeploymentArtifact();
161         artifact.setId("id-123");
162         artifact.setFileName("helloworld-k8s-blueprint.yaml");
163         artifact.setContent("some " + "yaml content");
164         artifact.setStatus(status);
165         artifact.setVersion(1);
166         artifact.setMetadata(createMetaData());
167         artifact.setMsInstanceInfo(createMsInstanceInfo());
168         artifact.setSpecificationInfo(createSpecificationInfo());
169
170        return artifact;
171     }
172
173     private static Map<String, Object> createSpecificationInfo() {
174         Map<String, Object> msInstanceInfo = new HashMap<>();
175         msInstanceInfo.put("id", "id-123");
176         return msInstanceInfo;
177     }
178
179     private static MsInstanceInfo createMsInstanceInfo() {
180         MsInstanceInfo msInstanceInfo = new MsInstanceInfo();
181         msInstanceInfo.setId(MsInstanceObjectMother.MS_INSTANCE_ID);
182         msInstanceInfo.setName(MsInstanceObjectMother.MS_INSTANCE_NAME);
183         msInstanceInfo.setRelease(MsInstanceObjectMother.RELEASE);
184         return msInstanceInfo;
185     }
186
187     private static Map<String, Object> createMetaData() {
188         Map<String, Object> metadata = new HashMap<>();
189         metadata.put("createdBy", USER);
190         metadata.put("createdOn", "someDate");
191         metadata.put("notes", "This is a test Deployment Artifact");
192         metadata.put("labels", Arrays.asList("hello", "world"));
193         return metadata;
194     }
195
196     public static Map<String, Object> createBlueprintResponse() {
197         Map<String, Object> blueprintMap = new HashMap<>();
198         blueprintMap.put("fileName", BLUEPRINT_FILENAME);
199         blueprintMap.put("content", BLUEPRINT_CONTENT); return blueprintMap;
200     }
201
202     public static Map<String, Object> createToolboxBlueprintResponse() {
203         Map<String, Object> blueprintResponseMap = new HashMap<>();
204         blueprintResponseMap.put("blueprint_name", "hello-buzzword-eom-k8s");
205         blueprintResponseMap.put("blueprint_content", BLUEPRINT_CONTENT);
206         blueprintResponseMap.put("componentSpecValidated", true);
207         return blueprintResponseMap;
208     }
209
210     public static List<DeploymentArtifact> createMockDeploymentArtifactsWithDifferentStatuses
211             (boolean devCompleteRequire) {
212         DeploymentArtifact d1;
213         if(devCompleteRequire){
214             d1  = createDeploymentArtifactDAO(DeploymentArtifactStatus.DEV_COMPLETE);
215         }else {
216             d1  = createDeploymentArtifactDAO(DeploymentArtifactStatus.NOT_NEEDED);
217         }
218         DeploymentArtifact d2 = createDeploymentArtifactDAO(DeploymentArtifactStatus.IN_DEV);
219         return new ArrayList<>(Arrays.asList(d1, d2));
220     }
221
222 }