Skip to content

Commit

Permalink
Fix issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
zaplatynski committed Oct 10, 2016
1 parent d00a527 commit 7ecf639
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
18 changes: 18 additions & 0 deletions toolbar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,27 @@
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<testResources>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>com.github.zaplatynski</groupId>
Expand Down
4 changes: 2 additions & 2 deletions toolbar/src/main/fsm/module.vm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<public>
<name>logging-console-button</name>
<displayname>Logging Console</displayname>
<name>${project.artifactId}</name>
<displayname>${project.name}</displayname>
<class>de.marza.firstspirit.modules.logging.toolbar.LoggingViewToolbarItemsPlugin</class>
<resources>
#set($myself = $project.artifact)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
2 changes: 2 additions & 0 deletions toolbar/src/test/resources/moduleTest.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=${project.artifactId}
displayName=${project.name}

0 comments on commit 7ecf639

Please sign in to comment.