Skip to content

Commit 9de29fe

Browse files
author
Yegor Bugayenko
committed
#6 reproduced unlock
1 parent 6134274 commit 9de29fe

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/test/java/co/stateful/RtLockTest.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.jcabi.http.mock.MkGrizzlyContainer;
3636
import com.jcabi.http.request.JdkRequest;
3737
import java.net.HttpURLConnection;
38+
import org.apache.commons.lang3.StringUtils;
3839
import org.hamcrest.MatcherAssert;
3940
import org.hamcrest.Matchers;
4041
import org.junit.Test;
@@ -47,18 +48,25 @@
4748
*/
4849
public final class RtLockTest {
4950

51+
/**
52+
* Front XML.
53+
*/
54+
private static final String XML = StringUtils.join(
55+
"<page><links><link rel='lock' href='#lock'/>",
56+
"<link rel='unlock' href='#unlock'/></links></page>"
57+
);
58+
5059
/**
5160
* RtLock can lock.
5261
* @throws Exception If some problem inside
5362
*/
5463
@Test
5564
public void locksViaHttp() throws Exception {
56-
final String xml = "<page><links><link rel='lock' href=''/></links></page>";
5765
final MkContainer container = new MkGrizzlyContainer()
58-
.next(new MkAnswer.Simple(xml))
66+
.next(new MkAnswer.Simple(RtLockTest.XML))
5967
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_SEE_OTHER, ""))
6068
.start();
61-
final Lock lock = new RtLock("test", new JdkRequest(container.home()));
69+
final Lock lock = new RtLock("", new JdkRequest(container.home()));
6270
try {
6371
MatcherAssert.assertThat(lock.lock(), Matchers.equalTo(true));
6472
} finally {
@@ -74,4 +82,30 @@ public void locksViaHttp() throws Exception {
7482
);
7583
}
7684

85+
/**
86+
* RtLock can unlock.
87+
* @throws Exception If some problem inside
88+
*/
89+
@Test
90+
public void unlocksViaHttp() throws Exception {
91+
final MkContainer container = new MkGrizzlyContainer()
92+
.next(new MkAnswer.Simple(RtLockTest.XML))
93+
.next(new MkAnswer.Simple(HttpURLConnection.HTTP_SEE_OTHER, ""))
94+
.start();
95+
final Lock lock = new RtLock("", new JdkRequest(container.home()));
96+
try {
97+
lock.unlock();
98+
} finally {
99+
container.stop();
100+
}
101+
MatcherAssert.assertThat(
102+
container.take().method(),
103+
Matchers.equalTo(Request.GET)
104+
);
105+
MatcherAssert.assertThat(
106+
container.take().method(),
107+
Matchers.equalTo(Request.GET)
108+
);
109+
}
110+
77111
}

0 commit comments

Comments
 (0)