Search in sources :

Example 1 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationServiceTest method shouldUpdateOrganization.

@Test
public void shouldUpdateOrganization() throws Exception {
    when(orgManager.update(anyString(), any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[1]));
    final OrganizationDto toUpdate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toUpdate).when().post(SECURE_PATH + "/organization/organization123");
    assertEquals(response.statusCode(), 200);
    final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
    assertEquals(createdOrganization, toUpdate);
    verify(linksInjector).injectLinks(any(), any());
    verify(orgManager).update(eq("organization123"), eq(toUpdate));
}
Also used : Response(io.restassured.response.Response) Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 2 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationServiceTest method shouldCreateOrganization.

@Test
public void shouldCreateOrganization() throws Exception {
    when(orgManager.create(any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[0]));
    final OrganizationDto toCreate = createOrganization();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toCreate).when().post(SECURE_PATH + "/organization");
    assertEquals(response.statusCode(), 201);
    final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
    assertEquals(createdOrganization, toCreate);
    verify(linksInjector).injectLinks(any(), any());
    verify(orgManager).create(eq(toCreate));
}
Also used : Response(io.restassured.response.Response) Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationDto(org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 3 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationManagerTest method shouldGetOrganizationById.

@Test
public void shouldGetOrganizationById() throws Exception {
    final OrganizationImpl toFetch = new OrganizationImpl("org123", "toFetchOrg", "org321");
    when(organizationDao.getById(eq("org123"))).thenReturn(toFetch);
    final Organization fetched = manager.getById("org123");
    assertEquals(fetched, toFetch);
    verify(organizationDao).getById("org123");
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 4 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationManagerTest method shouldGenerateIdentifierWhenCreatingOrganization.

@Test
public void shouldGenerateIdentifierWhenCreatingOrganization() throws Exception {
    final Organization organization = DtoFactory.newDto(OrganizationDto.class).withName("newOrg").withId("identifier");
    manager.create(organization);
    verify(organizationDao).create(organizationCaptor.capture());
    final String id = organizationCaptor.getValue().getId();
    assertNotNull(id);
    assertNotEquals(id, "identifier");
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 5 with Organization

use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.

the class OrganizationManagerTest method shouldUpdateOrganizationAndIgnoreNewIdAndParentFields.

@Test
public void shouldUpdateOrganizationAndIgnoreNewIdAndParentFields() throws Exception {
    final OrganizationImpl existing = new OrganizationImpl("org123", "oldName", "parent123");
    final OrganizationImpl expectedExistingToUpdate = new OrganizationImpl(existing);
    expectedExistingToUpdate.setQualifiedName("newName");
    final OrganizationImpl suborganization = new OrganizationImpl("org321", "oldName/suborgName", "org123");
    final OrganizationImpl expectedSuborganizationToUpdate = new OrganizationImpl(suborganization);
    expectedSuborganizationToUpdate.setQualifiedName(expectedExistingToUpdate.getQualifiedName() + "/" + suborganization.getName());
    when(organizationDao.getById(any())).thenReturn(existing);
    doReturn(new Page<>(singletonList(suborganization), 0, 1, 1)).when(organizationDao).getSuborganizations(anyString(), anyInt(), anyLong());
    final OrganizationImpl update = new OrganizationImpl("newId", "newName", "newParentId");
    final Organization updated = manager.update("organizationId", update);
    verify(organizationDao).getById("organizationId");
    verify(organizationDao, times(2)).update(organizationCaptor.capture());
    List<OrganizationImpl> updatedOrganizations = organizationCaptor.getAllValues();
    assertEquals(updatedOrganizations.get(0), expectedExistingToUpdate);
    assertEquals(updatedOrganizations.get(1), expectedSuborganizationToUpdate);
    verify(organizationDao).getSuborganizations(eq("oldName"), anyInt(), anyLong());
    assertEquals(updated, expectedExistingToUpdate);
}
Also used : Organization(org.eclipse.che.multiuser.organization.shared.model.Organization) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Aggregations

Organization (org.eclipse.che.multiuser.organization.shared.model.Organization)28 Test (org.testng.annotations.Test)18 OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)16 OrganizationDto (org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto)8 Response (io.restassured.response.Response)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)4 Subject (org.eclipse.che.commons.subject.Subject)4 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Transactional (com.google.inject.persist.Transactional)2 ArrayList (java.util.ArrayList)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 OrganizationPersistedEvent (org.eclipse.che.multiuser.organization.api.event.OrganizationPersistedEvent)2 ResourceManager (org.eclipse.che.multiuser.resource.api.usage.ResourceManager)2 Resource (org.eclipse.che.multiuser.resource.model.Resource)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2