1 package com.aragost.javahg.commands;
2
3 import static com.aragost.javahg.Phase.DRAFT;
4 import static com.aragost.javahg.Phase.PUBLIC;
5 import static com.aragost.javahg.Phase.SECRET;
6
7 import java.io.IOException;
8
9 import junit.framework.Assert;
10
11 import com.aragost.javahg.BaseRepository;
12 import com.aragost.javahg.Changeset;
13 import com.aragost.javahg.Repository;
14 import com.aragost.javahg.UnknownCommandException;
15 import com.aragost.javahg.test.AbstractTestCase;
16
17 import org.junit.Assume;
18 import org.junit.Test;
19
20 public class PhaseCommandTest extends AbstractTestCase {
21
22 private boolean isPhasesSupported() {
23 BaseRepository repo = getTestRepository();
24 try {
25 PhaseCommand.on(repo).rev(Changeset.NULL_ID).execute();
26 return true;
27 } catch (UnknownCommandException e) {
28 return false;
29 }
30 }
31
32 @Test
33 public void test() throws IOException {
34 Assume.assumeTrue(isPhasesSupported());
35 BaseRepository repo = getTestRepository();
36 Changeset cs1 = createChangeset();
37 Changeset cs2 = createChangeset();
38 Assert.assertEquals(DRAFT, cs1.phase());
39 Assert.assertEquals(DRAFT, cs2.phase());
40 PhaseCommand cmd = PhaseCommand.on(repo).pub().rev(cs2.getNode());
41 cmd.execute();
42 Assert.assertEquals(PUBLIC, cs1.phase());
43 Assert.assertEquals(PUBLIC, cs2.phase());
44
45 cmd = PhaseCommand.on(repo).secret().rev(cs2.getNode());
46 Assert.assertFalse(cmd.execute());
47 Assert.assertEquals(PUBLIC, cs1.phase());
48 Assert.assertEquals(PUBLIC, cs2.phase());
49
50 cmd = PhaseCommand.on(repo).secret().force().rev(cs1.getNode());
51 Assert.assertTrue(cmd.execute());
52 Assert.assertEquals(SECRET, cs1.phase());
53 Assert.assertEquals(SECRET, cs2.phase());
54
55 cmd = PhaseCommand.on(repo).pub().force().rev(cs1.getNode());
56 cmd.execute();
57 Assert.assertEquals(PUBLIC, cs1.phase());
58 Assert.assertEquals(SECRET, cs2.phase());
59 }
60
61 @Test
62 public void testPhaseMakesNoChanges() throws IOException {
63 Assume.assumeTrue(isPhasesSupported());
64 BaseRepository repo = getTestRepository();
65 Changeset cs = createChangeset();
66 PhaseCommand cmd = PhaseCommand.on(repo).draft().rev(cs.getNode());
67 Assert.assertFalse(cmd.execute());
68 }
69
70 @Test
71 public void testPhasesWhenPhasesNotSupported() throws IOException {
72 Assume.assumeTrue(!isPhasesSupported());
73 Changeset cs = createChangeset();
74 Assert.assertNull(cs.phase());
75 }
76
77 @Test
78 public void testPhasesUnknownRev() throws IOException {
79 Assume.assumeTrue(isPhasesSupported());
80
81 createChangeset();
82
83 Repository repo = getTestRepository();
84
85 try
86 {
87 repo.phases("abcdef124");
88 }
89 catch (ExecutionException e)
90 {
91 }
92
93 try
94 {
95 repo.phases("abcdef124");
96 }
97 catch (ExecutionException e)
98 {
99 }
100
101 try
102 {
103 repo.phases("abcdef124");
104 }
105 catch (ExecutionException e)
106 {
107 }
108
109
110 try
111 {
112 repo.phases("abcdef124");
113 }
114 catch (ExecutionException e)
115 {
116 }
117 }
118 }