Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧑‍💻 (org): Include test data for org service #166

Merged
merged 11 commits into from
Dec 16, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/backend-sonarqube-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
cache: maven

- name: mvn package
run: mvn -B verify --file backend/pom.xml
run: mvn -B clean verify --file backend/pom.xml

- name: Cache SonarQube packages
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# only build relevant service
- name: mvn package
run: mvn -B package --file backend/${{ matrix.service.directory }}/pom.xml
run: mvn -B clean package --file backend/${{ matrix.service.directory }}/pom.xml

- name: Extract metadata (tags, labels) for Docker
id: meta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package app.hopps.org.jpa;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.Arrays;
import java.util.List;

public record TreeSearchBommel(
Bommel bommel,
boolean cycleMark,
@JsonIgnore boolean cycleMark,
List<Long> cyclePath) {

public TreeSearchBommel(Bommel bommel, Boolean cycleMark, String cyclePath) {
this(bommel, cycleMark != null && cycleMark, parseCyclePath(cyclePath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ quarkus.banner.path=banner.txt
quarkus.flyway.migrate-at-start=true
quarkus.flyway.baseline-on-migrate=true
quarkus.flyway.clean-at-start=false
#
%test.quarkus.flyway.locations=db/migration,db/testdata
%dev.quarkus.flyway.locations=db/migration,db/testdata
########################################
# Keycloak/auth
########################################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
insert into Organization (type, id, slug, name, website, plz, city, street, number)
values
(0, 2, 'gruenes-herz-ev', 'Grünes Herz e.V.', 'https://gruenes-herz.de/', '27324', 'Schweringen', 'Am Lennestein', '110'),
(0, 3, 'kaeltekrieger', 'Eishockeyclub Kältekrieger e.V.', 'https://kaeltekrieger.de/', '89129', 'Langenau', 'August-Brust-Straße', '78'),
(0, 4, 'buehnefrei-ev', 'Theatervereine Bühnefrei e.V.', 'https://bühnefrei.de/', '33397', 'Rietberg', 'Dechant-Karthaus-Straße', '172');

insert into member
(id, email, firstName, lastName)
values
-- gruenes-herz-ev
(2, '[email protected]', 'Emanuel', 'Urban'),
(3, '[email protected]', 'Hartlieb', 'Reuter'),
(4, '[email protected]', 'Elgard', 'Nicklas'),
(5, '[email protected]', 'Gerald', 'Geiger'),
(6, '[email protected]', 'Jannick', 'Cao'),
(7, '[email protected]', 'Constance', 'Wendling'),
(8, '[email protected]', 'Florenz', 'Häfner'),
-- kaeltekrieger
(9, '[email protected]', 'Herlind', 'Kutscher'),
(10, '[email protected]', 'Annekathrin', 'Feldhof'),
(11, '[email protected]', 'Rosegunde', 'Wilhelmy'),
(12, '[email protected]', 'Eckhard', 'Weirich'),
(13, '[email protected]', 'Godo', 'Beckers'),
(14, '[email protected]', 'Klothilde', 'Püppel'),
-- buehnefrei-ev
(15, '[email protected]', 'Samantha', 'Adomeit'),
(16, '[email protected]', 'Margund', 'Linner'),
(17, '[email protected]', 'Birgit', 'Bork'),
(18, '[email protected]', 'Gunther', 'Kalb'),
(19, '[email protected]', 'Burckhard', 'Schlicker'),
(20, '[email protected]', 'Alix', 'Raff');

insert into Member_Verein (member_id, organizations_id)
values
-- gruenes-herz-ev
(2, 2),
(3, 2),
(4, 2),
(5, 2),
(6, 2),
(7, 2),
(8, 2),
-- kaeltekrieger
(9, 3),
(10, 3),
(11, 3),
(12, 3),
(13, 3),
(14, 3),
-- buehnefrei-ev
(15, 4),
(16, 4),
(17, 4),
(18, 4),
(19, 4),
(20, 4);

insert into Bommel (id, parent_id, name, emoji, responsibleMember_id)
values
-- gruenes-herz-ev (id=2)
(2, null, 'Grünes Herz e.V.', null, null),
(3, 2, 'Fundraising & Spenden', null, null),
(4, 2, 'Bildungs-Projekte', null, null),
(5, 2, 'Naturschutz-Projekte', null, null),
(6, 4, 'Schulvorträge', null, null),
(7, 4, 'Online Seminare', null, null),
(8, 6, 'Vortrag 1', null, null),
(9, 6, 'Vortrag 2', null, null),
(10, 5, 'Schutz eines Feuchte-Gebietes', null, null),
-- kaeltekrieger (id=3)
(11, null, 'Kältekrieger e.V.', null, null),
(12, 11, 'Verkauf', null, null),
(13, 11, 'Öffentlicher Lauf', null, null),
(14, 11, 'Mannschaften', null, null),
(15, 11, 'Stadion', null, null),
(16, 12, 'Kiosk', null, null),
(17, 12, 'Shop', null, null),
(18, 14, '1. Liga', null, null),
(19, 14, '2. Liga', null, null),
(20, 14, '3. Liga', null, null),
(21, 14, 'Jugend', null, null),
(22, 15, 'Eis Pflege', null, null),
-- buehnefrei-ev (id=4)
(23, null, 'Bühnefrei e.V.', null, null),
(24, 23, 'Kiosk', null, null),
(25, 23, 'Räumlichkeiten', null, null),
(26, 23, 'Workshops', null, null),
(27, 23, 'Projekte', null, null),
(28, 27, 'Der kleine Lord', null, null),
(29, 27, 'Das Hässliche Entlein', null, null),
(30, 27, 'König der Löwen', null, null)
;

update Organization
set rootBommel_id = 2
where id = 2;

update Organization
set rootBommel_id = 11
where id = 3;

update Organization
set rootBommel_id = 23
where id = 4;
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void shouldValidateUniqueness() throws Exception {
}

@Test
@DisplayName("should validate valid data")
@DisplayName("should invalidate non-unique slug")
void shouldInvalidateUniqueness() {

// given
Expand All @@ -117,6 +117,7 @@ void shouldInvalidateUniqueness() {
existingOrganization.setSlug("kegelclub-777");

QuarkusTransaction.begin();
organizationRepository.deleteAll();
organizationRepository.persist(existingOrganization);
QuarkusTransaction.commit();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package app.hopps.org.delegates;

import app.hopps.org.jpa.*;
import app.hopps.org.jpa.BommelRepository;
import app.hopps.org.jpa.Member;
import app.hopps.org.jpa.MemberRepository;
import app.hopps.org.jpa.Organization;
import app.hopps.org.jpa.OrganizationRepository;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize;

@QuarkusTest
Expand All @@ -31,8 +33,8 @@ class PersistOrganizationDelegateTests {
@BeforeEach
@Transactional
void cleanupDB() {
bommelRepository.deleteAll();
organizationRepository.deleteAll();
bommelRepository.deleteAll();
memberRepository.deleteAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.WebApplicationException;
import org.flywaydb.core.Flyway;
import org.instancio.Instancio;
Expand Down Expand Up @@ -35,9 +36,10 @@ class BommelTest {
Flyway flyway;

@BeforeEach
@Transactional
public void cleanDatabase() {
flyway.clean();
flyway.migrate();
orgRepo.deleteAll();
repo.deleteAll();
}

@Test
Expand Down Expand Up @@ -106,14 +108,23 @@ void getChildrenWithCycle() {
}

@Test
@TestTransaction
void simpleGetParentsTest() {
// Arrange
var existingBommels = resourceCreator.setupSimpleTree();
var expectedParentsList = List.of(existingBommels.get(1), existingBommels.getFirst());
flyway.clean();
flyway.migrate();

// bommel with id=2 is root
// id=4 is child of id=2
// id=7 is child of id=4

var expectedParentsList = List.of(
repo.findById(4L),
repo.findById(2L));

var child = repo.findById(7L);

// Act
List<TreeSearchBommel> treeSearchParents = repo.getParents(existingBommels.get(3));
List<TreeSearchBommel> treeSearchParents = repo.getParents(child);

// Assert
var actualParents = treeSearchParents.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package app.hopps.org.rest;

import app.hopps.org.jpa.BommelRepository;
import app.hopps.org.jpa.MemberRepository;
import app.hopps.org.jpa.Organization;
import app.hopps.org.jpa.OrganizationRepository;
import app.hopps.org.rest.model.NewOrganizationInput;
import app.hopps.org.rest.model.OrganizationInput;
import app.hopps.org.rest.model.OwnerInput;
Expand All @@ -17,10 +20,8 @@

import java.net.MalformedURLException;
import java.net.URI;
import java.util.Collections;

import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.*;

@QuarkusTest
Expand All @@ -30,6 +31,15 @@ class OrganizationResourceTests {
@Inject
Flyway flyway;

@Inject
OrganizationRepository organizationRepository;

@Inject
MemberRepository memberRepository;

@Inject
BommelRepository bommelRepository;

@BeforeEach
public void cleanDatabase() {
flyway.clean();
Expand Down Expand Up @@ -78,6 +88,12 @@ void shouldInvalidateVereinWithoutName() {

@Test
void shouldStartCreatingOrganization() throws MalformedURLException {
QuarkusTransaction.begin();
organizationRepository.deleteAll();
bommelRepository.deleteAll();
memberRepository.deleteAll();
QuarkusTransaction.commit();

OrganizationInput organizationInput = new OrganizationInput("Schützenverein", "schuetzenverein",
Organization.TYPE.EINGETRAGENER_VEREIN, URI.create("https://hopps.cloud").toURL(),
URI.create("https://hopps.cloud").toURL(), null);
Expand Down
Loading