Skip to content

Commit

Permalink
Use RemotePlantumlGenerator if --plantuml-server-url option is specif…
Browse files Browse the repository at this point in the history
…ied.

Signed-off-by: Sjoerd Talsma <sjoerdtalsma@users.noreply.github.com>
  • Loading branch information
sjoerdtalsma committed Dec 23, 2022
1 parent a8cd276 commit 45411a0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Expand Up @@ -24,8 +24,10 @@
public interface PlantumlGenerator {

static PlantumlGenerator getPlantumlGenerator(Configuration configuration) {
// return new RemotePlantumlGenerator();
return new BuiltinPlantumlGenerator();
return configuration.plantumlServerUrl()
.map(RemotePlantumlGenerator::new)
.map(PlantumlGenerator.class::cast)
.orElseGet(BuiltinPlantumlGenerator::new);
}

void generatePlantumlDiagramFromSource(String plantumlSource, FileFormat format, OutputStream out) throws IOException;
Expand Down
Expand Up @@ -32,10 +32,10 @@

public class RemotePlantumlGenerator implements PlantumlGenerator {
private static final String DEFAULT_PLANTUML_BASE_URL = "https://www.plantuml.com/plantuml/";
private static final Transcoder TRANSCODER =
TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(), new CompressionZlib());

private final String baseUrl;
private final Transcoder transcoder =
TranscoderImpl.utf8(new AsciiEncoder(), new ArobaseStringCompressor(), new CompressionZlib());

public RemotePlantumlGenerator() {
this(null);
Expand Down Expand Up @@ -64,7 +64,7 @@ public void generatePlantumlDiagramFromSource(String plantumlSource, FileFormat
private String encodeDiagram(final String diagramSource) {
try {
// TODO internalize transcoder to be able to remove PlantUML dependency altogether.
return transcoder.encode(requireNonNull(diagramSource, "UML diagram source was <null>."));
return TRANSCODER.encode(requireNonNull(diagramSource, "UML diagram source was <null>."));
} catch (IOException ioe) {
throw new IllegalStateException("Error encoding diagram: " + ioe.getMessage(), ioe);
}
Expand Down
Expand Up @@ -30,8 +30,17 @@
import static java.util.Collections.singleton;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

public class DependencyDiagramTest {
private ImageConfig mockImages;
Expand All @@ -54,6 +63,7 @@ public void prepareMocksDiagramAndExclusions() {
public void verifyMocks() {
verify(mockConfig, atLeastOnce()).images();
verify(mockImages, atLeastOnce()).formats();
verify(mockConfig, atLeast(0)).plantumlServerUrl();
verify(mockConfig, atLeast(0)).excludedPackageDependencies();
verify(mockConfig, atLeast(0)).indentation();
verifyNoMoreInteractions(mockConfig, mockImages);
Expand Down
Expand Up @@ -71,6 +71,7 @@ public void setUp() {

@AfterEach
public void tearDown() {
verify(config, atLeast(0)).plantumlServerUrl();
verify(config, atLeast(0)).images();
verify(config, atLeast(0)).destinationDirectory();
verify(config, atLeast(0)).logger();
Expand Down
Expand Up @@ -52,10 +52,12 @@ public void verifyMocks() {
public void testEquals() {
PackageDiagram packageUml = new PackageDiagram(config, "a.b.c", randomString());
Namespace namespace = new Namespace(packageUml, "a.b.c", randomString());

assertThat(namespace.equals(namespace), is(true));
assertThat(namespace, is(equalTo(new Namespace(null, "a.b.c", randomString()))));
assertThat(namespace, is(equalTo(new Namespace(packageUml, "a.b.c", randomString()))));
assertThat(namespace, is(not(equalTo(new Namespace(packageUml, "A.B.C", randomString())))));
verify(config, atLeastOnce()).plantumlServerUrl();
}

}

0 comments on commit 45411a0

Please sign in to comment.