Search in sources :

Example 51 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method shouldNotGenerateFactoryIfNoProjectsWithSourceStorage.

@Test
public void shouldNotGenerateFactoryIfNoProjectsWithSourceStorage() throws Exception {
    // given
    final String wsId = "workspace123234";
    WorkspaceImpl.WorkspaceImplBuilder ws = WorkspaceImpl.builder();
    WorkspaceConfigImpl.WorkspaceConfigImplBuilder wsConfig = WorkspaceConfigImpl.builder();
    ws.setId(wsId);
    wsConfig.setProjects(Arrays.asList(DTO.createDto(ProjectConfigDto.class).withPath("/proj1"), DTO.createDto(ProjectConfigDto.class).withPath("/proj2")));
    wsConfig.setName("wsname");
    wsConfig.setEnvironments(singletonMap("env1", DTO.createDto(EnvironmentDto.class)));
    wsConfig.setDefaultEnv("env1");
    ws.setStatus(WorkspaceStatus.RUNNING);
    wsConfig.setCommands(singletonList(DTO.createDto(CommandDto.class).withName("MCI").withType("mvn").withCommandLine("clean install")));
    ws.setConfig(wsConfig.build());
    WorkspaceImpl usersWorkspace = ws.build();
    when(workspaceManager.getWorkspace(eq(wsId))).thenReturn(usersWorkspace);
    // when
    Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SERVICE_PATH + "/workspace/" + wsId);
    // then
    assertEquals(response.getStatusCode(), BAD_REQUEST.getStatusCode());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 52 with Response

use of com.jayway.restassured.response.Response 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 53 with Response

use of com.jayway.restassured.response.Response 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 54 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method checkValidateResolver.

@Test
public void checkValidateResolver() throws Exception {
    final FactoryParametersResolver dummyResolver = Mockito.mock(FactoryParametersResolver.class);
    factoryParametersResolvers.add(dummyResolver);
    // invalid factory
    final String invalidFactoryMessage = "invalid factory";
    doThrow(new BadRequestException(invalidFactoryMessage)).when(acceptValidator).validateOnAccept(any());
    // create factory
    final FactoryDto expectFactory = DTO.createDto(FactoryDto.class).withV("4.0").withName("matchingResolverFactory");
    // accept resolver
    when(dummyResolver.accept(anyMapOf(String.class, String.class))).thenReturn(true);
    when(dummyResolver.createFactory(anyMapOf(String.class, String.class))).thenReturn(expectFactory);
    // when
    final Map<String, String> map = new HashMap<>();
    final Response response = given().contentType(ContentType.JSON).when().body(map).queryParam(VALIDATE_QUERY_PARAMETER, valueOf(true)).post(SERVICE_PATH + "/resolver");
    // then check we have a not found
    assertEquals(response.getStatusCode(), BAD_REQUEST.getStatusCode());
    assertTrue(response.getBody().prettyPrint().contains(invalidFactoryMessage));
    // check we call resolvers
    verify(dummyResolver).accept(anyMapOf(String.class, String.class));
    verify(dummyResolver).createFactory(anyMapOf(String.class, String.class));
    // check we call validator
    verify(acceptValidator).validateOnAccept(any());
}
Also used : Response(com.jayway.restassured.response.Response) HashMap(java.util.HashMap) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) BadRequestException(org.eclipse.che.api.core.BadRequestException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 55 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class FactoryServiceTest method shouldNotBeAbleToUpdateANullFactory.

@Test
public void shouldNotBeAbleToUpdateANullFactory() throws Exception {
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).when().put(SERVICE_PATH + "/" + FACTORY_ID);
    assertEquals(response.getStatusCode(), 400);
    assertEquals(DTO.createDtoFromJson(response.getBody().asString(), ServiceError.class).getMessage(), "Factory configuration required");
}
Also used : Response(com.jayway.restassured.response.Response) Test(org.testng.annotations.Test)

Aggregations

Response (com.jayway.restassured.response.Response)169 Test (org.testng.annotations.Test)129 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)35 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)31 Test (org.junit.Test)31 Matchers.anyString (org.mockito.Matchers.anyString)21 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)19 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)15 IOException (java.io.IOException)14 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 XPathExpressionException (javax.xml.xpath.XPathExpressionException)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Factory (org.eclipse.che.api.core.model.factory.Factory)11 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)11 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)11 DtoFactory (org.eclipse.che.dto.server.DtoFactory)11 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 InputStream (java.io.InputStream)6