summaryrefslogtreecommitdiffstats
path: root/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/MsInstanceObjectMother.java
blob: 976e31c18dea1ddd87c66475cc9ba5fe40ef9977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * ============LICENSE_START=======================================================
 *  org.onap.dcae
 *  ================================================================================
 *  Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
 *  ================================================================================
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  ============LICENSE_END=========================================================
 */

package org.onap.dcaegen2.platform.mod.objectmothers;

import org.onap.dcaegen2.platform.mod.model.specification.DeploymentType;
import org.onap.dcaegen2.platform.mod.model.microserviceinstance.DeploymentArtifactsRef;
import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance;
import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstanceStatus;
import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class MsInstanceObjectMother {

    public static final String MS_INSTANCE_NAME = "ms-instance-1";
    public static final String MS_INSTANCE_ID = "id-123";
    public static final String RELEASE = "2002";
    public static final String VERSION = "1.1";
    public static final String USER = "user-1";
    public static final String BASE_MS_TAG = "ms-instance-1-tag";
    public static final String SCRUMLEAD = "Sam";
    public static final String SYSTEMSENGINEER = "John";

    public static MsInstanceRequest getMsInstanceMockRequest() {
        Map<String, Object> metadataFromRequest = buildMockMetadataForRequest();

        MsInstanceRequest request = MsInstanceRequest.builder()
                .name(MS_INSTANCE_NAME)
                .release(RELEASE)
                .version(VERSION)
                .user(USER)
                .metadata(metadataFromRequest)
                .build();

        return request;
    }

    private static Map<String, Object> buildMockMetadataForRequest() {
        Map<String, Object> metadataFromRequest = new HashMap<>();
        metadataFromRequest.put("pstDueDate", "14-04-2020");
        metadataFromRequest.put("pstDueIteration", "1.2");
        metadataFromRequest.put("eteDueDate", "21-05-2020");
        metadataFromRequest.put("eteDueIteration", "1.3");
        metadataFromRequest.put("scrumLead", SCRUMLEAD);
        metadataFromRequest.put("systemsEngineer", SYSTEMSENGINEER);
        return metadataFromRequest;
    }


    public static MsInstance createMsInstance() {
        Map<String, Object> metadataFromResponse = buildMockMetadataForRequest().entrySet()
                .stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        metadataFromResponse.put("createdOn", "currentDate");
        metadataFromResponse.put("createdBy", USER);
        metadataFromResponse.put("scrumLead", SCRUMLEAD);
        metadataFromResponse.put("systemsEngineer", SYSTEMSENGINEER);

        Map<String, Object> msInfo = new HashMap<>();
        msInfo.put("id", BaseMsObjectMother.BASE_MS_ID);
        msInfo.put("name", BaseMsObjectMother.BASE_MS_NAME);
        msInfo.put("tag", BASE_MS_TAG);

        MsInstance msInstance = MsInstance.builder()
                .id(MS_INSTANCE_ID)
                .name(MS_INSTANCE_NAME)
                .release(RELEASE)
                .version(VERSION)
                .status(MsInstanceStatus.NEW)
                .metadata(metadataFromResponse)
                .msInfo(msInfo)
                .activeSpec(SpecificationObjectMother.getMockSpecification(DeploymentType.DOCKER))
                .build();

        return msInstance;
    }

    public static MsInstance getMsInstanceWithExistingDeploymentArtifactRef() {
        MsInstance msInstance = createMsInstance();

        DeploymentArtifactsRef deploymentArtifactRef = new DeploymentArtifactsRef();
        deploymentArtifactRef.setMostRecentVersion(1);

        ArrayList<String> deploymentArtifactList = new ArrayList<>();
        deploymentArtifactList.add("id-456");
        deploymentArtifactRef.setDeploymentArtifacts(deploymentArtifactList);

        msInstance.setDeploymentArtifactsInfo(deploymentArtifactRef);

        return msInstance;
    }
}