Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase code coverage - JDBC feeds publisher and JDBC feeds source #338

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test-suite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<pre>
___ __ __ __
/ | / /_____ ____ ___ / / / /____ ____ ____ ___ _____
/ /| |/ __/ __ \/ __ `__ \ / /_/ // __ \/ __ \/ __ \/ _ \/ ___/
/ ___ / /_/ /_/ / / / / / / / __ // /_/ / /_/ / /_/ / __/ /
/_/ |_\__/\____/_/ /_/ /_/ /_/ /_/ \____/ .___/ .___/\___/_/
/_/ /_/
</pre>

#How to switch between the different adapters like Hibernate adapter and JDBC adapter.#

The test-suite is designed to test the functionality of the atomhopper which uses different kinds of adapters to support different kind of DBs.
For running the functional test cases the adapter can be switched for 1 adapter to another and same functional test cases can be run with different adapters.
If in future a new DB is added then we can write the configuartion files for the new DB and try to run the same functional test cases. We should be able to insert and get the feeds from the new DB instance.



Steps:

* Rename atom-server.cfg.xml to atom-server_Hibernate.cfg.xml present at location /atom-hopper/test-suite/src/test/resources/META-INF/
* Rename atom-server_JDBC.cfg.xml to atom-server.cfg.xml present at location /atom-hopper/test-suite/src/test/resources/META-INF/
* Rename application-context.xml to application-context_Hibernate.xml present at location atom-hopper/test-suite/src/main/resources/META-INF
* Rename application-context_JDBC.xml to application-context.xml present at location atom-hopper/test-suite/src/main/resources/META-INF


###Notes Regarding Test Suite###

* All the existing test suite files should work with both the adapters.
* The working instance of postgresql is required for the JDBC adapter to work.
* Hibernate creates the internal database on Jetty server but postgres can't.
* The configuration related to JDBC(postgres db instance) can be changed in application-context_JDBC.xml file. The default configuration is already there in the file and pointing to local instance of postgres db running on 5432 port.
* Properties like allowOverrideDate, allowOverrideId can be added or their value can be changed in the file application-context_JDBC.xml.
16 changes: 13 additions & 3 deletions test-suite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>parent</artifactId>
<version>1.2.35-SNAPSHOT</version>
</parent>

<groupId>org.atomhopper</groupId>
<artifactId>test-suite</artifactId>
<packaging>jar</packaging>
Expand All @@ -34,7 +34,12 @@
<groupId>org.atomhopper.adapter</groupId>
<artifactId>hibernate-adapter</artifactId>
</dependency>


<dependency>
<groupId>org.atomhopper.adapter</groupId>
<artifactId>jdbc-adapter</artifactId>
</dependency>

<dependency>
<groupId>org.apache.abdera</groupId>
<artifactId>abdera-core</artifactId>
Expand Down Expand Up @@ -94,6 +99,12 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>

<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -156,4 +167,3 @@
</profile>
</profiles>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="atomHopperDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/atomhopper" />
<property name="username" value="postgres" />
<property name="password" value="password" />
<property name="minIdle" value="10" />
<property name="maxIdle" value="25" />
<property name="initialSize" value="10" />
<property name="maxActive" value="50" />
<property name="validationQuery" value="SELECT 1" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="10000" />
</bean>

<bean name="atomHopperJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg name="dataSource" ref="atomHopperDataSource"/>
</bean>

<bean name="jdbc-feed-publisher" class="org.atomhopper.jdbc.adapter.JdbcFeedPublisher">
<property name="jdbcTemplate" ref="atomHopperJdbcTemplate" />
<property name="allowOverrideId" value="true"/>

</bean>

<bean name="jdbc-feed-source" class="org.atomhopper.jdbc.adapter.JdbcFeedSource">
<property name="jdbcTemplate" ref="atomHopperJdbcTemplate" />
<property name="enableLoggingOnShortPage" value="true"/>
</bean>


<bean name="jdbc-feed-publisher1" class="org.atomhopper.jdbc.adapter.JdbcFeedPublisher">
<property name="jdbcTemplate" ref="atomHopperJdbcTemplate" />
<property name="allowOverrideId" value="true"/>
<property name="allowOverrideDate" value="true"/>
</bean>

<bean name="jdbc-feed-source1" class="org.atomhopper.jdbc.adapter.JdbcFeedSource">
<property name="jdbcTemplate" ref="atomHopperJdbcTemplate" />
</bean>

<bean name="feed-paging-processor" class="org.atomhopper.abdera.filter.FeedPagingProcessor"/>

<bean name="role-aware-feed-etag-processor" class="org.atomhopper.abdera.filter.HeaderValueFeedEntityTagProcessor">
<property name="headerName" value="x-access" />
<property name="hashETag" value="true"/>
<property name="headerTagPostfixMap">
<map>
<entry key="level1" value="L1"/>
<entry key="level2" value="L2"/>
</map>
</property>
</bean>

<bean name="selective-uri-json-filter" class="org.atomhopper.abdera.filter.SelectiveURIJSONFilter">
<property name="allowedURIs">
<list>
<value>/namespace2/feed2</value>
</list>
</property>
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.abdera.parser.Parser;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
Expand All @@ -16,9 +17,14 @@
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import static junit.framework.Assert.assertEquals;

Expand Down Expand Up @@ -59,13 +65,31 @@ public static String getFeedDirectionForwardMethod(String markerId) {

public static String getFeedDirectionBackwardMethod(String markerId) {
return getURL() + "?marker=" + markerId + "&direction=backward&limit=10";
}

public static String getURLMarkerLast() {
return urlAndPort + "/namespace3/feed3/?marker=last";
}

public static GetMethod getFeedMethodMarkerLast() {
return new GetMethod(getURLMarkerLast());
}

public static String getURLWithStartingAt() {
return urlAndPort + "/namespace3/feed3/?startingAt=" +"2011-03-10T11:54:30.207Z";
}

public static GetMethod getFeedMethodWithStartingAt() {
return new GetMethod(getURLWithStartingAt());
}


public static class WhenRequestingFeed {
@Test
public void shouldOrderCorrectlyForwardAndBackward() throws Exception {
final HttpMethod getFeedMethod = getFeedMethod();
assertEquals("Hitting Atom Hopper with an empty datastore should return a 200", HttpStatus.SC_OK, httpClient.executeMethod(getFeedMethod));

// Create 20 new entries
for(int i = 1; i < 21; i++) {
final HttpMethod postMethod = newPostEntryMethod("<order>" + Integer.toString(i) + "</order>");
Expand All @@ -74,6 +98,12 @@ public void shouldOrderCorrectlyForwardAndBackward() throws Exception {

// namespace3/feed3
assertEquals("Getting a feed should return a 200", HttpStatus.SC_OK, httpClient.executeMethod(getFeedMethod));

final HttpMethod getFeedMethodMarkerLast = getFeedMethodMarkerLast();
assertEquals("Getting a feed should return a 200", HttpStatus.SC_OK, httpClient.executeMethod(getFeedMethodMarkerLast));

final HttpMethod getFeedMethodWithStartingAt = getFeedMethodWithStartingAt();
assertEquals("Getting a feed should return a 200", HttpStatus.SC_OK, httpClient.executeMethod(getFeedMethodWithStartingAt));

// A bit verbose, but it checks the forward and backward direction of the feed
Parser parser = getInstance().getParser();
Expand Down Expand Up @@ -112,6 +142,7 @@ public void shouldOrderCorrectlyForwardAndBackward() throws Exception {
idCount++;
}
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

import java.util.Random;


@RunWith(Enclosed.class)
public class PostAndGetMultipleEntriesIntegrationTest extends JettyIntegrationTestHarness {
Expand Down Expand Up @@ -43,7 +45,7 @@ public static PostMethod newPostEntryMethod(String content) {
}

public static PostMethod newPostEntryMethodWithEntryId(String content, String entryId) {
final PostMethod post = new PostMethod(urlAndPort + "/namespace1/feed1/");
final PostMethod post = new PostMethod(urlAndPort + "/namespace7/feed7/");
post.addRequestHeader(new Header("content-type", "application/atom+xml"));
post.setRequestBody("<?xml version=\"1.0\" ?><entry xmlns=\"http://www.w3.org/2005/Atom\"><author><name>Chad</name></author><content>" + content + "</content>" +
"<id>" + entryId + "</id></entry>");
Expand All @@ -66,18 +68,28 @@ public void shouldCreateAndGetMultipleEntries() throws Exception {
//System.out.println(new String(getFeedMethod.getResponseBody()));

assertEquals("Getting the new feed should show that <b1>215</b1> was added", HttpStatus.SC_OK, httpClient.executeMethod(getFeedMethod));
assertTrue(new String(getFeedMethod.getResponseBody()).contains("<b1>215</b1>"));
}
}

public static class WhenPublishingDuplicatesGenerateError {

@Test
public void shouldGenerateErrorWhenDuplicates() throws Exception {
HttpMethod postMethod = newPostEntryMethodWithEntryId("<blah><a1>a1</a1><b1>200</b1></blah>", "urn:uuid:aa12175c-36a0-4136-bd98-6eb2d442e7ab");
String randomNumber = getRandomNumberString();
HttpMethod postMethod = newPostEntryMethodWithEntryId("<blah><a1>a1</a1><b1>200</b1></blah>", "urn:uuid:aa" + randomNumber + "c-36a0-4136-bd98-6eb2d442e7ad");
assertEquals("Creating a new entry should return a 201", HttpStatus.SC_CREATED, httpClient.executeMethod(postMethod));
postMethod = newPostEntryMethodWithEntryId("<blah><a1>a1</a1><b1>200</b1></blah>", "urn:uuid:aa12175c-36a0-4136-bd98-6eb2d442e7ab");
postMethod = newPostEntryMethodWithEntryId("<blah><a1>a1</a1><b1>200</b1></blah>", "urn:uuid:aa" + randomNumber +"c-36a0-4136-bd98-6eb2d442e7ad");
assertEquals("Creating the same entry should return a 409", HttpStatus.SC_CONFLICT, httpClient.executeMethod(postMethod));
}

public static String getRandomNumberString() {
// It will generate 6 digit random Number.
// from 0 to 999999
Random rnd = new Random();
int number = rnd.nextInt(99999);

// this will convert any number sequence into 6 character.
return String.format("%05d", number);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public void shouldReturnANewEntryWithETagRole() throws Exception {
final HttpMethod getFeedMethod = new GetMethod(urlAndPort + "/namespace6/feed6/");
getFeedMethod.addRequestHeader("x-access", "level1");
httpClient.executeMethod(getFeedMethod);
final String etagL1 = getFeedMethod.getResponseHeader("ETag").getValue();
assertTrue("The returned feed should set an etag in the header", etagL1.contains("W/"));
String etagL1 = "";
if(null != getFeedMethod.getResponseHeader("ETag")) {
etagL1 = getFeedMethod.getResponseHeader("ETag").getValue();
assertTrue("The returned feed should set an etag in the header", etagL1.contains("W/"));
}


final HttpMethod getFeedMethodAsLevel3 = new GetMethod(urlAndPort + "/namespace6/feed6");
getFeedMethodAsLevel3.addRequestHeader("x-access", "level3");
Expand Down
87 changes: 87 additions & 0 deletions test-suite/src/test/resources/META-INF/atom-server_JDBC.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>

<atom-hopper-config xmlns="http://atomhopper.org/atom/hopper-config/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://atomhopper.org/atom/hopper-config/v1.0 ./../../config/atom-hopper-config.xsd">
<defaults>
<author name="Atom Hopper" />
</defaults>

<host domain="localhost:24156" scheme="http" />

<provider-filters>
<provider-filter reference="selective-uri-json-filter"/>
</provider-filters>

<workspace title="Namespace" resource="/namespace/">
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed" resource="/feed">
<feed-source reference="jdbc-feed-source" />
<publisher reference="jdbc-feed-publisher" />
</feed>
</workspace>

<workspace title="Namespace1" resource="/namespace1/">
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed1" resource="/feed1">
<feed-source reference="jdbc-feed-source" />
<publisher reference="jdbc-feed-publisher" />
</feed>
</workspace>

<workspace title="Namespace2" resource="/namespace2/">
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed2" resource="/feed2">
<feed-source reference="jdbc-feed-source" />
<publisher reference="jdbc-feed-publisher" />
</feed>
</workspace>

<workspace title="Namespace3" resource="/namespace3/">
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed3" resource="/feed3">
<feed-source reference="jdbc-feed-source" />
<publisher reference="jdbc-feed-publisher" />
</feed>
</workspace>
<workspace title="Namespace4" resource="/namespace4/" enableRegexFeeds="true">
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed4" resource="/feed4/[0-9]*">
<feed-source reference="jdbc-feed-source" />
<publisher reference="jdbc-feed-publisher" />
</feed>
</workspace>

<workspace title="Namespace5" resource="/namespace5/" >
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed5" resource="/feed5/[0-9]*">
<feed-source reference="jdbc-feed-source" />
<publisher reference="jdbc-feed-publisher" />
</feed>
</workspace>
<workspace title="Namespace6" resource="/namespace6/" >
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed6" resource="/feed6">
<feed-source reference="jdbc-feed-source" />
<publisher reference="jdbc-feed-publisher" />
<feed-response-handlers>
<feed-response-handler reference="feed-paging-processor"/>
<feed-response-handler reference="role-aware-feed-etag-processor"/>
</feed-response-handlers>
</feed>
</workspace>

<workspace title="Namespace7" resource="/namespace7/">
<categories-descriptor reference="workspace-categories-descriptor" />

<feed title="feed7" resource="/feed7">
<feed-source reference="jdbc-feed-source1" />
<publisher reference="jdbc-feed-publisher1" />
</feed>
</workspace>
</atom-hopper-config>