diff --git a/toolbar/pom.xml b/toolbar/pom.xml index fe2fab9..990a484 100644 --- a/toolbar/pom.xml +++ b/toolbar/pom.xml @@ -29,9 +29,27 @@ ${project.parent.version} + + commons-io + commons-io + 2.4 + test + + + + + + src/test/resources + + **/*.properties + + true + + + com.github.zaplatynski diff --git a/toolbar/src/main/fsm/module.vm b/toolbar/src/main/fsm/module.vm index 3027df5..f1fcae2 100644 --- a/toolbar/src/main/fsm/module.vm +++ b/toolbar/src/main/fsm/module.vm @@ -1,6 +1,6 @@ - logging-console-button - Logging Console + ${project.artifactId} + ${project.name} de.marza.firstspirit.modules.logging.toolbar.LoggingViewToolbarItemsPlugin #set($myself = $project.artifact) diff --git a/toolbar/src/test/java/de/marza/firstspirit/modules/logging/toolbar/ModuleXmlTest.java b/toolbar/src/test/java/de/marza/firstspirit/modules/logging/toolbar/ModuleXmlTest.java new file mode 100644 index 0000000..06c4a9a --- /dev/null +++ b/toolbar/src/test/java/de/marza/firstspirit/modules/logging/toolbar/ModuleXmlTest.java @@ -0,0 +1,112 @@ + +package de.marza.firstspirit.modules.logging.toolbar; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ErrorCollector; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.util.Properties; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasXPath; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; +import static org.junit.Assume.assumeThat; + + +/** + * The type Module xml test. + */ +public class ModuleXmlTest { + + private static Node moduleXML; + private static Properties pomProperties; + + /** + * The Errors. + */ + @Rule + public ErrorCollector errors = new ErrorCollector(); + + /** + * Sets up before. + * + * @throws Exception the exception + */ + @BeforeClass + public static void setUpBefore() throws Exception { + final File file = new File("target/module.xml"); + final String content = FileUtils.readFileToString(file); + moduleXML = createXMLfromString(content); + + pomProperties = new Properties(); + pomProperties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("moduleTest.properties")); + } + + private static Node createXMLfromString(final String xmlString) throws Exception { + return DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .parse(new ByteArrayInputStream(xmlString.getBytes())) + .getDocumentElement(); + } + + + /** + * Test if display name is equal to pom name. + * + * @throws Exception the exception + */ + @Test + public void testIfDisplayNameIsEqualToPomName() throws Exception { + final String expectedName = pomProperties.getProperty("displayName"); + assertThat("Expect a specific value", moduleXML, hasXPath("/public/displayname", equalTo + (expectedName))); + } + + /** + * Test if name is equal tobasicworkflows. + * + * @throws Exception the exception + */ + @Test + public void testIfNameIsEqualTobasicworkflows() throws Exception { + final String expectedName = pomProperties.getProperty("name"); + assertThat("Expect a specific value", moduleXML, hasXPath("/public/name", equalTo + (expectedName))); + } + + /** + * Test all classes. + * + * @throws Exception the exception + */ + @Test + public void testAllClasses() throws Exception { + final XPath xPath = XPathFactory.newInstance().newXPath(); + final NodeList nodes = (NodeList) xPath.evaluate("//class", moduleXML, XPathConstants.NODESET); + assumeThat(nodes, is(notNullValue())); + System.out.println("Number of classes: " + nodes.getLength()); + for (int i = 0; i < nodes.getLength(); ++i) { + final Node clazz = nodes.item(i); + System.out.println("Check if '" + clazz.getTextContent() + "' is existent ..."); + try { + Class.forName(clazz.getTextContent()); + } catch (final Exception e) { + errors.addError(e); + } + } + } +} diff --git a/toolbar/src/test/resources/moduleTest.properties b/toolbar/src/test/resources/moduleTest.properties new file mode 100644 index 0000000..881a172 --- /dev/null +++ b/toolbar/src/test/resources/moduleTest.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +displayName=${project.name} \ No newline at end of file