svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / test / java / org / gvsig / fmap / dal / resource / spi / AbstractResourceTest.java @ 40767
History | View | Annotate | Download (3.66 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.resource.spi; |
25 |
|
26 |
import junit.framework.TestCase; |
27 |
|
28 |
import org.easymock.MockControl; |
29 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
30 |
import org.gvsig.fmap.dal.resource.ResourceParameters; |
31 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException; |
32 |
|
33 |
/**
|
34 |
* Unit tests for the class {@link AbstractResource}
|
35 |
*
|
36 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
37 |
*/
|
38 |
public class AbstractResourceTest extends TestCase { |
39 |
|
40 |
private AbstractResource resource;
|
41 |
private MockControl paramsControl;
|
42 |
private ResourceParameters params;
|
43 |
|
44 |
protected void setUp() throws Exception { |
45 |
super.setUp();
|
46 |
paramsControl = MockControl.createNiceControl(ResourceParameters.class); |
47 |
params = (ResourceParameters) paramsControl.getMock(); |
48 |
resource = new TestResource(params);
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* Test method for {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#getLastTimeOpen()}.
|
53 |
*/
|
54 |
public void testGetLastTimeOpen() throws ResourceNotifyOpenException { |
55 |
long time = resource.getLastTimeOpen();
|
56 |
resource.notifyOpen(); |
57 |
assertTrue("The resource last time open hasn't been updated",
|
58 |
resource.getLastTimeOpen() > time); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Test method for {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#getLastTimeUsed()}.
|
63 |
*/
|
64 |
public void testGetLastTimeUsed() throws Exception { |
65 |
long time = resource.getLastTimeUsed();
|
66 |
resource.execute(new ResourceAction() {
|
67 |
public Object run() throws Exception { |
68 |
try {
|
69 |
// Wait for 100 milliseconds
|
70 |
Thread.sleep(100); |
71 |
} catch (InterruptedException e) { |
72 |
// No problem
|
73 |
} |
74 |
return null; |
75 |
} |
76 |
}); |
77 |
assertTrue("The resource last time used hasn't been updated",
|
78 |
resource.getLastTimeUsed() > time); |
79 |
} |
80 |
|
81 |
/**
|
82 |
* Test method for {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#openCount()}.
|
83 |
*/
|
84 |
public void testOpenCount() throws Exception { |
85 |
assertEquals(0, resource.openCount());
|
86 |
resource.notifyOpen(); |
87 |
assertEquals(1, resource.openCount());
|
88 |
resource.notifyOpen(); |
89 |
resource.notifyOpen(); |
90 |
assertEquals(3, resource.openCount());
|
91 |
resource.notifyClose(); |
92 |
assertEquals(2, resource.openCount());
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Test method for
|
97 |
* {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
|
98 |
* .
|
99 |
*/
|
100 |
public void testExecute() throws Exception { |
101 |
final MutableBoolean testValue = new MutableBoolean(); |
102 |
resource.execute(new ResourceAction() {
|
103 |
public Object run() throws Exception { |
104 |
testValue.setValue(true);
|
105 |
return null; |
106 |
} |
107 |
}); |
108 |
assertTrue("Runnable execution not performed", testValue.isValue());
|
109 |
} |
110 |
|
111 |
public class MutableBoolean { |
112 |
private boolean value = false; |
113 |
|
114 |
public void setValue(boolean value) { |
115 |
this.value = value;
|
116 |
} |
117 |
|
118 |
public boolean isValue() { |
119 |
return value;
|
120 |
} |
121 |
} |
122 |
} |