/
MemoryTest.java
81 lines (73 loc) · 3.56 KB
/
MemoryTest.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
/**
* Copyright (C) 2016 RasPi Check Contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package de.eidottermihi.rpicheck.test;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import de.eidottermihi.rpicheck.ssh.beans.RaspiMemoryBean;
import de.eidottermihi.rpicheck.ssh.impl.RaspiQueryException;
import de.eidottermihi.rpicheck.ssh.impl.queries.MemoryQuery;
import de.eidottermihi.rpicheck.test.mocks.CommandMocker;
public class MemoryTest extends AbstractMockedQueryTest {
@Test
public void memory() throws RaspiQueryException, IOException {
String output = FileUtils.readFileToString(FileUtils
.getFile("src/test/java/de/eidottermihi/rpicheck/test/proc_meminfo.txt"));
sessionMocker.withCommand(
MemoryQuery.MEMORY_INFO_CMD,
new CommandMocker().withResponse(output).mock());
RaspiMemoryBean memoryBean = raspiQuery.queryMemoryInformation();
Assert.assertNotNull(memoryBean);
Assert.assertEquals(949328L * 1024, memoryBean.getTotalMemory()
.getBytes());
Assert.assertEquals(884628L * 1024, memoryBean.getTotalFree()
.getBytes());
Assert.assertEquals(64700L * 1024, memoryBean.getTotalUsed()
.getBytes());
Assert.assertEquals(64700.0 / 949328.0, memoryBean.getPercentageUsed(), 0.001);
}
@Test
public void memory_old_linux_kernel() throws RaspiQueryException, IOException {
String output = FileUtils.readFileToString(FileUtils
.getFile("src/test/java/de/eidottermihi/rpicheck/test/proc_meminfo_old.txt"));
sessionMocker.withCommand(
MemoryQuery.MEMORY_INFO_CMD,
new CommandMocker().withResponse(output).mock());
RaspiMemoryBean memoryBean = raspiQuery.queryMemoryInformation();
Assert.assertNotNull(memoryBean);
Assert.assertEquals(949328L * 1024, memoryBean.getTotalMemory()
.getBytes());
Assert.assertEquals(898024L * 1024, memoryBean.getTotalFree()
.getBytes());
Assert.assertEquals(51304L * 1024, memoryBean.getTotalUsed()
.getBytes());
Assert.assertEquals(51304.0 / 949328.0, memoryBean.getPercentageUsed(), 0.001);
}
@Test
public void memory_unknown_ouput() throws RaspiQueryException, IOException {
String output = FileUtils.readFileToString(FileUtils
.getFile("src/test/java/de/eidottermihi/rpicheck/test/proc_meminfo_error.txt"));
sessionMocker.withCommand(
MemoryQuery.MEMORY_INFO_CMD,
new CommandMocker().withResponse(output).mock());
RaspiMemoryBean memoryBean = raspiQuery.queryMemoryInformation();
Assert.assertNotNull(memoryBean);
Assert.assertEquals(memoryBean.getErrorMessage(), MemoryQuery.MEMORY_UNKNOWN_OUPUT);
}
}