Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hpdemo committed Feb 25, 2016
0 parents commit 7d6f552
Show file tree
Hide file tree
Showing 181 changed files with 16,098 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.idea/**
**/*.iml
**/target/*
*.log
*.bak
.idea
3 changes: 3 additions & 0 deletions git_trigger_sandbox.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
some text
more text
3rd line
56 changes: 56 additions & 0 deletions integration-tests/pom.xml
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>
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;
}
}
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);
}
}
3 changes: 3 additions & 0 deletions mocha/node_modules/expect.js/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions mocha/node_modules/expect.js/History.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d6f552

Please sign in to comment.