use of org.eclipse.che.api.devfile.shared.dto.UserDevfileDto in project che-server by eclipse-che.
the class DevfileServiceTest method shouldBeAbleToUpdateUserDevfile.
@Test
public void shouldBeAbleToUpdateUserDevfile() throws Exception {
// given
final UserDevfileDto devfileDto = TestObjectGenerator.createUserDevfileDto();
final UserDevfileImpl userDevfileImpl = new UserDevfileImpl(devfileDto, TEST_ACCOUNT);
when(userDevfileManager.updateUserDevfile(any(UserDevfile.class))).thenReturn(userDevfileImpl);
// when
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(DtoFactory.getInstance().toJson(devfileDto)).when().put(SECURE_PATH + "/devfile/" + devfileDto.getId());
// then
assertEquals(response.getStatusCode(), 200);
assertEquals(new UserDevfileImpl(unwrapDto(response, UserDevfileDto.class), TEST_ACCOUNT), userDevfileImpl);
verify(userDevfileManager).updateUserDevfile(devfileDto);
verify(linksInjector).injectLinks(any(), any());
}
use of org.eclipse.che.api.devfile.shared.dto.UserDevfileDto in project che-server by eclipse-che.
the class DevfileServiceTest method shouldCreateUserDevfileFromJson.
@Test(dataProvider = "validUserDevfiles")
public void shouldCreateUserDevfileFromJson(UserDevfileDto userDevfileDto) throws Exception {
final UserDevfileImpl userDevfileImpl = new UserDevfileImpl("id-123123", TEST_ACCOUNT, userDevfileDto);
when(userDevfileManager.createDevfile(any(UserDevfile.class))).thenReturn(userDevfileImpl);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(DtoFactory.getInstance().toJson(userDevfileDto)).when().post(SECURE_PATH + "/devfile");
assertEquals(response.getStatusCode(), 201);
UserDevfileDto dto = unwrapDto(response, UserDevfileDto.class);
assertEquals(dto.getNamespace(), TEST_ACCOUNT.getName());
assertEquals(new UserDevfileImpl(dto, TEST_ACCOUNT), userDevfileImpl);
verify(userDevfileManager).createDevfile(any(UserDevfile.class));
}
use of org.eclipse.che.api.devfile.shared.dto.UserDevfileDto in project devspaces-images by redhat-developer.
the class DevfileServiceLinksInjectorTest method shouldInjectLinks.
@Test
public void shouldInjectLinks() {
// given
final UserDevfileDto userDevfileDto = DtoFactory.newDto(UserDevfileDto.class).withId("id123");
DevfileServiceLinksInjector linksInjector = new DevfileServiceLinksInjector();
// when
final UserDevfileDto withLinks = linksInjector.injectLinks(userDevfileDto, context);
// then
assertEquals(withLinks.getLinks().size(), 1);
assertNotNull(withLinks.getLink(Constants.LINK_REL_SELF));
assertEquals(withLinks.getLinks().get(0).getMethod(), HttpMethod.GET);
assertEquals(withLinks.getLinks().get(0).getHref(), URI_BASE + SERVICE_PATH + "/id123");
assertEquals(withLinks.getLinks().get(0).getProduces(), MediaType.APPLICATION_JSON);
}
use of org.eclipse.che.api.devfile.shared.dto.UserDevfileDto in project devspaces-images by redhat-developer.
the class DevfileServiceTest method shouldCreateUserDevfileFromJson.
@Test(dataProvider = "validUserDevfiles")
public void shouldCreateUserDevfileFromJson(UserDevfileDto userDevfileDto) throws Exception {
final UserDevfileImpl userDevfileImpl = new UserDevfileImpl("id-123123", TEST_ACCOUNT, userDevfileDto);
when(userDevfileManager.createDevfile(any(UserDevfile.class))).thenReturn(userDevfileImpl);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(DtoFactory.getInstance().toJson(userDevfileDto)).when().post(SECURE_PATH + "/devfile");
assertEquals(response.getStatusCode(), 201);
UserDevfileDto dto = unwrapDto(response, UserDevfileDto.class);
assertEquals(dto.getNamespace(), TEST_ACCOUNT.getName());
assertEquals(new UserDevfileImpl(dto, TEST_ACCOUNT), userDevfileImpl);
verify(userDevfileManager).createDevfile(any(UserDevfile.class));
}
use of org.eclipse.che.api.devfile.shared.dto.UserDevfileDto in project devspaces-images by redhat-developer.
the class DevfileService method getUserDevfiles.
@GET
@Path("search")
@Produces(APPLICATION_JSON)
@Operation(summary = "Get devfiles which user can read. This operation can be performed only by authorized user. " + "It is possible to add additional constraints for the desired devfiles by specifying\n" + "multiple query parameters that is representing fields of the devfile. All constrains\n" + "would be combined with \"And\" condition. Also, it is possible to specify 'like:' prefix\n" + "for the query parameters. In this case instead of an exact match would be used SQL pattern like search.\n" + "Examples id=sdfsdf5&devfile.meta.name=like:%dfdf&", responses = { @ApiResponse(responseCode = "200", description = "The devfiles successfully fetched", content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserDevfileDto.class)))), @ApiResponse(responseCode = "500", description = "Internal server error occurred during devfiles fetching") })
public Response getUserDevfiles(@Parameter(description = "The number of the items to skip") @DefaultValue("0") @QueryParam("skipCount") Integer skipCount, @Parameter(description = "The limit of the items in the response, default is 30, maximum 60") @DefaultValue("30") @QueryParam("maxItems") Integer maxItems, @Parameter(description = "A list of fields and directions of sort. By default items would be sorted by id. Example id:asc,name:desc.") @QueryParam("order") String order) throws ServerException, BadRequestException {
final Set<String> skip = ImmutableSet.of("token", "skipCount", "maxItems", "order");
Map<String, Set<String>> queryParams = URLEncodedUtils.parse(uriInfo.getRequestUri());
final List<Pair<String, String>> query = queryParams.entrySet().stream().filter(param -> !param.getValue().isEmpty()).filter(param -> !skip.contains(param.getKey())).map(entry -> Pair.of(entry.getKey(), entry.getValue().iterator().next())).collect(toList());
List<Pair<String, String>> searchOrder = Collections.emptyList();
if (order != null && !order.isEmpty()) {
try {
searchOrder = Splitter.on(",").trimResults().omitEmptyStrings().withKeyValueSeparator(":").split(order).entrySet().stream().map(e -> Pair.of(e.getKey(), e.getValue())).collect(toList());
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid `order` query parameter format." + e.getMessage());
}
}
Page<? extends UserDevfile> userDevfilesPage = userDevfileManager.getUserDevfiles(maxItems, skipCount, query, searchOrder);
List<UserDevfileDto> list = userDevfilesPage.getItems().stream().map(DtoConverter::asDto).map(dto -> linksInjector.injectLinks(asDto(dto), getServiceContext())).collect(toList());
return Response.ok().entity(list).header("Link", createLinkHeader(userDevfilesPage)).build();
}
Aggregations