Class CentralDogmaRule

java.lang.Object
org.junit.rules.ExternalResource
org.junit.rules.TemporaryFolder
com.linecorp.centraldogma.testing.junit4.CentralDogmaRule
All Implemented Interfaces:
TestRule

public class CentralDogmaRule extends TemporaryFolder
A JUnit Rule that starts an embedded Central Dogma server.

 > public class MyTest {
 >     @ClassRule
 >     public static final CentralDogmaRule rule = new CentralDogmaRule();
 >
 >     @Test
 >     public void test() throws Exception {
 >         CentralDogma dogma = rule.client();
 >         dogma.push(...).join();
 >         ...
 >     }
 > }
 
  • Constructor Details

    • CentralDogmaRule

      public CentralDogmaRule()
      Creates a new instance with TLS disabled.
    • CentralDogmaRule

      public CentralDogmaRule(boolean useTls)
      Creates a new instance.
  • Method Details

    • before

      protected void before() throws Throwable
      Starts an embedded server and calls scaffold(CentralDogma).
      Overrides:
      before in class TemporaryFolder
      Throws:
      Throwable
    • after

      protected void after()
      Stops the server and deletes the temporary files created by the server.
      Overrides:
      after in class TemporaryFolder
    • start

      public final void start()
      Creates a new server, configures it with configure(CentralDogmaBuilder) and starts the server. Note that you don't need to call this method if you did not stop the server with stop(), because the server is automatically started up by JUnit.
    • startAsync

      public final CompletableFuture<Void> startAsync()
      Creates a new server, configures it with configure(CentralDogmaBuilder), and starts the server asynchronously.
    • stop

      public final void stop()
      Stops the server and deletes the temporary files created by the server. Note that you don't usually need to call this method manually because the server is automatically stopped at the end by JUnit.
    • stopAsync

      public final CompletableFuture<Void> stopAsync()
      Stops the server and deletes the temporary files created by the server. Note that you don't usually need to call this method manually because the server is automatically stopped at the end by JUnit.
    • useTls

      public boolean useTls()
      Returns whether the server is running over TLS or not.
    • dogma

      public final CentralDogma dogma()
      Returns the server.
      Throws:
      IllegalStateException - if Central Dogma did not start yet
    • projectManager

      public ProjectManager projectManager()
      Returns the ProjectManager of the server.
      Throws:
      IllegalStateException - if Central Dogma did not start yet
    • mirroringService

      public final MirroringService mirroringService()
      Returns the MirroringService of the server.
      Throws:
      IllegalStateException - if Central Dogma did not start yet
    • client

      public final CentralDogma client()
      Returns the HTTP-based CentralDogma client.
      Throws:
      IllegalStateException - if Central Dogma did not start yet
    • legacyClient

      public final CentralDogma legacyClient()
      Returns the Thrift-based CentralDogma client.
      Throws:
      IllegalStateException - if Central Dogma did not start yet
    • httpClient

      public final WebClient httpClient()
      Returns the HTTP client.
      Throws:
      IllegalStateException - if Central Dogma did not start yet
    • serverAddress

      public final InetSocketAddress serverAddress()
      Returns the server address.
      Throws:
      IllegalStateException - if Central Dogma did not start yet
    • configure

      protected void configure(CentralDogmaBuilder builder)
      Override this method to configure the server.
    • configureClient

      protected void configureClient(ArmeriaCentralDogmaBuilder builder)
      Override this method to configure the HTTP-based CentralDogma client builder.
    • configureClient

      protected void configureClient(LegacyCentralDogmaBuilder builder)
      Override this method to configure the Thrift-based CentralDogma client builder.
    • configureHttpClient

      protected void configureHttpClient(WebClientBuilder builder)
      Override this method to configure the WebClient builder.
    • scaffold

      protected void scaffold(CentralDogma client)
      Override this method to perform the initial updates on the server, such as creating a repository and populating sample data.