Package com.aragost.javahg.commands

Source Code of com.aragost.javahg.commands.PhaseCommandTest

package com.aragost.javahg.commands;

import static com.aragost.javahg.Phase.DRAFT;
import static com.aragost.javahg.Phase.PUBLIC;
import static com.aragost.javahg.Phase.SECRET;

import java.io.IOException;

import junit.framework.Assert;

import com.aragost.javahg.BaseRepository;
import com.aragost.javahg.Changeset;
import com.aragost.javahg.Repository;
import com.aragost.javahg.UnknownCommandException;
import com.aragost.javahg.test.AbstractTestCase;

import org.junit.Assume;
import org.junit.Test;

public class PhaseCommandTest extends AbstractTestCase {

    private boolean isPhasesSupported() {
        BaseRepository repo = getTestRepository();
        try {
            PhaseCommand.on(repo).rev(Changeset.NULL_ID).execute();
            return true;
        } catch (UnknownCommandException e) {
            return false;
        }
    }

    @Test
    public void test() throws IOException {
        Assume.assumeTrue(isPhasesSupported());
        BaseRepository repo = getTestRepository();
        Changeset cs1 = createChangeset();
        Changeset cs2 = createChangeset();
        Assert.assertEquals(DRAFT, cs1.phase());
        Assert.assertEquals(DRAFT, cs2.phase());
        PhaseCommand cmd = PhaseCommand.on(repo).pub().rev(cs2.getNode());
        cmd.execute();
        Assert.assertEquals(PUBLIC, cs1.phase());
        Assert.assertEquals(PUBLIC, cs2.phase());

        cmd = PhaseCommand.on(repo).secret().rev(cs2.getNode());
        Assert.assertFalse(cmd.execute());
        Assert.assertEquals(PUBLIC, cs1.phase());
        Assert.assertEquals(PUBLIC, cs2.phase());

        cmd = PhaseCommand.on(repo).secret().force().rev(cs1.getNode());
        Assert.assertTrue(cmd.execute());
        Assert.assertEquals(SECRET, cs1.phase());
        Assert.assertEquals(SECRET, cs2.phase());
       
        cmd = PhaseCommand.on(repo).pub().force().rev(cs1.getNode());
        cmd.execute();
        Assert.assertEquals(PUBLIC, cs1.phase());
        Assert.assertEquals(SECRET, cs2.phase());
    }

    @Test
    public void testPhaseMakesNoChanges() throws IOException {
        Assume.assumeTrue(isPhasesSupported());
        BaseRepository repo = getTestRepository();
        Changeset cs = createChangeset();
        PhaseCommand cmd = PhaseCommand.on(repo).draft().rev(cs.getNode());
        Assert.assertFalse(cmd.execute());
    }
   
    @Test
    public void testPhasesWhenPhasesNotSupported() throws IOException {
        Assume.assumeTrue(!isPhasesSupported());
        Changeset cs = createChangeset();
        Assert.assertNull(cs.phase());       
    }

    @Test
    public void testPhasesUnknownRev() throws IOException {
        Assume.assumeTrue(isPhasesSupported());

      createChangeset();
     
      Repository repo = getTestRepository();
     
      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
     
      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
     
      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
     

      try
      {
         repo.phases("abcdef124");
      }
      catch (ExecutionException e)
      {
      }
    }
}
TOP

Related Classes of com.aragost.javahg.commands.PhaseCommandTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.