Search in sources :

Example 1 with UserDevfileDto

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());
}
Also used : Response(io.restassured.response.Response) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) Test(org.testng.annotations.Test)

Example 2 with UserDevfileDto

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));
}
Also used : Response(io.restassured.response.Response) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) Test(org.testng.annotations.Test)

Example 3 with UserDevfileDto

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);
}
Also used : UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) Test(org.testng.annotations.Test)

Example 4 with UserDevfileDto

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));
}
Also used : Response(io.restassured.response.Response) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) Test(org.testng.annotations.Test)

Example 5 with UserDevfileDto

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();
}
Also used : URLEncodedUtils(org.eclipse.che.commons.lang.URLEncodedUtils) DtoConverter.asDto(org.eclipse.che.api.devfile.server.DtoConverter.asDto) DefaultValue(jakarta.ws.rs.DefaultValue) Page(org.eclipse.che.api.core.Page) GET(jakarta.ws.rs.GET) PUT(jakarta.ws.rs.PUT) Path(jakarta.ws.rs.Path) Inject(javax.inject.Inject) Content(io.swagger.v3.oas.annotations.media.Content) DevfileSchemaProvider(org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider) Operation(io.swagger.v3.oas.annotations.Operation) Response(jakarta.ws.rs.core.Response) Service(org.eclipse.che.api.core.rest.Service) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Map(java.util.Map) CURRENT_API_VERSION(org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_API_VERSION) ConflictException(org.eclipse.che.api.core.ConflictException) Produces(jakarta.ws.rs.Produces) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) Splitter(com.google.common.base.Splitter) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Schema(io.swagger.v3.oas.annotations.media.Schema) Consumes(jakarta.ws.rs.Consumes) DevfileDto(org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto) ImmutableSet(com.google.common.collect.ImmutableSet) POST(jakarta.ws.rs.POST) Set(java.util.Set) IOException(java.io.IOException) SUPPORTED_VERSIONS(org.eclipse.che.api.workspace.server.devfile.Constants.SUPPORTED_VERSIONS) Pair(org.eclipse.che.commons.lang.Pair) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(org.eclipse.che.api.core.NotFoundException) Parameter(io.swagger.v3.oas.annotations.Parameter) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) Collectors.toList(java.util.stream.Collectors.toList) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) ServerException(org.eclipse.che.api.core.ServerException) Tag(io.swagger.v3.oas.annotations.tags.Tag) APPLICATION_JSON(jakarta.ws.rs.core.MediaType.APPLICATION_JSON) QueryParam(jakarta.ws.rs.QueryParam) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) DELETE(jakarta.ws.rs.DELETE) PathParam(jakarta.ws.rs.PathParam) Collections(java.util.Collections) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) BadRequestException(org.eclipse.che.api.core.BadRequestException) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) Pair(org.eclipse.che.commons.lang.Pair) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

UserDevfileDto (org.eclipse.che.api.devfile.shared.dto.UserDevfileDto)12 Test (org.testng.annotations.Test)10 Response (io.restassured.response.Response)8 UserDevfile (org.eclipse.che.api.core.model.workspace.devfile.UserDevfile)8 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)8 Splitter (com.google.common.base.Splitter)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Operation (io.swagger.v3.oas.annotations.Operation)2 Parameter (io.swagger.v3.oas.annotations.Parameter)2 ArraySchema (io.swagger.v3.oas.annotations.media.ArraySchema)2 Content (io.swagger.v3.oas.annotations.media.Content)2 Schema (io.swagger.v3.oas.annotations.media.Schema)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 Tag (io.swagger.v3.oas.annotations.tags.Tag)2 Consumes (jakarta.ws.rs.Consumes)2 DELETE (jakarta.ws.rs.DELETE)2 DefaultValue (jakarta.ws.rs.DefaultValue)2 GET (jakarta.ws.rs.GET)2 POST (jakarta.ws.rs.POST)2 PUT (jakarta.ws.rs.PUT)2