This repository has been archived by the owner on Mar 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # README.md # pom.xml
- Loading branch information
Showing
9 changed files
with
213 additions
and
58 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
language: java | ||
script: mvn -e clean install site | ||
jdk: | ||
- oraclejdk9 | ||
- oraclejdk8 | ||
- openjdk7 | ||
install: mvn -B -V -e package -DskipTests | ||
script: mvn -B -e verify site |
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 |
---|---|---|
@@ -1,34 +1,45 @@ | ||
properties([[ | ||
$class: 'BuildDiscarderProperty', | ||
strategy: [ | ||
$class: 'LogRotator', | ||
artifactDaysToKeepStr: '-1', | ||
artifactNumToKeepStr: '10', | ||
daysToKeepStr: '-1', | ||
numToKeepStr: '10' | ||
] | ||
]]) | ||
|
||
node { | ||
timestamps { | ||
stage('Pre Build Cleanup') { | ||
step($class: 'WsCleanup') | ||
} | ||
stage('Checkout') { | ||
checkout scm | ||
} | ||
pipeline { | ||
agent any | ||
options { | ||
buildDiscarder(logRotator(artifactDaysToKeepStr: '-1', artifactNumToKeepStr: '10', daysToKeepStr: '-1', numToKeepStr: '10')) | ||
timestamps() | ||
} | ||
tools { | ||
// withMaven ignores tools: https://issues.jenkins-ci.org/browse/JENKINS-43651 | ||
maven 'MVN-3' | ||
jdk 'JDK-9' | ||
} | ||
environment { | ||
MAVEN_ARGS = '-e -Dmaven.repo.local=.repository' | ||
} | ||
stages { | ||
stage('Build') { | ||
withMaven(maven: 'MVN-3', jdk: 'JDK-9', mavenLocalRepo: '.repository', options: [junitPublisher(disabled: true)]) { | ||
sh 'mvn -e install site -DskipTests' | ||
steps { | ||
withMaven(maven: 'MVN-3', jdk: 'JDK-9', publisherStrategy: 'EXPLICIT', options: [ | ||
artifactsPublisher(disabled: false), dependenciesFingerprintPublisher(disabled: false), openTasksPublisher(disabled: false) | ||
]) { | ||
sh "mvn ${MAVEN_ARGS} package -DskipTests" | ||
} | ||
} | ||
} | ||
stage('Verify') { | ||
steps { | ||
withMaven(maven: 'MVN-3', jdk: 'JDK-9', publisherStrategy: 'EXPLICIT', options: [junitPublisher(disabled: false)]) { | ||
sh "mvn ${MAVEN_ARGS} verify" | ||
} | ||
} | ||
} | ||
stage('Test') { | ||
withMaven(maven: 'MVN-3', jdk: 'JDK-9', mavenLocalRepo: '.repository', options: [openTasksPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true)]) { | ||
sh 'mvn -e test' | ||
stage('Build Docs') { | ||
steps { | ||
withMaven(maven: 'MVN-3', jdk: 'JDK-9', publisherStrategy: 'EXPLICIT') { | ||
sh "mvn ${MAVEN_ARGS} site" | ||
} | ||
} | ||
} | ||
stage('Post Build Cleanup') { | ||
step($class: 'WsCleanup') | ||
} | ||
post { | ||
always { | ||
cleanWs() | ||
} | ||
} | ||
} |
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
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
114 changes: 114 additions & 0 deletions
114
src/test/java/biz/gabrys/maven/plugins/directory/content/transform/XsltTransformerTest.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,114 @@ | ||
package biz.gabrys.maven.plugins.directory.content.transform; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doAnswer; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
|
||
import javax.xml.XMLConstants; | ||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerConfigurationException; | ||
import javax.xml.transform.TransformerException; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.stream.StreamResult; | ||
import javax.xml.transform.stream.StreamSource; | ||
|
||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.invocation.InvocationOnMock; | ||
import org.mockito.stubbing.Answer; | ||
|
||
public class XsltTransformerTest { | ||
|
||
@Test(expected = TransformException.class) | ||
public void transform_invalidData_throwsException() throws TransformerException, TransformException { | ||
final XsltTransformer xsltTransformer = spy(new XsltTransformer()); | ||
|
||
final TransformerFactory factory = mock(TransformerFactory.class); | ||
doReturn(factory).when(xsltTransformer).createTransformerFactory(); | ||
final Transformer transformer = mock(Transformer.class); | ||
doReturn(transformer).when(xsltTransformer).createTransformer(eq(factory), any(File.class)); | ||
|
||
doThrow(TransformerException.class).when(transformer).transform(any(StreamSource.class), any(StreamResult.class)); | ||
final String xml = "xml"; | ||
final File xslt = mock(File.class); | ||
|
||
xsltTransformer.transform(xml, xslt); | ||
} | ||
|
||
@Test | ||
public void transform_correctData_returnsTransformedDocument() throws TransformerException, TransformException { | ||
final XsltTransformer xsltTransformer = spy(new XsltTransformer()); | ||
|
||
final TransformerFactory factory = mock(TransformerFactory.class); | ||
doReturn(factory).when(xsltTransformer).createTransformerFactory(); | ||
final Transformer transformer = mock(Transformer.class); | ||
doReturn(transformer).when(xsltTransformer).createTransformer(eq(factory), any(File.class)); | ||
|
||
doAnswer(new Answer<Void>() { | ||
|
||
@Override | ||
public Void answer(final InvocationOnMock invocation) throws IOException { | ||
final StreamResult result = (StreamResult) invocation.getArgument(1); | ||
result.getWriter().append("document"); | ||
return null; | ||
} | ||
}).when(transformer).transform(any(StreamSource.class), any(StreamResult.class)); | ||
|
||
final String xml = "xml"; | ||
final File xslt = mock(File.class); | ||
|
||
final String result = xsltTransformer.transform(xml, xslt); | ||
|
||
assertThat(result).isEqualTo("document"); | ||
} | ||
|
||
@Test(expected = TransformException.class) | ||
public void createTransformer_sourceIsInvalid_throwsException() throws TransformerConfigurationException, TransformException { | ||
final TransformerFactory factory = mock(TransformerFactory.class); | ||
when(factory.newTransformer(any(StreamSource.class))).thenThrow(TransformerConfigurationException.class); | ||
|
||
final File xslt = mock(File.class); | ||
when(xslt.toURI()).thenReturn(URI.create("uri")); | ||
|
||
new XsltTransformer().createTransformer(factory, xslt); | ||
} | ||
|
||
@Test | ||
public void createTransformer_sourceIsValid_returnsTransformer() throws TransformerConfigurationException, TransformException { | ||
final TransformerFactory factory = mock(TransformerFactory.class); | ||
final Transformer transformer = mock(Transformer.class); | ||
when(factory.newTransformer(any(StreamSource.class))).thenReturn(transformer); | ||
|
||
final File xslt = mock(File.class); | ||
final String uri = "file.xslt"; | ||
when(xslt.toURI()).thenReturn(URI.create(uri)); | ||
|
||
final Transformer result = new XsltTransformer().createTransformer(factory, xslt); | ||
|
||
assertThat(result).isSameAs(transformer); | ||
final ArgumentCaptor<StreamSource> captor = ArgumentCaptor.forClass(StreamSource.class); | ||
verify(factory).newTransformer(captor.capture()); | ||
final StreamSource source = captor.getValue(); | ||
assertThat(source).isNotNull(); | ||
assertThat(source.getSystemId()).isEqualTo(uri); | ||
} | ||
|
||
@Test | ||
public void createTransformerFactory() throws TransformException { | ||
final TransformerFactory result = new XsltTransformer().createTransformerFactory(); | ||
|
||
assertThat(result).isNotNull(); | ||
assertThat(result.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)).isTrue(); | ||
} | ||
} |
Oops, something went wrong.