Search in sources :

Example 1 with CustomUserFieldEntity

use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.

the class CustomUserFieldsResourceNotAdminTest method shouldNotUpdateField.

@Test
public void shouldNotUpdateField() {
    reset(customUserFieldService);
    final CustomUserFieldEntity field = new CustomUserFieldEntity();
    field.setKey("test-update");
    field.setLabel("Test");
    final Response response = orgTarget("/" + field.getKey()).request().put(Entity.json(field));
    assertEquals(FORBIDDEN_403, response.getStatus());
    verify(customUserFieldService, never()).update(any());
}
Also used : Response(javax.ws.rs.core.Response) CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) Test(org.junit.Test)

Example 2 with CustomUserFieldEntity

use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.

the class CustomUserFieldsResourceAdminTest method shouldUpdate.

@Test
public void shouldUpdate() {
    reset(customUserFieldService);
    final CustomUserFieldEntity field = new CustomUserFieldEntity();
    field.setKey("test-update");
    field.setLabel("Test");
    ArgumentCaptor<CustomUserFieldEntity> argument = ArgumentCaptor.forClass(CustomUserFieldEntity.class);
    when(customUserFieldService.update(any())).thenReturn(field);
    final Response response = orgTarget("/" + field.getKey()).request().put(Entity.json(field));
    assertEquals(OK_200, response.getStatus());
    verify(customUserFieldService, times(1)).update(any());
    verify(customUserFieldService).update(argument.capture());
    assertNotNull("Field provided can't be null", argument.getValue());
    assertEquals(field.getKey(), argument.getValue().getKey());
}
Also used : Response(javax.ws.rs.core.Response) CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) Test(org.junit.Test)

Example 3 with CustomUserFieldEntity

use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.

the class CustomUserFieldsResourceAdminTest method shouldCreateField.

@Test
public void shouldCreateField() {
    reset(customUserFieldService);
    final CustomUserFieldEntity field = new CustomUserFieldEntity();
    field.setKey("TestResCreate");
    field.setLabel("TestResCreate");
    ArgumentCaptor<CustomUserFieldEntity> argument = ArgumentCaptor.forClass(CustomUserFieldEntity.class);
    when(customUserFieldService.create(any())).thenReturn(field);
    final Response response = orgTarget().request().post(Entity.json(field));
    assertEquals(CREATED_201, response.getStatus());
    verify(customUserFieldService, times(1)).create(any());
    verify(customUserFieldService).create(argument.capture());
    assertNotNull("Field provided can't be null", argument.getValue());
    assertEquals(field.getKey(), argument.getValue().getKey());
    assertTrue("LocationHeader value", response.getHeaderString("Location").endsWith(this.contextPath() + "/" + field.getKey()));
}
Also used : Response(javax.ws.rs.core.Response) CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) Test(org.junit.Test)

Example 4 with CustomUserFieldEntity

use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.

the class ConfigurationCustomFieldsResourceTest method shouldListCustomFields.

@Test
public void shouldListCustomFields() {
    final CustomUserFieldEntity customUserFieldEntity = new CustomUserFieldEntity();
    customUserFieldEntity.setKey("key1");
    customUserFieldEntity.setLabel("label 1");
    customUserFieldEntity.setRequired(true);
    customUserFieldEntity.setValues(Arrays.asList("a", "b"));
    doReturn(Arrays.asList(customUserFieldEntity)).when(customUserFieldService).listAllFields();
    final Response response = target().request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    final List<CustomUserFieldEntity> listOfCustomUserFields = response.readEntity(new GenericType<List<CustomUserFieldEntity>>() {
    });
    assertEquals(1, listOfCustomUserFields.size());
    assertEquals(customUserFieldEntity.getKey(), listOfCustomUserFields.get(0).getKey());
    assertEquals(customUserFieldEntity.getLabel(), listOfCustomUserFields.get(0).getLabel());
    assertEquals(customUserFieldEntity.isRequired(), listOfCustomUserFields.get(0).isRequired());
    assertTrue(listOfCustomUserFields.get(0).getValues().containsAll(customUserFieldEntity.getValues()));
}
Also used : Response(javax.ws.rs.core.Response) CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) List(java.util.List) Test(org.junit.Test)

Example 5 with CustomUserFieldEntity

use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.

the class CustomUserFieldsServiceTest method shouldNotCreateExistingField.

@Test(expected = CustomUserFieldAlreadyExistException.class)
public void shouldNotCreateExistingField() throws Exception {
    final CustomUserFieldEntity newFieldEntity = new CustomUserFieldEntity();
    newFieldEntity.setKey("NEWKEYUPPERCASE");
    newFieldEntity.setLabel("New Field Label");
    newFieldEntity.setRequired(true);
    newFieldEntity.setValues(Arrays.asList("test"));
    when(customUserFieldsRepository.findById(anyString(), anyString(), any())).thenReturn(Optional.of(mock(CustomUserField.class)));
    service.create(newFieldEntity);
    verify(customUserFieldsRepository, never()).create(any());
}
Also used : CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) Test(org.junit.Test)

Aggregations

CustomUserFieldEntity (io.gravitee.rest.api.model.CustomUserFieldEntity)13 Test (org.junit.Test)11 Response (javax.ws.rs.core.Response)6 CustomUserField (io.gravitee.repository.management.model.CustomUserField)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 Date (java.util.Date)1 List (java.util.List)1