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

test: add unit tests for Links and Share persistence classes #95

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
65315ca
test: add test for Share entity class
federicorispo Jul 11, 2023
dbde8db
test: add test for CollaborationLink entity class
federicorispo Jul 11, 2023
4d4c889
test: add test for Link entity class and add javadoc
federicorispo Jul 12, 2023
f502e5e
chore(format): reformat CollaborationLinkRepositoryEbean class
federicorispo Nov 6, 2023
d5e82e3
test: add UTs and javadoc for the CollaborationLinkRepositoryEbean class
federicorispo Nov 6, 2023
9f5a44d
chore(format): reformat LinkRepositoryEbean class
federicorispo Nov 11, 2023
55a1f99
test: add UTs and javadoc for the LinkRepositoryEbean class
federicorispo Nov 11, 2023
efa14c2
chore(format): reformat ShareRepository and ShareRepositoryEbean class
federicorispo Nov 11, 2023
a4542e8
test: add UTs and javadoc for the ShareRepositoryEbean class
federicorispo Nov 13, 2023
a953e7e
fix: add sonarqube suggestions and fix failing IT
federicorispo Feb 14, 2024
5e98125
fix: SearchBuilder contains the right mShares attributes
federicorispo Jan 14, 2025
41a263c
chore(javadoc): add javadoc for the Share class
federicorispo Jan 17, 2025
39987cd
chore(formatting): align javadoc and formatting code
federicorispo Jan 17, 2025
c3689af
doc: update OpenAPI YAML definition updating the preview endpoints
federicorispo Jan 17, 2025
d4519fa
test: in DatabaseMigration7 the db connection should be properly closed
federicorispo Jan 17, 2025
15a837d
chore: small fixes
federicorispo Jan 17, 2025
3a8cf12
test: in LinkTest add access-code assertions
federicorispo Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ core/.classpath
core/.project
core/.settings/


# JetBrains IDE
.idea/
*.iml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@

package com.zextras.carbonio.files.dal.dao.ebean;

import com.zextras.carbonio.files.Files;
import com.zextras.carbonio.files.Files.Db;
import com.zextras.carbonio.files.Files.Db.Tables;
import com.zextras.carbonio.files.dal.dao.ebean.ACL.SharePermission;
import io.ebean.annotation.WhenCreated;
import java.time.Instant;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* Represents an Ebean {@link CollaborationLink} entity that matches a record of the {@link
* Files.Db.Tables#COLLABORATION_LINK} table.
*
* <p>The collaboration link has properties mapped to the corresponding table columns:
*
* <ul>
* <li>{@code id}: The unique identifier of the link.
* <li>{@code nodeId}: The identifier of the associated node.
* <li>{@code invitationId}: The public identifier of the url link.
* <li>{@code createdAt}: The timestamp indicating when the link was created.
* <li>{@code permissions}: The permissions assigned to the link necessary to create the share
* between the user that clicked on the link and the related node.
* </ul>
*
* <p>The constructor should not care to check if the values in input are valid or not because these
* controls <strong>must</strong> be already done before calling the constructor.
*/
@Entity
@Table(name = Tables.COLLABORATION_LINK)
public class CollaborationLink {
Expand All @@ -29,41 +47,66 @@ public class CollaborationLink {
@Column(name = Db.CollaborationLink.INVITATION_ID, nullable = false, length = 8)
private String invitationId;

@WhenCreated
@Column(name = Db.CollaborationLink.CREATED_AT, nullable = false)
private Instant createdAt;

@Column(name = Db.CollaborationLink.PERMISSIONS, nullable = false)
private short permissions;

/**
* Creates a new {@link CollaborationLink} entity that can be saved in the database.
*
* @param linkId is a {@link UUID} representing the collaboration link identifier.
* @param nodeId is a {@link String} representing the {@link Node} identifier associated to the
* collaboration link.
* @param invitationId is a {@link String} of <code>8</code> alphanumeric characters representing
* the public identifier of the URL link.
* @param createdAt is an {@link Instant} of the link creation timestamp.
* @param permissions is a <code>short</code> representing the permission necessary to create the
* {@link Share} between the user that used the link and the related node.
*/
public CollaborationLink(
UUID linkId,
String nodeId,
String invitationId,
short permissions
) {
UUID linkId, String nodeId, String invitationId, Instant createdAt, short permissions) {
this.id = linkId;
this.nodeId = nodeId;
this.invitationId = invitationId;
this.createdAt = createdAt;
this.permissions = permissions;
}

/**
* @return an {@link UUID} representing the unique identifier of the collaboration link.
*/
public UUID getId() {
return id;
}

/**
* @return a {@link String} representing the identifier of the associated node.
*/
public String getNodeId() {
return nodeId;
}

/**
* @return a {@link String} of <code>8</code> alphanumeric characters representing the invitation
* identifier used to build the complete URL.
*/
public String getInvitationId() {
return invitationId;
}

/**
* @return an {@link Instant} representing the creation timestamp of the collaboration link.
*/
public Instant getCreatedAt() {
return createdAt;
}

/**
* @return a {@link SharePermission} representing the permission necessary to create the share
* between the user that used the link and the related node.
*/
public SharePermission getPermissions() {
return ACL.decode(permissions).getSharePermission();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,157 +6,172 @@

import com.zextras.carbonio.files.Files;
import com.zextras.carbonio.files.Files.Db;

import java.util.Optional;
import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* <p>Represents an Ebean {@link Link} entity that matches a record of the {@link Files.Db.Link}
* table.</p>
* <p>The implementation of constructors and setters should not care to check if the values in
* input are valid or not because, when these methods are called, these controls
* <strong>must</strong> be already done.</p>
* Represents an Ebean {@link Link} entity that matches a record of the {@link Files.Db.Link} table.
*
* <p>The public link has properties mapped to the corresponding table columns:
*
* <ul>
* <li>{@code id}: The unique identifier of the link.
* <li>{@code nodeId}: The identifier of the associated node.
* <li>{@code publicId}: The public identifier of the URL link.
* <li>{@code createdAt}: The timestamp indicating when the link was created.
* <li>{@code expiresAt}: The timestamp indicating when the link should expire.
* <li>{@code description}: A small description of the link (maximum 300 characters).
* <li>{@code access code}: A string to have in order to access the resource.
* </ul>
*
* <p>The constructor and setters should not care to check if the values in input are valid or not
* because, when these methods are called, these controls <strong>must</strong> be already done.
*/
@Entity
@Table(name = Files.Db.Tables.LINK)
public class Link {

@Id
@Column(name = Db.Link.ID, nullable = false, length = 36)
private String mId;
private String id;

@Column(name = Db.Link.NODE_ID, nullable = false, length = 36)
private String mNodeId;
private String nodeId;

@Column(name = Db.Link.PUBLIC_ID, nullable = false)
private String mPublicId;
private String publicId;

@Column(name = Files.Db.Link.CREATED_AT, nullable = false)
private Long mCreatedAt;
private Long createdAt;

@Column(name = Files.Db.Link.EXPIRES_AT)
private Long mExpiresAt;
private Long expiresAt;

@Column(name = Db.Link.DESCRIPTION, length = 300)
private String mDescription;
private String description;

@Column(name = Db.Link.ACCESS_CODE, length = 255)
private String mAccessCode;

/**
* <p>Creates a new {@link Link} entity that can be saved in the database.</p>
* <p>This constructor does not set the expiration timestamp and the description of the link.</p>
*
* @param linkId is a {@link String} of the unique identifier of the link.
* @param nodeId is a {@link String} of the related node id.
* @param publicId is a {@link String} of the public id used to build the complete url.
* @param createdAt is a {@link Long} of the creation timestamp.
*/
public Link(
String linkId,
String nodeId,
String publicId,
Long createdAt
) {
mId = linkId;
mNodeId = nodeId;
mPublicId = publicId;
mCreatedAt = createdAt;
}
private String accessCode;

/**
* Creates a new {@link Link} entity that can be saved in the database.
*
* @param linkId is a {@link String} of the unique identifier of the link.
* @param nodeId is a {@link String} of the related node id.
* @param publicId is a {@link String} of the public id used to build the complete url.
* @param createdAt is a {@link Long} of the creation timestamp.
* @param expiresAt is a {@link Long} of the expiration timestamp.
* @param description is a {@link String} of the link description.
* @param linkId is a {@link String} representing the unique identifier of the link.
* @param nodeId is a {@link String} representing the {@link Node} identifier associated to the
* public link.
* @param publicId is a {@link String} representing the public identifier of the URL link.
* @param createdAt is a {@link Long} of the link creation timestamp.
* @param expiresAt is a {@link Long} of the link expiration timestamp. It can be nullable.
* @param description is a {@link String} of the link description (maximum 300 characters). It can
* be nullable.
*/
public Link(
String linkId,
String nodeId,
String publicId,
Long createdAt,
Long expiresAt,
String description
) {
mId = linkId;
mNodeId = nodeId;
mPublicId = publicId;
mCreatedAt = createdAt;
mExpiresAt = expiresAt;
mDescription = description;
String linkId,
String nodeId,
String publicId,
Long createdAt,
@Nullable Long expiresAt,
@Nullable String description) {
id = linkId;
this.nodeId = nodeId;
this.publicId = publicId;
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.description = description;
}

/**
* @return a {@link String} representing the link id.
* @return a {@link String} representing the unique identifier of the public link.
*/
public String getLinkId() {
return mId;
return id;
}

/**
* @return a {@link String} representing the id of the related node.
* @return a {@link String} representing the identifier of the associated node.
*/
public String getNodeId() {
return mNodeId;
return nodeId;
}

/**
* @return a {@link String} of the public id used to build the complete url.
* @return a {@link String} representing the public identifier used to build the complete URL.
*/
public String getPublicId() {
return mPublicId;
return publicId;
}

/**
* @return a {@link Long} representing the creation timestamp of the link.
* @return a {@link Long} representing the creation timestamp of the public link.
*/
public Long getCreatedAt() {
return mCreatedAt;
return createdAt;
}

/**
* @return an {@link Optional} containing a {@link Long} representing the expiration timestamp of
* the link, if exists.
* the link, if exists.
*/
public Optional<Long> getExpiresAt() {
return Optional.ofNullable(mExpiresAt);
return Optional.ofNullable(expiresAt);
}

public void setExpiresAt(Long expiresAt) {
/**
* Allows to set/unset the expiration timestamp of the existing link. If the timestamp is equal to
* zero than the expiration is disabled and the public link will not expire.
*
* @param expiresAt is a {@link Long} representing the expiration timestamp.
* @return the current {@link Link}.
*/
public Link setExpiresAt(Long expiresAt) {
if (expiresAt == 0) {
mExpiresAt = null;
this.expiresAt = null;
} else {
mExpiresAt = expiresAt;
this.expiresAt = expiresAt;
}

return this;
}

/**
* @return an {@link Optional} containing a {@link String} representing the link description, if
* exists.
* exists.
*/
public Optional<String> getDescription() {
return Optional.ofNullable(mDescription);
return Optional.ofNullable(description);
}

public void setDescription(String description) {
mDescription = description;
/**
* Allows to add/change the description of the existing public link.
*
* @param description is a {@link String} of the link description (maximum 300 characters).
* @return the current {@link Link}.
*/
public Link setDescription(String description) {
this.description = description;
return this;
}

/**
* @return an {@link Optional} containing a {@link String} representing the link access code, if
* exists.
*/
public Optional<String> getAccessCode() {
return Optional.ofNullable(mAccessCode);
return Optional.ofNullable(accessCode);
}

/**
* Allows to add/change the access code of the existing public link.
*
* @param accessCode is a {@link String} of the link code that the user must have in order to
* access the resource.
*/
public void setAccessCode(String accessCode) {
mAccessCode = accessCode.isEmpty() ? null : accessCode; // If accessCode is empty, set it to null since it is used as optional
this.accessCode = accessCode.isEmpty() ? null : accessCode; // If accessCode is empty, set it to null since it is used as optional
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* Represents an Ebean {@link Node} entity that matches a record of the {@link Files.Db.Tables#NODE}
* table.
*
* <p>The implementation of constructors and setters should not care to check if the values in input
* <p>The implementation of the constructor and setters should not care to check if the values in input
* are valid or not because, when these methods are called, these controls <strong>must</strong> be
* already done.
*/
Expand Down
Loading