diff --git a/DockerHostVagrantfile b/DockerHostVagrantfile index 8b1a97a..6f5c39c 100644 --- a/DockerHostVagrantfile +++ b/DockerHostVagrantfile @@ -9,6 +9,6 @@ Vagrant.configure("2") do |config| config.vm.provision "shell", inline: "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill" - config.vm.network :forwarded_port, host: 8080, guest: 8080 + #config.vm.network :forwarded_port, host: 8080, guest: 8080 config.vm.network :forwarded_port, host: 5432, guest: 5432 end diff --git a/pom.xml b/pom.xml index 9d5ec11..a414ac2 100755 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,12 @@ postgresql 9.3-1101-jdbc41 - + + junit + junit + ${junit.version} + test + org.springframework spring-test diff --git a/scripts/dummy_data.sql b/scripts/dummy_data.sql new file mode 100644 index 0000000..681d310 --- /dev/null +++ b/scripts/dummy_data.sql @@ -0,0 +1,55 @@ +INSERT INTO conf_admin.location( + name, short_desc, full_desc, parking_info, create_dttm, last_update_dttm) + VALUES ('Sample Location', 'short', 'full', 'no parking', CURRENT_DATE, CURRENT_DATE); + +INSERT INTO conf_admin.conference( + name, short_desc, full_desc, start_date, end_date, location_id, + create_dttm, last_update_dttm) + select 'Sample Conference', 'short desc', 'full desc', CURRENT_DATE - 1, CURRENT_DATE, location.id, + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + from conf_admin.location where location.name = 'Sample Location'; + +INSERT INTO conf_admin.room( + short_desc, full_desc, conference_id) + select 'Short Description', 'Full Description', conference.id + from conf_admin.conference where conference.name = 'Sample Conference'; + +INSERT INTO conf_admin.presenter( + user_id, short_bio, job_title, company_affiliation_id) + VALUES (null, 'short bio', 'sample title', null); + +INSERT INTO conf_admin.conference_session( + name, short_desc, full_desc, conference_id, conference_session_type_id, + room_id, start_dttm, duration, create_dttm, last_update_dttm, + conference_session_presenter_id) + SELECT 'Session name', 'short desc', 'full desc', conference.id, null, + room.id, CURRENT_DATE, 30, CURRENT_DATE, CURRENT_DATE, + null + from conf_admin.conference,conf_admin.room where conference.name = 'Sample Conference' and room.short_desc = 'Short Description'; + +INSERT INTO conf_admin.conference_session_presenter( + conference_session_id, presenter_id) + select conference_session.id, presenter.id + from conf_admin.presenter, conf_admin.conference_session + where presenter.job_title = 'sample title' and conference_session.name = 'Session name'; + + + +/* +select * from conf_admin.conference; +select * from conf_admin.location; +select * from conf_admin.presenter; +select * from conf_admin.room; +select * from conf_admin.conference_session; +select * from conf_admin.conference_session_presenter; +select * from conf_admin.conference; + +delete from conf_admin.conference_session_presenter cascade; +delete from conf_admin.conference_session cascade; +delete from conf_admin.room cascade; +delete from conf_admin.conference cascade; +delete from conf_admin.location cascade; +delete from conf_admin.presenter cascade; +delete from conf_admin.conference cascade; +*/ + diff --git a/src/main/java/com/ioextendedgr/web/builder/ConferenceSessionBuilder.java b/src/main/java/com/ioextendedgr/web/builder/ConferenceSessionBuilder.java new file mode 100644 index 0000000..0cce8a0 --- /dev/null +++ b/src/main/java/com/ioextendedgr/web/builder/ConferenceSessionBuilder.java @@ -0,0 +1,57 @@ +package com.ioextendedgr.web.builder; + +import com.ioextendedgr.web.data.Conference; +import com.ioextendedgr.web.data.ConferenceSession; +import com.ioextendedgr.web.data.ConferenceSessionPresenter; +import com.ioextendedgr.web.viewDto.ConferenceSessionView; +import com.ioextendedgr.web.viewDto.ConferenceView; +import org.springframework.util.CollectionUtils; + +import java.util.*; + +/** + * Created by Scott Williams on 3/4/2015. + */ +public class ConferenceSessionBuilder { + + public static List build(Collection datas) { + if (CollectionUtils.isEmpty(datas)) { + return new ArrayList<>(); + } + + List views = new ArrayList<>(); + for (ConferenceSession data : datas) { + views.add(build(data)); + } + return views; + } + + + public static ConferenceSessionView build(ConferenceSession data) { + if (data == null) + return null; + + ConferenceSessionView view = new ConferenceSessionView(); + + view.setId(data.getId()); + view.setName(data.getName()); + view.setConferenceId(data.getConference().getId()); + view.setDurationMinutes(data.getDuration()); + view.setShortDesc(data.getShortDesc()); + view.setFullDesc(data.getFullDesc()); + view.setCreateDttm(data.getCreateDttm()); + view.setLastUpdateDttm(data.getLastUpdateDttm()); + Set cspIds = new HashSet<>(); + for(ConferenceSessionPresenter csp: data.getConferenceSessionPresenters()){ + cspIds.add(csp.getId()); + } + view.setPresenterIds(new ArrayList<>(cspIds)); + view.setRoomId(data.getRoom().getId()); + view.setStartDttm(data.getStartDttm()); + + return view; + } + + + + } diff --git a/src/main/java/com/ioextendedgr/web/controller/ConferenceController.java b/src/main/java/com/ioextendedgr/web/controller/ConferenceController.java index a5b8ea0..f722bab 100644 --- a/src/main/java/com/ioextendedgr/web/controller/ConferenceController.java +++ b/src/main/java/com/ioextendedgr/web/controller/ConferenceController.java @@ -32,7 +32,7 @@ public ConferenceView findConferenceById(@PathVariable("id") Integer id) { } @RequestMapping("/conference/{id}/conferenceSessions") - public Collection findConferenceSessionsByConferenceId(@PathVariable("id") Long id) { + public Collection findConferenceSessionsByConferenceId(@PathVariable("id") Integer id) { return conferenceService.findConferenceSessionsByConferenceId(id); } } diff --git a/src/main/java/com/ioextendedgr/web/controller/ConferenceSessionController.java b/src/main/java/com/ioextendedgr/web/controller/ConferenceSessionController.java index 5231729..dff6a6d 100644 --- a/src/main/java/com/ioextendedgr/web/controller/ConferenceSessionController.java +++ b/src/main/java/com/ioextendedgr/web/controller/ConferenceSessionController.java @@ -11,19 +11,19 @@ import com.ioextendedgr.web.viewDto.ConferenceSessionView; @RestController -@RequestMapping("/api") +@RequestMapping("/api/conferenceSession") public class ConferenceSessionController { @Autowired private ConferenceService conferenceService; - @RequestMapping("/conferenceSession") + @RequestMapping("") public Collection findAllConferenceSessions() { return conferenceService.findAllConferenceSessions(); } - @RequestMapping("/conferenceSession/{id}") - public ConferenceSessionView findConferenceSessionById(@PathVariable("id") Long id) { + @RequestMapping("/{id}") + public ConferenceSessionView findConferenceSessionById(@PathVariable("id") Integer id) { return conferenceService.findConferenceSessionById(id); } } diff --git a/src/main/java/com/ioextendedgr/web/repository/ConferenceSessionRepository.java b/src/main/java/com/ioextendedgr/web/repository/ConferenceSessionRepository.java new file mode 100644 index 0000000..7253931 --- /dev/null +++ b/src/main/java/com/ioextendedgr/web/repository/ConferenceSessionRepository.java @@ -0,0 +1,15 @@ +package com.ioextendedgr.web.repository; + +import com.ioextendedgr.web.data.ConferenceSession; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +/** + * Created by Scott Williams on 3/4/2015. + */ +public interface ConferenceSessionRepository extends JpaRepository { + + public List findByConferenceId(Integer id); + +} diff --git a/src/main/java/com/ioextendedgr/web/service/ConferenceService.java b/src/main/java/com/ioextendedgr/web/service/ConferenceService.java index 2c2a427..ed68413 100644 --- a/src/main/java/com/ioextendedgr/web/service/ConferenceService.java +++ b/src/main/java/com/ioextendedgr/web/service/ConferenceService.java @@ -2,6 +2,8 @@ import java.util.Collection; +import com.ioextendedgr.web.builder.ConferenceSessionBuilder; +import com.ioextendedgr.web.repository.ConferenceSessionRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -21,6 +23,9 @@ public class ConferenceService { @Autowired private ConferenceRepository conferenceRepository; + @Autowired + private ConferenceSessionRepository conferenceSessionRepository; + public Collection findAllConferences() { return ConferenceViewBuilder.build(conferenceRepository.findAll()); } @@ -38,15 +43,15 @@ public PresenterView findPresenterById(Long id) { } public Collection findAllConferenceSessions() { - return stubFactory.findAllConferenceSessions(); + return ConferenceSessionBuilder.build(conferenceSessionRepository.findAll()); } - public ConferenceSessionView findConferenceSessionById(Long id) { - return stubFactory.findConferenceSessionById(id); + public ConferenceSessionView findConferenceSessionById(Integer id) { + return ConferenceSessionBuilder.build(conferenceSessionRepository.findOne(id)); } - public Collection findConferenceSessionsByConferenceId(Long id) { - return stubFactory.findConferenceSessionsByConferenceId(id); + public Collection findConferenceSessionsByConferenceId(Integer id) { + return ConferenceSessionBuilder.build(conferenceSessionRepository.findByConferenceId(id)); } } diff --git a/src/main/java/com/ioextendedgr/web/util/StubFactory.java b/src/main/java/com/ioextendedgr/web/util/StubFactory.java index c45a5d0..3c4d023 100644 --- a/src/main/java/com/ioextendedgr/web/util/StubFactory.java +++ b/src/main/java/com/ioextendedgr/web/util/StubFactory.java @@ -23,9 +23,9 @@ @Component public class StubFactory { - Map conferenceViewsByIdMap = new HashMap(); - Map presenterViewsByIdMap = new HashMap(); - Map conferenceSessionByIdMap = new HashMap(); + Map conferenceViewsByIdMap = new HashMap(); + Map presenterViewsByIdMap = new HashMap(); + Map conferenceSessionByIdMap = new HashMap(); public StubFactory() { init(); @@ -84,7 +84,7 @@ private void initializeConferenceSessions() { private void initializePresenterViews() { List presenterViews = createPresenterViews(); for (PresenterView currPresenterView : presenterViews) { - presenterViewsByIdMap.put(currPresenterView.getId(), currPresenterView); + presenterViewsByIdMap.put(currPresenterView.getId().intValue(), currPresenterView); } } @@ -92,7 +92,7 @@ private void initializePresenterViews() { private void initializeConferenceViews() { List createConferenceViews = createConferenceViews(); for (ConferenceView currConferenceView : createConferenceViews) { - conferenceViewsByIdMap.put(currConferenceView.getId(), currConferenceView); + conferenceViewsByIdMap.put(currConferenceView.getId().intValue(), currConferenceView); } } @@ -121,45 +121,45 @@ private List createPresenterViews() { private ConferenceSessionView toConferenceSessionView(int index) { ConferenceSessionView dto = new ConferenceSessionView(); - - List conferenceIds = new ArrayList(conferenceViewsByIdMap.keySet()); - List presenterIds = new ArrayList(presenterViewsByIdMap.keySet()); - + + List conferenceIds = new ArrayList(conferenceViewsByIdMap.keySet()); + List presenterIds = new ArrayList(presenterViewsByIdMap.keySet()); + Random random = new Random(); - - dto.setId(Long.valueOf(50 + index)); + + dto.setId(50 + index); dto.setConferenceId(conferenceIds.get(random.nextInt(conferenceIds.size()))); dto.setCreateDttm(new Date()); dto.setDurationMinutes((index % 2 == 0) ? 30 : 60); dto.setFullDesc(format("Full description of the session talk for session: %d", dto.getId())); dto.setLastUpdateDttm(new Date()); dto.setName(format("Name of Session for %d", dto.getId())); - - List selectedPresenterIds = null; + + List selectedPresenterIds = null; if (index % 2 == 0) { selectedPresenterIds = toSinglePresenterIdList(random, presenterIds); } else { selectedPresenterIds = toMultiplePresenterIdsList(random, presenterIds); } dto.setPresenterIds(selectedPresenterIds); - dto.setRoomId(-1L); + dto.setRoomId(-1); dto.setShortDesc(format("Short Description Session: %d", dto.getId())); dto.setStartDttm(new Date()); - + return dto; } - private List toMultiplePresenterIdsList(Random random, List presenterIds) { - Set presenterIdSet = new HashSet(); + private List toMultiplePresenterIdsList(Random random, List presenterIds) { + Set presenterIdSet = new HashSet(); presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size()))); presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size()))); presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size()))); presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size()))); - return new ArrayList(presenterIdSet); + return new ArrayList(presenterIdSet); } - private List toSinglePresenterIdList(Random random, List presenterIds) { - List presenterIdList = new ArrayList(); + private List toSinglePresenterIdList(Random random, List presenterIds) { + List presenterIdList = new ArrayList(); presenterIdList.add(presenterIds.get(random.nextInt(presenterIds.size()))); return presenterIdList; } diff --git a/src/main/java/com/ioextendedgr/web/viewDto/ConferenceSessionView.java b/src/main/java/com/ioextendedgr/web/viewDto/ConferenceSessionView.java index 780add0..658bb75 100644 --- a/src/main/java/com/ioextendedgr/web/viewDto/ConferenceSessionView.java +++ b/src/main/java/com/ioextendedgr/web/viewDto/ConferenceSessionView.java @@ -5,23 +5,23 @@ public class ConferenceSessionView { - private Long id; + private Integer id; private String name; private String shortDesc; private String fullDesc; - private Long conferenceId; - private List presenterIds; - private Long roomId; + private Integer conferenceId; + private List presenterIds; + private Integer roomId; private Date startDttm; private Integer durationMinutes; private Date createDttm; private Date lastUpdateDttm; - public Long getId() { + public Integer getId() { return id; } - public void setId(Long id) { + public void setId(Integer id) { this.id = id; } public String getName() { @@ -42,22 +42,22 @@ public String getFullDesc() { public void setFullDesc(String fullDesc) { this.fullDesc = fullDesc; } - public Long getConferenceId() { + public Integer getConferenceId() { return conferenceId; } - public void setConferenceId(Long conferenceId) { + public void setConferenceId(Integer conferenceId) { this.conferenceId = conferenceId; } - public List getPresenterIds() { + public List getPresenterIds() { return presenterIds; } - public void setPresenterIds(List presenterIds) { + public void setPresenterIds(List presenterIds) { this.presenterIds = presenterIds; } - public Long getRoomId() { + public Integer getRoomId() { return roomId; } - public void setRoomId(Long roomId) { + public void setRoomId(Integer roomId) { this.roomId = roomId; } public Date getStartDttm() { diff --git a/src/test/java/base/BaseSpringIT.java b/src/test/java/base/BaseSpringIT.java new file mode 100644 index 0000000..a8fe854 --- /dev/null +++ b/src/test/java/base/BaseSpringIT.java @@ -0,0 +1,24 @@ +package base; + +import com.ioextendedgr.web.Application; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.ConfigFileApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Application.class, initializers = ConfigFileApplicationContextInitializer.class) +@Transactional +@WebAppConfiguration +public class BaseSpringIT { + + @Ignore + @Test + public void testBaseContextBuild(){ + + } +} diff --git a/src/test/java/com/ioextendedgr/web/service/ConferenceServiceTest.java b/src/test/java/com/ioextendedgr/web/service/ConferenceServiceTest.java new file mode 100644 index 0000000..a2d1475 --- /dev/null +++ b/src/test/java/com/ioextendedgr/web/service/ConferenceServiceTest.java @@ -0,0 +1,61 @@ +package com.ioextendedgr.web.service; + +import base.BaseSpringIT; +import com.ioextendedgr.web.repository.ConferenceRepository; +import com.ioextendedgr.web.viewDto.ConferenceSessionView; +import com.ioextendedgr.web.viewDto.ConferenceView; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.List; + +@Ignore +public class ConferenceServiceTest extends BaseSpringIT{ + + private static Logger logger = LoggerFactory.getLogger(ConferenceServiceTest.class); + + @Autowired + private ConferenceService conferenceService; + + @Autowired + private ConferenceRepository conferenceRepository; + + @Before + public void setup(){ + //Can't get the boot log levels turned down... + logger.info("\n\n\n\n\n\n\n\n"); + } + + @After + public void teardown(){ + logger.info("\n\n\n\n\n\n\n\n"); + } + + @Test + public void testConference(){ + logger.info("{}", conferenceRepository.findAll().size()); + List conferenceViews = new ArrayList<>(conferenceService.findAllConferences()); + } + + @Test + public void testConferenceSession(){ + List conferenceViews = new ArrayList<>(conferenceService.findAllConferences()); + + List conferenceSessionViews = new ArrayList<>(conferenceService.findAllConferenceSessions()); + + ConferenceSessionView cv1 = conferenceService.findConferenceSessionById(conferenceSessionViews.get(0).getId()); + + ConferenceSessionView cv2 = new ArrayList<>(conferenceService.findConferenceSessionsByConferenceId(conferenceViews.get(0).getId().intValue())).get(0); + + logger.info(""); + + } + + +} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..71ddeb5 --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,9 @@ +spring.jpa.hibernate.ddl-auto=validate +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.username=postgres +spring.datasource.password=postgres +spring.datasource.driverClassName=org.postgresql.Driver +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.properties.hibernate.show_sql=true +spring.jpa.properties.hibernate.default_schema=conf_admin +#logging.level.:ERROR \ No newline at end of file