-
Notifications
You must be signed in to change notification settings - Fork 513
/
ServerLogResource1_8Test.java
83 lines (69 loc) · 3.23 KB
/
ServerLogResource1_8Test.java
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
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8;
import org.apache.struts.mock.MockHttpServletResponse;
import org.junit.Assert;
import org.junit.Test;
import org.openmrs.module.webservices.helper.ServerLogActionWrapper;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.module.webservices.rest.web.MockServerLogActionWrapper;
import org.openmrs.module.webservices.rest.web.api.RestService;
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController;
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import java.util.ArrayList;
/**
* Integration tests for the ServerLogResource class
*/
public class ServerLogResource1_8Test extends BaseModuleWebContextSensitiveTest {
@Autowired
RestService restService;
@Autowired
private MainResourceController mainResourceController;
private MockServerLogActionWrapper mockServerLogActionWrapper = new MockServerLogActionWrapper();
public String getURI() {
return "serverlog";
}
@Test
public void testGetAll() {
ServerLogResource1_8 serverLogResource = (ServerLogResource1_8) restService
.getResourceBySupportedClass(ServerLogActionWrapper.class);
serverLogResource.setServerLogActionWrapper(mockServerLogActionWrapper);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
MockHttpServletResponse response = new MockHttpServletResponse();
SimpleObject result = mainResourceController.get(getURI(), request, response);
ArrayList<String[]> serverLog = result.get("serverLog");
Assert.assertEquals(serverLog.size(), 0);
String mockLogLine1 = "INFO - Simple.appender(115) |2018-03-03 15:44:54,834| Info Message";
// Add some mock log lines to mockMemoryAppenderBuffer
mockServerLogActionWrapper.mockMemoryAppenderBuffer.add(mockLogLine1);
result = mainResourceController.get(getURI(), request, response);
serverLog = result.get("serverLog");
Assert.assertNotEquals(serverLog.size(), 0);
String[] logLine1 = serverLog.get(0);
Assert.assertNotEquals(logLine1[0], null);
Assert.assertNotEquals(logLine1[1], null);
Assert.assertNotEquals(logLine1[2], null);
Assert.assertNotEquals(logLine1[3], null);
}
@Test(expected = Exception.class)
public void shouldThrowExceptionWhenRequestGetDefaultByUuid() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
MockHttpServletResponse response = new MockHttpServletResponse();
SimpleObject result = mainResourceController.get(getURI() + "/" + getUuid(), request, response);
ArrayList<String[]> serverLog = result.get("serverLog");
}
public String getUuid() {
return "log1";
}
}