Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
558 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?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:util="http://www.springframework.org/schema/util" | ||
xmlns:jdbc="http://www.springframework.org/schema/jdbc" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd | ||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> | ||
|
||
<bean name="petDao" class="play.baseline.dao.PetDaoImpl"> | ||
<constructor-arg ref="dataSource"/> | ||
</bean> | ||
|
||
<jdbc:embedded-database id="dataSource" type="HSQL"> | ||
<jdbc:script location="classpath:db/schema.sql"/> | ||
<jdbc:script location="classpath:db/pets.sql"/> | ||
</jdbc:embedded-database> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Set root logger level to DEBUG and its only appender to A1. | ||
log4j.rootLogger=DEBUG, A1 | ||
log4j.logger.org.springframework=INFO | ||
|
||
# A1 is set to be a ConsoleAppender. | ||
log4j.appender.A1=org.apache.log4j.ConsoleAppender | ||
|
||
# A1 uses PatternLayout. | ||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n |
76 changes: 76 additions & 0 deletions
76
baseline/service/src/test/java/remotemock/IntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package remotemock; | ||
|
||
import com.google.common.collect.Lists; | ||
import org.codehaus.jackson.map.ObjectMapper; | ||
import org.codehaus.jackson.type.TypeReference; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.springframework.util.AntPathMatcher; | ||
import play.baseline.BaselineService; | ||
import play.baseline.Main; | ||
import play.baseline.model.Pet; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.mockito.Mockito.doReturn; | ||
|
||
/** | ||
* Run server. (with database) | ||
* Make a call & check result | ||
*/ | ||
public class IntegrationTest { | ||
|
||
private static String PATH_QUERY_BY_NAME = "/pets/list/name={name}&age={age}"; | ||
|
||
private static Process server; | ||
|
||
@BeforeClass | ||
public static void startServer() throws IOException, InterruptedException { | ||
String classpath = System.getProperty("java.class.path"); | ||
String className = Main.class.getCanonicalName(); | ||
ProcessBuilder pb = new ProcessBuilder("java", "-cp", classpath, className, "-Dlog4j.debug=true"); | ||
pb.inheritIO(); | ||
server = pb.start(); | ||
Thread.sleep(5000); | ||
} | ||
|
||
@org.junit.Test | ||
public void testListByNameAndAge() throws InterruptedException, IOException { | ||
String query = PATH_QUERY_BY_NAME.replace("{name}", "Cango").replace("{age}", "3"); | ||
String response = getResponse(query); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
List<Pet> pets = mapper.readValue(response, new TypeReference<List<Pet>>() { | ||
}); | ||
|
||
Pet pet = new Pet(); | ||
pet.setId(1); | ||
pet.setName("Cango"); | ||
pet.setAge(3); | ||
pet.setOwner("Osman Bosman"); | ||
List<Pet> exptected = Lists.newArrayList(pet); | ||
|
||
Assert.assertEquals("Invalid return value", exptected, pets); | ||
} | ||
|
||
@AfterClass | ||
public static void stopServer() throws IOException { | ||
server.destroy(); | ||
} | ||
|
||
private String getResponse(String path) throws IOException { | ||
URL url = new URL("http://localhost:8118" + path); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); | ||
return reader.readLine(); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
baseline/stub-service/src/main/java/play/baseline/stub/MockDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package play.baseline.stub; | ||
|
||
import play.resultsetmock.annotations.Param; | ||
import play.resultsetmock.annotations.Query; | ||
|
||
/** | ||
* With this interface we map sql queries, updates, calls to Java methods. | ||
*/ | ||
public interface MockDatabase { | ||
|
||
@Query("select * from pets where name = ? and age = ?") | ||
public QueryResult queryPetsTable( | ||
@Param("name") String name, | ||
@Param("age") int age); | ||
|
||
/* | ||
@Query("select * from pets where owner_firstname = ?") | ||
public QueryResult queryPetsTable( | ||
@Param("owner_firstname") String ownerFirstName); | ||
*/ | ||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
baseline/stub-service/src/main/java/play/baseline/stub/MockDatabaseImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package play.baseline.stub; | ||
|
||
import play.baseline.model.Pet; | ||
import play.remotemock.annotation.Remotable; | ||
import play.resultsetmock.annotations.Param; | ||
import play.resultsetmock.annotations.Query; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Default responses for sql calls, updates, queries... So that stub server starts up without errors. | ||
*/ | ||
@Remotable(MockDatabase.class) | ||
public class MockDatabaseImpl implements MockDatabase { | ||
|
||
@Override | ||
public QueryResult queryPetsTable(String name, int age) { | ||
return null; | ||
} | ||
|
||
/* | ||
@Override | ||
public QueryResult queryPetsTable(String ownerFirstName) { | ||
return null; | ||
} | ||
*/ | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
baseline/stub-service/src/main/java/play/baseline/stub/QueryResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package play.baseline.stub; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Created by IntelliJ IDEA. | ||
* User: akpinarc | ||
* Date: 6/28/12 | ||
* Time: 2:02 PM | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public interface QueryResult extends Serializable { | ||
} |
34 changes: 0 additions & 34 deletions
34
baseline/stub-service/src/main/java/play/baseline/stub/StubMyServiceImpl.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.