summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dcae/ci/api/tests/composition/CompositionMicroServicesApiTests.java
blob: 9808400839d4cfb58113fe7b821dd4402984d184 (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
package org.onap.dcae.ci.api.tests.composition;

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

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.utilities.DcaeTestConstants;
import org.onap.dcae.ci.utilities.DcaeUtil;
import org.onap.dcae.ci.report.Report;
import org.onap.sdc.dcae.composition.model.ModelDcae;
import org.testng.annotations.*;

import java.io.IOException;

import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;


import com.aventstack.extentreports.Status;


public class CompositionMicroServicesApiTests extends DcaeRestBaseTest {
	
	@Test
	public void getAllElementsTest() throws IOException, ParseException{
		Report.log(Status.INFO, "getAllElementsTest start");
		RestResponse services = DcaeRestClient.getElements();
		Report.log(Status.INFO, "getAllElementsTest response=%s", services);
		assertThat(services.getStatusCode().intValue()).isEqualTo(200);
		String response = services.getResponse();
		JSONParser parser = new JSONParser();
		JSONObject o = (JSONObject) parser.parse(response);
		JSONObject ele = (JSONObject) o.get("data");
		String arrString = ele.get("elements").toString();
		assertThat(arrString)
			.as("Check that elements not empty")
			.isNotEmpty();
	}
	
	@Test
	public void getMsElementsTest() throws IOException, ParseException{
		Report.log(Status.INFO, "getMsElementsTest start");
		RestResponse services = DcaeUtil.SdcElementsModelType.getMsElements();
		Report.log(Status.INFO, "getMsElementsTest response=%s", services);
		assertThat(services.getStatusCode().intValue()).isEqualTo(200);
		String response = services.getResponse();
		JSONParser parser = new JSONParser();
		JSONObject o = (JSONObject) parser.parse(response);
		JSONObject ele = (JSONObject) o.get("data");
		String arrString = ele.get("element").toString();
		assertThat(arrString)
			.as("Check that elements not empty")
			.isNotEmpty();
	}
	
	@Test
	public void getItemModelTest() throws IOException{
		Report.log(Status.INFO, "getItemModelTest start");
		RestResponse itemModelRes = DcaeUtil.SdcElementsModelType.getItemModelFromSdc(0);
		Report.log(Status.INFO, "getItemModelTest response=%s", itemModelRes);
		assertThat(itemModelRes.getStatusCode().intValue()).isEqualTo(200);
		
		String response = itemModelRes.getResponse();
		JSONObject object = (JSONObject) JSONValue.parse(response);
		String errorMsg = object.get("error").toString();
		assertThat(errorMsg).isEqualTo(DcaeTestConstants.Composition.EMPTY_OBJECT);
	}
	
	@Test
	public void getItemTypeTest() throws IOException{
		Report.log(Status.INFO, "getItemModelTest start");
		RestResponse itemModelRes = DcaeUtil.SdcElementsModelType.getItemModelFromSdc(0);
		Report.log(Status.INFO, "itemModelRes response=%s", itemModelRes);
		String response = itemModelRes.getResponse();
		
		String uuid = DcaeUtil.SdcElementsModelType.getItemUuid(0);
		
		ModelDcae model = gson.fromJson(response, ModelDcae.class);
		Report.log(Status.INFO, "model "+model);
		String type = model.getData().getModel().getNodes().get(0).getType();
		Report.log(Status.INFO, "type "+type);

		RestResponse services = DcaeRestClient.getItemType(uuid, type);
		assertThat(services.getStatusCode().intValue()).isEqualTo(200);
	}

}