Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update IT tests and small bug fixes (#5)
Browse files Browse the repository at this point in the history
Update IT tests and small bug fixes
haiphucnguyen authored Nov 17, 2024
1 parent a275ebf commit 5cf917d
Showing 21 changed files with 52 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -24,9 +24,11 @@ public class FsObject extends AbstractAuditingEntity<Long> implements Serializab
@Column(name = "description", length = 4000)
private String description;

@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "descendant", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<FsObjectPath> ancestors = new HashSet<>();

@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "ancestor", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<FsObjectPath> descendants = new HashSet<>();
}
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.List;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "fw_workflow")
@@ -19,6 +20,7 @@ public class Workflow {
private String name;
private String description;

@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "workflow")
private List<WorkflowState> states;
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/** A Authority. */
@@ -45,9 +46,11 @@ public class Authority implements Serializable {
@Column(name = "description")
private String description;

@EqualsAndHashCode.Exclude
@ManyToMany(mappedBy = "authorities")
private Set<User> users;

@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "authority", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<AuthorityResourcePermission> authorityResourcePermissions;

Original file line number Diff line number Diff line change
@@ -24,10 +24,12 @@ public class AuthorityResourcePermission {
@Id
private Permission permission;

@EqualsAndHashCode.Exclude
@ManyToOne
@JoinColumn(name = "authority_name", insertable = false, updatable = false)
private Authority authority;

@EqualsAndHashCode.Exclude
@ManyToOne
@JoinColumn(name = "resource_name", insertable = false, updatable = false)
private Resource resource;
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ public class Organization {

private String description;

@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "organization")
private Set<Team> teams;
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ public class Resource {
@Column(name = "description", length = 256)
private String description;

@EqualsAndHashCode.Exclude
@OneToMany(mappedBy = "resource", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<AuthorityResourcePermission> authorityResourcePermissions = new HashSet<>();
}
Original file line number Diff line number Diff line change
@@ -34,9 +34,11 @@ public class Team {
private String description;

@ManyToOne
@EqualsAndHashCode.Exclude
@JoinColumn(name = "organization_id")
private Organization organization;

@ManyToMany(mappedBy = "teams")
@EqualsAndHashCode.Exclude
private Set<User> users = new HashSet<>();
}
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@ public class User extends AbstractAuditingEntity<Long> implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Include
private Long id;

@@ -73,13 +72,6 @@ public class User extends AbstractAuditingEntity<Long> implements Serializable {
@JoinColumn(name = "manager_id")
private User manager;

@ManyToMany
@JoinTable(
name = "fw_user_team",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "team_id"))
private Set<Team> teams;

@Size(max = 20)
@Column(name = "activation_key", length = 20)
@JsonIgnore
@@ -115,6 +107,16 @@ public class User extends AbstractAuditingEntity<Long> implements Serializable {
private LocalDateTime lastLoginTime;

@JsonIgnore
@EqualsAndHashCode.Exclude
@ManyToMany
@JoinTable(
name = "fw_user_team",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "team_id"))
private Set<Team> teams;

@JsonIgnore
@EqualsAndHashCode.Exclude
@ManyToMany
@JoinTable(
name = "fw_user_authority",
Original file line number Diff line number Diff line change
@@ -19,9 +19,6 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat

String USERS_BY_EMAIL_CACHE = "usersByEmail";

@Query("SELECT u FROM User u LEFT JOIN FETCH u.teams WHERE u.id = :userId")
Optional<User> findByIdWithTeams(@Param("userId") Long userId);

Optional<User> findOneByActivationKey(String activationKey);

List<User> findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefore(
Original file line number Diff line number Diff line change
@@ -129,14 +129,12 @@ public void addUsersToAuthority(List<Long> userIds, String authorityName) {

@Transactional
public void removeUserFromAuthority(Long userId, String authorityName) {
// Find the user
User user =
userRepository
.findById(userId)
.orElseThrow(
() -> new IllegalArgumentException("User not found: " + userId));

// Find the authority
Authority authority =
authorityRepository
.findById(authorityName)
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TeamService {

private final TeamRepository teamRepository;
@@ -74,10 +75,9 @@ public void deleteTeams(List<Long> ids) {
teamRepository.deleteAllByIdInBatch(ids);
}

public Team findTeamById(Long id) {
return teamRepository
.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Team not found with id: " + id));
@Transactional(readOnly = true)
public Optional<TeamDTO> findTeamById(Long id) {
return teamRepository.findById(id).map(teamMapper::toDto);
}

@Transactional(readOnly = true)
@@ -96,7 +96,6 @@ public List<UserDTO> findUsersNotInTeam(String searchTerm, Long teamId, Pageable
return userMapper.toDtos(teamRepository.findUsersNotInTeam(searchTerm, teamId, pageable));
}

@Transactional
public void addUsersToTeam(List<Long> userIds, Long teamId) {
// Fetch the authority entity
Team team =
@@ -117,14 +116,12 @@ public void addUsersToTeam(List<Long> userIds, Long teamId) {

@Transactional
public void removeUserFromTeam(Long userId, Long teamId) {
// Find the user
User user =
userRepository
.findByIdWithTeams(userId)
.findById(userId)
.orElseThrow(
() -> new IllegalArgumentException("User not found: " + userId));

// Find the team
Team team =
teamRepository
.findById(teamId)
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
import io.flexwork.db.service.LiquibaseService;
import io.flexwork.modules.usermanagement.domain.Tenant;
import io.flexwork.modules.usermanagement.repository.TenantRepository;
import jakarta.transaction.Transactional;
import java.util.Optional;
import java.util.Random;
import java.util.UUID;
@@ -15,8 +14,10 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TenantService {

private static final Logger LOG = LoggerFactory.getLogger(TenantService.class);
@@ -35,7 +36,6 @@ public TenantService(TenantRepository tenantRepository, LiquibaseService liquiba
* @return the tenant realm
*/
@SneakyThrows
@Transactional
public Tenant registerNewTenant(Tenant tenant) {
LOG.info("Registering new tenant: {}", tenant);

@@ -64,6 +64,7 @@ public Tenant registerNewTenant(Tenant tenant) {
return tenant;
}

@Transactional(readOnly = true)
public Tenant getDefaultTenant() {
return tenantRepository
.findByNameIgnoreCase(DEFAULT_TENANT)
Original file line number Diff line number Diff line change
@@ -15,5 +15,5 @@ public class TeamDTO {
private String slogan;
private String description;
private Long organizationId;
private Long memberCount;
private Long usersCount;
}
Original file line number Diff line number Diff line change
@@ -111,9 +111,11 @@ public ResponseEntity<Void> deleteTeams(@RequestBody List<Long> ids) {

// Find a team by ID
@GetMapping("/{id}")
public ResponseEntity<Team> findTeamById(@PathVariable Long id) {
Team team = teamService.findTeamById(id);
return ResponseEntity.ok(team);
public ResponseEntity<TeamDTO> findTeamById(@PathVariable Long id) {
return teamService
.findTeamById(id)
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.notFound().build());
}

// Find teams
@@ -132,12 +134,7 @@ public ResponseEntity<Page<UserDTO>> findUsersByTeamId(
@GetMapping("/users/{userId}")
public ResponseEntity<List<TeamDTO>> getTeamsByUserId(@PathVariable Long userId) {
List<TeamDTO> teams = teamService.findAllTeamsByUserId(userId);

if (teams.isEmpty()) {
return ResponseEntity.noContent().build();
}

return ResponseEntity.ok(teams);
return (teams.isEmpty()) ? ResponseEntity.noContent().build() : ResponseEntity.ok(teams);
}

@PostMapping("/{teamId}/add-users")
3 changes: 3 additions & 0 deletions server/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
@@ -114,6 +114,9 @@ spring:
hibernate.order_updates: true
hibernate.query.fail_on_pagination_over_collection_fetch: true
hibernate.query.in_clause_parameter_padding: true
# hibernate.show_sql: true
# hibernate.format_sql: true
# hibernate.use_sql_comments: true
hibernate:
ddl-auto: none
naming:
9 changes: 0 additions & 9 deletions server/src/test/java/io/flexwork/IntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.flexwork;

import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;

import io.flexwork.config.AsyncSyncConfiguration;
import io.flexwork.config.EmbeddedSQL;
import io.flexwork.config.FlexworkProperties;
@@ -12,8 +10,6 @@
import java.lang.annotation.Target;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlGroup;

/** Base composite annotation for integration tests. */
@Target(ElementType.TYPE)
@@ -22,9 +18,4 @@
classes = {FlexworkApp.class, JacksonConfiguration.class, AsyncSyncConfiguration.class})
@EnableConfigurationProperties({FlexworkProperties.class})
@EmbeddedSQL
@SqlGroup({
@Sql("/sql/users-management.sql"),
@Sql("/sql/accounts.sql"),
@Sql(value = "/sql/cleanup.sql", executionPhase = AFTER_TEST_METHOD)
})
public @interface IntegrationTest {}
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
import io.flexwork.modules.crm.domain.Account;
import io.flexwork.modules.crm.repository.AccountRepository;
import io.flexwork.modules.crm.service.dto.AccountDTO;
import io.flexwork.modules.crm.service.mapper.AccountMapper;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,13 +14,11 @@
public class AccountServiceIT {

@Autowired private AccountService accountService;

@Autowired private AccountMapper accountMapper;
@Autowired private AccountRepository accountRepository;

@Test
public void testUpdatedAccount() {
Account savedAccount = accountRepository.findByName("account_1").orElseThrow();
Account savedAccount = accountRepository.findByName("Acme Corporation").orElseThrow();
AccountDTO accountDTO =
AccountDTO.builder()
.id(savedAccount.getId())
@@ -38,7 +35,7 @@ public void testUpdatedAccount() {
() -> assertEquals("account_type2", returnedUpdateAccount.getType()),
() -> assertEquals("industry2", returnedUpdateAccount.getIndustry()),
() -> assertEquals("status2", returnedUpdateAccount.getStatus()),
() -> assertNull(savedAccount.getAssignedToUser()));
() -> assertNotNull(savedAccount.getAssignedToUser()));
}

@Test
48 changes: 0 additions & 48 deletions server/src/test/resources/sql/accounts.sql

This file was deleted.

11 changes: 0 additions & 11 deletions server/src/test/resources/sql/cleanup.sql

This file was deleted.

81 changes: 0 additions & 81 deletions server/src/test/resources/sql/users-management.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@
</changeSet>

<changeSet author="flexapp"
id="00000000000000:02-table-for-tests" context="test">
id="00000000000000:02-table-for-tests">
<createTable tableName="fw_date_time_wrapper">
<column name="id" type="BIGINT">
<constraints primaryKey="true"
@@ -207,15 +207,15 @@
</changeSet>

<changeSet author="flexapp"
id="00000000000000:03-insert-default-authority-data" context="!test">
id="00000000000000:03-insert-default-authority-data">
<loadData
file="config/liquibase/tenant/data/fw_authority.csv" separator=";"
tableName="fw_authority" usePreparedStatements="true">
<column name="name" type="string" />
</loadData>
</changeSet>
<changeSet author="flexapp"
id="00000000000000:04-insert-default-user-data" context="!test">
id="00000000000000:04-insert-default-user-data">
<loadData file="config/liquibase/tenant/data/fw_user.csv"
separator=";" tableName="fw_user" usePreparedStatements="true">
<column name="id" type="NUMERIC" />
@@ -245,8 +245,7 @@
</loadData>
</changeSet>
<changeSet author="flexapp"
id="00000000000000:05-insert-default-user-authority-data"
context="!test">
id="00000000000000:05-insert-default-user-authority-data">
<loadData
file="config/liquibase/tenant/data/fw_user_authority.csv"
separator=";" tableName="fw_user_authority"
@@ -265,7 +264,7 @@
</loadData>
</changeSet>
<changeSet author="flexapp"
id="00000000000000:06-insert-default-fw-team-data" context="!test">
id="00000000000000:06-insert-default-fw-team-data">
<loadData file="config/liquibase/tenant/data/fw_team.csv"
tableName="fw_team" separator=";">

@@ -278,8 +277,7 @@
</loadData>
</changeSet>
<changeSet author="flexapp"
id="00000000000000:07-insert-default-fw-user-team-data"
context="!test">
id="00000000000000:07-insert-default-fw-user-team-data">
<loadData
file="config/liquibase/tenant/data/fw_user_team.csv"
tableName="fw_user_team" separator=";">
@@ -288,16 +286,15 @@
</loadData>
</changeSet>
<changeSet author="flexapp"
id="00000000000000:08-insert-default-fw-resource" context="!test">
id="00000000000000:08-insert-default-fw-resource">
<loadData file="config/liquibase/tenant/data/fw_resource.csv"
separator=";" tableName="fw_resource" usePreparedStatements="true">
<column name="name" type="STRING" />
<column name="description" type="STRING" />
</loadData>
</changeSet>
<changeSet author="flexapp"
id="00000000000000:09-insert-default-fw-authority-resource-permission"
context="!test">
id="00000000000000:09-insert-default-fw-authority-resource-permission">
<loadData
file="config/liquibase/tenant/data/fw_authority_resource_permission.csv"
separator=";" tableName="fw_authority_resource_permission"

0 comments on commit 5cf917d

Please sign in to comment.