Ejemplo n.º 1
0
  @Test
  public void returnsStubMappingNearMissesForARequest() {
    stubFor(
        get(urlEqualTo("/mypath"))
            .withHeader("My-Header", equalTo("matched"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        get(urlEqualTo("/otherpath"))
            .withHeader("My-Header", equalTo("otherheaderval"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        get(urlEqualTo("/yet/another/path"))
            .withHeader("X-Alt-Header", equalTo("matchonthis"))
            .willReturn(aResponse().withStatus(200)));

    List<NearMiss> nearMisses =
        WireMock.findNearMissesFor(
            LoggedRequest.createFrom(
                mockRequest().url("/otherpath").header("My-Header", "notmatched")));

    assertThat(nearMisses.get(0).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(0).getStubMapping().getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(1).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(1).getStubMapping().getRequest().getUrl(), is("/mypath"));
    assertThat(nearMisses.get(2).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(2).getStubMapping().getRequest().getUrl(), is("/yet/another/path"));
  }
Ejemplo n.º 2
0
  @Before
  public void setUpWireMock() {
    stubFor(
        get(urlEqualTo("/"))
            .withHeader("Authorization", containing("Basic dGVzdDoxMjM0"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        get(urlEqualTo("/vaaraurl"))
            .withHeader("Authorization", containing("Basic dGVzdDoxMjM0"))
            .willReturn(aResponse().withStatus(400)));
    stubFor(
        post(urlEqualTo("/kivaurl"))
            .withHeader("Authorization", containing("Basic dGVzdDoxMjM0"))
            .withRequestBody(containing("submission[file]"))
            .withRequestBody(containing("test.zip"))
            .willReturn(aResponse().withBody("All tests passed").withStatus(200)));
    stubFor(
        put(urlEqualTo("/putty?api_version=7&client=tmc_cli&client_version=1"))
            .withHeader("Authorization", containing("Basic dGVzdDoxMjM0"))
            .willReturn(aResponse().withBody("OK").withStatus(200)));
    stubFor(
        put(urlEqualTo("/putty_with_headers?api_version=7&client=tmc_cli&client_version=1"))
            .withHeader("Authorization", containing("Basic dGVzdDoxMjM0"))
            .withRequestBody(containing(new BasicNameValuePair("mark_as_read", "1").toString()))
            .willReturn(aResponse().withBody("OK").withStatus(200)));

    urlCommunicator = new UrlCommunicator(settings);
    serverAddress += wireMockRule.port();
  }
  @Test
  public void testGroups() throws Exception {
    String groupsJson =
        IOUtils.toString(
            new ClassPathResource("mocks/oauth-client-credentials.json").getInputStream());
    String oauthJson =
        IOUtils.toString(new ClassPathResource("mocks/voot-groups.json").getInputStream());

    stubFor(
        post(urlEqualTo("/oauth/token"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody(groupsJson)));
    stubFor(
        get(urlEqualTo("/internal/external-groups/" + personId))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody(oauthJson)));

    List<ExternalGroup> groups = client.groups(personId);
    assertEquals(2, groups.size());

    ExternalGroup group = groups.get(0);
    assertEquals("urn:collab:group:foo:go", group.getIdentifier());
    assertEquals("go", group.getName());
    assertEquals("Go description", group.getDescription());
    assertEquals("foo", group.getGroupProvider().getIdentifier());
  }
Ejemplo n.º 4
0
  @Test
  public void nearMisses() {
    stubFor(
        get(urlEqualTo("/mypath"))
            .withHeader("My-Header", equalTo("matched"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        get(urlEqualTo("/otherpath"))
            .withHeader("My-Header", equalTo("otherheaderval"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        get(urlEqualTo("/yet/another/path"))
            .withHeader("X-Alt-Header", equalTo("matchonthis"))
            .willReturn(aResponse().withStatus(200)));

    testClient.get("/otherpath", withHeader("My-Header", "notmatched"));

    List<NearMiss> nearMisses = WireMock.findNearMissesForAllUnmatched();

    assertThat(nearMisses.get(0).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(0).getStubMapping().getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(1).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(1).getStubMapping().getRequest().getUrl(), is("/mypath"));
    assertThat(nearMisses.get(2).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(2).getStubMapping().getRequest().getUrl(), is("/yet/another/path"));
  }
  private void mockCepServiceServer() {
    stubFor(
        get(urlEqualTo("/addresses/01001000"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withHeader("charset", "UTF-8")
                    .withBody(
                        "\"{ "
                            + "\"cep\": \"01001000\", "
                            + "\"street\": \"Praça da Sé - lado ímpar\", "
                            + "\"neighborhood\": \"Sé\", "
                            + "\"city\": \"São Paulo\", "
                            + "\"state\": \"SP\" "
                            + "}\"")));

    stubFor(
        get(urlEqualTo("/addresses/00000000"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withHeader("charset", "UTF-8")
                    .withBody("{\"errorMessage\": \"CEP invalido\"}")));
  }
  /*
   * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-1
   * available local phone numbers in the United States in the 510 area code.
   */
  @Test
  public void testSearchUSLocalPhoneNumbersWith501AreaCode() {
    stubFor(
        put(urlEqualTo("/test/configuration/voiceuri"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody(VoxboneAvailablePhoneNumbersEndpointTestUtils.VoiceURIJSonResponse)));
    stubFor(
        get(urlEqualTo(
                "/test/inventory/didgroup?countryCodeA3=USA&areaCode=501&pageNumber=0&pageSize=50"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody(VoxboneAvailablePhoneNumbersEndpointTestUtils.body501AreaCode)));
    // Get Account using admin email address and user email address
    Client jerseyClient = Client.create();
    jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken));

    String provisioningURL = deploymentUrl + baseURL + "US/Local.json";
    WebResource webResource = jerseyClient.resource(provisioningURL);

    ClientResponse clientResponse =
        webResource
            .queryParam("areaCode", "501")
            .accept("application/json")
            .get(ClientResponse.class);
    assertTrue(clientResponse.getStatus() == 200);
    String response = clientResponse.getEntity(String.class);
    System.out.println(response);
    assertTrue(!response.trim().equalsIgnoreCase("[]"));
    JsonParser parser = new JsonParser();
    JsonArray jsonResponse = parser.parse(response).getAsJsonArray();

    System.out.println(jsonResponse);

    assertTrue(jsonResponse.size() == 15);
    System.out.println((jsonResponse.get(0).getAsJsonObject().toString()));
    assertTrue(
        jsonResponse
            .get(0)
            .getAsJsonObject()
            .toString()
            .equalsIgnoreCase(
                VoxboneAvailablePhoneNumbersEndpointTestUtils.firstJSonResult501AreaCode));
  }
  @Test
  public void readTest() throws Exception {
    ItemEntityGenerator response = new ItemEntityGenerator();
    response.addItem("title", "torrentUrl", Long.MAX_VALUE, 1, 1000);

    stubFor(
        get(urlEqualTo("/?type=search&search=title"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/xml")
                    .withBody(response.toString())));

    dao.setClient(client);
    dao.setMediaType(MediaType.APPLICATION_XML_TYPE);
    dao.setBaseUri(new URI("http://localhost:8089"));

    List<FeedResult> results = dao.read("title");
    Assert.assertNotNull(results);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals("title", results.get(0).getTitle());
    Assert.assertEquals("torrentUrl", results.get(0).getTorrentURL());
    Assert.assertEquals(Long.MAX_VALUE, results.get(0).getContentLength());
    Assert.assertEquals(1, results.get(0).getSeeders());
    Assert.assertEquals(1000, results.get(0).getLeechers());
  }
Ejemplo n.º 8
0
  @Test
  public void metricsAreSentToServer() throws Exception {
    stubFor(post(urlEqualTo("/endpoint")).willReturn(aResponse().withBody("OK").withStatus(200)));

    new LibratoWriterFactory(
            ImmutableList.<String>of(),
            true,
            new URL("http://*****:*****@.name == 'ObjectPendingFinalizationCount.ObjectPendingFinalizationCount')]")));
  }
  /** Gets all groups members of a group. */
  @Test
  public void getGroupMembers() throws Exception {
    // stub for expected request to get groups group nenbers
    stubFor(
        get(urlEqualTo("/api/v3/groups/1/members?private_token=" + PRIVATE_TOKEN))
            .willReturn(aResponse().withStatus(200).withBodyFile("/api/v3/groups/1/members.json")));

    List<GitLabGroupMemberInfo> members = client.getGroupMembers(1);

    assertThat(members, hasSize(3));

    GitLabGroupMemberInfo normalMember = members.get(0);
    GitLabGroupMemberInfo blockedMember = members.get(1);
    GitLabGroupMemberInfo adminMember = members.get(2);

    assertThat(normalMember.getGroupId(), is(1));
    assertThat(normalMember.getAccessLevel(), is(GitLabAccessLevel.DEVELOPER));
    assertThat(normalMember.getId(), is(1));
    assertThat(normalMember.isBlocked(), is(false));

    assertThat(blockedMember.isBlocked(), is(true));

    assertThat(adminMember.getGroupId(), is(1));
    assertThat(adminMember.getAccessLevel(), is(GitLabAccessLevel.OWNER));
    assertThat(adminMember.getId(), is(3));
    assertThat(adminMember.isBlocked(), is(false));
  }
Ejemplo n.º 10
0
  @Test(expected = HystrixRuntimeException.class)
  public void testDependencyUnavailable() throws RealmAuthenticationException {

    stubFor(
        post(urlEqualTo(WS_CUSTOMER_SERVICE_URL))
            .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));

    customerUserRealm.authenticate(EMAIL, PASSWORD, newHashSet(UID), emptySet());
  }
 private void mockEmitMessages() {
   WireMock.stubFor(
       WireMock.post(WireMock.urlMatching(MOCKED_COLLECTION))
           .willReturn(
               WireMock.aResponse()
                   .withStatus(200)
                   .withHeader("Content-Type", "text/html")
                   .withBody("")));
 }
Ejemplo n.º 12
0
  @Test // For github issue #600, At the DB the IncomingPhoneNumber is '+2222' and we dial '2222',
        // Restcomm should find this number even without the '+'
  public synchronized void testDialClientAliceWithoutPlusSign()
      throws InterruptedException, ParseException {
    stubFor(
        get(urlPathEqualTo("/1111"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody(dialClientRcml)));

    // Phone2 register as alice
    SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
    assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));

    // Prepare second phone to receive call
    SipCall aliceCall = alicePhone.createSipCall();
    aliceCall.listenForIncomingCall();

    // Create outgoing call with first phone
    final SipCall bobCall = bobPhone.createSipCall();
    bobCall.initiateOutgoingCall(
        bobContact, "sip:[email protected]:5080", null, body, "application", "sdp", null, null);
    assertLastOperationSuccess(bobCall);
    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    final int response = bobCall.getLastReceivedResponse().getStatusCode();
    assertTrue(response == Response.TRYING || response == Response.RINGING);

    if (response == Response.TRYING) {
      assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
      assertEquals(Response.RINGING, bobCall.getLastReceivedResponse().getStatusCode());
    }

    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    assertEquals(Response.OK, bobCall.getLastReceivedResponse().getStatusCode());

    bobCall.sendInviteOkAck();
    assertTrue(!(bobCall.getLastReceivedResponse().getStatusCode() >= 400));

    assertTrue(aliceCall.waitForIncomingCall(30 * 1000));
    assertTrue(aliceCall.sendIncomingCallResponse(Response.RINGING, "Ringing-Alice", 3600));
    String receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());
    assertTrue(
        aliceCall.sendIncomingCallResponse(
            Response.OK, "OK-Alice", 3600, receivedBody, "application", "sdp", null, null));
    assertTrue(aliceCall.waitForAck(50 * 1000));

    Thread.sleep(3000);

    // hangup.
    bobCall.disconnect();

    aliceCall.listenForDisconnect();
    assertTrue(aliceCall.waitForDisconnect(30 * 1000));
    assertTrue(aliceCall.respondToDisconnect());
  }
Ejemplo n.º 13
0
  // Non regression test for https://telestax.atlassian.net/browse/RESTCOMM-585
  @Test
  public synchronized void testDialWithCustomHeaders() throws InterruptedException, ParseException {
    // Received request: GET
    // /rcml?CallSid=CA154c8c93d7eb439989a6ea42915b6c1b&AccountSid=ACae6e420f425248d6a26948c17a9e2acf&From=bob&To=%2B17778&
    // CallStatus=ringing&ApiVersion=2012-04-24&Direction=inbound&CallerName&ForwardedFrom&SipHeader_X-MyCustom-Header1=Value1&SipHeader_X-MyCustom-Header2=Value2 HTTP/1.1
    stubFor(
        get(urlPathEqualTo("/1111"))
            .withQueryParam("SipHeader_X-MyCustom-Header1", containing("Value1"))
            .withQueryParam("SipHeader_X-MyCustom-Header2", containing("Value2"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody(playRcml)));

    ArrayList<String> additionalHeaders = new ArrayList<String>();
    additionalHeaders.add(
        bobPhone
            .getParent()
            .getHeaderFactory()
            .createHeader("X-MyCustom-Header1", "Value1")
            .toString());
    additionalHeaders.add(
        bobPhone
            .getParent()
            .getHeaderFactory()
            .createHeader("X-MyCustom-Header2", "Value2")
            .toString());

    // Initiate a call using Bob
    final SipCall bobCall = bobPhone.createSipCall();

    bobCall.initiateOutgoingCall(
        bobContact, dialRestcomm, null, body, "application", "sdp", additionalHeaders, null);
    assertLastOperationSuccess(bobCall);

    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));

    final int response = bobCall.getLastReceivedResponse().getStatusCode();
    assertTrue(response == Response.TRYING || response == Response.RINGING);
    if (response == Response.TRYING) {
      assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
      assertEquals(Response.RINGING, bobCall.getLastReceivedResponse().getStatusCode());
    }

    assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
    assertEquals(Response.OK, bobCall.getLastReceivedResponse().getStatusCode());
    bobCall.sendInviteOkAck();
    assertTrue(!(bobCall.getLastReceivedResponse().getStatusCode() >= 400));

    bobCall.listenForDisconnect();

    Thread.sleep(1000);

    assertTrue(bobCall.waitForDisconnect(5 * 1000));
    assertTrue(bobCall.respondToDisconnect());
  }
Ejemplo n.º 14
0
  @Test
  public void testDownload() throws Exception {
    byte[] data = {1, 2, 3};

    stubFor(get(urlEqualTo("/endpoint")).willReturn(aResponse().withStatus(SC_OK).withBody(data)));

    InputStream stream = endpoint.download();

    assertArrayEquals(data, toByteArray(stream));
  }
  @Before
  public void setupTest() {
    testDataDir = new File("src/test/test-data");
    if (!testDataDir.isDirectory())
      fail("Request test data directory " + testDataDir.getAbsolutePath() + " not found!");

    fusionApiPort = wireMockRule.port();
    fusionHostAndPort = "http://" + fusionHost + ":" + fusionApiPort;
    fusionPipelineEndpoint = "/api/apollo/index-pipelines/logs-default/collections/logs";
    fusionEndpoints = fusionHostAndPort + fusionPipelineEndpoint;

    // mock out the Fusion indexing pipeline endpoint and the session API endpoint
    stubFor(
        post(urlEqualTo(fusionPipelineEndpoint + "?echo=false"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        post(urlEqualTo("/api/session?realmName=" + fusionRealm))
            .willReturn(aResponse().withStatus(200)));
  }
Ejemplo n.º 16
0
  @Test
  @Ignore("Works in isolation but fails when executed as part of test suite")
  public void testUpload() throws Exception {
    stubFor(
        put(urlEqualTo("/endpoint"))
            .withHeader(CONTENT_TYPE, matching("mock/type"))
            .willReturn(aResponse().withStatus(SC_NO_CONTENT)));

    File file = File.createTempFile("unit-test", ".tmp");
    endpoint.upload(file, ContentType.create("mock/type"));
  }
Ejemplo n.º 17
0
  @Test
  public void testProbe() throws Exception {
    stubFor(
        options(urlEqualTo("/endpoint"))
            .willReturn(aResponse().withStatus(SC_OK).withHeader(HttpHeaders.ALLOW, "PUT")));

    endpoint.probe();

    assertThat(endpoint.isDownloadAllowed().get(), is(false));
    assertThat(endpoint.isUploadAllowed().get(), is(true));
  }
  /** Attempts to get a group that doesn't exist. */
  @Test
  public void getNonexistentGroup() throws Exception {
    // stub for expected request to get the group
    stubFor(
        get(urlEqualTo("/api/v3/groups/1?private_token=" + PRIVATE_TOKEN))
            .willReturn(aResponse().withStatus(404).withBodyFile("/404.json")));

    // should not find group
    thrown.expect(GroupNotFoundException.class);

    client.getGroup(1);
  }
  /** Gets a group. */
  @Test
  public void getGroup() throws Exception {
    // stub for expected request to get the group
    stubFor(
        get(urlEqualTo("/api/v3/groups/1?private_token=" + PRIVATE_TOKEN))
            .willReturn(aResponse().withStatus(200).withBodyFile("/api/v3/groups/1.json")));

    GitLabGroupInfo group = client.getGroup(1);
    assertThat(group.getId(), is(1));
    assertThat(group.getName(), is("Group Name"));
    assertThat(group.getPath(), is("groupname"));
  }
  @Test
  public void matchesOnWellFormedCookie() {
    stubFor(
        get(urlEqualTo("/good/cookie"))
            .withCookie("my_cookie", containing("mycookievalue"))
            .willReturn(aResponse().withStatus(200)));

    WireMockResponse response =
        testClient.get("/good/cookie", withHeader(COOKIE, "my_cookie=xxx-mycookievalue-xxx"));

    assertThat(response.statusCode(), is(200));
  }
  @Test
  public void doesNotMatchWhenExpectedCookieHasTheWrongValue() {
    stubFor(
        get(urlEqualTo("/bad/cookie"))
            .withCookie("my_cookie", containing("mycookievalue"))
            .willReturn(aResponse().withStatus(200)));

    WireMockResponse response =
        testClient.get("/bad/cookie", withHeader(COOKIE, "my_cookie=youwontfindthis"));

    assertThat(response.statusCode(), is(404));
  }
Ejemplo n.º 22
0
  /**
   * Test for {@link HeaderEndpoint#requestHeader(String)} with a <i>skipped header</i>.
   *
   * @since 1.3.0
   */
  @Test
  public final void testRequestHeaderSkip() {

    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);

    String subpath = "/requestheaderskip";

    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody("hello")));

    headerEndpoint.requestHeaderSkip(null);
    verify(getRequestedFor(urlMatching(subpath)));
  }
  @Test(expected = FileOperationException.class)
  public void shouldThrowExceptionIfAlfrescoReturnedUnexpectedResponseCode() {

    stubFor(
        post(urlEqualTo(WEB_CONTEXT + UPLOAD_PATH))
            .willReturn(
                aResponse()
                    .withStatus(500)
                    .withBody(alfrescoResponseOf("file1234", "text/plain"))));

    fileSender.send("abc.txt", toInputStream("aa"));
  }
  /** Attempts to get groups for the authenticated user with invalid token. */
  @Test
  public void getAllGroupsWithInvalidPrivateToken() throws Exception {
    // stub for expected request to get all groups
    stubFor(
        get(urlEqualTo("/api/v3/groups?private_token=" + PRIVATE_TOKEN))
            .willReturn(aResponse().withStatus(401).withBodyFile("/401.json")));

    // authentication should fail
    thrown.expect(AuthenticationFailedException.class);

    // try to get the groups from the API and expect it to throw and exception
    client.getGroups();
  }
  @Test
  public void doesNotMatchWhenExpectedCookieIsMalformed() {
    stubFor(
        get(urlEqualTo("/very-bad/cookie"))
            .withCookie("my_cookie", containing("mycookievalue"))
            .willReturn(aResponse().withStatus(200)));

    WireMockResponse response =
        testClient.get(
            "/very-bad/cookie", withHeader(COOKIE, "my_cookieyouwontfindthis;;sldfjskldjf%%"));

    assertThat(response.statusCode(), is(404));
  }
Ejemplo n.º 26
0
  /**
   * Test for a request {@link Header}.
   *
   * @since 1.3.0
   */
  @Test
  public final void testRequestHeader() {

    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);

    String subpath = "/requestheader", header = "mobile";

    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));

    headerEndpoint.requestHeader(header);

    verify(getRequestedFor(urlMatching(subpath)).withHeader("User-Agent", matching(header)));
  }
Ejemplo n.º 27
0
  @Test(expected = RealmAuthenticationException.class)
  public void testNotAuthenticateWithEmptyResponse() throws RealmAuthenticationException {

    stubFor(
        post(urlEqualTo(WS_CUSTOMER_SERVICE_URL))
            .willReturn(
                aResponse()
                    .withStatus(OK.value())
                    .withHeader(ContentTypeHeader.KEY, TEXT_XML_VALUE)
                    .withBody(SOAP_EMPTY_RESPONSE)));

    customerUserRealm.authenticate(EMAIL, PASSWORD, newHashSet(UID), emptySet());
  }
  @Test
  public void doesNotMatchWhenExpectedCookieIsAbsent() {
    stubFor(
        get(urlEqualTo("/missing/cookie"))
            .withCookie("my_cookie", containing("mycookievalue"))
            .willReturn(aResponse().withStatus(200)));

    WireMockResponse response =
        testClient.get(
            "/missing/cookie", withHeader(COOKIE, "the_wrong_cookie=xxx-mycookievalue-xxx"));

    assertThat(response.statusCode(), is(404));
  }
Ejemplo n.º 29
0
  /**
   * Test for {@link HeaderEndpoint#requestHeaderTypeError(int)}.
   *
   * @since 1.3.0
   */
  @Test
  public final void testRequestHeaderTypeError() {

    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);

    String subpath = "/requestheadertypeerror";

    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody("hello")));

    expectedException.expect(Is.isA(InvocationException.class));

    assertNull(headerEndpoint.requestHeaderTypeError(512));
  }
  @Test(expected = FeedException.class)
  public void readWebAppExceptionTest() throws Exception {

    stubFor(
        get(urlEqualTo("/?type=search&search=title"))
            .willReturn(aResponse().withStatus(500).withHeader("Content-Type", "application/xml")));

    dao.setMediaType(MediaType.APPLICATION_XML_TYPE);
    dao.setBaseUri(new URI("http://localhost:8089"));
    dao.setClient(client);

    dao.read("title");
    Assert.fail();
  }