-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into setup-sonarcloud
- Loading branch information
Showing
7 changed files
with
405 additions
and
13 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/ch/sbb/polarion/extension/pdf_exporter/util/VersionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ch.sbb.polarion.extension.pdf_exporter.util; | ||
|
||
import ch.sbb.polarion.extension.pdf_exporter.util.configuration.WeasyPrintStatusProvider; | ||
import lombok.experimental.UtilityClass; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
@UtilityClass | ||
public class VersionUtils { | ||
|
||
public static @Nullable String getLatestCompatibleVersionWeasyPrintService() { | ||
try (InputStream input = WeasyPrintStatusProvider.class.getClassLoader().getResourceAsStream("versions.properties")) { | ||
if (input == null) { | ||
return null; | ||
} | ||
|
||
Properties properties = new Properties(); | ||
properties.load(input); | ||
return properties.getProperty("weasyprint-service.version"); | ||
} catch (IOException e) { | ||
return null; | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...sbb/polarion/extension/pdf_exporter/util/configuration/WeasyPrintProbeStatusProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ch.sbb.polarion.extension.pdf_exporter.util.configuration; | ||
|
||
import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus; | ||
import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider; | ||
import ch.sbb.polarion.extension.generic.configuration.Status; | ||
import ch.sbb.polarion.extension.generic.util.Discoverable; | ||
import ch.sbb.polarion.extension.pdf_exporter.converter.HtmlToPdfConverter; | ||
import ch.sbb.polarion.extension.pdf_exporter.rest.model.conversion.Orientation; | ||
import ch.sbb.polarion.extension.pdf_exporter.rest.model.conversion.PaperSize; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Discoverable | ||
public class WeasyPrintProbeStatusProvider extends ConfigurationStatusProvider { | ||
|
||
private static final String WEASY_PRINT_SERVICE_TEST_CONVERSION = "WeasyPrint Service: WeasyPrint probe"; | ||
|
||
private final HtmlToPdfConverter htmlToPdfConverter; | ||
|
||
public WeasyPrintProbeStatusProvider() { | ||
this.htmlToPdfConverter = new HtmlToPdfConverter(); | ||
} | ||
|
||
public WeasyPrintProbeStatusProvider(HtmlToPdfConverter htmlToPdfConverter) { | ||
this.htmlToPdfConverter = htmlToPdfConverter; | ||
} | ||
|
||
@Override | ||
public @NotNull ConfigurationStatus getStatus(@NotNull Context context) { | ||
try { | ||
htmlToPdfConverter.convert("<html><body>test html</body></html>", Orientation.PORTRAIT, PaperSize.A4); | ||
|
||
return new ConfigurationStatus(WEASY_PRINT_SERVICE_TEST_CONVERSION, Status.OK); | ||
} catch (Exception e) { | ||
return new ConfigurationStatus(WEASY_PRINT_SERVICE_TEST_CONVERSION, Status.ERROR, e.getMessage()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
.../java/ch/sbb/polarion/extension/pdf_exporter/weasyprint/service/model/WeasyPrintInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
weasyprint-service.version=62.4.6 |
43 changes: 43 additions & 0 deletions
43
...polarion/extension/pdf_exporter/util/configuration/WeasyPrintProbeStatusProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ch.sbb.polarion.extension.pdf_exporter.util.configuration; | ||
|
||
import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus; | ||
import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider; | ||
import ch.sbb.polarion.extension.generic.configuration.Status; | ||
import ch.sbb.polarion.extension.pdf_exporter.converter.HtmlToPdfConverter; | ||
import ch.sbb.polarion.extension.pdf_exporter.rest.model.conversion.Orientation; | ||
import ch.sbb.polarion.extension.pdf_exporter.rest.model.conversion.PaperSize; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import javax.ws.rs.ProcessingException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith({MockitoExtension.class}) | ||
class WeasyPrintProbeStatusProviderTest { | ||
|
||
@Test | ||
void testHappyPath() { | ||
HtmlToPdfConverter htmlToPdfConverter = mock(HtmlToPdfConverter.class); | ||
when(htmlToPdfConverter.convert("<html><body>test html</body></html>", Orientation.PORTRAIT, PaperSize.A4)).thenReturn(new byte[0]); | ||
WeasyPrintProbeStatusProvider weasyPrintProbeStatusProvider = new WeasyPrintProbeStatusProvider(htmlToPdfConverter); | ||
|
||
ConfigurationStatus status = weasyPrintProbeStatusProvider.getStatus(ConfigurationStatusProvider.Context.builder().build()); | ||
|
||
assertEquals(new ConfigurationStatus("WeasyPrint Service: WeasyPrint probe", Status.OK), status); | ||
} | ||
|
||
@Test | ||
void testConnectionRefused() { | ||
HtmlToPdfConverter htmlToPdfConverter = mock(HtmlToPdfConverter.class); | ||
when(htmlToPdfConverter.convert("<html><body>test html</body></html>", Orientation.PORTRAIT, PaperSize.A4)).thenThrow(new ProcessingException("java.net.ConnectException: Connection refused")); | ||
WeasyPrintProbeStatusProvider weasyPrintProbeStatusProvider = new WeasyPrintProbeStatusProvider(htmlToPdfConverter); | ||
|
||
ConfigurationStatus status = weasyPrintProbeStatusProvider.getStatus(ConfigurationStatusProvider.Context.builder().build()); | ||
|
||
assertEquals(new ConfigurationStatus("WeasyPrint Service: WeasyPrint probe", Status.ERROR, "java.net.ConnectException: Connection refused"), status); | ||
} | ||
} |
Oops, something went wrong.