aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
blob: 33a00c21bdde20d219f0ed723da26f6e84dc1682 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2021 Nordix Foundation.
 * ================================================================================
 * 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.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.clamp.acm.runtime.util;

import java.util.List;
import javax.ws.rs.core.Response.Status;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;

/**
 * Class to hold/create all parameters for test cases.
 *
 */
public class CommonTestData {
    private static final Coder CODER = new StandardCoder();

    /**
     * Gets the standard automation composition parameters.
     *
     * @param dbName the database name
     * @return the standard automation composition parameters
     * @throws AutomationCompositionRuntimeException on errors reading the automation composition parameters
     */
    public static AcRuntimeParameterGroup geParameterGroup(final String dbName) {
        try {
            return CODER.convert(getParameterGroupAsString(dbName), AcRuntimeParameterGroup.class);

        } catch (CoderException e) {
            throw new AutomationCompositionRuntimeException(Status.NOT_ACCEPTABLE,
                "cannot read automation composition parameters", e);
        }
    }

    /**
     * Gets the standard automation composition parameters, as a String.
     *
     * @param dbName the database name
     * @return the standard automation composition parameters as string
     */
    public static String getParameterGroupAsString(final String dbName) {
        return ResourceUtils.getResourceAsString("src/test/resources/parameters/TestParameters.json")
            .replace("${dbName}", "jdbc:h2:mem:" + dbName);
    }

    /**
     * Create a new PolicyModelsProvider.
     *
     * @param databaseProviderParameters the database Provider Parameters
     * @return a new PolicyModelsProvider
     */
    public static PolicyModelsProvider getPolicyModelsProvider(
        PolicyModelsProviderParameters databaseProviderParameters) {
        try {
            return new PolicyModelsProviderFactory().createPolicyModelsProvider(databaseProviderParameters);
        } catch (PfModelException e) {
            throw new PfModelRuntimeException(e);
        }
    }

    /**
     * Create a List of Participants.
     *
     * @return a List of Participants
     */
    public static List<Participant> createParticipants() {
        var participant1 = createParticipant(
            new ToscaConceptIdentifier("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant",
                "2.3.4"),
            new ToscaConceptIdentifier("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant",
                "2.3.4"));
        var participant2 = createParticipant(
            new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1"),
            new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1"));
        var participant3 = createParticipant(
            new ToscaConceptIdentifier("org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant", "2.2.1"),
            new ToscaConceptIdentifier("org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant", "2.2.1"));
        return List.of(participant1, participant2, participant3);
    }

    /**
     * Create a new Participant.
     *
     * @param participantType the participant Type
     * @param participantId the participant id
     * @return a new Participant
     */
    public static Participant createParticipant(ToscaConceptIdentifier participantType,
        ToscaConceptIdentifier participantId) {
        var participant = new Participant();
        participant.setDefinition(participantId);
        participant.setParticipantType(participantType);
        participant.setName(participantId.getName());
        participant.setVersion(participantId.getVersion());
        return participant;
    }
}