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
|
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021-2022 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.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to hold/create all parameters for test cases.
*
*/
public class CommonTestData {
private static final Coder CODER = new StandardCoder();
public static final String TOSCA_SERVICE_TEMPLATE_YAML =
"clamp/acm/test/pmsh_multiple_ac_tosca.yaml";
public static final String TOSCA_ST_TEMPLATE_YAML =
"clamp/acm/pmsh/funtional-pmsh-usecase.yaml";
/**
* 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 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;
}
}
|