diff --git a/.gitignore b/.gitignore index d6e805c..7ed5735 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ dcsc-web/build/** utilities/build/** **/build/** bin/** +out/** .DS_STORE .settings .project diff --git a/athena/src/main/java/org/dcsc/athena/services/TutorUserService.java b/athena/src/main/java/org/dcsc/athena/services/TutorUserService.java new file mode 100644 index 0000000..d61ffcf --- /dev/null +++ b/athena/src/main/java/org/dcsc/athena/services/TutorUserService.java @@ -0,0 +1,7 @@ +package org.dcsc.athena.services; + +import org.springframework.stereotype.Service; + +@Service +public class TutorUserService { +} diff --git a/build.gradle b/build.gradle index c710d23..1d726e7 100644 --- a/build.gradle +++ b/build.gradle @@ -113,6 +113,14 @@ subprojects { thymeleafVersion = '2.1.2.RELEASE' thymeleafLayoutVersion = '1.2.8' } + + dependencies { + testCompile "junit:junit:$junitVersion" + testCompile "org.mockito:mockito-all:$mockitoVersion" + testCompile "org.powermock:powermock-mockito-release-full:$powerMockVersion" + testCompile "org.springframework:spring-test:$springVersion" + testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion" + } } task wrapper(type: Wrapper) { diff --git a/core/src/main/java/org/dcsc/core/user/group/Group.java b/core/src/main/java/org/dcsc/core/user/group/Group.java index 05f6bda..6a8f6d4 100644 --- a/core/src/main/java/org/dcsc/core/user/group/Group.java +++ b/core/src/main/java/org/dcsc/core/user/group/Group.java @@ -1,6 +1,7 @@ package org.dcsc.core.user.group; import javax.persistence.*; +import java.util.List; @Entity @Table(name = "dcsc_groups", schema = "dcsc_accounts") @@ -13,6 +14,9 @@ public class Group { @Column(name = "name") private String name; + @OneToMany(mappedBy = "group", fetch = FetchType.EAGER) + private List userGroups; + public long getId() { return id; } @@ -28,4 +32,12 @@ public String getName() { public void setName(String name) { this.name = name; } + + public List getUserGroups() { + return userGroups; + } + + public void setUserGroups(List userGroups) { + this.userGroups = userGroups; + } } diff --git a/core/src/main/java/org/dcsc/core/user/group/GroupRepository.java b/core/src/main/java/org/dcsc/core/user/group/GroupRepository.java new file mode 100644 index 0000000..d175f5b --- /dev/null +++ b/core/src/main/java/org/dcsc/core/user/group/GroupRepository.java @@ -0,0 +1,11 @@ +package org.dcsc.core.user.group; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface GroupRepository extends JpaRepository { + Optional findGroupByName(String name); +} diff --git a/core/src/main/java/org/dcsc/core/user/group/GroupService.java b/core/src/main/java/org/dcsc/core/user/group/GroupService.java new file mode 100644 index 0000000..d5a8f76 --- /dev/null +++ b/core/src/main/java/org/dcsc/core/user/group/GroupService.java @@ -0,0 +1,18 @@ +package org.dcsc.core.user.group; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class GroupService { + @Autowired + private GroupRepository groupRepository; + + // TODO: Use a more appropriate exception + @Transactional(readOnly = true) + public Group getGroup(String groupName) throws Exception { + return groupRepository.findGroupByName(groupName) + .orElseThrow(() -> new Exception(String.format("Could not find group with name - %s", groupName))); + } +} diff --git a/src/main/resources b/src/main/resources index e84622b..8e7b5b6 160000 --- a/src/main/resources +++ b/src/main/resources @@ -1 +1 @@ -Subproject commit e84622beadf289d137350f4a23156aa2003dd476 +Subproject commit 8e7b5b65bc7751c6a4a375be11adc7d5c0f59598 diff --git a/utilities/src/test/java/org/dcsc/utilities/converter/LocalDateTimeConverterTest.java b/utilities/src/test/java/org/dcsc/utilities/converter/LocalDateTimeConverterTest.java new file mode 100644 index 0000000..d32eb5e --- /dev/null +++ b/utilities/src/test/java/org/dcsc/utilities/converter/LocalDateTimeConverterTest.java @@ -0,0 +1,40 @@ +package org.dcsc.utilities.converter; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import javax.persistence.AttributeConverter; +import java.sql.Timestamp; +import java.time.LocalDateTime; + +@RunWith(MockitoJUnitRunner.class) +public class LocalDateTimeConverterTest { + private static final AttributeConverter converter = new LocalDateTimeConverter(); + + @Test + public void convertToDatabaseColumnWithNullLocalDateTime() { + Assert.assertNull(converter.convertToDatabaseColumn(null)); + } + + @Test + public void convertToDatabaseColumn() { + LocalDateTime localDateTime = LocalDateTime.now(); + + Assert.assertEquals(Timestamp.valueOf(localDateTime), converter.convertToDatabaseColumn(localDateTime)); + } + + @Test + public void convertToEntityAttributeWithNullTimestamp() { + Assert.assertNull(converter.convertToEntityAttribute(null)); + } + + @Test + public void convertToEntityAttribute() { + LocalDateTime localDateTime = LocalDateTime.now(); + Timestamp timestamp = Timestamp.valueOf(localDateTime); + + Assert.assertEquals(localDateTime, converter.convertToEntityAttribute(timestamp)); + } +} \ No newline at end of file