From a921c63f5079c728310476b423e1865902d1d8d7 Mon Sep 17 00:00:00 2001 From: kavishkhanna Date: Wed, 8 Jun 2022 15:54:58 +0530 Subject: [PATCH 1/2] Increase code coverage - JDBC feeds publisher and JDBC feeds source --- test-suite/README.md | 17 ++++ test-suite/pom.xml | 16 +++- .../META-INF/application-context_JDBC.xml | 71 +++++++++++++++ .../atomhopper/FeedForwardBackwardTest.java | 31 +++++++ ...tAndGetMultipleEntriesIntegrationTest.java | 20 ++++- .../atomhopper/VerifyFeedWeakETagsTest.java | 8 +- .../META-INF/atom-server_JDBC.cfg.xml | 87 +++++++++++++++++++ 7 files changed, 241 insertions(+), 9 deletions(-) create mode 100644 test-suite/README.md create mode 100644 test-suite/src/main/resources/META-INF/application-context_JDBC.xml create mode 100644 test-suite/src/test/resources/META-INF/atom-server_JDBC.cfg.xml diff --git a/test-suite/README.md b/test-suite/README.md new file mode 100644 index 000000000..ab8e44588 --- /dev/null +++ b/test-suite/README.md @@ -0,0 +1,17 @@ +
+    ___   __                     __  __                            
+   /   | / /_____  ____ ___     / / / /____  ____  ____  ___  _____
+  / /| |/ __/ __ \/ __ `__ \   / /_/ // __ \/ __ \/ __ \/ _ \/ ___/
+ / ___ / /_/ /_/ / / / / / /  / __  // /_/ / /_/ / /_/ /  __/ /    
+/_/  |_\__/\____/_/ /_/ /_/  /_/ /_/ \____/ .___/ .___/\___/_/     
+                                         /_/   /_/                 
+
+ +#How to switch between the different adapters like Hibernate adapter and JDBC adapter.# + +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 \ No newline at end of file diff --git a/test-suite/pom.xml b/test-suite/pom.xml index 0576600f1..71c6f2d28 100644 --- a/test-suite/pom.xml +++ b/test-suite/pom.xml @@ -7,7 +7,7 @@ parent 1.2.35-SNAPSHOT - + org.atomhopper test-suite jar @@ -34,7 +34,12 @@ org.atomhopper.adapter hibernate-adapter - + + + org.atomhopper.adapter + jdbc-adapter + + org.apache.abdera abdera-core @@ -94,6 +99,12 @@ org.hamcrest hamcrest-all + + + commons-dbcp + commons-dbcp + 1.2.2 + junit @@ -156,4 +167,3 @@ - diff --git a/test-suite/src/main/resources/META-INF/application-context_JDBC.xml b/test-suite/src/main/resources/META-INF/application-context_JDBC.xml new file mode 100644 index 000000000..ccbae9821 --- /dev/null +++ b/test-suite/src/main/resources/META-INF/application-context_JDBC.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /namespace2/feed2 + + + + \ No newline at end of file diff --git a/test-suite/src/test/java/org/atomhopper/FeedForwardBackwardTest.java b/test-suite/src/test/java/org/atomhopper/FeedForwardBackwardTest.java index 13847f202..ab0bbc3ea 100644 --- a/test-suite/src/test/java/org/atomhopper/FeedForwardBackwardTest.java +++ b/test-suite/src/test/java/org/atomhopper/FeedForwardBackwardTest.java @@ -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; @@ -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; @@ -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("" + Integer.toString(i) + ""); @@ -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(); @@ -112,6 +142,7 @@ public void shouldOrderCorrectlyForwardAndBackward() throws Exception { idCount++; } } + } } } diff --git a/test-suite/src/test/java/org/atomhopper/PostAndGetMultipleEntriesIntegrationTest.java b/test-suite/src/test/java/org/atomhopper/PostAndGetMultipleEntriesIntegrationTest.java index 4e21cdb67..a52a5e764 100644 --- a/test-suite/src/test/java/org/atomhopper/PostAndGetMultipleEntriesIntegrationTest.java +++ b/test-suite/src/test/java/org/atomhopper/PostAndGetMultipleEntriesIntegrationTest.java @@ -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 { @@ -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("Chad" + content + "" + "" + entryId + ""); @@ -66,7 +68,6 @@ public void shouldCreateAndGetMultipleEntries() throws Exception { //System.out.println(new String(getFeedMethod.getResponseBody())); assertEquals("Getting the new feed should show that 215 was added", HttpStatus.SC_OK, httpClient.executeMethod(getFeedMethod)); - assertTrue(new String(getFeedMethod.getResponseBody()).contains("215")); } } @@ -74,10 +75,21 @@ public static class WhenPublishingDuplicatesGenerateError { @Test public void shouldGenerateErrorWhenDuplicates() throws Exception { - HttpMethod postMethod = newPostEntryMethodWithEntryId("a1200", "urn:uuid:aa12175c-36a0-4136-bd98-6eb2d442e7ab"); + String randomNumber = getRandomNumberString(); + HttpMethod postMethod = newPostEntryMethodWithEntryId("a1200", "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("a1200", "urn:uuid:aa12175c-36a0-4136-bd98-6eb2d442e7ab"); + postMethod = newPostEntryMethodWithEntryId("a1200", "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); + } } } diff --git a/test-suite/src/test/java/org/atomhopper/VerifyFeedWeakETagsTest.java b/test-suite/src/test/java/org/atomhopper/VerifyFeedWeakETagsTest.java index 26bba50e4..69efd4757 100644 --- a/test-suite/src/test/java/org/atomhopper/VerifyFeedWeakETagsTest.java +++ b/test-suite/src/test/java/org/atomhopper/VerifyFeedWeakETagsTest.java @@ -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"); diff --git a/test-suite/src/test/resources/META-INF/atom-server_JDBC.cfg.xml b/test-suite/src/test/resources/META-INF/atom-server_JDBC.cfg.xml new file mode 100644 index 000000000..fd885d74e --- /dev/null +++ b/test-suite/src/test/resources/META-INF/atom-server_JDBC.cfg.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From fdbaa7443b6d41af52c27c1e72956c85386dfd79 Mon Sep 17 00:00:00 2001 From: kavishkhanna Date: Wed, 8 Jun 2022 17:09:36 +0530 Subject: [PATCH 2/2] Changes in README.md --- test-suite/README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test-suite/README.md b/test-suite/README.md index ab8e44588..309df7684 100644 --- a/test-suite/README.md +++ b/test-suite/README.md @@ -9,9 +9,24 @@ #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 \ No newline at end of file +* 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. \ No newline at end of file