Skip to content

Commit

Permalink
initial version of Wilma that uses the new proxy - further step to im…
Browse files Browse the repository at this point in the history
…plement #67
  • Loading branch information
tkohegyi committed Dec 25, 2015
1 parent 46c410a commit 60d431e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
compile project(':wilma-application:wilma-core')
compile project(':wilma-application:wilma-properties')

compile ('com.epam.wilma:browsermob-proxy:2.0-beta-8-wilma-1.4.83'){
compile ('com.epam.wilma:browsermob-proxy:2.0-beta-8-wilma-1.4.85'){
// compile ('com.epam.wilma:browsermob-proxy:2.0-beta-8-wilma-1.4.DEV'){
exclude (module:'slf4j-jdk14')
exclude (module:'commons-logging')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public class BrowserMobConfigurationAccess implements ConfigurationAccessBase {
public void loadProperties() {
Integer proxyPort = propertyHolder.getInt("proxy.port");
Integer requestTimeout = propertyHolder.getInt("proxy.request.timeout");
properties = new ProxyPropertyDTO(proxyPort, requestTimeout);
String responseVolatileString = propertyHolder.get("proxy.response.volatile");
Boolean responseVolatile = false;
if (responseVolatileString != null && "true".equals(responseVolatileString)) {
responseVolatile = true;
}
properties = new ProxyPropertyDTO(proxyPort, requestTimeout, responseVolatile);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@

/**
* Holds module specific properties.
* @author Tunde_Kovacs
* @author Tunde_Kovacs, Tamas Kohegyi
*
*/
public class ProxyPropertyDTO {

private final Integer proxyPort;
private final Integer requestTimeout;
private final Boolean allowResponseUpdate;

/**
* Constructs a new property holding object with the given fields.
* @param proxyPort the port used by the proxy
* @param requestTimeout the value of a request timeout in milliseconds
* @param allowResponseUpdate wether proxy should work in mode that allows response update (slower), or not (faster)
*/
public ProxyPropertyDTO(final Integer proxyPort, final Integer requestTimeout) {
public ProxyPropertyDTO(final Integer proxyPort, final Integer requestTimeout, final Boolean allowResponseUpdate) {
super();
this.proxyPort = proxyPort;
this.requestTimeout = requestTimeout;
this.allowResponseUpdate = allowResponseUpdate;
}

public Integer getProxyPort() {
Expand All @@ -47,4 +50,7 @@ public Integer getRequestTimeout() {
return requestTimeout;
}

public Boolean getAllowResponseUpdate() {
return allowResponseUpdate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class BrowserMobProxy implements Proxy {
private final Logger logger = LoggerFactory.getLogger(BrowserMobProxy.class);
private Integer proxyPort;
private Integer requestTimeout;
private Boolean responseVolatile;

@Autowired
private ProxyServer server;
Expand All @@ -59,6 +60,7 @@ public void start() {
getProperties();
server.setPort(proxyPort);
server.start(requestTimeout);
server.setResponseVolatile(responseVolatile);
server.setCaptureContent(true);
server.setCaptureBinaryContent(true);
server.addRequestInterceptor(requestInterceptor);
Expand All @@ -72,6 +74,7 @@ private void getProperties() {
ProxyPropertyDTO properties = configurationAccess.getProperties();
proxyPort = properties.getProxyPort();
requestTimeout = properties.getRequestTimeout();
responseVolatile = properties.getAllowResponseUpdate();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void setUp() {
MockitoAnnotations.initMocks(this);
given(propertyHolder.getInt("proxy.request.timeout")).willReturn(REQUEST_TIMEOUT);
given(propertyHolder.getInt("proxy.port")).willReturn(PROXY_PORT);
given(propertyHolder.get("proxy.response.volatile")).willReturn(null);
}

@Test
Expand All @@ -74,4 +75,36 @@ public void testLoadPropertiesShouldSetRequestTimeout() {
ProxyPropertyDTO actual = underTest.getProperties();
assertEquals(actual.getRequestTimeout(), Integer.valueOf(REQUEST_TIMEOUT));
}

@Test
public void testLoadPropertiesShouldSetDefaultResponseUpdateVolatileAsFalse() {
//GIVEN in setUp
//WHEN
underTest.loadProperties();
//THENs
ProxyPropertyDTO actual = underTest.getProperties();
assertEquals(actual.getAllowResponseUpdate(), Boolean.valueOf(false));
}

@Test
public void testLoadPropertiesShouldSetResponseUpdateVolatileAsFalse() {
//GIVEN in setUp
given(propertyHolder.get("proxy.response.volatile")).willReturn("false");
//WHEN
underTest.loadProperties();
//THENs
ProxyPropertyDTO actual = underTest.getProperties();
assertEquals(actual.getAllowResponseUpdate(), Boolean.valueOf(false));
}
@Test

public void testLoadPropertiesShouldSetResponseUpdateVolatileAsTrue() {
//GIVEN in setUp
given(propertyHolder.get("proxy.response.volatile")).willReturn("true");
//WHEN
underTest.loadProperties();
//THENs
ProxyPropertyDTO actual = underTest.getProperties();
assertEquals(actual.getAllowResponseUpdate(), Boolean.valueOf(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testStartShouldStartTheProxySuccessfully() throws Exception {
// GIVEN
int requestTimeout = 30000;
int proxyPort = 9092;
propertiesDTO = new ProxyPropertyDTO(proxyPort, requestTimeout);
propertiesDTO = new ProxyPropertyDTO(proxyPort, requestTimeout, false);
given(configurationAccess.getProperties()).willReturn(propertiesDTO);
// WHEN
underTest.start();
Expand All @@ -95,7 +95,7 @@ public void testStartShouldStartTheProxySuccessfully() throws Exception {
public void testStartShouldThrowExceptionWhenTheProxyCannotBeStarted() throws Exception {
// GIVEN
int requestTimeout = 30000;
propertiesDTO = new ProxyPropertyDTO(0, requestTimeout);
propertiesDTO = new ProxyPropertyDTO(0, requestTimeout, false);
given(configurationAccess.getProperties()).willReturn(propertiesDTO);
Mockito.doThrow(Exception.class).when(server).start(requestTimeout);
// WHEN
Expand Down

0 comments on commit 60d431e

Please sign in to comment.