2 * In Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
7 package com.samsung.samserver.integration;
9 import com.samsung.samserver.web.rest.service.vm.UInfo;
10 import io.restassured.RestAssured;
11 import io.restassured.http.ContentType;
12 import io.restassured.response.Response;
13 import org.apache.commons.io.IOUtils;
14 import org.springframework.core.io.ResourceLoader;
15 import java.nio.charset.StandardCharsets;
16 import java.util.List;
18 import static io.restassured.RestAssured.given;
21 * Base class for REST API Integration Tests.
24 public abstract class RestApi {
27 ResourceLoader resourceLoader;
29 protected Response registerDevice(String inResource) throws Exception {
30 String in = IOUtils.toString(resourceLoader.getResource(inResource).getInputStream(), StandardCharsets.UTF_8);
31 String uri = "/api/device-service/register-device";
32 Response resp = given()
33 .contentType(ContentType.JSON)
35 .when().port(this.localServerPort)
36 .post(RestAssured.baseURI + uri);
37 resp.then().log().all();
41 protected Response sendData(String inResource, String duid) throws Exception {
42 String in = IOUtils.toString(resourceLoader.getResource(inResource).getInputStream(), StandardCharsets.UTF_8);
43 String uri = "/api/device-service/send-data";
44 Response resp = given()
45 .queryParam("duid", duid)
46 .contentType(ContentType.JSON)
48 .when().port(this.localServerPort)
49 .post(RestAssured.baseURI + uri);
50 resp.then().log().all();
54 protected Response getUpdates(String duid) {
55 String uri = "/api/device-service/get-updates";
56 Response resp = given()
57 .queryParam("duid", duid)
58 .when().port(this.localServerPort)
59 .get(RestAssured.baseURI + uri);
60 resp.then().log().all();
64 protected Response get(String uri) {
65 Response resp = given()
66 .when().port(this.localServerPort)
67 .get(RestAssured.baseURI + uri);
68 resp.then().log().all();
72 protected Response post(String uri) {
73 Response resp = given()
74 .when().port(this.localServerPort)
75 .post(RestAssured.baseURI + uri);
76 resp.then().log().all();
80 protected String getUriFromUInfo(List<UInfo> infoList, String type) {
82 for (UInfo uInfo: infoList) {
83 if (uInfo.getType().equals(type)){
91 protected String getCuriFromUInfo(List<UInfo> infoList, String type) {
93 for (UInfo uInfo: infoList) {
94 if (uInfo.getType().equals(type)){
95 curi = uInfo.getCuri();