Search in sources :

Example 1 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldReturnFactoryByIdentifierWithoutValidation.

@Test
public void shouldReturnFactoryByIdentifierWithoutValidation() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    when(factoryManager.getFactoryImages(FACTORY_ID)).thenReturn(emptySet());
    final Response response = given().when().expect().statusCode(200).get(SERVICE_PATH + "/" + FACTORY_ID);
    assertEquals(getFromResponse(response, FactoryDto.class).withLinks(emptyList()), factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 2 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldThrowNotFoundExceptionWhenUpdatingNonExistingFactory.

@Test
public void shouldThrowNotFoundExceptionWhenUpdatingNonExistingFactory() throws Exception {
    final Factory factory = createFactoryWithStorage(FACTORY_NAME, "git", "https://github.com/codenvy/platform-api.git");
    doThrow(new NotFoundException(format("Factory with id %s is not found.", FACTORY_ID))).when(factoryManager).getById(anyString());
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(JsonHelper.toJson(factory)).when().put(SERVICE_PATH + "/" + FACTORY_ID);
    assertEquals(response.getStatusCode(), 404);
    assertEquals(DTO.createDtoFromJson(response.getBody().asString(), ServiceError.class).getMessage(), format("Factory with id %s is not found.", FACTORY_ID));
}
Also used : Response(com.jayway.restassured.response.Response) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 3 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldSaveFactoryFromFormDataWithoutImages.

@Test
public void shouldSaveFactoryFromFormDataWithoutImages() throws Exception {
    final Factory factory = createFactory();
    final FactoryDto factoryDto = asDto(factory, user);
    when(factoryManager.saveFactory(any(FactoryDto.class), anySetOf(FactoryImage.class))).thenReturn(factory);
    doReturn(factoryDto).when(factoryBuilderSpy).build(any(InputStream.class));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", JsonHelper.toJson(factoryDto), APPLICATION_JSON).expect().statusCode(200).when().post(SERVICE_PATH);
    final FactoryDto result = getFromResponse(response, FactoryDto.class);
    factoryDto.withLinks(result.getLinks()).getCreator().withCreated(result.getCreator().getCreated());
    assertEquals(result, factoryDto);
}
Also used : Response(com.jayway.restassured.response.Response) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 4 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldReturnFactoryListByCreatorAttribute.

@Test
public void shouldReturnFactoryListByCreatorAttribute() throws Exception {
    final Factory factory1 = createNamedFactory("factory1");
    final Factory factory2 = createNamedFactory("factory2");
    when(factoryManager.getByAttribute(2, 0, ImmutableList.of(Pair.of("factory.creator.name", user.getName())))).thenReturn(ImmutableList.of(factory1, factory2));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).when().expect().statusCode(200).get(SERVICE_PATH + "/find?maxItems=2&skipCount=0&factory.creator.name=" + user.getName());
    final Set<FactoryDto> res = unwrapDtoList(response, FactoryDto.class).stream().map(f -> f.withLinks(emptyList())).collect(toSet());
    assertEquals(res.size(), 2);
    assertTrue(res.containsAll(ImmutableList.of(asDto(factory1, user), asDto(factory2, user))));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceConfig(org.eclipse.che.api.core.model.workspace.WorkspaceConfig) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) Matchers.anySetOf(org.mockito.Matchers.anySetOf) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test) RestAssured.given(com.jayway.restassured.RestAssured.given) Thread.currentThread(java.lang.Thread.currentThread) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) Collections.singletonList(java.util.Collections.singletonList) Mockito.doThrow(org.mockito.Mockito.doThrow) PreferenceManager(org.eclipse.che.api.user.server.PreferenceManager) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) Path(java.nio.file.Path) Mockito.doReturn(org.mockito.Mockito.doReturn) GenericContainerRequest(org.everrest.core.GenericContainerRequest) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) AuthorImpl(org.eclipse.che.api.factory.server.model.impl.AuthorImpl) Set(java.util.Set) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) Mockito.doNothing(org.mockito.Mockito.doNothing) Pair(org.eclipse.che.commons.lang.Pair) Matchers.any(org.mockito.Matchers.any) ApiExceptionMapper(org.eclipse.che.api.core.rest.ApiExceptionMapper) BadRequestException(org.eclipse.che.api.core.BadRequestException) UriInfo(javax.ws.rs.core.UriInfo) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) ADMIN_USER_NAME(org.everrest.assured.JettyHttpServer.ADMIN_USER_NAME) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Mock(org.mockito.Mock) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) FactoryParametersResolverHolder(org.eclipse.che.api.factory.server.FactoryService.FactoryParametersResolverHolder) VALIDATE_QUERY_PARAMETER(org.eclipse.che.api.factory.server.FactoryService.VALIDATE_QUERY_PARAMETER) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) User(org.eclipse.che.api.core.model.user.User) JsonHelper(org.eclipse.che.commons.json.JsonHelper) DtoConverter.asDto(org.eclipse.che.api.factory.server.DtoConverter.asDto) EverrestJetty(org.everrest.assured.EverrestJetty) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Files(java.nio.file.Files) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) File(java.io.File) String.valueOf(java.lang.String.valueOf) Paths(java.nio.file.Paths) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) ContentType(com.jayway.restassured.http.ContentType) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) URL(java.net.URL) FactoryBuilder(org.eclipse.che.api.factory.server.builder.FactoryBuilder) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Matchers.eq(org.mockito.Matchers.eq) URI(java.net.URI) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyList(java.util.Collections.emptyList) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) String.format(java.lang.String.format) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ServiceError(org.eclipse.che.api.core.rest.shared.dto.ServiceError) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) Assert.assertEquals(org.testng.Assert.assertEquals) SourceStorageParametersValidator(org.eclipse.che.api.factory.server.impl.SourceStorageParametersValidator) HashMap(java.util.HashMap) Response(com.jayway.restassured.response.Response) HashSet(java.util.HashSet) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ImmutableList(com.google.common.collect.ImmutableList) Matchers.anyMapOf(org.mockito.Matchers.anyMapOf) Collections.singletonMap(java.util.Collections.singletonMap) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Collections.emptySet(java.util.Collections.emptySet) JsonSyntaxException(com.google.gson.JsonSyntaxException) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) Mockito.when(org.mockito.Mockito.when) NotFoundException(org.eclipse.che.api.core.NotFoundException) Filter(org.everrest.core.Filter) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Factory(org.eclipse.che.api.core.model.factory.Factory) RequestFilter(org.everrest.core.RequestFilter) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Assert.assertTrue(org.testng.Assert.assertTrue) ADMIN_USER_PASSWORD(org.everrest.assured.JettyHttpServer.ADMIN_USER_PASSWORD) UserManager(org.eclipse.che.api.user.server.UserManager) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Example 5 with Factory

use of org.eclipse.che.api.core.model.factory.Factory in project che by eclipse.

the class FactoryServiceTest method shouldBeAbleToRemoveFactory.

/**
     * Checks that the user can remove an existing factory
     */
@Test
public void shouldBeAbleToRemoveFactory() throws Exception {
    final Factory factory = createFactory();
    when(factoryManager.getById(FACTORY_ID)).thenReturn(factory);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).param("id", FACTORY_ID).when().delete(SERVICE_PATH + "/" + FACTORY_ID);
    assertEquals(response.getStatusCode(), 204);
    // check there was a call on the remove operation with expected ID
    verify(factoryManager).removeFactory(FACTORY_ID);
}
Also used : Response(com.jayway.restassured.response.Response) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Test(org.testng.annotations.Test)

Aggregations

Factory (org.eclipse.che.api.core.model.factory.Factory)14 DtoFactory (org.eclipse.che.dto.server.DtoFactory)14 Test (org.testng.annotations.Test)12 Response (com.jayway.restassured.response.Response)11 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)10 InputStream (java.io.InputStream)5 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 APPLICATION_JSON (javax.ws.rs.core.MediaType.APPLICATION_JSON)2 TEXT_PLAIN (javax.ws.rs.core.MediaType.TEXT_PLAIN)2 UriInfo (javax.ws.rs.core.UriInfo)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2