My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// JODConverter - Java OpenDocument Converter
// Copyright 2009 Art of Solving Ltd
// Copyright 2004-2009 Mirko Nasato
//
// JODConverter is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// JODConverter 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General
// Public License along with JODConverter. If not, see
// <http://www.gnu.org/licenses/>.
//
package org.artofsolving.jodconverter.sigar;

import java.util.List;

import org.artofsolving.jodconverter.process.NonUniqueResultException;
import org.artofsolving.jodconverter.process.ProcessManager;
import org.artofsolving.jodconverter.process.SigarProcessManager;
import org.artofsolving.jodconverter.sigar.SimplePTQL.Strategy;
import org.artofsolving.jodconverter.util.PlatformUtils;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.Test;

@Test
public class SimplePTQLTest {

public void simpleQuery() throws Exception {
ProcessManager spm = new SigarProcessManager();
SimplePTQL ptql = new SimplePTQL.Builder(SimplePTQL.STATE_NAME(), SimplePTQL.EQ(), "java").createQuery();
Assert.assertEquals(ptql.getQuery(), "State.Name.eq=java");

List<Long> find = spm.find(ptql);
Assert.assertTrue(find.size() > 0);

if(find.size() > 1) {
try {
spm.findSingle(ptql);
Assert.fail("Should not reach here, should get exception");
} catch(NonUniqueResultException nre) {
//More than one results where found
}
}

ptql = new SimplePTQL.Builder(SimplePTQL.PID_PID(), SimplePTQL.EQ(), String.valueOf(find.get(0))).createQuery();
Long findSingle = spm.findSingle(ptql);
Assert.assertEquals(findSingle, find.get(0));

ptql = new SimplePTQL.Builder(SimplePTQL.STATE_NAME(), SimplePTQL.EQ(), "Hopefully There is no Process called this").createQuery();
List<Long> find2 = spm.find(ptql);
Assert.assertTrue(find2.size() == 0);

ptql = new SimplePTQL.Builder(SimplePTQL.PID_PID(), SimplePTQL.GT(), "1").createQuery();
List<Long> find3 = spm.find(ptql);
Assert.assertTrue(find3.size() > 1);
}

public void args() throws Exception {
SimplePTQL ptql = new SimplePTQL.Builder(SimplePTQL.STATE_NAME(), SimplePTQL.RE(), "office.*")
.addArgs("*", SimplePTQL.RE(), "\\Qpipe,name,office1\\E", Strategy.ESCAPE)
.createQuery();
Assert.assertEquals(ptql.getQuery(), "State.Name.re=office.*,Args.*.re=pipe.name.office1");

ptql = new SimplePTQL.Builder(SimplePTQL.STATE_NAME(), SimplePTQL.EQ(), "office.*")
.addArgs("*", SimplePTQL.RE(), "\\Qpipe,name,office1\\E", Strategy.ESCAPE)
.addArgs("*", SimplePTQL.EQ(), "\\Qpipe,name=office2\\E", Strategy.ESCAPE)
.setStrategy(Strategy.ESCAPE)
.createQuery();

Assert.assertEquals(ptql.getQuery(), "State.Name.eq=office.*,Args.*.re=pipe.name.office1,Args.*.eq=pipe.name=office2");

try {
ptql = new SimplePTQL.Builder(SimplePTQL.STATE_NAME(), SimplePTQL.EQ(), "office.*")
.addArgs("1", SimplePTQL.RE(), "\\Qpipe,name,office1\\E", Strategy.ESCAPE)
.addArgs("2", SimplePTQL.EQ(), "\\Qpipe,name,office2\\E", Strategy.NOT_ESCAPE)
.createQuery();

Assert.fail("Method should have thrown IllegalArgumentException");
} catch(IllegalArgumentException ex) {}
}

public void realArguments() throws Exception {
if (PlatformUtils.isWindows()) {
throw new SkipException("Sleep only works on unix");
}

Process process = new ProcessBuilder("sleep", "60s").start();
Assert.assertNotNull(process);

SimplePTQL ptql = new SimplePTQL.Builder(SimplePTQL.STATE_NAME(), SimplePTQL.EQ(), "sleep")
.addArgs("1", SimplePTQL.EQ(), "60s", Strategy.NOT_ESCAPE).createQuery();


ProcessManager spm = new SigarProcessManager();
Long findSingle = spm.findSingle(ptql);
Assert.assertTrue(findSingle > 0L);

spm.kill(findSingle, 9);
Assert.assertEquals(spm.findSingle(ptql).longValue(), 0L);
}
}

Change log

r185 by shervin.asgari on Mar 28, 2011   Diff
Changed implementation of SimplePTQL to
add the possibility to use '*' as argument
number in Args
Changed the tests accordingly
Go to: 

Older revisions

r182 by mirko.nasato on Mar 27, 2011   Diff
reverted change r173 about copyright
year - just makes merging more
difficult
r178 by shervin.asgari on Mar 22, 2011   Diff
Added ISSUE 52 - Autokill open pipes
r173 by shervin.asgari on Mar 21, 2011   Diff
- Changed copyright statement
- Removed ProcessManager in
DefaultOfficeManager
All revisions of this file

File info

Size: 4344 bytes, 109 lines

File properties

svn:mime-type
text/plain
Powered by Google Project Hosting