test tags and more tests

master
Markus Kreth 7 years ago
parent b43b04e37e
commit 80d9fc8263
  1. 1
      .classpath
  2. 10
      pom.xml
  3. 4
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/ZonedDateTimeAttributeConverter.java
  4. 11
      src/test/java/de/kreth/vaadin/clubhelper/AllTests.java
  5. 12
      src/test/java/de/kreth/vaadin/clubhelper/FastTestsOnly.java
  6. 2
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessSpringTest.java
  7. 48
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/ZonedDateTimeAttributeConverterTest.java
  8. 2
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDataTest.java
  9. 3
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoRelativeTest.java
  10. 2
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoTest.java
  11. 4
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilterTest.java
  12. 43
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGroupValidatorTest.java
  13. 53
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ZonedDateTimeConverterTest.java

@ -32,6 +32,7 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>

@ -140,6 +140,11 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.seleniumhq.selenium</groupId> -->
@ -238,6 +243,11 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>

@ -10,7 +10,7 @@ import javax.persistence.Converter;
@Converter(autoApply = true)
public class ZonedDateTimeAttributeConverter
implements
AttributeConverter<ZonedDateTime, Date> {
AttributeConverter<ZonedDateTime, Date> {
@Override
public Date convertToDatabaseColumn(ZonedDateTime attribute) {
@ -20,7 +20,7 @@ public class ZonedDateTimeAttributeConverter
@Override
public ZonedDateTime convertToEntityAttribute(Date dbData) {
return ZonedDateTime.ofInstant(dbData.toInstant(),
ZoneId.from(dbData.toInstant()));
ZoneId.systemDefault());
}
}

@ -0,0 +1,11 @@
package de.kreth.vaadin.clubhelper;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
@SelectPackages("de.kreth.vaadin.clubhelper")
public class AllTests {
}

@ -0,0 +1,12 @@
package de.kreth.vaadin.clubhelper;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.ExcludeTags;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
@SelectPackages("de.kreth.vaadin.clubhelper")
@ExcludeTags("spring")
public class FastTestsOnly {
}

@ -14,6 +14,7 @@ import javax.persistence.TypedQuery;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,6 +30,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = TestConfiguration.class)
@Tag("spring")
class EventBusinessSpringTest {
private List<Person> persons;

@ -0,0 +1,48 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.business;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ZonedDateTimeAttributeConverterTest {
private ZonedDateTimeAttributeConverter converter;
@BeforeEach
void setUp() throws Exception {
this.converter = new ZonedDateTimeAttributeConverter();
}
@Test
void testZonedToDate() {
ZonedDateTime zonedDatetime = ZonedDateTime.of(2019, 4, 25, 21, 43, 13, 0, ZoneId.systemDefault());
Date actualDate = converter.convertToDatabaseColumn(zonedDatetime);
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(actualDate);
assertEquals(21, calendar.get(Calendar.HOUR_OF_DAY));
assertEquals(43, calendar.get(Calendar.MINUTE));
assertEquals(13, calendar.get(Calendar.SECOND));
assertEquals(0, calendar.get(Calendar.MILLISECOND));
}
@Test
void testDateToZoned() {
GregorianCalendar calendar = new GregorianCalendar();
ZonedDateTime zonedDateTime = converter.convertToEntityAttribute(calendar.getTime());
assertNotNull(zonedDateTime);
assertEquals(calendar.get(Calendar.HOUR_OF_DAY), zonedDateTime.get(ChronoField.HOUR_OF_DAY));
assertEquals(calendar.get(Calendar.MINUTE), zonedDateTime.get(ChronoField.MINUTE_OF_HOUR));
assertEquals(calendar.get(Calendar.SECOND), zonedDateTime.get(ChronoField.SECOND_OF_MINUTE));
assertEquals(calendar.get(Calendar.MILLISECOND), zonedDateTime.get(ChronoField.MILLI_OF_SECOND));
}
}

@ -12,6 +12,7 @@ import java.util.Set;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -25,6 +26,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration;
@SpringBootTest
@ContextConfiguration(classes = TestConfiguration.class)
@Tag("spring")
public class ClubEventDataTest {
@Autowired

@ -16,6 +16,7 @@ import org.hibernate.SessionFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -26,6 +27,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration;
@SpringBootTest
@ContextConfiguration(classes = TestConfiguration.class)
@Tag("spring")
@Disabled
public class PersonDaoRelativeTest {
@ -42,6 +44,7 @@ public class PersonDaoRelativeTest {
private SessionFactory sessionFactory;
private Person person1;
private Person person2;
@BeforeEach

@ -12,6 +12,7 @@ import javax.persistence.EntityManager;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -23,6 +24,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration;
@SpringBootTest
@ContextConfiguration(classes = TestConfiguration.class)
@Tag("spring")
public class PersonDaoTest {
@Autowired

@ -14,6 +14,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@ -29,10 +30,13 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration;
@SpringBootTest
@ContextConfiguration(classes = TestConfiguration.class)
@Tag("spring")
class PersonFilterTest {
private PersonFilter filter;
private List<Person> persons;
private final List<GroupDef> groups = setupData();
@Autowired

@ -0,0 +1,43 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.vaadin.data.ValidationResult;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
class PersonGroupValidatorTest {
private PersonGroupValidator validator;
private Person person;
@BeforeEach
void setUp() throws Exception {
validator = new PersonGroupValidator();
person = new Person();
}
@Test
void testError() {
ValidationResult result = validator.apply(person, null);
assertTrue(result.isError());
}
@Test
void testOk() {
GroupDef group = new GroupDef();
group.setPersongroups(new ArrayList<>());
person.add(group);
ValidationResult result = validator.apply(person, null);
assertFalse(result.isError());
}
}

@ -0,0 +1,53 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.vaadin.data.Result;
class ZonedDateTimeConverterTest {
private ZonedDateTimeConverter converter;
@BeforeEach
void setUp() throws Exception {
converter = new ZonedDateTimeConverter();
}
@Test
void testConvertToModelNull() {
Result<ZonedDateTime> result = converter.convertToModel(null, null);
assertNotNull(result);
assertFalse(result.isError());
assertNull(result.getOrThrow(msg -> new RuntimeException(msg)));
}
@Test
void testConvertToModel() {
LocalDate now = LocalDate.now();
Result<ZonedDateTime> result = converter.convertToModel(now, null);
assertNotNull(result);
assertFalse(result.isError());
ZonedDateTime actual = result.getOrThrow(msg -> new RuntimeException(msg));
assertEquals(0, actual.get(ChronoField.HOUR_OF_DAY));
assertEquals(0, actual.get(ChronoField.MINUTE_OF_DAY));
assertEquals(0, actual.get(ChronoField.SECOND_OF_MINUTE));
assertEquals(0, actual.get(ChronoField.MILLI_OF_SECOND));
}
@Test
void testConvertToPresentation() {
ZonedDateTime now = ZonedDateTime.now();
assertEquals(now.toLocalDate(), converter.convertToPresentation(now, null));
}
}
Loading…
Cancel
Save