summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dcae/ci/api/tests/composition/SaveAndSubmitCompositionFullFlowTest.java
blob: f2d7a2416226a96ec364dc0f0365ae02df6fa215 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package org.onap.dcae.ci.api.tests.composition;


import com.aventstack.extentreports.Status;
import com.google.gson.reflect.TypeToken;
import org.onap.dcae.ci.api.tests.DcaeRestBaseTest;
import org.onap.dcae.ci.entities.RestResponse;
import org.onap.dcae.ci.utilities.DcaeRestClient;
import org.onap.dcae.ci.report.Report;
import org.onap.sdc.dcae.composition.restmodels.CreateMcResponse;
import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest;
import org.onap.sdc.dcae.composition.restmodels.MonitoringComponent;
import org.onap.sdc.dcae.composition.restmodels.VfcmtData;
import org.onap.sdc.dcae.composition.restmodels.sdc.Resource;
import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
import org.onap.sdc.dcae.composition.services.Service;
import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

public class SaveAndSubmitCompositionFullFlowTest extends DcaeRestBaseTest {

    private Resource baseTemplate = null;


    @BeforeClass
    public void setup() {
        try {
			Report.log(Status.INFO, "running before class - find a base template");
            Resource[] resources = gson.fromJson(DcaeRestClient.getAllMonitoringTemplatesVfcmts().getResponse(), Resource[].class);
            if (resources.length > 0){
                baseTemplate = resources[0];
            }
        } catch (Exception e) {
			Report.log(Status.ERROR, e);
        }
    }


    @Test
    public void saveAndSubmitCompositionSuccessTest() throws IOException {

        CreateVFCMTRequest request = new CreateVFCMTRequest();
        // If you crashed here (below) it is because your environment has no Base Monitoring Templates
        request.setTemplateUuid(baseTemplate.getUuid());
        Service service = createServiceWithVFiAsSdcDesigner();
        request.setVfiName(service.getResources().get(0).getResourceInstanceName());
        request.setServiceUuid(service.getUuid());
        DcaeRestClient.fillCreateMcRequestMandatoryFields(request);

        RestResponse response = DcaeRestClient.createMc(gson.toJson(request));
        assertThat(response.getStatusCode())
                .as("status code")
                .isEqualTo(200);

        CreateMcResponse mcResponse = gson.fromJson(response.getResponse(), CreateMcResponse.class);
		Report.log(Status.INFO, "Vfcmt created successfully. About to update composition");
        String initialUuid =  mcResponse.getVfcmt().getUuid();
        response = DcaeRestClient.saveComposition(request.getServiceUuid(), request.getVfiName(), initialUuid, gson.toJson(mcResponse.getCdump()));
        assertThat(response.getStatusCode())
                .as("status code")
                .isEqualTo(200);

        ResourceDetailed mc = gson.fromJson(response.getResponse(), ResourceDetailed.class);
        // the save action should check the mc out then in - promoting the version
        assertThat(mc.getLifecycleState()).isEqualTo(DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name());
        assertThat(mc.getVersion()).isEqualTo("0.2");

		Report.log(Status.INFO, "About to submit the composition");
        response = DcaeRestClient.submitComposition(request.getServiceUuid(), request.getVfiName(), mc.getUuid());
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		// the submit action should certify the mc.
		Report.log(Status.INFO, "Save new composition version after submit");
		response = DcaeRestClient.saveComposition(request.getServiceUuid(), request.getVfiName(), initialUuid, gson.toJson(mcResponse.getCdump()));
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		// the save action should promote the mc version to 1.1 and create a new reference to it - both references should be kept at this point
		mc = gson.fromJson(response.getResponse(), ResourceDetailed.class);
		assertThat(mc.getLifecycleState()).isEqualTo(DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name());
		assertThat(mc.getVersion()).isEqualTo("1.1");

		response = DcaeRestClient.getServiceExternalReferences(service.getUuid(), service.getVersion());
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		Report.log(Status.INFO, "Verify service vfi has references to both mc versions");
		Type typeToken = new TypeToken<Map<String, List<MonitoringComponent>>>(){}.getType();
		Map<String, List<MonitoringComponent>> monitoringComponents = gson.fromJson(response.getResponse(), typeToken);
		assertThat(monitoringComponents.get("monitoringComponents").size()).isEqualTo(2);
		Report.log(Status.INFO, "About to re-submit the composition");
		response = DcaeRestClient.submitComposition(request.getServiceUuid(), request.getVfiName(), mc.getUuid());
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		// a successful submission of the new version should result in the deletion of the previous reference
		response = DcaeRestClient.getServiceExternalReferences(service.getUuid(), service.getVersion());
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		monitoringComponents = gson.fromJson(response.getResponse(), typeToken);
		List<MonitoringComponent> mcList = monitoringComponents.get("monitoringComponents");
		assertThat(mcList.size()).isEqualTo(1);
		assertThat(mcList.get(0).getUuid()).isEqualTo(mc.getUuid());

    }


	@Test
	public void certifiedMcCheckoutAndBindToServiceSuccessTest() throws IOException {

		CreateVFCMTRequest request = new CreateVFCMTRequest();
		// If you crashed here (below) it is because your environment has no Base Monitoring Templates
		request.setTemplateUuid(baseTemplate.getUuid());
		Service service = createServiceWithVFiAsSdcDesigner();
		request.setVfiName(service.getResources().get(0).getResourceInstanceName());
		request.setServiceUuid(service.getUuid());
		DcaeRestClient.fillCreateMcRequestMandatoryFields(request);

		RestResponse response = DcaeRestClient.createMc(gson.toJson(request));
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);

		CreateMcResponse mcResponse = gson.fromJson(response.getResponse(), CreateMcResponse.class);
		String initialUuid =  mcResponse.getVfcmt().getUuid();

		response = DcaeRestClient.getLatestMcUuid(request.getContextType(), request.getServiceUuid(), request.getVfiName(), initialUuid);
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		VfcmtData getLatestUuidRes = gson.fromJson(response.getResponse(), VfcmtData.class);
		assertThat(initialUuid).isEqualTo(getLatestUuidRes.getUuid());

		response = DcaeRestClient.getServiceExternalReferences(service.getUuid(), service.getVersion());
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		Report.log(Status.INFO, "Verify service vfi only references initial mc version");
		Type typeToken = new TypeToken<Map<String, List<MonitoringComponent>>>(){}.getType();
		Map<String, List<MonitoringComponent>> monitoringComponents = gson.fromJson(response.getResponse(), typeToken);
		assertThat(monitoringComponents.get("monitoringComponents").size()).isEqualTo(1);
		Report.log(Status.INFO, "About to submit the composition");
		response = DcaeRestClient.submitComposition(request.getServiceUuid(), request.getVfiName(), initialUuid);
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);

		response = DcaeRestClient.getLatestMcUuid(request.getContextType(), request.getServiceUuid(), request.getVfiName(), initialUuid);
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		getLatestUuidRes = gson.fromJson(response.getResponse(), VfcmtData.class);
		Report.log(Status.INFO, "Verify latest Mc uuid is not the initial one");
		assertThat(initialUuid).isNotEqualTo(getLatestUuidRes.getUuid());
		response = DcaeRestClient.getServiceExternalReferences(service.getUuid(), service.getVersion());
		assertThat(response.getStatusCode())
				.as("status code")
				.isEqualTo(200);
		Report.log(Status.INFO, "Verify service vfi has references to both mc versions");

		monitoringComponents = gson.fromJson(response.getResponse(), typeToken);
		assertThat(monitoringComponents.get("monitoringComponents").size()).isEqualTo(2);

	}

}