forked from Kika1977/hpe-demo-app
-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 7d6f552
Showing
181 changed files
with
16,098 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/.idea/** | ||
**/*.iml | ||
**/target/* | ||
*.log | ||
*.bak | ||
.idea |
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,3 @@ | ||
some text | ||
more text | ||
3rd line |
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,56 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<artifactId>app-all</artifactId> | ||
<groupId>discover-demo-app</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>integration-tests</artifactId> | ||
<packaging>jar</packaging> | ||
<name>integration-tests Maven Webapp</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.jayway.restassured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<version>2.4.0</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.12.4</version> | ||
<configuration> | ||
<skipTests>true</skipTests> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
<finalName>integration-tests</finalName> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>runTests</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.12.4</version> | ||
<configuration> | ||
<skipTests>false</skipTests> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
78 changes: 78 additions & 0 deletions
78
integration-tests/src/test/java/com/hp/devops/demoapp/ConfigurationService.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,78 @@ | ||
package com.hp.devops.demoapp; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
/** | ||
* User: belozovs | ||
* Date: 11/25/14 | ||
* Description | ||
*/ | ||
public class ConfigurationService { | ||
|
||
private static ConfigurationService instance = new ConfigurationService(); | ||
|
||
private String protocol = "http"; | ||
private String hostName = "localhost"; | ||
private int port = 9999; | ||
private String basePath = "/api"; | ||
private String proxyHost = ""; //rhvwebcachevip.bastion.europe.hp.com | ||
private int proxyPort = 0; //8080 | ||
|
||
private ConfigurationService(){ | ||
|
||
} | ||
public static ConfigurationService getInstance(){ | ||
if(System.getProperty("hostname")!=null){ | ||
instance.hostName = System.getProperty("hostname"); | ||
} | ||
if(System.getProperty("port")!=null){ | ||
instance.port = Integer.parseInt(System.getProperty("port")); | ||
} | ||
if(System.getProperty("protocol")!=null){ | ||
instance.protocol = System.getProperty("protocol"); | ||
} | ||
if(System.getProperty("basepath")!=null){ | ||
instance.basePath = System.getProperty("basepath"); | ||
} | ||
if(System.getProperty("proxyhost")!=null){ | ||
instance.proxyHost =System.getProperty("proxyhost"); | ||
} | ||
if(System.getProperty("proxyport")!=null){ | ||
instance.proxyPort =Integer.parseInt(System.getProperty("proxyport")); | ||
} | ||
System.out.println("Starting the test for " + instance.protocol + "://" + instance.hostName + ":" + instance.port + instance.basePath); | ||
if(!instance.proxyHost.isEmpty()){ | ||
System.out.println("The tests will run via proxy: " + instance.proxyHost + ":" + instance.proxyPort); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
public String getProtocol() { | ||
return protocol; | ||
} | ||
|
||
public String getHostName() { | ||
return hostName; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
public String getBasePath() { | ||
return basePath; | ||
} | ||
|
||
public String getProxyHost() { | ||
return proxyHost; | ||
} | ||
|
||
public int getProxyPort() { | ||
return proxyPort; | ||
} | ||
|
||
public String getBaseUri(){ | ||
return protocol + "://" + hostName; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
integration-tests/src/test/java/com/hp/devops/demoapp/RestServletTest.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,88 @@ | ||
package com.hp.devops.demoapp;/** | ||
* Created with IntelliJ IDEA. | ||
* User: belozovs | ||
* Date: 11/25/14 | ||
* Time: 4:32 PM | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
|
||
import com.jayway.restassured.RestAssured; | ||
import com.jayway.restassured.http.ContentType; | ||
import com.jayway.restassured.specification.RequestSpecification; | ||
import org.junit.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import static com.jayway.restassured.path.json.JsonPath.from; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.isOneOf; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class RestServletTest { | ||
|
||
private static RequestSpecification spec; | ||
private static ConfigurationService configurationService = ConfigurationService.getInstance(); | ||
|
||
@BeforeClass | ||
public static void setUpBeforeClass() throws Exception { | ||
RestAssured.baseURI = configurationService.getBaseUri(); | ||
RestAssured.port = configurationService.getPort(); | ||
RestAssured.basePath = configurationService.getBasePath(); | ||
if (!configurationService.getProxyHost().isEmpty()) { | ||
RestAssured.proxy(configurationService.getProxyHost(), configurationService.getProxyPort()); | ||
} | ||
|
||
spec = RestAssured.given(); | ||
System.out.println("Base URI: " + configurationService.getBaseUri()); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownAfterClass() throws Exception { | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testGetBands() throws Exception { | ||
String result = spec.log().all().expect().statusCode(isOneOf(200)).get("/bands").asString(); | ||
List bandsList = from(result).get(""); | ||
assertEquals("We should have 5 bands", 5, bandsList.size()); | ||
} | ||
|
||
@Test | ||
public void testReloadDb() throws Exception { | ||
spec.log().all().expect().statusCode(200).contentType(ContentType.TEXT).body(equalTo("done")).get("/reloadDB"); | ||
} | ||
|
||
@Test | ||
public void testVoteForBand() throws Exception { | ||
String response1 = spec.log().all().expect().statusCode(200).when().put("/band/1/vote").asString(); | ||
List votesList1 = from(response1).get(""); | ||
int votes1 = ((HashMap<String, Integer>) votesList1.get(0)).get("votes"); | ||
System.out.println("Votes1: " + votesList1.get(0)); | ||
String response2 = spec.log().all().expect().statusCode(200).when().put("/band/1/vote").asString(); | ||
List votesList2 = from(response2).get(""); | ||
int votes2 = ((HashMap<String, Integer>) votesList2.get(0)).get("votes"); | ||
System.out.println("Votes2: " + votesList2.get(0)); | ||
int diff = votes2 - votes1; | ||
assertTrue("Votes should increase by 1", diff == 1); | ||
} | ||
|
||
@Test | ||
public void testMultipleVotingBlocked() throws Exception { | ||
String cookieValue; | ||
cookieValue = spec.log().all().expect().statusCode(isOneOf(200)).get("/bands").getCookie("hpDevopsDemoApp"); | ||
assertTrue("cookie value should be equal 'null'", cookieValue == null); | ||
cookieValue = spec.log().all().expect().statusCode(200).when().put("/band/1/vote").getCookie("hpDevopsDemoApp"); | ||
assertTrue("cookie value should be equal 'true'", cookieValue.compareTo("true") == 0); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.