Search in sources :

Example 1 with HttpRequestFailoverMatcher

use of com.github.dreamhead.moco.model.HttpRequestFailoverMatcher in project moco by dreamhead.

the class HttpRequestMatcherTest method should_be_match_if_failover_field_is_null.

@Test
public void should_be_match_if_failover_field_is_null() {
    HttpRequest request = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    HttpRequest failover = DefaultHttpRequest.builder().withUri("/uri").withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    assertThat(new HttpRequestFailoverMatcher(failover).match(request), is(true));
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) HttpRequestFailoverMatcher(com.github.dreamhead.moco.model.HttpRequestFailoverMatcher) Test(org.junit.Test)

Example 2 with HttpRequestFailoverMatcher

use of com.github.dreamhead.moco.model.HttpRequestFailoverMatcher in project moco by dreamhead.

the class HttpRequestMatcherTest method should_be_match_even_if_target_request_has_more_headers.

@Test
public void should_be_match_even_if_target_request_has_more_headers() {
    HttpRequest request = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    HttpRequest failover = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Host", "localhost:12306")).build();
    assertThat(new HttpRequestFailoverMatcher(failover).match(request), is(true));
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) HttpRequestFailoverMatcher(com.github.dreamhead.moco.model.HttpRequestFailoverMatcher) Test(org.junit.Test)

Example 3 with HttpRequestFailoverMatcher

use of com.github.dreamhead.moco.model.HttpRequestFailoverMatcher in project moco by dreamhead.

the class HttpRequestMatcherTest method should_not_be_match_if_uri_is_different.

@Test
public void should_not_be_match_if_uri_is_different() {
    HttpRequest request = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withUri("/foo").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    HttpRequest another = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withUri("/bar").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    assertThat(new HttpRequestFailoverMatcher(request).match(another), is(false));
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) HttpRequestFailoverMatcher(com.github.dreamhead.moco.model.HttpRequestFailoverMatcher) Test(org.junit.Test)

Example 4 with HttpRequestFailoverMatcher

use of com.github.dreamhead.moco.model.HttpRequestFailoverMatcher in project moco by dreamhead.

the class HttpRequestMatcherTest method should_be_match_if_request_is_same.

@Test
public void should_be_match_if_request_is_same() {
    HttpRequest request = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    assertThat(new HttpRequestFailoverMatcher(request).match(request), is(true));
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) HttpRequestFailoverMatcher(com.github.dreamhead.moco.model.HttpRequestFailoverMatcher) Test(org.junit.Test)

Example 5 with HttpRequestFailoverMatcher

use of com.github.dreamhead.moco.model.HttpRequestFailoverMatcher in project moco by dreamhead.

the class HttpRequestMatcherTest method should_not_be_match_if_request_is_different.

@Test
public void should_not_be_match_if_request_is_different() {
    HttpRequest request = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("proxy").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    HttpRequest another = DefaultHttpRequest.builder().withUri("/uri").withVersion(HttpProtocolVersion.VERSION_1_1).withMethod(HttpMethod.POST).withTextContent("different").withHeaders(of("Cookie", "loggedIn=true", "Host", "localhost:12306")).build();
    assertThat(new HttpRequestFailoverMatcher(request).match(another), is(false));
}
Also used : HttpRequest(com.github.dreamhead.moco.HttpRequest) DefaultHttpRequest(com.github.dreamhead.moco.model.DefaultHttpRequest) HttpRequestFailoverMatcher(com.github.dreamhead.moco.model.HttpRequestFailoverMatcher) Test(org.junit.Test)

Aggregations

HttpRequest (com.github.dreamhead.moco.HttpRequest)5 DefaultHttpRequest (com.github.dreamhead.moco.model.DefaultHttpRequest)5 HttpRequestFailoverMatcher (com.github.dreamhead.moco.model.HttpRequestFailoverMatcher)5 Test (org.junit.Test)5