diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 9ad367c..3dbf59e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - release/* workflow_dispatch: # Allows manual triggering of the workflow @@ -33,16 +34,6 @@ jobs: java-version: '25' - name: Run Tests run: mvn clean test - - name: Upload Test Results - uses: actions/upload-artifact@v3 - with: - name: surefire-reports - path: target/surefire-reports/ - - name: Upload Coverage Report - uses: actions/upload-artifact@v3 - with: - name: jacoco-report - path: target/jacoco/coverage-reports/jacoco.xml package: name: Package @@ -62,15 +53,4 @@ jobs: name: packaged-app path: target/Help-Me-Help-1.0-SNAPSHOT-jar-with-dependencies.jar - deployPages: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: self-hosted - steps: - - uses: actions/checkout@v3 - - name: Set up JDK - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '25' + diff --git a/.gitignore b/.gitignore index bee94ec..07e3800 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.war *.ear *.nar +target/ ############################## ## Maven @@ -37,3 +38,15 @@ out/ ############################## *.db *.DS_Store + +############################## +## VSCode +############################## +.vscode/ + +############################## +## Misc +############################## +.settings/* +.project +.classpath diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index dc3b895..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "java.configuration.updateBuildConfiguration": "interactive" -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4895163..0bb117f 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,25 @@ javafx-controls ${javafx.version} + + + org.springframework.security + spring-security-crypto + 7.0.2 + + + + tools.jackson.core + jackson-databind + 3.1.0 + compile + + + + commons-logging + commons-logging + 1.3.5 + @@ -80,6 +99,28 @@ maven-javadoc-plugin 3.12.0 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.6.1 + + + package + + shade + + + + + edu.group5.app.App + + + + + + diff --git a/src/main/java/edu/group5/app/App.java b/src/main/java/edu/group5/app/App.java index 7fd22a6..5886cd4 100644 --- a/src/main/java/edu/group5/app/App.java +++ b/src/main/java/edu/group5/app/App.java @@ -1,10 +1,24 @@ package edu.group5.app; +import java.util.HashMap; + +import edu.group5.app.control.OrgAPIWrapper; +import tools.jackson.core.type.TypeReference; +import tools.jackson.databind.ObjectMapper; + /** * Hello world! */ public class App { - public static void main(String[] args) { - System.out.println("Hello World!"); - } + public static void main(String[] args) throws InterruptedException { + OrgAPIWrapper orgWrap = new OrgAPIWrapper("https://app.innsamlingskontrollen.no/api/public/v1/all"); + System.out.println(); + System.out.println(); + orgWrap.importData(); + Object[] imports = orgWrap.getData(); + ObjectMapper objectMapper = new ObjectMapper(); + HashMap map = objectMapper.convertValue(imports[0], new TypeReference>() { + }); + System.out.println(map.get("org_number")); + } } diff --git a/src/main/java/edu/group5/app/control/OrgAPIWrapper.java b/src/main/java/edu/group5/app/control/OrgAPIWrapper.java new file mode 100644 index 0000000..f8bc7ab --- /dev/null +++ b/src/main/java/edu/group5/app/control/OrgAPIWrapper.java @@ -0,0 +1,54 @@ +package edu.group5.app.control; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +import tools.jackson.core.exc.StreamReadException; +import tools.jackson.databind.ObjectMapper; + +public class OrgAPIWrapper extends Wrapper { + private Object[] data; + private HttpClient client; + private HttpRequest request; + + public OrgAPIWrapper(String urlString) { + if (urlString == null) { + throw new IllegalArgumentException("url can't be null"); + } else if (urlString.isBlank()) { + throw new IllegalArgumentException("url can't be blank"); + } + try { + URI uri = URI.create(urlString); + this.client = HttpClient.newHttpClient(); + this.request = HttpRequest.newBuilder() + .uri(uri) + .GET() + .build(); + } catch (IllegalArgumentException IAe) { + throw new IllegalArgumentException("url has to be valid"); + } + + } + + @Override + public boolean importData() throws InterruptedException { + try { + HttpResponse response = this.client.send( + this.request, HttpResponse.BodyHandlers.ofString()); + this.data = new ObjectMapper().readValue(response.body(), Object[].class); + return true; + } catch (IOException IOe) { + return false; + } catch (StreamReadException e) { + throw new StreamReadException("The URL leads to a website that can't be parsed"); + } + } + + @Override + public Object[] getData() { + return this.data; + } +} diff --git a/src/main/java/edu/group5/app/control/Wrapper.java b/src/main/java/edu/group5/app/control/Wrapper.java index 9655c26..012ea2c 100644 --- a/src/main/java/edu/group5/app/control/Wrapper.java +++ b/src/main/java/edu/group5/app/control/Wrapper.java @@ -1,5 +1,11 @@ package edu.group5.app.control; -public class Wrapper { - +abstract class Wrapper { + + protected Wrapper() { + } + + public abstract boolean importData() throws InterruptedException; + + public abstract Object getData(); } diff --git a/src/main/java/edu/group5/app/model/DBRepository.java b/src/main/java/edu/group5/app/model/DBRepository.java index 3ec2945..1196eae 100644 --- a/src/main/java/edu/group5/app/model/DBRepository.java +++ b/src/main/java/edu/group5/app/model/DBRepository.java @@ -2,6 +2,7 @@ import java.util.HashMap; +import java.util.Map; /** * Abstract base class for repositories that store their data @@ -9,32 +10,16 @@ * *

* Extends {@link Repository} and specifies that the content - * is stored as a {@link HashMap}. + * is stored as a {@link Map}. *

*/ -public abstract class DBRepository extends Repository { - /** - * The underlying data structure containing the repository entities. - */ - protected HashMap content; - +public abstract class DBRepository extends Repository { /** * Constructs a DBRepository with the given content. * * @param content the HashMap used to store repository entities */ - protected DBRepository(HashMap content) { + protected DBRepository(Map content) { super(content); - this.content = content; - } - - /** - * Returns the underlying HashMap containing the repository entities. - * - * @return the repository content as a HashMap - */ - @Override - public HashMap getContent() { - return content; } } diff --git a/src/main/java/edu/group5/app/model/Repository.java b/src/main/java/edu/group5/app/model/Repository.java index 3d50bbe..5396b2f 100644 --- a/src/main/java/edu/group5/app/model/Repository.java +++ b/src/main/java/edu/group5/app/model/Repository.java @@ -1,25 +1,26 @@ package edu.group5.app.model; +import java.util.Map; + /** * Represents a repository. */ -public abstract class Repository { - /** - * The underlying data structure that holds the repository's content. - */ - protected Object content; - +public abstract class Repository { + protected final Map content; /** * Constructs a new Repository with the specified content. * * @param content the underlying data structure used to store entities */ - protected Repository(Object content) { + public Repository(Map content) { this.content = content; } /** + * Gets the content of the repo * @return content of the repo */ - public abstract Object getContent(); + public Map getContent() { + return content; + } } diff --git a/src/main/java/edu/group5/app/model/organization/Organization.java b/src/main/java/edu/group5/app/model/organization/Organization.java index 825945f..be0e810 100644 --- a/src/main/java/edu/group5/app/model/organization/Organization.java +++ b/src/main/java/edu/group5/app/model/organization/Organization.java @@ -1,5 +1,61 @@ package edu.group5.app.model.organization; -public class Organization { - +import java.util.Objects; + +/** + * Represents an organization. + * + *

+ * An organization is identified by an organization number, a name, + * trust status, website URL, pre-approval status, and a textual description. + * + *

+ * Instances are validated on creation: + *

    + *
  • orgNumber must be non-negative
  • + *
  • name and websiteURL must not be null or blank
  • + *
  • description must not be null
  • + *
+ */ +public record Organization( + int orgNumber, + String name, + boolean trusted, + String websiteURL, + boolean isPreApproved, + String description) { + /** + * Creates a new organization. + * + * @param orgNumber the organization number; must be non-negative + * @param name the organization name; must not be null or blank + * @param trusted whether the organization is trusted + * @param websiteURL the organization's website URL; must not be null or + * blank + * @param isPreApproved whether the organization is pre-approved + * @param description a textual description of the organization; must not be + * null + * @throws NullPointerException if name, websiteURL or description is null + * @throws IllegalArgumentException if orgNumber is negative, or if name or + * websiteURL is blank + */ + public Organization(int orgNumber, String name, boolean trusted, String websiteURL, boolean isPreApproved, + String description) { + if (orgNumber < 0) { + throw new IllegalArgumentException("orgNumber cannot be negative"); + } + this.orgNumber = orgNumber; + this.name = Objects.requireNonNull(name, "name cannot be null"); + this.trusted = trusted; + this.websiteURL = Objects.requireNonNull(websiteURL, "websiteURL cannot be null"); + this.isPreApproved = isPreApproved; + this.description = Objects.requireNonNull(description, "description cannot be null"); + + if (name.isBlank()) { + throw new IllegalArgumentException("name cannot be blank"); + } + if (websiteURL.isBlank()) { + throw new IllegalArgumentException("websiteURL cannot be blank"); + } + } } diff --git a/src/main/java/edu/group5/app/model/organization/OrganizationRepository.java b/src/main/java/edu/group5/app/model/organization/OrganizationRepository.java new file mode 100644 index 0000000..14a77d0 --- /dev/null +++ b/src/main/java/edu/group5/app/model/organization/OrganizationRepository.java @@ -0,0 +1,38 @@ +package edu.group5.app.model.organization; + +import edu.group5.app.model.Repository; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Handles the business logic associated with organizations + */ +public class OrganizationRepository extends Repository { + /** + * Creates a new Organization Repository + * + * @param content holds all current organizations in the repository; must not be null + * @throws NullPointerException if content is null + */ + public OrganizationRepository(Map content) { + super(Objects.requireNonNull(content, "content cannot be null")); + } + + /** + * Gets all trusted organizations in the repository + * @return all organizations with trusted = true + */ + public Map getTrustedOrganizations() { + Map trustedOrganizations = new HashMap<>(); + + content.forEach((orgNr, org) -> { + if (org.trusted()) { + trustedOrganizations.put(orgNr, org); + } + }); + + return trustedOrganizations; + } +} diff --git a/src/main/java/edu/group5/app/model/user/User.java b/src/main/java/edu/group5/app/model/user/User.java index e163785..8dd48cd 100644 --- a/src/main/java/edu/group5/app/model/user/User.java +++ b/src/main/java/edu/group5/app/model/user/User.java @@ -1,5 +1,120 @@ package edu.group5.app.model.user; - +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +/** + * User class represents a user in the system. It is an abstract class that will be extended by specific user types such as Donor, Recipient, and Admin. + * Each user has a unique userId, a role that defines their permissions in the system, and personal information such as first name, last name, email, and password hash. + * The constructor validates that all required fields are provided and throws an IllegalArgumentException if any of the fields are null or empty. + * This ensures that the User objects are always in a valid state when created. + * The class also includes a method to verify the user's password + * by comparing the provided plaintext password with the stored hashed password using BCrypt. + * + */ public class User { + private int userId; + private String role; + private String firstName; + private String lastName; + private String email; + private String passwordHash; + + /** + * Constructor for User class. Validates that all required fields + * are provided and throws an IllegalArgumentException if any of the fields are null or empty. + * @param userId the unique identifier for the user, must be a positive integer + * @param role the role of the user (e.g., "Donor", "Recipient", "Admin") + * @param firstName the first name of the user + * @param lastName the last name of the user + * @param email the email address of the user + * @param passwordHash the hashed password of the user, used for authentication purposes + */ + public User(int userId, String role, String firstName, + String lastName, String email, String passwordHash) { + if (userId <= 0) { + throw new IllegalArgumentException("User ID must be positive"); + } + if (role == null || role.trim().isEmpty()) { + throw new IllegalArgumentException("Role cannot be null or empty"); + } + if (firstName == null || firstName.trim().isEmpty()) { + throw new IllegalArgumentException("First name cannot be null or empty"); + } + if (lastName == null || lastName.trim().isEmpty()) { + throw new IllegalArgumentException("Last name cannot be null or empty"); + } + if (email == null || email.trim().isEmpty()) { + throw new IllegalArgumentException("Email cannot be null or empty"); + } + if (passwordHash == null || passwordHash.trim().isEmpty()) { + throw new IllegalArgumentException("Password hash cannot be null or empty"); + } + this.userId = userId; + this.role = role.trim(); + this.firstName = firstName.trim(); + this.lastName = lastName.trim(); + this.email = email.trim(); + this.passwordHash = passwordHash; +} + + /** + * Gets the unique identifier for the user. + * @return the userId of the user + */ + public int getUserId() { + return userId; + } + + /** + * Gets the role of the user, which defines their permissions in the system. + * @return the role of the user + */ + public String getRole() { + return role; + } + /** + * Gets the first name of the user. + * @return the first name of the user + */ + public String getFirstName() { + return firstName; + } + + /** + * Gets the last name of the user. + * @return the last name of the user + */ + public String getLastName() { + return lastName; + } + + /** + * Gets the email address of the user. + * @return the email of the user + */ + public String getEmail() { + return email; + } + + /** + * Gets the hashed password of the user. + * This is used for authentication purposes and should not be exposed in plaintext. + * @return the password hash of the user + */ + public String getPasswordHash() { + return passwordHash; + } + + /** + * Verifies if the provided password matches the stored password hash. + * This method uses BCrypt to compare the plaintext password with the hashed password. + * @param password the plaintext password to verify + * @return true if the password is correct, false otherwise + */ + public boolean verifyPassword(String password) { + if (password == null || password.isEmpty()) { + return false; + } + BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); + return encoder.matches(password, this.passwordHash); + } } diff --git a/src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java b/src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java new file mode 100644 index 0000000..6f22c85 --- /dev/null +++ b/src/test/java/edu/group5/app/control/OrgAPIWrapperTest.java @@ -0,0 +1,74 @@ +package edu.group5.app.control; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import tools.jackson.core.exc.StreamReadException; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.lang.IllegalArgumentException; + +public class OrgAPIWrapperTest { + String testURL; + String wrongURL; + String wrongURL2; + + @BeforeEach + void init() { + this.testURL = "https://app.innsamlingskontrollen.no/api/public/v1/all"; + this.wrongURL = "This is not a URL"; + this.wrongURL2 = "https://www.google.com"; + } + + @Test + public void nullURLThrowsException() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> new OrgAPIWrapper(null)); + assertEquals("url can't be null", exception.getMessage()); + } + + @Test + public void emptyURLThrowsException() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new OrgAPIWrapper("")); + assertEquals("url can't be blank", exception.getMessage()); + } + + @Test + public void faultyURLThrowsException() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> new OrgAPIWrapper(this.wrongURL)); + assertEquals("url has to be valid", exception.getMessage()); + } + + // @Test + // public void noConnectionReturnsFalseImport() { + // assertDoesNotThrow(() -> { + // OrgAPIWrapper api = new OrgAPIWrapper(this.testURL); + // assertFalse(api.importData()); + // }); + // } + + @Test + public void importsNonEmptyData() { + assertDoesNotThrow(() -> { + OrgAPIWrapper api = new OrgAPIWrapper(testURL); + assertTrue(api.importData()); + assertFalse(api.getData().length == 0); + }); + } + + @Test + public void nonParseableSiteThrowsExceptionWhenImporting() { + assertDoesNotThrow(() -> { + OrgAPIWrapper api = new OrgAPIWrapper(this.wrongURL2); + StreamReadException exception = assertThrows(StreamReadException.class, () -> api.importData()); + assertEquals("The URL leads to a website that can't be parsed", exception.getMessage()); + }); + } + +} diff --git a/src/test/java/edu/group5/app/control/WrapperTest.java b/src/test/java/edu/group5/app/control/WrapperTest.java new file mode 100644 index 0000000..d626fd7 --- /dev/null +++ b/src/test/java/edu/group5/app/control/WrapperTest.java @@ -0,0 +1,5 @@ +package edu.group5.app.control; + +public class WrapperTest { + +} diff --git a/src/test/java/edu/group5/app/model/organization/OrganizationRepositoryTest.java b/src/test/java/edu/group5/app/model/organization/OrganizationRepositoryTest.java new file mode 100644 index 0000000..3a3392e --- /dev/null +++ b/src/test/java/edu/group5/app/model/organization/OrganizationRepositoryTest.java @@ -0,0 +1,48 @@ +package edu.group5.app.model.organization; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +class OrganizationRepositoryTest { + + private OrganizationRepository repository; + + @BeforeEach + void setUp() { + Map content = new HashMap<>(); + + Organization trustedOrganization1 = new Organization(1, "Trusted Org1", true, "org.com", true, "description"); + Organization trustedOrganization2 = new Organization(2, "Trusted Org2", true, "org.com", true, "description"); + Organization untrustedOrganization1 = new Organization(3, "Untrusted Org1", false, "org.com", true, "description"); + Organization untrustedOrganization2 = new Organization(4, "Untrusted Org2", false, "org.com", true, "description"); + + content.put(1, trustedOrganization1); + content.put(2, trustedOrganization2); + content.put(3, untrustedOrganization1); + content.put(4, untrustedOrganization2); + + repository = new OrganizationRepository(content); + } + + @Test + void constructor_ThrowsWhenContentIsNull() { + assertThrows(NullPointerException.class, () -> new OrganizationRepository(null)); + } + + @Test + void getTrustedOrganizations_OnlyReturnsTrustedOrganizations() { + Map trusted = repository.getTrustedOrganizations(); + + assertEquals(2, trusted.size()); + assertTrue(trusted.containsKey(1)); + assertTrue(trusted.containsKey(2)); + assertFalse(trusted.containsKey(3)); + assertFalse(trusted.containsKey(4)); + assertTrue(trusted.values().stream().allMatch(Organization::trusted)); + } +} \ No newline at end of file diff --git a/src/test/java/edu/group5/app/model/organization/OrganizationTest.java b/src/test/java/edu/group5/app/model/organization/OrganizationTest.java new file mode 100644 index 0000000..7f1b898 --- /dev/null +++ b/src/test/java/edu/group5/app/model/organization/OrganizationTest.java @@ -0,0 +1,101 @@ +package edu.group5.app.model.organization; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class OrganizationTest { + + @Test + void constructor_CreatesAnOrganizationWhenInputIsValid() { + Organization org = new Organization( + 1, + "Org", + true, + "org.com", + true, + "Org description" + ); + + assertAll( + () -> assertEquals(1, org.orgNumber()), + () -> assertEquals("Org", org.name()), + () -> assertTrue(org.trusted()), + () -> assertEquals("org.com", org.websiteURL()), + () -> assertTrue(org.isPreApproved()), + () -> assertEquals("Org description", org.description()) + ); + } + + @Test + void constructor_ThrowsWhenOrgNumberIsNegative() { + assertThrows(IllegalArgumentException.class, () -> new Organization( + -1, + "Org", + true, + "org.com", + true, + "Org description" + )); + } + + @Test + void constructor_ThrowsWhenNameIsNull() { + assertThrows(NullPointerException.class, () -> new Organization( + 1, + null, + true, + "org.com", + true, + "Org description" + )); + } + + @Test + void constructor_ThrowsWhenNameIsBlank() { + assertThrows(IllegalArgumentException.class, () -> new Organization( + 1, + "", + true, + "org.com", + true, + "Org description" + )); + } + + @Test + void constructor_ThrowsWhenWebsiteURLIsNull() { + assertThrows(NullPointerException.class, () -> new Organization( + 1, + "Org", + true, + null, + true, + "Org description" + )); + } + + @Test + void constructor_ThrowsWhenWebsiteURLIsBlank() { + assertThrows(IllegalArgumentException.class, () -> new Organization( + 1, + "Org", + true, + "", + true, + "Org description" + )); + } + + @Test + void constructor_ThrowsWhenDescriptionIsNull() { + assertThrows(NullPointerException.class, () -> new Organization( + 1, + "Org", + true, + "org.com", + true, + null + )); + } +} \ No newline at end of file diff --git a/src/test/java/edu/group5/app/model/user/UserTest.java b/src/test/java/edu/group5/app/model/user/UserTest.java new file mode 100644 index 0000000..1e7277a --- /dev/null +++ b/src/test/java/edu/group5/app/model/user/UserTest.java @@ -0,0 +1,136 @@ +package edu.group5.app.model.user; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +public class UserTest { + private static final int TEST_USER_ID = 1; + private static final String TEST_ROLE = "Donor"; + private static final String TEST_FIRST_NAME = "John"; + private static final String TEST_LAST_NAME = "Doe"; + private static final String TEST_EMAIL = "john.doe@example.com"; + private static final String TEST_PASSWORD = "password123"; + private static final String TEST_PASSWORD_HASH = new BCryptPasswordEncoder().encode(TEST_PASSWORD); + + private static final int WRONG_USER_ID = -5; + private static final String WRONG_ROLE = ""; + private static final String WRONG_FIRST_NAME = ""; + private static final String WRONG_LAST_NAME = ""; + private static final String WRONG_EMAIL = ""; + private static final String WRONG_PASSWORD_HASH = ""; + + private void constructorTest(int userId, String role, String firstName, String lastName, String email, String passwordHash, boolean negativeTest) { + boolean exceptionThrown = negativeTest; + try { + new User(userId, role, firstName, lastName, email, passwordHash); + } catch (Exception e) { + exceptionThrown = !negativeTest; + } finally { + assertFalse(exceptionThrown); + } + } + + @Test + public void constructorThrowsNoException() { + constructorTest(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH, false); + } + + @Test + public void constructorWithNegativeUserIdThrowsException() { + constructorTest(WRONG_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithEmptyRoleThrowsException() { + constructorTest(TEST_USER_ID, WRONG_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithEmptyFirstNameThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, WRONG_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithEmptyLastNameThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, WRONG_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithEmptyEmailThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, WRONG_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithEmptyPasswordHashThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, WRONG_PASSWORD_HASH, true); + } + + private void getMethodComparer(User user, boolean negativeTest) { + if (user.getUserId() == TEST_USER_ID && + user.getRole().equals(TEST_ROLE) && + user.getFirstName().equals(TEST_FIRST_NAME) && + user.getLastName().equals(TEST_LAST_NAME) && + user.getEmail().equals(TEST_EMAIL) && + user.getPasswordHash() != null) { + assertFalse(negativeTest); + } + } + + @Test + public void getMethodsReturnCorrectInformation() { + User testUser = new User(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH); + getMethodComparer(testUser, false); + } + + @Test + public void verifyPasswordReturnsTrueForCorrectPassword() { + User testUser = new User(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH); + assertTrue(testUser.verifyPassword(TEST_PASSWORD)); + } + + @Test + public void verifyPasswordReturnsFalseForIncorrectPassword() { + User testUser = new User(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH); + assertFalse(testUser.verifyPassword("wrongPassword")); + } + + @Test + public void verifyPasswordReturnsFalseForNullPassword() { + User testUser = new User(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH); + assertFalse(testUser.verifyPassword(null)); + } + + @Test + public void verifyPasswordReturnsFalseForEmptyPassword() { + User testUser = new User(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH); + assertFalse(testUser.verifyPassword("")); + } + + @Test + public void constructorWithNullRoleThrowsException() { + constructorTest(TEST_USER_ID, null, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithNullFirstNameThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, null, TEST_LAST_NAME, TEST_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithNullLastNameThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, null, TEST_EMAIL, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithNullEmailThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, null, TEST_PASSWORD_HASH, true); + } + + @Test + public void constructorWithNullPasswordHashThrowsException() { + constructorTest(TEST_USER_ID, TEST_ROLE, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_EMAIL, null, true); + } +} diff --git a/src/test/java/edu/group5/app/utils/UtilitiesTest.java b/src/test/java/edu/group5/app/utils/UtilitiesTest.java new file mode 100644 index 0000000..88aa0c9 --- /dev/null +++ b/src/test/java/edu/group5/app/utils/UtilitiesTest.java @@ -0,0 +1,5 @@ +package edu.group5.app.utils; + +public class UtilitiesTest { + +} diff --git a/src/test/java/edu/group5/app/view/ViewTest.java b/src/test/java/edu/group5/app/view/ViewTest.java new file mode 100644 index 0000000..bd0cd83 --- /dev/null +++ b/src/test/java/edu/group5/app/view/ViewTest.java @@ -0,0 +1,5 @@ +package edu.group5.app.view; + +public class ViewTest { + +} diff --git a/target/classes/edu/group5/app/App.class b/target/classes/edu/group5/app/App.class deleted file mode 100644 index e3679e1..0000000 Binary files a/target/classes/edu/group5/app/App.class and /dev/null differ diff --git a/target/classes/edu/group5/app/control/Wrapper.class b/target/classes/edu/group5/app/control/Wrapper.class deleted file mode 100644 index cbe1488..0000000 Binary files a/target/classes/edu/group5/app/control/Wrapper.class and /dev/null differ diff --git a/target/classes/edu/group5/app/model/donation/Donation.class b/target/classes/edu/group5/app/model/donation/Donation.class deleted file mode 100644 index 687d00e..0000000 Binary files a/target/classes/edu/group5/app/model/donation/Donation.class and /dev/null differ diff --git a/target/classes/edu/group5/app/model/organization/Organization.class b/target/classes/edu/group5/app/model/organization/Organization.class deleted file mode 100644 index af118dd..0000000 Binary files a/target/classes/edu/group5/app/model/organization/Organization.class and /dev/null differ diff --git a/target/classes/edu/group5/app/model/user/User.class b/target/classes/edu/group5/app/model/user/User.class deleted file mode 100644 index 950b2f7..0000000 Binary files a/target/classes/edu/group5/app/model/user/User.class and /dev/null differ diff --git a/target/classes/edu/group5/app/utils/Utilities.class b/target/classes/edu/group5/app/utils/Utilities.class deleted file mode 100644 index 9fb7579..0000000 Binary files a/target/classes/edu/group5/app/utils/Utilities.class and /dev/null differ diff --git a/target/classes/edu/group5/app/view/View.class b/target/classes/edu/group5/app/view/View.class deleted file mode 100644 index bc21f75..0000000 Binary files a/target/classes/edu/group5/app/view/View.class and /dev/null differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst deleted file mode 100644 index 28e9804..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -edu\group5\app\App.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst deleted file mode 100644 index 16a5464..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1 +0,0 @@ -C:\Users\marjo\Documents\Github\Help-Me-Help\src\main\java\edu\group5\app\App.java diff --git a/target/test-classes/edu/group5/app/AppTest.class b/target/test-classes/edu/group5/app/AppTest.class deleted file mode 100644 index 4c66499..0000000 Binary files a/target/test-classes/edu/group5/app/AppTest.class and /dev/null differ