Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Commit

Permalink
[UnitTest] Minimal UnitTest for quarkusio/quarkus#7102.
Browse files Browse the repository at this point in the history
Signed-off-by: Juri Berlanda <[email protected]>
  • Loading branch information
Juri Berlanda committed Jun 12, 2020
1 parent fddd39d commit c87c657
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 0 deletions.
88 changes: 88 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.duckdns.owly.bugs.quarkus</groupId>
<artifactId>quarkus-7102</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<quarkus.platform.version>1.5.1.Final</quarkus.platform.version>
<quarkus-plugin.version>${quarkus.platform.version}</quarkus-plugin.version>

<surefire-plugin.version>2.22.2</surefire-plugin.version>

<!-- Plugins -->
<compiler-plugin.version>3.8.1</compiler-plugin.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-universe-bom</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Database -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<!-- Test dependency -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>
43 changes: 43 additions & 0 deletions src/main/java/org/owly/duckdns/bugs/quarkus/entity/TestEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.owly.duckdns.bugs.quarkus.entity;

import io.quarkus.hibernate.orm.panache.PanacheEntity;

import javax.persistence.Entity;
import java.util.Objects;

@Entity
public class TestEntity extends PanacheEntity {
private String name;

public TestEntity() {
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String toString() {
return "TestEntity(name=" + this.getName() + ", id=" + super.id + ")";
}

public boolean equals(final Object other) {
return other instanceof TestEntity &&
super.equals(other) &&
Objects.equals(this.id, ((TestEntity) other).id) &&
Objects.equals(this.name, ((TestEntity) other).name);
}

public int hashCode() {
final int PRIME = 59;
int result = super.hashCode();
final String name = this.getName();
final Long id = this.id;
result = result * PRIME + (name == null ? 43 : name.hashCode());
result = result * PRIME + (id == null ? 43 : id.hashCode());
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.owly.duckdns.bugs.quarkus.repo;

import io.quarkus.hibernate.orm.panache.PanacheRepository;
import org.owly.duckdns.bugs.quarkus.entity.TestEntity;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class TestEntityRepo implements PanacheRepository<TestEntity> {
}
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
quarkus.hibernate-orm.database.generation=create
quarkus.datasource.db-kind=h2
quarkus.datasource.jdbc.url=jdbc:h2:mem:test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.owly.duckdns.bugs.quarkus.test;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.owly.duckdns.bugs.quarkus.entity.TestEntity;
import org.owly.duckdns.bugs.quarkus.repo.TestEntityRepo;

import javax.inject.Inject;
import javax.transaction.Transactional;

@QuarkusTest
public class TestEntityRepoTest {
@Inject
TestEntityRepo testEntityRepo;

@ParameterizedTest(name = "#{index} - Executing findAll() in between: {0}")
@ValueSource(booleans = {true, false})
public void testUpdate(boolean executeFindAll) {
// Create
TestEntity testEntity = new TestEntity();
testEntity.setName("Start");
create(testEntity);

// Call getAll
if (executeFindAll)
testEntityRepo.findAll().list();

// Update
update(testEntity.id);

// Compare
Assertions.assertEquals("Start Updated", testEntityRepo.findById(testEntity.id).getName());
}

@Transactional
void create(TestEntity testEntity) {
testEntityRepo.persist(testEntity);
}

@Transactional
void update(long id) {
TestEntity testEntity = testEntityRepo.findById(id);
testEntity.setName(testEntity.getName() + " Updated");
testEntityRepo.persist(testEntity);
}
}

0 comments on commit c87c657

Please sign in to comment.