Skip to content

Commit

Permalink
VIC-660: CRUD Agencies
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanalicic committed May 17, 2022
1 parent b44da57 commit 1078f85
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 185 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.caritas.cob.agencyservice.api.repository.diocese;

import de.caritas.cob.agencyservice.api.repository.TenantAware;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -14,9 +13,6 @@
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;

/**
* Diocese entity.
Expand All @@ -27,9 +23,7 @@
@NoArgsConstructor
@Getter
@Setter
@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")})
@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")
public class Diocese implements TenantAware {
public class Diocese {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
Expand All @@ -47,6 +41,4 @@ public class Diocese implements TenantAware {
@Column(name = "update_date")
private LocalDateTime updateDate;

@Column(name = "tenant_id")
private Long tenantId;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package de.caritas.cob.agencyservice.api.repository.diocese;

import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
Expand All @@ -18,9 +16,4 @@ public interface DioceseRepository extends PagingAndSortingRepository<Diocese, L
* @return {@link Page} of {@link Diocese}
*/
Page<Diocese> findAll(Pageable pageable);


@Query("select a from Diocese as a where a.dioceseId = :var ")
Optional<Diocese> findById(Long var);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<include file="db/changelog/changeset/0005_agency_delete_flag/0005_changeSet.xml"/>
<include file="db/changelog/changeset/0006_agency_url_and_external_flag/0006_changeSet.xml"/>
<include file="db/changelog/changeset/0007_tenant_id/0007_changeSet.xml"/>
<include file="db/changelog/changeset/0008_tenant_id/0008_changeSet.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<include file="db/changelog/changeset/0005_agency_delete_flag/0005_changeSet.xml"/>
<include file="db/changelog/changeset/0006_agency_url_and_external_flag/0006_changeSet.xml"/>
<include file="db/changelog/changeset/0007_tenant_id/0007_changeSet.xml"/>
<include file="db/changelog/changeset/0008_tenant_id/0008_changeSet.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<include file="db/changelog/changeset/0005_agency_delete_flag/0005_changeSet.xml"/>
<include file="db/changelog/changeset/0006_agency_url_and_external_flag/0006_changeSet.xml"/>
<include file="db/changelog/changeset/0007_tenant_id/0007_changeSet.xml"/>
<include file="db/changelog/changeset/0008_tenant_id/0008_changeSet.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<include file="db/changelog/changeset/0005_agency_delete_flag/0005_changeSet.xml"/>
<include file="db/changelog/changeset/0006_agency_url_and_external_flag/0006_changeSet.xml"/>
<include file="db/changelog/changeset/0007_tenant_id/0007_changeSet.xml"/>
<include file="db/changelog/changeset/0008_tenant_id/0008_changeSet.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<changeSet author="aalicic" id="tenantIdRemoveDiocese">
<sqlFile path="db/changelog/changeset/0008_tenant_id_remove/tenant_id.sql" stripComments="true"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `agencyservice`.`diocese`
DROP COLUMN `tenant_id`;
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package de.caritas.cob.agencyservice.api.admin.service;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import de.caritas.cob.agencyservice.AgencyServiceApplication;
import de.caritas.cob.agencyservice.api.model.DioceseResponseDTO;
import de.caritas.cob.agencyservice.api.model.PaginationLinks;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -19,42 +23,58 @@
@SpringBootTest(classes = AgencyServiceApplication.class)
@TestPropertySource(properties = "spring.profiles.active=testing")
@AutoConfigureTestDatabase(replace = Replace.ANY)
public class DioceseAdminServiceIT extends DioceseAdminServiceITBase {
public class DioceseAdminServiceIT {

@Autowired
protected DioceseAdminService dioceseAdminService;

@Test
public void findAllDioceses_Should_returnOneResult_When_perPageIsSetToOne() {
super.findAllDioceses_Should_returnOneResult_When_perPageIsSetToOne();
List<DioceseResponseDTO> dioceses = this.dioceseAdminService
.findAllDioceses(0, 1)
.getEmbedded();

assertThat(dioceses, hasSize(1));
}

@Test
public void findAllDioceses_Should_returnOneResult_When_perPageIsSetToOneAndPageIsSetToOne() {
super.findAllDioceses_Should_returnOneResult_When_perPageIsSetToOneAndPageIsSetToOne();
List<DioceseResponseDTO> dioceses = this.dioceseAdminService
.findAllDioceses(1, 1)
.getEmbedded();

assertThat(dioceses, hasSize(1));
}

@Test
public void findAllDioceses_Should_returnOneResult_When_paginationParamsAreZero() {
super.findAllDioceses_Should_returnOneResult_When_paginationParamsAreZero();
}
List<DioceseResponseDTO> dioceses = this.dioceseAdminService
.findAllDioceses(0, 0)
.getEmbedded();

@Test
public void findAllDioceses_Should_returnOneResult_When_paginationParamsAreNegative() {
super.findAllDioceses_Should_returnOneResult_When_paginationParamsAreNegative();
assertThat(dioceses, hasSize(1));
}

@Test
public void findAllDioceses_Should_returnPaginatedEntities_When_paginationParamsAreSplitted() {
List<DioceseResponseDTO> firstPage = this.dioceseAdminService
.findAllDioceses(0, 20)
.getEmbedded();
List<DioceseResponseDTO> secondPage = this.dioceseAdminService
.findAllDioceses(2, 20)
public void findAllDioceses_Should_returnOneResult_When_paginationParamsAreNegative() {
List<DioceseResponseDTO> dioceses = this.dioceseAdminService
.findAllDioceses(-100, -1000)
.getEmbedded();
assertThat(firstPage, hasSize(20));
assertThat(secondPage, hasSize(9));

assertThat(dioceses, hasSize(1));
}

@Test
public void buildAgencyAdminSearchResult_Should_haveExpectedLinks_When_AllParamsAreProvided() {
super.buildAgencyAdminSearchResult_Should_haveExpectedLinks_When_AllParamsAreProvided();
PaginationLinks paginationLinks = this.dioceseAdminService
.findAllDioceses(1, 20).getLinks();

assertThat(paginationLinks.getSelf(), notNullValue());
assertThat(paginationLinks.getSelf().getHref(),
endsWith("/agencyadmin/dioceses?page=1&perPage=20"));
assertThat(paginationLinks.getPrevious(), nullValue());
assertThat(paginationLinks.getNext(), notNullValue());
assertThat(paginationLinks.getNext().getHref(),
endsWith("/agencyadmin/dioceses?page=2&perPage=20"));
}
}

This file was deleted.

This file was deleted.

0 comments on commit 1078f85

Please sign in to comment.