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());
}
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);
}
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))));
}
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());
}
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");
}
Aggregations