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.fasterxml.jackson.core.type.TypeReference;
10 import com.fasterxml.jackson.databind.ObjectMapper;
11 import com.samsung.samserver.SamserverApp;
12 import com.samsung.samserver.web.rest.service.vm.UInfo;
13 import io.restassured.response.Response;
14 import org.apache.commons.io.IOUtils;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.boot.context.embedded.LocalServerPort;
22 import org.springframework.boot.test.context.SpringBootTest;
23 import org.springframework.core.io.ResourceLoader;
24 import org.springframework.http.HttpStatus;
25 import org.springframework.test.context.junit4.SpringRunner;
27 import java.nio.charset.StandardCharsets;
28 import java.util.List;
31 * Integration Test for
33 * send data report, analyze & generate blacklist update
34 * get update & confirm
37 @RunWith(SpringRunner.class)
38 @SpringBootTest(classes = SamserverApp.class, webEnvironment = SpringBootTest. WebEnvironment.RANDOM_PORT)
39 public class TestScenario2 extends RestApi {
41 Logger log = LoggerFactory.getLogger(TestScenario1.class);
44 void setLocalServerPort(int localServerPort) {
45 this.localServerPort = localServerPort;
49 void setResourceLoader(ResourceLoader resourceLoader) {
50 this.resourceLoader = resourceLoader;
55 public void test() throws Exception {
57 log.info("test {}", this.getClass().getSimpleName());
61 String inResourceRegisterDevice = "classpath:test-data/"+this.getClass().getSimpleName()+"/in-registerDevice";
62 String outResourceRegisterDevice = "classpath:test-data/"+this.getClass().getSimpleName()+"/out-registerDevice";
63 String outRegisterDevice = IOUtils.toString(resourceLoader.getResource(outResourceRegisterDevice).getInputStream(), StandardCharsets.UTF_8);
64 Response resp = registerDevice(inResourceRegisterDevice);
65 resp.then().assertThat().statusCode(HttpStatus.OK.value());
66 String duid = resp.asString();
67 Assert.assertEquals(outRegisterDevice, duid);
71 String inResourceSendData = "classpath:test-data/"+this.getClass().getSimpleName()+"/in-sendData";
72 resp = sendData(inResourceSendData, duid);
73 resp.then().assertThat().statusCode(HttpStatus.OK.value());
77 resp = getUpdates(duid);
78 resp.then().assertThat().statusCode(HttpStatus.OK.value());
79 String updates = resp.asString();
81 // get update data by uri
83 ObjectMapper mapper = new ObjectMapper();
84 List<UInfo> infoList = mapper.readValue(updates, new TypeReference<List<UInfo>>(){});
85 String infoType = "blacklist";
86 String uri = getUriFromUInfo(infoList, infoType);
87 Assert.assertNotNull(uri);
89 String outResourceGetUdata = "classpath:test-data/"+this.getClass().getSimpleName()+"/out-getUdata";
90 String outGetUdata = IOUtils.toString(resourceLoader.getResource(outResourceGetUdata).getInputStream(), StandardCharsets.UTF_8);
92 resp.then().assertThat().statusCode(HttpStatus.OK.value());
93 String udata = resp.asString();
94 Assert.assertEquals(outGetUdata, udata);
96 // confirm update by curi
98 String curi = getCuriFromUInfo(infoList, infoType);
99 Assert.assertNotNull(curi);
101 resp.then().assertThat().statusCode(HttpStatus.OK.value());
103 // check that there is no more "blacklist" data in get updates
105 resp = getUpdates(duid);
106 resp.then().assertThat().statusCode(HttpStatus.OK.value());
107 updates = resp.asString();
108 infoList = mapper.readValue(updates, new TypeReference<List<UInfo>>(){});
109 uri = getUriFromUInfo(infoList, infoType);
110 Assert.assertNull(uri);