forked from makersacademy/acebook-java-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from The-Socialites/Testing
Testing
- Loading branch information
Showing
13 changed files
with
331 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
|
||
public class ThirdPartyVenue { | ||
private String full_address; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/java/com/makersacademy/acebook/model/AttendeeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import com.makersacademy.acebook.repository.AttendeesRepository; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceException; | ||
import javax.transaction.Transactional; | ||
import java.util.Date; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.InstanceOfAssertFactories.type; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@SpringBootTest | ||
public class AttendeeTest { | ||
|
||
@Autowired | ||
private AttendeesRepository attendeesRepository; | ||
|
||
@Test | ||
public void testAttendeeCreation() { | ||
Event event = new Event(); | ||
User user = new User(); | ||
Attendee attendee = new Attendee(); | ||
attendee.setEvent(event); | ||
attendee.setUser(user); | ||
|
||
|
||
assertNotNull(attendee); | ||
assertEquals(user, attendee.getUser()); | ||
assertEquals(event, attendee.getEvent()); | ||
} | ||
|
||
// @Transactional | ||
// @Test | ||
// public void test_unique_constraint_on_user_event_combination() { | ||
// User user = new User(); | ||
// Event event = new Event(); | ||
// | ||
// Attendee attendee1 = new Attendee(); | ||
// attendee1.setUser(user); | ||
// attendee1.setEvent(event); | ||
// | ||
// Attendee attendee2 = new Attendee(); | ||
// attendee2.setUser(user); | ||
// attendee2.setEvent(event); | ||
// | ||
// | ||
// assertThrows(PersistenceException.class, () -> { | ||
// attendeesRepository.save(attendee1); | ||
// attendeesRepository.save(attendee2); | ||
// }); | ||
|
||
} | ||
|
||
|
||
|
||
|
16 changes: 16 additions & 0 deletions
16
src/test/java/com/makersacademy/acebook/model/AuthorityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class AuthorityTest { | ||
|
||
@Test | ||
public void test_create_authority_with_valid_username_and_authority() { | ||
Authority authority = new Authority("user1", "ROLE_USER"); | ||
assertNotNull(authority); | ||
assertEquals("user1", authority.getUsername()); | ||
assertEquals("ROLE_USER", authority.getAuthority()); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/test/java/com/makersacademy/acebook/model/CommentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import java.util.Date; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class CommentTest { | ||
|
||
@Test | ||
public void test_create_comment_instance_with_valid_data() { | ||
User user = new User("john_doe", "password123", "john.doe@example.com", true); | ||
Event event = new Event(); | ||
Comment comment = new Comment(); | ||
comment.setContent("This is a sample comment"); | ||
comment.setCreatedAt(new Date()); | ||
comment.setUser(user); | ||
comment.setEvent(event); | ||
|
||
assertEquals("This is a sample comment", comment.getContent()); | ||
assertNotNull(comment.getCreatedAt()); | ||
assertEquals(user, comment.getUser()); | ||
assertEquals(event, comment.getEvent()); | ||
} | ||
|
||
@Test | ||
public void test_large_content_handling() { | ||
Comment comment = new Comment(); | ||
String largeContent = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; | ||
comment.setContent(largeContent); | ||
assertEquals(largeContent, comment.getContent()); | ||
} | ||
|
||
@Test | ||
public void test_handles_multiple_associations() { | ||
User user = new User("john_doe", "password", "john.doe@example.com", true); | ||
Event event = new Event(); | ||
Comment comment1 = new Comment(); | ||
Comment comment2 = new Comment(); | ||
|
||
comment1.setUser(user); | ||
comment1.setEvent(event); | ||
|
||
comment2.setUser(user); | ||
comment2.setEvent(event); | ||
|
||
assertEquals(user, comment1.getUser()); | ||
assertEquals(user, comment2.getUser()); | ||
assertEquals(event, comment1.getEvent()); | ||
assertEquals(event, comment2.getEvent()); | ||
} | ||
|
||
// @Test | ||
// public void test_formatted_created_at_valid_date() { | ||
// Comment comment = new Comment(); | ||
// LocalDateTime now = LocalDateTime.now(); | ||
// comment.setCreatedAt(Date.from(now.atZone(ZoneId.systemDefault()).toInstant())); | ||
// | ||
// String formattedDate = comment.getFormattedCreatedAt(); | ||
// | ||
// assertEquals(now.format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm")), formattedDate); | ||
// } | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/com/makersacademy/acebook/model/EventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Date; | ||
import java.util.Optional; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class EventTest { | ||
@Test | ||
public void testEventCreation() { | ||
User user = new User(); | ||
Event event = new Event(); | ||
Date createdDate = new Date(2024, 01, 01); | ||
Date scheduledDate = new Date(2024, 12, 31); | ||
event.setCreatedAt(createdDate); | ||
event.setScheduledDate(scheduledDate); | ||
event.setScheduledStartTime("00:00"); | ||
event.setScheduledEndTime("21:59"); | ||
event.setLocation("Newcastle-Upon-Tyne"); | ||
event.setUser(user); | ||
event.setEventImageUrl("www.image.com"); | ||
event.setAttendees(1L); | ||
event.setUserAttending(true); | ||
|
||
|
||
assertNotNull(event); | ||
assertEquals(new Date(2024, 01, 01), event.getCreatedAt()); | ||
assertEquals(new Date(2024, 12, 31), event.getScheduledDate()); | ||
assertEquals("00:00", event.getScheduledStartTime()); | ||
assertEquals("21:59", event.getScheduledEndTime()); | ||
assertEquals("Newcastle-Upon-Tyne", event.getLocation()); | ||
assertEquals(user, event.getUser()); | ||
assertEquals("www.image.com", event.getEventImageUrl()); | ||
assertEquals(Long.valueOf(1L), event.getAttendees()); | ||
assertEquals(true, event.getUserAttending()); | ||
|
||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/test/java/com/makersacademy/acebook/model/PostTest.java
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
src/test/java/com/makersacademy/acebook/model/ThirdPartyEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
public class ThirdPartyEventTest { | ||
|
||
@Test | ||
public void test_create_third_party_event_instance_with_valid_data() { | ||
ThirdPartyEvent thirdPartyEvent = new ThirdPartyEvent(); | ||
thirdPartyEvent.setName("Music Gig"); | ||
thirdPartyEvent.setLink("www.musicgig.com"); | ||
thirdPartyEvent.setDescription("Greatest music gig ever! You must come along"); | ||
thirdPartyEvent.setStartTime("2024-12-01 00:00:00"); | ||
thirdPartyEvent.setEndTime("2024-12-01 23:59:12"); | ||
thirdPartyEvent.setThumbnail("https://example.com/thumbnail.jpg"); | ||
ThirdPartyVenue venue = new ThirdPartyVenue(); | ||
thirdPartyEvent.setVenue(venue); | ||
|
||
assertEquals("Music Gig", thirdPartyEvent.getName()); | ||
assertEquals("www.musicgig.com", thirdPartyEvent.getLink()); | ||
assertEquals("Greatest music gig ever! You must come along", thirdPartyEvent.getDescription()); | ||
assertEquals("2024-12-01 00:00:00", thirdPartyEvent.getStartTime()); | ||
assertEquals("2024-12-01 23:59:12", thirdPartyEvent.getEndTime()); | ||
assertEquals("https://example.com/thumbnail.jpg", thirdPartyEvent.getThumbnail()); | ||
assertEquals(venue, thirdPartyEvent.getVenue()); | ||
} | ||
|
||
@Test | ||
public void test_correctly_formats_start_time() { | ||
ThirdPartyEvent event = new ThirdPartyEvent(); | ||
event.setStartTime("2023-10-01 15:30:00"); | ||
String formattedStartTime = event.getFormattedStartTime(); | ||
assertEquals("01-10-2023 15:30", formattedStartTime); | ||
} | ||
|
||
@Test | ||
public void test_correctly_formats_end_time() { | ||
ThirdPartyEvent event = new ThirdPartyEvent(); | ||
event.setEndTime("2022-12-31 23:59:59"); | ||
String formattedEndTime = event.getFormattedEndTime(); | ||
assertEquals("31-12-2022 23:59", formattedEndTime); | ||
} | ||
|
||
@Test | ||
public void test_handles_empty_start_time_string() { | ||
ThirdPartyEvent event = new ThirdPartyEvent(); | ||
event.setStartTime(""); | ||
String formattedStartTime = event.getFormattedStartTime(); | ||
assertNull(formattedStartTime); | ||
} | ||
|
||
@Test | ||
public void test_handles_empty_end_time_string() { | ||
ThirdPartyEvent event = new ThirdPartyEvent(); | ||
event.setEndTime(""); | ||
String formattedEndTime = event.getFormattedEndTime(); | ||
assertNull(formattedEndTime); | ||
} | ||
|
||
@Test | ||
public void test_ignores_unknown_json_properties() { | ||
ThirdPartyEvent event = new ThirdPartyEvent(); | ||
String json = "{\"event_id\":\"12345\",\"name\":\"Test Event\",\"link\":\"www.testevent.com\",\"unknown\":\"This is unknown\",\"description\":\"This is a test event\"}"; | ||
ObjectMapper mapper = new ObjectMapper(); | ||
try { | ||
event = mapper.readValue(json, ThirdPartyEvent.class); | ||
} catch (JsonProcessingException e) { | ||
e.printStackTrace(); | ||
} | ||
assertNull(event.getStartTime()); | ||
assertNull(event.getEndTime()); | ||
assertNull(event.getVenue()); | ||
assertNull(event.getThumbnail()); | ||
assertEquals("12345", event.getEventId()); | ||
assertEquals("Test Event", event.getName()); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/com/makersacademy/acebook/model/ThirdPartyVenueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ThirdPartyVenueTest { | ||
@Test | ||
public void testCreateThirdPartyVenue(){ | ||
ThirdPartyVenue venue = new ThirdPartyVenue(); | ||
venue.setFull_address("1 Station Road, Wandsworth, London, UK SW17 9RT"); | ||
|
||
assertEquals("1 Station Road, Wandsworth, London, UK SW17 9RT", venue.getFull_address()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/test/java/com/makersacademy/acebook/model/UserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.makersacademy.acebook.model; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Date; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class UserTest { | ||
|
||
@Test | ||
public void createUser() { | ||
User user = new User(); | ||
user.setUsername("ShaniaTwain"); | ||
user.setPassword("password123"); | ||
user.setEmail("test@email.com"); | ||
user.setProfilePictureUrl("www.image.com"); | ||
user.setLanguage("Spanish"); | ||
user.setCity("Barcelona"); | ||
|
||
assertNotNull(user); | ||
assertEquals("ShaniaTwain", user.getUsername()); | ||
assertEquals("password123", user.getPassword()); | ||
assertEquals("test@email.com", user.getEmail()); | ||
assertEquals("www.image.com", user.getProfilePictureUrl()); | ||
assertEquals("Spanish", user.getLanguage()); | ||
assertEquals("Barcelona", user.getCity()); | ||
} | ||
} |