@Test
  public void testRemoveNodeShouldReturnOkResponse() throws Exception {
    doReturn(new NodeInfo()).when(mockFacade).removeNode("dns");

    Response result = service.removeNode("dns");
    assertEquals(result.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
  }
 @Test(dependsOnMethods = {"updateCollectionObject"})
 public void deleteCollectionObject() {
   ClientResponse<Response> res = collectionObjectClient.deleteCollectionObject(deleteId);
   verbose("deleteCollectionObject: csid=" + deleteId);
   verbose("deleteCollectionObject: status = " + res.getStatus());
   Assert.assertEquals(res.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
 }
  @Test
  public void testDeleteDownloadedArtifact() throws Exception {
    doReturn(artifact).when(service).createArtifact(artifact.getName());

    Response response = service.deleteDownloadedArtifact(artifact.getName(), version.toString());
    assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
    verify(mockFacade).deleteDownloadedArtifact(artifact, version);
  }
  @Test
  public void testDeleteStorageProperty() throws Exception {
    String key = "x";

    Response response = service.deleteStorageProperty(key);
    assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
    verify(mockFacade).deleteStorageProperty(key);
  }
  @Test
  public void testClientResponse() throws Exception {
    Client client = ProxyFactory.create(Client.class, generateBaseUrl());

    Assert.assertEquals("basic", client.getBasic());
    Assert.assertEquals("basic", client.getForwardBasic());
    Assert.assertEquals("object1", client.getObject(1).getEntity());
    Assert.assertEquals("object1", client.getForwardedObject(1).getEntity());
    ClientResponse<?> cr = (ClientResponse<?>) client.getObject(0);
    Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), cr.getStatus());
    cr.releaseConnection();
    cr = (ClientResponse<?>) client.getForwardedObject(0);
    Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), cr.getStatus());
    cr.releaseConnection();

    client.putForwardBasic("testBasic");
    Assert.assertEquals("testBasic", client.getBasic());
    client.postForwardBasic("testBasic1");
    Assert.assertEquals("testBasic1", client.getBasic());
    client.deleteForwardBasic();
    Assert.assertEquals("basic", client.getBasic());
  }
  @Test
  public void testTryingToAddInvalidResearcherUrls()
      throws InterruptedException, JSONException, URISyntaxException {
    String accessToken =
        getAccessToken(this.client1ClientId, this.client1ClientSecret, this.client1RedirectUri);
    assertNotNull(accessToken);
    ResearcherUrl rUrlToCreate = new ResearcherUrl();
    rUrlToCreate.setUrl(new Url(""));
    rUrlToCreate.setUrlName("");
    // Create
    ClientResponse postResponse =
        memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());

    String _351Chars = new String();
    for (int i = 0; i < 531; i++) {
      _351Chars += "a";
    }

    rUrlToCreate.setUrl(new Url(_351Chars));
    postResponse = memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());

    rUrlToCreate.setUrl(new Url("http://myurl.com"));
    rUrlToCreate.setUrlName(_351Chars);
    postResponse = memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());

    rUrlToCreate.setUrlName("The name");
    postResponse = memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());

    // Read it to delete it
    ClientResponse getResponse =
        memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    ResearcherUrl gotResearcherUrl = getResponse.getEntity(ResearcherUrl.class);
    ClientResponse deleteResponse =
        memberV2ApiClient.deleteResearcherUrl(
            this.user1OrcidId, gotResearcherUrl.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
  }
Ejemplo n.º 7
0
  /** Test task delete. */
  @Test
  public final void testTaskDelete() {
    Response rs;
    rs = target("/v1.0/tasks/" + UUID.randomUUID()).request().delete();
    Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rs.getStatus());

    Task testTask = TestDataIT.createTask();
    testTask.setApplicationId(apps.get((int) (Math.random() * apps.size())));
    rs =
        target("/v1.0/tasks")
            .request(Constants.INDIGOMIMETYPE)
            .post(Entity.entity(testTask, Constants.INDIGOMIMETYPE));
    String id = rs.readEntity(Task.class).getId();
    rs = target("/v1.0/tasks/" + id).request().delete();
    Assert.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), rs.getStatus());
    rs = target("/v1.0/tasks/" + id).request().delete();
    Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rs.getStatus());
  }
  @Test(
      groups = {"wso2.greg", "wso2.greg.es"},
      description = "Deleting of ratings added using rest api",
      dependsOnMethods = "getRatings")
  public void deleteRatings() throws JSONException, IOException, InterruptedException {

    queryParamMap.clear();

    queryParamMap.put("path", path);

    ClientResponse response =
        genericRestClient.geneticRestRequestDelete(
            registryAPIUrl + generalPath + "/rating",
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_JSON,
            null,
            queryParamMap,
            headerMap,
            sessionCookie);

    assertTrue(
        (response.getStatusCode() == Response.Status.NO_CONTENT.getStatusCode()),
        "Wrong status code ,Expected 204 ,Received " + response.getStatusCode());
  }
  @Test
  public void testResearcherUrl() throws InterruptedException, JSONException, URISyntaxException {
    String accessToken =
        getAccessToken(this.client1ClientId, this.client1ClientSecret, this.client1RedirectUri);
    assertNotNull(accessToken);
    ResearcherUrl rUrlToCreate =
        (ResearcherUrl)
            unmarshallFromPath(
                "/record_2.0_rc2/samples/researcher-url-2.0_rc2.xml", ResearcherUrl.class);
    assertNotNull(rUrlToCreate);
    Long time = System.currentTimeMillis();
    rUrlToCreate.setCreatedDate(null);
    rUrlToCreate.setLastModifiedDate(null);
    rUrlToCreate.setPath(null);
    rUrlToCreate.setPutCode(null);
    rUrlToCreate.setSource(null);
    rUrlToCreate.setUrl(new Url(rUrlToCreate.getUrl().getValue() + time));
    rUrlToCreate.setUrlName(String.valueOf(time));

    // Create
    ClientResponse postResponse =
        memberV2ApiClient.createResearcherUrls(user1OrcidId, rUrlToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue(
        "Location header path should match pattern, but was " + locationPath,
        locationPath.matches(".*/v2.0_rc2/" + user1OrcidId + "/researcher-urls/\\d+"));

    // Read
    ClientResponse getResponse =
        memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    ResearcherUrl gotResearcherUrl = getResponse.getEntity(ResearcherUrl.class);
    assertNotNull(gotResearcherUrl);
    assertNotNull(gotResearcherUrl.getPutCode());
    assertNotNull(gotResearcherUrl.getSource());
    assertNotNull(gotResearcherUrl.getCreatedDate());
    assertNotNull(gotResearcherUrl.getLastModifiedDate());
    assertEquals(this.client1ClientId, gotResearcherUrl.getSource().retrieveSourcePath());
    assertEquals("http://site1.com/" + time, gotResearcherUrl.getUrl().getValue());
    assertEquals(String.valueOf(time), gotResearcherUrl.getUrlName());
    assertEquals("public", gotResearcherUrl.getVisibility().value());

    // Update
    LastModifiedDate initialLastModified = gotResearcherUrl.getLastModifiedDate();
    Long currentTime = System.currentTimeMillis();
    gotResearcherUrl.setUrlName(gotResearcherUrl.getUrlName() + " - " + currentTime);
    gotResearcherUrl.getUrl().setValue(gotResearcherUrl.getUrl().getValue() + currentTime);
    gotResearcherUrl.setVisibility(Visibility.LIMITED);
    ClientResponse updatedResearcherUrlResponse =
        memberV2ApiClient.updateResearcherUrls(this.user1OrcidId, gotResearcherUrl, accessToken);
    assertNotNull(updatedResearcherUrlResponse);
    assertEquals(Response.Status.OK.getStatusCode(), updatedResearcherUrlResponse.getStatus());
    ResearcherUrl updatedResearcherUrl =
        updatedResearcherUrlResponse.getEntity(ResearcherUrl.class);
    assertNotNull(updatedResearcherUrl);
    assertEquals(
        "http://site1.com/" + time + currentTime, updatedResearcherUrl.getUrl().getValue());
    assertEquals(String.valueOf(time) + " - " + currentTime, updatedResearcherUrl.getUrlName());
    // Keep it public, since it is more restrictive than the user visibility
    // default
    assertEquals("public", updatedResearcherUrl.getVisibility().value());
    assertFalse(initialLastModified.equals(updatedResearcherUrl.getLastModifiedDate()));

    // Delete
    ClientResponse deleteResponse =
        memberV2ApiClient.deleteResearcherUrl(
            this.user1OrcidId, gotResearcherUrl.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
  }
 @Test
 public void testStopDownload() throws Exception {
   Response result = service.stopDownload("id");
   assertEquals(result.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
 }
Ejemplo n.º 11
0
 private void readEntityIfPossible(ClientResponse response) {
   if (status != Response.Status.NO_CONTENT.getStatusCode()) {
     this.entity = readEntity(response, Object.class);
   }
 }