com.jayway.restassured.response.Response Java Examples

The following examples show how to use com.jayway.restassured.response.Response. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkspacePermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldCheckPermissionsOnCommandRemoving() throws Exception {
  when(subject.hasPermission("workspace", "workspace123", "configure")).thenReturn(true);

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .pathParam("id", "workspace123")
          .when()
          .delete(SECURE_PATH + "/workspace/{id}/command/run-application");

  assertEquals(response.getStatusCode(), 204);
  verify(workspaceService).deleteCommand(eq("workspace123"), eq("run-application"));
  verify(subject).hasPermission(eq("workspace"), eq("workspace123"), eq("configure"));
}
 
Example #2
Source File: ChannelRecoveryTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorHandlingBpUnreachable() {

    Mockito.when(mock.getChannel("channel-123"))
           .thenReturn(Optional.of(createChannel("X.Y", "http://joyn-bpX.muc/bp", "channel-123")));
    Mockito.when(mock.isBounceProxyForChannelResponding("channel-123")).thenReturn(false);
    Mockito.when(mock.createChannel("channel-123", null))
           .thenReturn(createChannel("1.1", "http://joyn-bp1.muc/bp", "channel-123"));

    Response response = //
            given(). //
                   queryParam("bp", "X.Y").and().queryParam("status", "unreachable").when().put(serverUrl
                           + "/channel-123");

    assertEquals(201 /* Created */, response.getStatusCode());
    assertEquals("http://joyn-bp1.muc/bp/channels/channel-123", response.getHeader("Location"));
    assertEquals("1.1", response.getHeader("bp"));
    Mockito.verify(mock).getChannel("channel-123");
    Mockito.verify(mock).isBounceProxyForChannelResponding("channel-123");
    Mockito.verify(mock).createChannel("channel-123", null);
    Mockito.verifyNoMoreInteractions(mock);
    Mockito.verify(notifierMock).alertBounceProxyUnreachable("channel-123",
                                                             "X.Y",
                                                             "127.0.0.1",
                                                             "Bounce Proxy unreachable for Channel Service");
}
 
Example #3
Source File: FactoryPermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldMakeSureThatUserIsCreatorOnRemovingFactory() throws Exception {
  doReturn("user123").when(subject).getUserId();

  Factory factory = mock(Factory.class);
  doReturn(new AuthorImpl("user123", 12345L)).when(factory).getCreator();
  when(factoryManager.getById("factory123")).thenReturn(factory);

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .delete(SECURE_PATH + "/factory/factory123");

  assertEquals(response.getStatusCode(), 204);
  verify(service).removeFactory(eq("factory123"));
}
 
Example #4
Source File: WorkspaceServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldUpdateCommand() throws Exception {
  final WorkspaceImpl workspace = createWorkspace(createConfigDto());
  when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
  when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
  final CommandDto commandDto = createCommandDto();

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .body(commandDto)
          .when()
          .put(
              SECURE_PATH
                  + "/workspace/"
                  + workspace.getId()
                  + "/command/"
                  + commandDto.getName());

  assertEquals(response.getStatusCode(), 200);
  verify(wsManager).updateWorkspace(any(), any());
}
 
Example #5
Source File: UserServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldCreateUserFromEntity() throws Exception {
  final UserDto newUser =
      newDto(UserDto.class)
          .withName("test")
          .withEmail("[email protected]")
          .withPassword("password12345");
  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .body(newUser)
          .contentType("application/json")
          .post(SECURE_PATH + "/user");

  assertEquals(response.statusCode(), 201);
  verify(userManager).create(userCaptor.capture(), anyBoolean());
  final User user = userCaptor.getValue();
  assertEquals(user.getEmail(), "[email protected]");
  assertEquals(user.getName(), "test");
  assertEquals(user.getPassword(), "password12345");
}
 
Example #6
Source File: WorkspaceServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldDeleteProject() throws Exception {
  final WorkspaceImpl workspace = createWorkspace(createConfigDto());
  when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
  final ProjectConfig firstProject = workspace.getConfig().getProjects().iterator().next();

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .delete(
              SECURE_PATH
                  + "/workspace/"
                  + workspace.getId()
                  + "/project"
                  + firstProject.getPath());

  assertEquals(response.getStatusCode(), 204);
  verify(wsManager).updateWorkspace(any(), any());
}
 
Example #7
Source File: ProfileServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldBeAbleToRemoveSpecifiedAttributes() throws Exception {
  when(profileManager.getById(SUBJECT.getUserId()))
      .thenReturn(
          new ProfileImpl(
              SUBJECT.getUserId(),
              ImmutableMap.of(
                  "attr1", "value1",
                  "attr2", "value2",
                  "attr3", "value3")));
  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .contentType("application/json")
          .body(asList("attr1", "attr3"))
          .delete(SECURE_PATH + "/profile/attributes");

  assertEquals(response.getStatusCode(), 204);
  verify(profileManager).update(profileCaptor.capture());
  final Profile profile = profileCaptor.getValue();
  assertEquals(profile.getAttributes(), ImmutableMap.of("attr2", "value2"));
}
 
Example #8
Source File: IT_restBase.java    From movieapp-dialog with Apache License 2.0 6 votes vote down vote up
/**
 *<ul>
 *<li><B>Info: </B>Ensure that initChat records the clientId in the rest response</li>
 *<li><B>Step: </B>Connect to Showcase Dialog app using initchat rest api call</li>
 *<li><B>Verify: </B>Validate that the rest response JSON element clientId is not empty</li>
 *</ul>
 */
@Test
public void initChatClientId() {

	Response response = 
			RestAssured.given()
					   .contentType(ContentType.JSON)
					   .param("firstTime", "true")
					   .get(RestAPI.initchat)
					   .then()
					   .statusCode(200)
					   .extract()
					   .response();
	
       JsonPath jp = new JsonPath(response.asString());
	
	//Validate that the client id is not empty
	Assert.assertFalse("ERROR: Return clientId is empty",
						jp.get(CLIENTID).toString().isEmpty());
	
}
 
Example #9
Source File: ResourceServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldReturnTotalResourcesForGivenAccount() throws Exception {
  doReturn(singletonList(resource)).when(resourceManager).getTotalResources(any());

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .when()
          .get(SECURE_PATH + "/resource/account123");

  assertEquals(response.statusCode(), 200);
  verify(resourceManager).getTotalResources(eq("account123"));
  final List<ResourceDto> resources = unwrapDtoList(response, ResourceDto.class);
  assertEquals(resources.size(), 1);
  final ResourceDto fetchedResource = resources.get(0);
  assertEquals(fetchedResource.getType(), RESOURCE_TYPE);
  assertEquals(new Long(fetchedResource.getAmount()), RESOURCE_AMOUNT);
  assertEquals(fetchedResource.getUnit(), RESOURCE_UNIT);
}
 
Example #10
Source File: AdminUserServiceTest.java    From codenvy with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void throwsBadRequestExceptionWhenProvidedTwoSearchParams() throws Exception {
  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .expect()
          .statusCode(400)
          .get(SECURE_PATH + "/admin/user/find?emailPart=admin@&namePart=admin");

  final String actual =
      DtoFactory.getInstance()
          .createDtoFromJson(response.body().print(), ServiceError.class)
          .getMessage();
  assertEquals(actual, "Expected either user's e-mail or name part, while both values received");
}
 
Example #11
Source File: ActivityPermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldThrowExceptionWhenNotAuthzdToGetActivity() throws Exception {
  doThrow(
          new ForbiddenException(
              "The user does not have permission to "
                  + SystemDomain.MONITOR_SYSTEM_ACTION
                  + " workspace with id 'workspace123'"))
      .when(subject)
      .checkPermission(
          eq(SystemDomain.DOMAIN_ID), eq(null), eq(SystemDomain.MONITOR_SYSTEM_ACTION));

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .get(SECURE_PATH + "/activity?status=STARTING");

  assertEquals(response.getStatusCode(), 403);
}
 
Example #12
Source File: MessagingLoadDistributionTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
private List<ImmutableMessage> getMessagesFromBounceProxy(BounceProxyCommunicationMock bpMock,
                                                          String channelUrl,
                                                          String channelId) throws IOException, EncodingException,
                                                                            UnsuppportedVersionException {

    String previousBaseUri = RestAssured.baseURI;
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, "jsessionid");
    String sessionId = Utilities.getSessionId(channelUrl, "jsessionid");

    /* @formatter:off */
    Response response = bpMock.onrequest()
                              .with()
                              .header("X-Atmosphere-tracking-id", bpMock.getReceiverId())
                              .expect()
                              .statusCode(200)
                              .when()
                              .get(";jsessionid=" + sessionId);
    /* @formatter:on */

    List<ImmutableMessage> messagesFromResponse = bpMock.getJoynrMessagesFromResponse(response);

    RestAssured.baseURI = previousBaseUri;

    return messagesFromResponse;
}
 
Example #13
Source File: DataSetServiceTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void updateRawContentShouldCheckAvailableSpaceEvenIfTheSizeIsNotProvidedByFrontEnd() throws Exception {

    // given
    final String datasetId = createCSVDataSet(this.getClass().getResourceAsStream("../avengers.csv"), "dataset2");

    Mockito.reset(quotaService);
    Mockito.when(quotaService.getAvailableSpace()).thenReturn(10L);

    // when
    final Response response = given() //
            .body(IOUtils.toString(this.getClass().getResourceAsStream(TAGADA_CSV), UTF_8))
            .when() //
            .put("/datasets/{id}/raw", datasetId);

    // then
    assertEquals(413, response.getStatusCode());
    assertFalse(cacheManager.has(new UpdateDataSetCacheKey(datasetId)));
}
 
Example #14
Source File: OrganizationServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldGetOrganizationsByCurrentUserIfParameterIsNotSpecified() throws Exception {
  final OrganizationDto toFetch = createOrganization();

  doReturn(new Page<>(singletonList(toFetch), 0, 1, 1))
      .when(orgManager)
      .getByMember(anyString(), anyInt(), anyInt());

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .when()
          .expect()
          .statusCode(200)
          .get(SECURE_PATH + "/organization?skipCount=0&maxItems=1");

  final List<OrganizationDto> organizationDtos = unwrapDtoList(response, OrganizationDto.class);
  assertEquals(organizationDtos.size(), 1);
  assertEquals(organizationDtos.get(0), toFetch);
  verify(orgManager).getByMember(CURRENT_USER_ID, 1, 0);
  verify(linksInjector).injectLinks(any(), any());
}
 
Example #15
Source File: WorkspacePermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldCheckPermissionsOnCommandAdding() throws Exception {
  when(subject.hasPermission("workspace", "workspace123", "configure")).thenReturn(true);

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .pathParam("id", "workspace123")
          .when()
          .post(SECURE_PATH + "/workspace/{id}/command");

  assertEquals(response.getStatusCode(), 204);
  verify(workspaceService).addCommand(eq("workspace123"), any());
  verify(subject).hasPermission(eq("workspace"), eq("workspace123"), eq("configure"));
}
 
Example #16
Source File: WorkspacePermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldCheckAccountPermissionsAccessOnWorkspaceCreationFromConfig() throws Exception {
  doNothing().when(permissionsFilter).checkAccountPermissions(anyString(), any());

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .body(DtoFactory.newDto(WorkspaceConfigDto.class))
          .when()
          .post(SECURE_PATH + "/workspace?namespace=userok");

  assertEquals(response.getStatusCode(), 204);
  verify(workspaceService)
      .create(any(WorkspaceConfigDto.class), any(), any(), any(), eq("userok"));
  verify(permissionsFilter).checkAccountPermissions("userok", AccountOperation.CREATE_WORKSPACE);
  verifyZeroInteractions(subject);
}
 
Example #17
Source File: MessagingTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Test
public void testPostMessageChannelWasMigrated() throws Exception {
    Mockito.when(mock.isAssignedForChannel("channel-123")).thenReturn(false);
    Mockito.when(mock.hasChannelAssignmentMoved("channel-123")).thenReturn(true);

    ImmutableMessage message = createJoynrMessage();
    byte[] serializedMessage = message.getSerializedMessage();

    Response response = //
            given(). //
                   contentType(ContentType.BINARY)
                   .when()
                   .body(serializedMessage)
                   .post(serverUrl + "/channels/channel-123/message");

    assertEquals(410 /* Gone */, response.getStatusCode());
    assertNull(response.getHeader("Location"));
    assertNull(response.getHeader("msgId"));
    Mockito.verify(mock, Mockito.never()).passMessageToReceiver("channel-123", serializedMessage);
}
 
Example #18
Source File: PreparationAPITest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void should_throw_exception_on_preparation_head_change_with_unknown_step() throws Exception {
    // given
    String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
    final String preparationId = testClient.createPreparationFromDataset(tagadaId, "testPreparation", home.getId());

    // when
    final Response response = given()
            .when()//
            .put("/api/preparations/{id}/head/{stepId}", preparationId, "unknown_step_id");

    // then
    response
            .then()//
            .statusCode(404)//
            .assertThat()//
            .body("code", is("TDP_PS_PREPARATION_STEP_DOES_NOT_EXIST"));
}
 
Example #19
Source File: FactoryPermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldReturnForbiddenWhenUserIsNotCreatorOnRemovingForeignFactory() throws Exception {
  doReturn("user321").when(subject).getUserId();

  Factory factory = mock(Factory.class);
  doReturn(new AuthorImpl("user123", 12345L)).when(factory).getCreator();
  when(factoryManager.getById("factory123")).thenReturn(factory);

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .delete(SECURE_PATH + "/factory/factory123");

  assertEquals(response.getStatusCode(), 403);
  verify(service, never()).removeFactory(any());
}
 
Example #20
Source File: PreparationControllerTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnErrorWhenScopeIsNotConsistentOnTransformationUpdate() throws Exception {
    // given
    final String preparationId = createPreparation("1234", "my preparation");
    final String stepId = applyTransformation(preparationId, "actions/append_upper_case.json");

    // when
    final Response request = given()
            .body(IOUtils.toString(PreparationControllerTest.class
                    .getResourceAsStream("error/incomplete_transformation_params.json"), UTF_8))//
            .contentType(ContentType.JSON)//
            .when()//
            .put("/preparations/{id}/actions/{action}", preparationId, stepId);

    // then
    request
            .then()//
            .statusCode(400)//
            .assertThat()//
            .body("code", is("TDP_BASE_MISSING_ACTION_SCOPE"));
}
 
Example #21
Source File: OrganizationServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldGetChildOrganizations() throws Exception {
  final OrganizationDto toFetch = createOrganization();

  doReturn(new Page<>(singletonList(toFetch), 0, 1, 1))
      .when(orgManager)
      .getByParent(anyString(), anyInt(), anyLong());

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .when()
          .expect()
          .statusCode(200)
          .get(SECURE_PATH + "/organization/parentOrg123/organizations?skipCount=0&maxItems=1");

  final List<OrganizationDto> organizationDtos = unwrapDtoList(response, OrganizationDto.class);
  assertEquals(organizationDtos.size(), 1);
  assertEquals(organizationDtos.get(0), toFetch);
  verify(orgManager).getByParent("parentOrg123", 1, 0);
  verify(linksInjector).injectLinks(any(), any());
}
 
Example #22
Source File: WorkspaceServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldNotUpdateTheWorkspaceWithConfigAndDevfileAtTheSameTime() throws Exception {
  final WorkspaceDto workspaceDto =
      newDto(WorkspaceDto.class)
          .withId("workspace123")
          .withConfig(newDto(WorkspaceConfigDto.class))
          .withDevfile(newDto(DevfileDto.class));

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .body(workspaceDto)
          .when()
          .put(SECURE_PATH + "/workspace/" + workspaceDto.getId());

  assertEquals(response.getStatusCode(), 400);
  assertEquals(
      unwrapError(response),
      "Required non-null workspace configuration or devfile update but not both");
}
 
Example #23
Source File: FactoryServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldReturnFactoryByIdentifierWithValidation() throws Exception {
  final Factory factory = createFactory();
  final FactoryDto factoryDto = asDto(factory, user);
  when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
  doNothing().when(acceptValidator).validateOnAccept(any(FactoryDto.class));

  final Response response =
      given()
          .when()
          .expect()
          .statusCode(200)
          .get(SERVICE_PATH + "/" + FACTORY_ID + "?validate=true");

  assertEquals(getFromResponse(response, FactoryDto.class).withLinks(emptyList()), factoryDto);
}
 
Example #24
Source File: WorkspaceServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void createShouldReturn400WhenAttributesAreNotValid() throws Exception {
  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .body(createConfigDto())
          .when()
          .post(SECURE_PATH + "/workspace?attribute=factoryId=factoryId123");

  assertEquals(response.getStatusCode(), 400);
  assertEquals(
      unwrapError(response),
      "Attribute 'factoryId=factoryId123' is not valid, "
          + "it should contain name and value separated "
          + "with colon. For example: attributeName:attributeValue");
}
 
Example #25
Source File: ActivityPermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldThrowExceptionWhenUpdatingNotOwnedWorkspace() throws Exception {
  doThrow(
          new ForbiddenException(
              "The user does not have permission to "
                  + WorkspaceDomain.USE
                  + " workspace with id 'workspace123'"))
      .when(subject)
      .checkPermission(anyString(), anyString(), anyString());

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .when()
          .put(SECURE_PATH + "/activity/workspace123");

  assertEquals(response.getStatusCode(), 403);
}
 
Example #26
Source File: WorkspaceServiceTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldNotUpdateTheWorkspaceWithoutConfigAndDevfile() throws Exception {
  final WorkspaceDto workspaceDto = newDto(WorkspaceDto.class).withId("workspace123");

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .body(workspaceDto)
          .when()
          .put(SECURE_PATH + "/workspace/" + workspaceDto.getId());

  assertEquals(response.getStatusCode(), 400);
  assertEquals(
      unwrapError(response),
      "Required non-null workspace configuration or devfile update but not both");
}
 
Example #27
Source File: DataSetServiceTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void copyDataSetShouldCheckIfThereIsEnoughSpaceAvailable() throws Exception {

    // given
    final String datasetId = createCSVDataSet(this.getClass().getResourceAsStream("../avengers.csv"), "dataset2");

    Mockito.reset(quotaService);
    Mockito.when(quotaService.getAvailableSpace()).thenReturn(10L);

    // when
    final Response response = given() //
            .queryParam("copyName", "copy") //
            .post("/datasets/{id}/copy", datasetId);

    // then
    assertEquals(413, response.getStatusCode());
    assertFalse(cacheManager.has(new UpdateDataSetCacheKey(datasetId)));
}
 
Example #28
Source File: WorkspacePermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldCheckPermissionsOnProjectRemoving() throws Exception {
  when(subject.hasPermission("workspace", "workspace123", "configure")).thenReturn(true);

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .pathParam("id", "workspace123")
          .when()
          .delete(SECURE_PATH + "/workspace/{id}/project/spring");

  assertEquals(response.getStatusCode(), 204);
  verify(workspaceService).deleteProject(eq("workspace123"), eq("spring"));
  verify(subject).hasPermission(eq("workspace"), eq("workspace123"), eq("configure"));
}
 
Example #29
Source File: GetPermissionsFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldDoChainIfUserHasAnyPermissionsForInstance() throws Exception {
  when(permissionsManager.get("user123", "test", "test123"))
      .thenReturn(new TestPermissions("user123", "test", "test123", singletonList("read")));

  final Response response =
      given()
          .auth()
          .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
          .contentType("application/json")
          .when()
          .get(SECURE_PATH + "/permissions/test/all?instance=test123");

  assertEquals(response.getStatusCode(), 204);
  verify(permissionsService).getUsersPermissions(eq("test"), eq("test123"), anyInt(), anyInt());
  verify(instanceValidator).validate("test", "test123");
}
 
Example #30
Source File: PreparationAPITest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Test
public void should_fail_properly_on_append_error() throws Exception {
    // given
    final String missingScopeAction = IOUtils.toString(
            PreparationAPITest.class.getResourceAsStream("transformation/upper_case_firstname_without_scope.json"),
            UTF_8);
    final String preparationId =
            testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparation", home.getId());

    // when
    final Response request = given() //
            .contentType(ContentType.JSON)//
            .body(missingScopeAction)//
            .when()//
            .post("/api/preparations/{id}/actions", preparationId);

    // then
    request
            .then()//
            .statusCode(400)//
            .body("code", is("TDP_BASE_MISSING_ACTION_SCOPE"));
}