dhp-build tests upgraded to junit5
This commit is contained in:
parent
23668d4a6a
commit
c02718c10b
|
@ -1,6 +1,6 @@
|
||||||
package eu.dnetlib.maven.plugin.properties;
|
package eu.dnetlib.maven.plugin.properties;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static eu.dnetlib.maven.plugin.properties.GenerateOoziePropertiesMojo.PROPERTY_NAME_SANDBOX_NAME;
|
import static eu.dnetlib.maven.plugin.properties.GenerateOoziePropertiesMojo.PROPERTY_NAME_SANDBOX_NAME;
|
||||||
|
@ -9,14 +9,14 @@ import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertNull;
|
import static junit.framework.Assert.assertNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author mhorst
|
* @author mhorst, claudio.atzori
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GenerateOoziePropertiesMojoTest {
|
public class GenerateOoziePropertiesMojoTest {
|
||||||
|
|
||||||
private GenerateOoziePropertiesMojo mojo = new GenerateOoziePropertiesMojo();
|
private GenerateOoziePropertiesMojo mojo = new GenerateOoziePropertiesMojo();
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeEach
|
||||||
public void clearSystemProperties() {
|
public void clearSystemProperties() {
|
||||||
System.clearProperty(PROPERTY_NAME_SANDBOX_NAME);
|
System.clearProperty(PROPERTY_NAME_SANDBOX_NAME);
|
||||||
System.clearProperty(PROPERTY_NAME_WF_SOURCE_DIR);
|
System.clearProperty(PROPERTY_NAME_WF_SOURCE_DIR);
|
||||||
|
|
|
@ -2,11 +2,11 @@ package eu.dnetlib.maven.plugin.properties;
|
||||||
|
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.*;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
@ -15,9 +15,10 @@ import java.util.Properties;
|
||||||
import static eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.PROPERTY_PREFIX_ENV;
|
import static eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.PROPERTY_PREFIX_ENV;
|
||||||
import static junit.framework.Assert.*;
|
import static junit.framework.Assert.*;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.lenient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author mhorst
|
* @author mhorst, claudio.atzori
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
@ -28,12 +29,13 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
private WritePredefinedProjectProperties mojo;
|
private WritePredefinedProjectProperties mojo;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeEach
|
||||||
public void init(@TempDir File testFolder) {
|
public void init(@TempDir File testFolder) {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
mojo = new WritePredefinedProjectProperties();
|
mojo = new WritePredefinedProjectProperties();
|
||||||
mojo.outputFile = getPropertiesFileLocation(testFolder);
|
mojo.outputFile = getPropertiesFileLocation(testFolder);
|
||||||
mojo.project = mavenProject;
|
mojo.project = mavenProject;
|
||||||
doReturn(new Properties()).when(mavenProject).getProperties();
|
lenient().doReturn(new Properties()).when(mavenProject).getProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------- TESTS ---------------------------------------------
|
// ----------------------------------- TESTS ---------------------------------------------
|
||||||
|
@ -45,7 +47,7 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(mojo.outputFile.getParentFile());
|
||||||
assertEquals(0, storedProperties.size());
|
assertEquals(0, storedProperties.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,14 +65,14 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(mojo.outputFile.getParentFile());
|
||||||
assertEquals(1, storedProperties.size());
|
assertEquals(1, storedProperties.size());
|
||||||
assertTrue(storedProperties.containsKey(key));
|
assertTrue(storedProperties.containsKey(key));
|
||||||
assertEquals(value, storedProperties.getProperty(key));
|
assertEquals(value, storedProperties.getProperty(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=MojoExecutionException.class)
|
@Test()
|
||||||
public void testExecuteWithProjectPropertiesAndInvalidOutputFile(@TempDir File testFolder) throws Exception {
|
public void testExecuteWithProjectPropertiesAndInvalidOutputFile(@TempDir File testFolder) {
|
||||||
// given
|
// given
|
||||||
String key = "projectPropertyKey";
|
String key = "projectPropertyKey";
|
||||||
String value = "projectPropertyValue";
|
String value = "projectPropertyValue";
|
||||||
|
@ -80,11 +82,11 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
mojo.outputFile = testFolder;
|
mojo.outputFile = testFolder;
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
mojo.execute();
|
Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteWithProjectPropertiesExclusion() throws Exception {
|
public void testExecuteWithProjectPropertiesExclusion(@TempDir File testFolder) throws Exception {
|
||||||
// given
|
// given
|
||||||
String key = "projectPropertyKey";
|
String key = "projectPropertyKey";
|
||||||
String value = "projectPropertyValue";
|
String value = "projectPropertyValue";
|
||||||
|
@ -101,14 +103,14 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(testFolder);
|
||||||
assertEquals(1, storedProperties.size());
|
assertEquals(1, storedProperties.size());
|
||||||
assertTrue(storedProperties.containsKey(key));
|
assertTrue(storedProperties.containsKey(key));
|
||||||
assertEquals(value, storedProperties.getProperty(key));
|
assertEquals(value, storedProperties.getProperty(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteWithProjectPropertiesInclusion() throws Exception {
|
public void testExecuteWithProjectPropertiesInclusion(@TempDir File testFolder) throws Exception {
|
||||||
// given
|
// given
|
||||||
String key = "projectPropertyKey";
|
String key = "projectPropertyKey";
|
||||||
String value = "projectPropertyValue";
|
String value = "projectPropertyValue";
|
||||||
|
@ -125,7 +127,7 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(testFolder);
|
||||||
assertEquals(1, storedProperties.size());
|
assertEquals(1, storedProperties.size());
|
||||||
assertTrue(storedProperties.containsKey(includedKey));
|
assertTrue(storedProperties.containsKey(includedKey));
|
||||||
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
||||||
|
@ -155,14 +157,14 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(testFolder);
|
||||||
assertEquals(1, storedProperties.size());
|
assertEquals(1, storedProperties.size());
|
||||||
assertTrue(storedProperties.containsKey(includedKey));
|
assertTrue(storedProperties.containsKey(includedKey));
|
||||||
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteIncludingPropertyKeysFromClasspathResource() throws Exception {
|
public void testExecuteIncludingPropertyKeysFromClasspathResource(@TempDir File testFolder) throws Exception {
|
||||||
// given
|
// given
|
||||||
String key = "projectPropertyKey";
|
String key = "projectPropertyKey";
|
||||||
String value = "projectPropertyValue";
|
String value = "projectPropertyValue";
|
||||||
|
@ -180,14 +182,14 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(testFolder);
|
||||||
assertEquals(1, storedProperties.size());
|
assertEquals(1, storedProperties.size());
|
||||||
assertTrue(storedProperties.containsKey(includedKey));
|
assertTrue(storedProperties.containsKey(includedKey));
|
||||||
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=MojoExecutionException.class)
|
@Test
|
||||||
public void testExecuteIncludingPropertyKeysFromBlankLocation() throws Exception {
|
public void testExecuteIncludingPropertyKeysFromBlankLocation() {
|
||||||
// given
|
// given
|
||||||
String key = "projectPropertyKey";
|
String key = "projectPropertyKey";
|
||||||
String value = "projectPropertyValue";
|
String value = "projectPropertyValue";
|
||||||
|
@ -201,7 +203,7 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
mojo.setIncludePropertyKeysFromFiles(new String[] {""});
|
mojo.setIncludePropertyKeysFromFiles(new String[] {""});
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
mojo.execute();
|
Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -228,13 +230,13 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(testFolder);
|
||||||
assertEquals(1, storedProperties.size());
|
assertEquals(1, storedProperties.size());
|
||||||
assertTrue(storedProperties.containsKey(includedKey));
|
assertTrue(storedProperties.containsKey(includedKey));
|
||||||
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
assertEquals(includedValue, storedProperties.getProperty(includedKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=MojoExecutionException.class)
|
@Test
|
||||||
public void testExecuteIncludingPropertyKeysFromInvalidXmlFile(@TempDir File testFolder) throws Exception {
|
public void testExecuteIncludingPropertyKeysFromInvalidXmlFile(@TempDir File testFolder) throws Exception {
|
||||||
// given
|
// given
|
||||||
String key = "projectPropertyKey";
|
String key = "projectPropertyKey";
|
||||||
|
@ -254,11 +256,11 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
mojo.setIncludePropertyKeysFromFiles(new String[] {includedPropertiesFile.getAbsolutePath()});
|
mojo.setIncludePropertyKeysFromFiles(new String[] {includedPropertiesFile.getAbsolutePath()});
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
mojo.execute();
|
Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteWithQuietModeOn() throws Exception {
|
public void testExecuteWithQuietModeOn(@TempDir File testFolder) throws Exception {
|
||||||
// given
|
// given
|
||||||
mojo.setQuiet(true);
|
mojo.setQuiet(true);
|
||||||
mojo.setIncludePropertyKeysFromFiles(new String[] {"invalid location"});
|
mojo.setIncludePropertyKeysFromFiles(new String[] {"invalid location"});
|
||||||
|
@ -268,17 +270,17 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(testFolder);
|
||||||
assertEquals(0, storedProperties.size());
|
assertEquals(0, storedProperties.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=MojoExecutionException.class)
|
@Test
|
||||||
public void testExecuteIncludingPropertyKeysFromInvalidFile() throws Exception {
|
public void testExecuteIncludingPropertyKeysFromInvalidFile() {
|
||||||
// given
|
// given
|
||||||
mojo.setIncludePropertyKeysFromFiles(new String[] {"invalid location"});
|
mojo.setIncludePropertyKeysFromFiles(new String[] {"invalid location"});
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
mojo.execute();
|
Assertions.assertThrows(MojoExecutionException.class, () -> mojo.execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -299,7 +301,7 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteWithSystemProperties() throws Exception {
|
public void testExecuteWithSystemProperties(@TempDir File testFolder) throws Exception {
|
||||||
// given
|
// given
|
||||||
String key = "systemPropertyKey";
|
String key = "systemPropertyKey";
|
||||||
String value = "systemPropertyValue";
|
String value = "systemPropertyValue";
|
||||||
|
@ -311,7 +313,7 @@ public class WritePredefinedProjectPropertiesTest {
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
assertTrue(mojo.outputFile.exists());
|
assertTrue(mojo.outputFile.exists());
|
||||||
Properties storedProperties = getStoredProperties();
|
Properties storedProperties = getStoredProperties(testFolder);
|
||||||
assertTrue(storedProperties.size() > 0);
|
assertTrue(storedProperties.size() > 0);
|
||||||
assertTrue(storedProperties.containsKey(key));
|
assertTrue(storedProperties.containsKey(key));
|
||||||
assertEquals(value, storedProperties.getProperty(key));
|
assertEquals(value, storedProperties.getProperty(key));
|
||||||
|
|
Loading…
Reference in New Issue