Skip to content

Commit

Permalink
Merge pull request #232 from justinhrobbins/feature_229
Browse files Browse the repository at this point in the history
Feature 229
  • Loading branch information
justinhrobbins committed Apr 16, 2016
2 parents a08ae62 + b7936f0 commit bf6c8d9
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 112 deletions.
13 changes: 13 additions & 0 deletions FlashCards_Config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,18 @@

<build>
<finalName>FlashCards_Config</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
10 changes: 5 additions & 5 deletions FlashCards_Config/src/main/resources/default.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#Profiles
repository.profile=spring-data
security.profile=security-http
tests.data.profile=test-data
test.data.profile=test-data

# DataSource properties
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
hibernate.hikari.dataSource.url=jdbc:mysql://localhost/flashcardapp_db?useConfigs=maxPerformance&amp;rewriteBatchedStatements=true
hibernate.hikari.dataSource.user=flashcarduser
hibernate.hikari.dataSource.password=flashcard
hikari.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
hikari.dataSource.url=jdbc:mysql://localhost/flashcardapp_db?useConfigs=maxPerformance&amp;rewriteBatchedStatements=true
hikari.dataSource.user=flashcarduser
hikari.dataSource.password=flashcard
hibernate.hikari.dataSource.cachePrepStmts=true
hibernate.hikari.dataSource.prepStmtCacheSize=250
hibernate.hikari.dataSource.prepStmtCacheSqlLimit=2048
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:property-placeholder location="classpath*:/default.properties,classpath*:/test.properties" order="1" ignore-unresolvable="true" />

</beans>
8 changes: 8 additions & 0 deletions FlashCards_Config/src/test/resources/test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# DataSource properties
hikari.dataSourceClassName=org.h2.jdbcx.JdbcDataSource
hikari.dataSource.url=jdbc:h2:mem:flashcardsDb;MVCC=true

# Hibernate / JPA properties
jpaVendorAdapter.database=H2
jpaVendorAdapter.databasePlatform=org.hibernate.dialect.H2Dialect
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

package org.robbins.flashcards.webservices;

import com.google.common.collect.Sets;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -18,7 +18,6 @@
import org.springframework.test.context.ContextConfiguration;

import javax.inject.Inject;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand All @@ -30,7 +29,10 @@ public class FlashCardsResourceIT extends GenericEntityRestTest<FlashCardDto, Lo

// this entity will be created in @Before and we'll use it for our JUnit tests and
// then delete it in @After
private FlashCardDto entity = new FlashCardDtoBuilder().withQuestion("Web API Test 'Question'").withAnswer("Web API Test 'Answer'").build();
private FlashCardDto entity = new FlashCardDtoBuilder()
.withQuestion(randomQuestion())
.withAnswer(randomQuestion())
.build();

@Override
public void setEntity(final FlashCardDto entity) {
Expand All @@ -56,13 +58,36 @@ public GenericRestCrudFacade<FlashCardDto, Long> getClient() {
@Test
public void testSearchByTagsIn() throws FlashCardsException
{
final Set<TagDto> tags = new HashSet<>();
tags.add(new TagDto(2L, "two"));
tags.add(new TagDto(20L, "twenty"));
final FlashCardDto flashCard = givenFlashCardHasTwoTags();

final List<FlashCardDto> searchResult = client.findByTagsIn(tags);
final List<FlashCardDto> searchResult = client.findByTagsIn(flashCard.getTags());

assertTrue(searchResult.size() > 0);

cleanupFlashCard(flashCard);
}

private FlashCardDto givenFlashCardHasTwoTags() {
final FlashCardDto flashCard = setupFlashCard();
TagDto tag1 = new TagDtoBuilder().withName(randomTagName()).build();
TagDto tag2 = new TagDtoBuilder().withName(randomTagName()).build();

tag1 = tagClient.save(tag1);
tag2 = tagClient.save(tag2);

flashCard.getTags().add(tag1);
flashCard.getTags().add(tag2);

return client.save(flashCard);
}

private FlashCardDto setupFlashCard() throws FlashCardsException
{
final FlashCardDto flashCardDto = new FlashCardDtoBuilder()
.withQuestion(randomQuestion())
.withAnswer(randomAnwer())
.build();
return client.save(flashCardDto);
}

@Test
Expand All @@ -86,11 +111,11 @@ public void createNewFlashCard_WithNewTag() throws FlashCardsException
{

final FlashCardDto flashCard = new FlashCardDto();
flashCard.setQuestion("Question4");
flashCard.setAnswer("Answer4");
flashCard.setQuestion(randomQuestion());
flashCard.setAnswer(randomAnwer());

final TagDto tag = new TagDto();
tag.setName("tag4");
tag.setName(randomTagName());
flashCard.getTags().add(tag);

final FlashCardDto newFlashCard = client.save(flashCard);
Expand All @@ -104,7 +129,7 @@ public void createNewFlashCard_WithNewTag() throws FlashCardsException
@Test
public void testFindFlashCardsForTag() throws FlashCardsException
{
final FlashCardDto flashCard = setupFlashCard();
final FlashCardDto flashCard = givenFlashCardHasTwoTags();

final List<FlashCardDto> results = client.findFlashCardsForTag(flashCard.getTags().iterator().next().getId(), null);
assertTrue(results != null);
Expand All @@ -113,15 +138,29 @@ public void testFindFlashCardsForTag() throws FlashCardsException
cleanupFlashCard(flashCard);
}

private FlashCardDto setupFlashCard() throws FlashCardsException
{
final FlashCardDto flashCardDto = new FlashCardDtoBuilder().withQuestion("question").withAnswer("answer").build();
flashCardDto.setTags(Sets.newHashSet(new TagDtoBuilder().withName("tag_name").build()));
return client.save(flashCardDto);
}

private void cleanupFlashCard(FlashCardDto flashCard) {
final Set<TagDto> tags = flashCard.getTags();
client.delete(flashCard.getId());
tagClient.delete(flashCard.getTags().iterator().next().getId());
cleanupTags(tags);
}

private void cleanupTags(Set<TagDto> tags) {
tags.forEach(tag -> tagClient.delete(tag.getId()));
}

private String randomQuestion() {
return randomString("Question", 10);
}

private String randomAnwer() {
return randomString("Answer", 10);
}

private String randomTagName() {
return randomString("Tag", 10);
}

private String randomString(final String prefix, final int size) {
return prefix + ": " + RandomStringUtils.randomAlphabetic(size);
}
}
6 changes: 0 additions & 6 deletions FlashCards_Repository/FlashCards_Repository_Jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
<scope>runtime</scope>
</dependency>

<!-- JDBC Connection pooling -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
</dependency>

<!-- H2 driver -->
<dependency>
<groupId>com.h2database</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<import resource="classpath:META-INF/test-applicationContext-config.xml" />
<import resource="classpath:META-INF/applicationContext-repository-jpa-commons.xml" />
<import resource="classpath:test-infrastructure.xml" />
<import resource="classpath:META-INF/infrastructure.xml" />

<context:component-scan base-package="org.robbins.flashcards.jpa.repository" />

Expand Down
10 changes: 6 additions & 4 deletions FlashCards_Repository/FlashCards_Repository_Jpa_Commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
<artifactId>FlashCards_Config</artifactId>
<version>${project.version}</version>
</dependency>

<!-- JDBC Connection pooling -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<groupId>org.robbins.flashcards</groupId>
<artifactId>FlashCards_Config</artifactId>
<type>test-jar</type>
<version>${project.version}</version>
</dependency>

<!-- JDBC Connection pooling -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
Expand All @@ -17,14 +15,10 @@

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaProperties">
<props>
<prop key="hibernate.connection.provider_class">${hibernate.connection.provider_class}</prop>
<prop key="hibernate.hikari.dataSourceClassName">${hibernate.hikari.dataSourceClassName}</prop>
<prop key="hibernate.hikari.dataSource.url">${hibernate.hikari.dataSource.url}</prop>
<prop key="hibernate.hikari.dataSource.user">${hibernate.hikari.dataSource.user}</prop>
<prop key="hibernate.hikari.dataSource.password">${hibernate.hikari.dataSource.password}</prop>
<prop key="hibernate.hikari.dataSource.cachePrepStmts">${hibernate.hikari.dataSource.cachePrepStmts}</prop>
<prop key="hibernate.hikari.dataSource.prepStmtCacheSize">${hibernate.hikari.dataSource.prepStmtCacheSize}</prop>
<prop key="hibernate.hikari.dataSource.prepStmtCacheSqlLimit">${hibernate.hikari.dataSource.prepStmtCacheSqlLimit}</prop>
Expand All @@ -46,15 +40,26 @@
<property name="databasePlatform" value="${jpaVendorAdapter.databasePlatform}" />
</bean>

<!-- data source is only used by jdbc initializer. it should be moved into a confing bean -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/flashcardapp_db?useConfigs=maxPerformance&amp;rewriteBatchedStatements=true" />
<property name="user" value="fcuser_c3po" />
<property name="password" value="flashcard" />
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="springHikariCP" />
<property name="dataSourceClassName" value="${hikari.dataSourceClassName}" />
<property name="dataSourceProperties">
<props>
<prop key="url">${hikari.dataSource.url}</prop>
<prop key="user">${hikari.dataSource.user}</prop>
<prop key="password">${hikari.dataSource.password}</prop>
</props>
</property>
</bean>

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>

<beans profile="default">
<util:list id="initResourceNames" />
</beans>

<beans profile="minimal-test-data">
<util:list id="initResourceNames">
<value>init-data/user.json</value>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@
<scope>runtime</scope>
</dependency>

<!-- JDBC Connection pooling -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
</dependency>

<!-- H2 driver -->
<dependency>
<groupId>com.h2database</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd">

<import resource="classpath:META-INF/test-applicationContext-config.xml" />
<import resource="classpath:META-INF/applicationContext-repository-jpa-commons.xml" />
<import resource="classpath:test-infrastructure.xml" />
<import resource="classpath:META-INF/infrastructure.xml" />

<bean id="loggedInUser" class="org.robbins.flashcards.dto.UserDto"
scope="prototype">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FlashCardsApplicationContextInitializer implements ApplicationConte

private final String REPOSITORY_PROFILE_PROPERTY = "repository.profile";
private final String SECURITY_PROFILE_PROPERTY = "security.profile";
private final String TESTDATA_PROFILE_PROPERTY= "tests.data.profile";
private final String TESTDATA_PROFILE_PROPERTY= "test.data.profile";

private final String DEFAULT_REPOSITORY_PROFILE = "spring-data";
private final String DEFAULT_SECURITY_PROFILE = "security-http";
Expand Down
Loading

0 comments on commit bf6c8d9

Please sign in to comment.