Skip to content
Snippets Groups Projects
Commit a4e7873b authored by Mads Lundegaard's avatar Mads Lundegaard Committed by Eirik Steira
Browse files

Added a tagRepository test and added javadoc

parent 03083c58
No related branches found
No related tags found
1 merge request!165Weekly merge to Master
Showing with 193 additions and 3 deletions
......@@ -18,6 +18,8 @@ import java.io.IOException;
/**
* Controls the buttons and changeable elements on login.fxml,
* the page where you log into the application
*
* @author madslun
* @version 1.0 22.03.2020
*/
public class Login {
......
......@@ -21,6 +21,8 @@ import javax.persistence.EntityManager;
/**
* Controls the buttons and changeable elements on signup.fxml,
* a page where you create a new user for the application
*
* @author madslun, Simon Jensen
* @version 1.0 22.03.2020
*/
public class SignUp {
......
......@@ -4,6 +4,15 @@ import NTNU.IDATT1002.models.GeoLocation;
import javax.persistence.EntityManager;
/**
* GeoLocation Repository.
* <p>
* Implements {@link Repository} which supports regular Create, Read, Update and Delete operations.
*
* @author madslun
* @version 1.0 96.04.20
* @see NTNU.IDATT1002.repository.Repository
*/
public class GeoLocatioRepository extends AbstractRepository<GeoLocation, Long> {
/**
......
......@@ -8,6 +8,7 @@ import javax.persistence.EntityManager;
* User Repository.
* Implementation of {@link AbstractRepository} which supports regular Create, Read, Update and Delete operations.
*
* @author madslun
* @version 1.0 22.03.20
*/
public class UserRepository extends AbstractRepository<User, String> {
......
......@@ -14,7 +14,9 @@ import java.util.Date;
import java.util.Optional;
/**
* User Service
* Works together with loginrepository and userrepository
* Combines authentication and connections to database through repositories
*
* @author madslun
* @version 1.0 22.03.20
*/
......
......@@ -8,6 +8,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
/**
* Handles the authentication logic for user login and signup
*
* @author madslun
* @version 1.0 06.04.20
* */
public class Authentication {
public static Random r = new SecureRandom();
......
package NTNU.IDATT1002.utils;
import NTNU.IDATT1002.database.EntityManagerConfig;
import NTNU.IDATT1002.models.GeoLocation;
import NTNU.IDATT1002.repository.GeoLocatioRepository;
import com.drew.imaging.ImageMetadataReader;
......@@ -17,13 +16,15 @@ import com.drew.metadata.file.FileTypeDirectory;
import com.drew.metadata.iptc.IptcDirectory;
import com.drew.metadata.jpeg.JpegDirectory;
import javax.persistence.EntityManager;
import java.io.File;
import java.io.IOException;
/**
* Class MetaDataExtractor. Extracts metadata and geolocation and histogram from it.
*
* @author madslun
* @version 1.0 06.04.20
*/
public class MetaDataExtractor {
......
package NTNU.IDATT1002.repository;
import static org.junit.jupiter.api.Assertions.*;
import NTNU.IDATT1002.models.Tag;
import java.util.List;
import java.util.Optional;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Test for {@link TagRepository}
*
* @author madslun
* @version 1.0 06.04.20
*/
class TagRepositoryTest {
private TagRepository tagRepository;
private static final Long TAG_INITIAL_ID = 1L;
/**
* Sets up testdata used through testing the repository
*/
@BeforeEach
public void setUp() {
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("ImageApplicationTest");
EntityManager entityManager = entityManagerFactory.createEntityManager();
tagRepository = new TagRepository(entityManager);
}
/**
* Test that tries to save a new tag
*/
@Test
void testSaveReturnsInstance() {
Optional<Tag> optionalTag = tagRepository.save(new Tag());
assertTrue(optionalTag.isPresent());
}
/**
* Test that tries to save two tags and makes sure both are returned
*/
@Test
void testSaveReturnsAllSavedEntities() {
tagRepository.save(new Tag());
tagRepository.save(new Tag());
List<?> foundTags = tagRepository.findAll();
assertEquals(2, foundTags.size());
}
/**
* Test that tries to save a tag with invalid entity and makes sure an empty optional is returned
*/
@Test
void testInvalidEntityReturnsEmptyOptional() {
Optional<Tag> optionalTag = tagRepository.save(null);
assertTrue(optionalTag.isEmpty());
}
/**
* Test that saves a tag and finds the same tag by tag id
*/
@Test
void testFindByIdReturnsOptionalWithCorrectId() {
tagRepository.save(new Tag());
Optional<Tag> optionalTag = tagRepository.findById(TAG_INITIAL_ID);
assertTrue(optionalTag.isPresent());
assertEquals(TAG_INITIAL_ID, optionalTag.get().getTagId());
}
/**
* Test that save a new tag, then proceeds to delete the tag, finally checks that the tag does not exist anymore
*/
@Test
void testDeleteById() {
tagRepository.save(new Tag());
Optional<Tag> optionalTag = tagRepository.findById(TAG_INITIAL_ID);
optionalTag.ifPresent(Tag -> tagRepository.deleteById(TAG_INITIAL_ID));
Optional<Tag> deletedTag = tagRepository.findById(TAG_INITIAL_ID);
assertTrue(deletedTag.isEmpty());
}
/**
* Test that tries to create a new tag that already has the same name, then makes sure the last tag was not saved
*/
@Test
void testFindOrCreateTagFindsCreatedTag() {
String takenName = "Test";
Tag firstTag = new Tag(takenName);
tagRepository.save(firstTag);
tagRepository.findOrCreate(new Tag(takenName));
List<?> foundTags = tagRepository.findAll();
assertEquals(1, foundTags.size());
}
/**
* Test that tries to create a new tag that does not exist
*/
@Test
void testFindOrCreateTagCreatesNewTag() {
String availableName = "Test123";
Tag firstTag = new Tag("Test321");
tagRepository.save(firstTag);
tagRepository.findOrCreate(new Tag(availableName));
List<?> foundTags = tagRepository.findAll();
assertEquals(2, foundTags.size());
}
/**
* Test that tries to create several tags with the same name
*/
@Test
void testFindOrCreateTagWhenSeveralExists() {
String availableName = "Test123";
Tag firstTag = new Tag(availableName);
tagRepository.save(firstTag);
tagRepository.findOrCreate(new Tag(availableName));
tagRepository.findOrCreate(new Tag(availableName));
tagRepository.findOrCreate(new Tag(availableName));
List<?> foundTags = tagRepository.findAll();
assertEquals(1, foundTags.size());
}
/**
* Test that tries to create a tag whit an empty string and makes sure null is returned
*/
@Test
void testCreateOrFindTagWithEmptyStringReturnsNull() {
String emptyName = "";
Tag testTag = new Tag(emptyName);
assertEquals(null, tagRepository.findOrCreate(testTag));
}
/**
* Test that tries to create a tag with a whitespace as name and makes sure null is returned
*/
@Test
void testCreateOrFindTagWithWhitespaceReturnsNull() {
String whiteSpaceName = " ";
Tag testTag = new Tag(whiteSpaceName);
assertEquals(null, tagRepository.findOrCreate(testTag));
}
}
\ No newline at end of file
......@@ -12,6 +12,12 @@ import javax.persistence.Persistence;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link UserService}
*
* @author madslun
* @version 1.0 06.04.20
*/
class UserServiceTest {
private UserService userService;
......
package NTNU.IDATT1002.utils;
import NTNU.IDATT1002.repository.TagRepository;
import org.junit.jupiter.api.Test;
import java.nio.charset.Charset;
......@@ -8,6 +9,13 @@ import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test for {@link Authentication}
*
* @author madslun
* @version 1.0 06.04.20
*/
class AuthenticationTest {
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment