SECARSP-268 *Implement device policies state request mechanism: update data type...
[platform/core/security/suspicious-activity-monitor.git] / server / samserver / src / test / java / com / samsung / samserver / web / rest / service / device / SendDataRestServiceTest.java
1 /*
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.
5  */
6 package com.samsung.samserver.web.rest.service.device;
7
8 import com.samsung.samserver.SamserverApp;
9 import com.samsung.samserver.domain.*;
10 import com.samsung.samserver.service.*;
11 import com.samsung.samserver.web.rest.errors.DeviceServiceError;
12 import com.samsung.samserver.web.rest.service.vm.Data;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.boot.test.context.SpringBootTest;
15 import org.springframework.http.ResponseEntity;
16 import org.springframework.test.context.junit4.SpringRunner;
17 import org.slf4j.Logger;
18 import org.junit.runner.RunWith;
19 import org.junit.*;
20 import org.mockito.*;
21
22 import static org.mockito.Mockito.*;
23
24 /**
25  * Test class for the SendDataRestService.
26  *
27  * @see SendDataRestService
28  */
29 @RunWith(SpringRunner.class)
30 @SpringBootTest(classes = SamserverApp.class)
31 public class SendDataRestServiceTest {
32     @Mock
33     Logger log;
34     @Mock
35     DeviceService deviceService;
36     @Mock
37     ReportService reportService;
38     @Mock
39     ReportTypeService reportTypeService;
40     @Mock
41     AnalyzeService analyzeService;
42     @Mock
43     UpdatesService updatesService;
44
45     @Autowired
46     SendDataRestService sendDataRestService;
47
48     @Before
49     public void setUp() {
50         MockitoAnnotations.initMocks(this);
51     }
52
53     @Test (expected = DeviceServiceError.DeviceNotFoundException.class)
54     public void testSendData() throws Exception {
55         when(deviceService.findOne(anyString())).thenReturn(null);
56         when(reportService.save(any())).thenReturn(new Report("data", new ReportType("name", "descr"), new Device()));
57         when(reportTypeService.save(any())).thenReturn(new ReportType("name", "descr"));
58         when(reportTypeService.findOne(anyString())).thenReturn(null);
59
60         ResponseEntity<Void> result = sendDataRestService.sendData("duid", new Data.DataLogs());
61         Assert.assertEquals(null, result);
62     }
63
64     @Test (expected = DeviceServiceError.DeviceNotFoundException.class)
65     public void testSendDataConfirm() throws Exception {
66         when(deviceService.findOne(anyString())).thenReturn(null);
67
68         ResponseEntity<Void> result = sendDataRestService.sendDataConfirm("duid", "uuid");
69         Assert.assertEquals(null, result);
70     }
71 }