Search in sources :

Example 1 with ApplicationTypesEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity in project gravitee-management-rest-api by gravitee-io.

the class ConfigurationResourceTest method shouldGetApplicationTypes.

@Test
public void shouldGetApplicationTypes() throws TechnicalException {
    resetAllMocks();
    ApplicationTypesEntity typesEntity = new ApplicationTypesEntity();
    List<ApplicationTypeEntity> data = new ArrayList<>();
    ApplicationTypeEntity simple = new ApplicationTypeEntity();
    simple.setId("simple");
    simple.setAllowed_grant_types(new ArrayList<>());
    simple.setDefault_grant_types(new ArrayList<>());
    simple.setMandatory_grant_types(new ArrayList<>());
    simple.setName("Simple");
    simple.setDescription("Simple type");
    data.add(simple);
    ApplicationTypeEntity web = new ApplicationTypeEntity();
    web.setId("web");
    List<ApplicationGrantTypeEntity> grantTypes = new ArrayList<>();
    ApplicationGrantTypeEntity grantType = new ApplicationGrantTypeEntity();
    grantType.setName("name");
    List<String> responses_types = new ArrayList<>();
    responses_types.add("token");
    grantType.setResponse_types(responses_types);
    grantTypes.add(grantType);
    web.setAllowed_grant_types(grantTypes);
    web.setDefault_grant_types(new ArrayList<>());
    web.setMandatory_grant_types(new ArrayList<>());
    web.setName("Web");
    web.setDescription("Web type");
    data.add(web);
    typesEntity.setData(data);
    when(applicationTypeService.getEnabledApplicationTypes()).thenReturn(typesEntity);
    final Response response = target().path("applications").path("types").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    final ConfigurationApplicationTypesResponse appTypes = response.readEntity(ConfigurationApplicationTypesResponse.class);
    assertNotNull(appTypes);
    @Valid List<ApplicationType> types = appTypes.getData();
    assertNotNull(types);
    assertEquals(2, types.size());
    assertEquals("web", types.get(1).getId());
    assertEquals(1, types.get(1).getAllowedGrantTypes().size());
}
Also used : ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ApplicationGrantTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity) Response(javax.ws.rs.core.Response) Valid(javax.validation.Valid) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) Test(org.junit.Test)

Example 2 with ApplicationTypesEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationTypeServiceImpl method getFilteredApplicationTypes.

public ApplicationTypesEntity getFilteredApplicationTypes(JsonNode jsonTypes) {
    ApplicationTypesEntity applicationTypesEntity = this.getApplicationTypesEntity();
    List<ApplicationTypeEntity> filteredData = applicationTypesEntity.getData().stream().filter(typeEntity -> jsonTypes.get(typeEntity.getId()).get("enabled").asBoolean(false)).collect(Collectors.toList());
    applicationTypesEntity.setData(filteredData);
    return applicationTypesEntity;
}
Also used : ConfigService(io.gravitee.rest.api.service.ConfigService) Charset.defaultCharset(java.nio.charset.Charset.defaultCharset) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApplicationTypeService(io.gravitee.rest.api.service.configuration.application.ApplicationTypeService) Autowired(org.springframework.beans.factory.annotation.Autowired) ApplicationTypeNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationTypeNotFoundException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Application(io.gravitee.rest.api.model.settings.Application) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Component(org.springframework.stereotype.Component) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) InputStream(java.io.InputStream) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity)

Example 3 with ApplicationTypesEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationTypeServiceTest method shouldGetEnabledApplicationTypes.

@Test
public void shouldGetEnabledApplicationTypes() throws TechnicalException, IOException {
    JsonNode jsonTypes = objectMapper.readTree("{ \"simple\": { \"enabled\": false }, \"web\": { \"enabled\": true }, \"browser\": { \"enabled\": true }, \"backend_to_backend\": { \"enabled\": false }, \"native\": { \"enabled\": true } }");
    ApplicationTypesEntity enabledApplicationsTypes = applicationTypeService.getFilteredApplicationTypes(jsonTypes);
    assertNotNull(enabledApplicationsTypes);
    assertEquals(3, enabledApplicationsTypes.getData().size());
}
Also used : ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 4 with ApplicationTypesEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationTypeServiceTest method shouldGetAllApplicationTypes.

@Test
public void shouldGetAllApplicationTypes() throws TechnicalException, IOException {
    JsonNode jsonTypes = objectMapper.readTree("{ \"simple\": { \"enabled\": true }, \"web\": { \"enabled\": true }, \"browser\": { \"enabled\": true }, \"backend_to_backend\": { \"enabled\": true }, \"native\": { \"enabled\": true } }");
    ApplicationTypesEntity enabledApplicationsTypes = applicationTypeService.getFilteredApplicationTypes(jsonTypes);
    assertNotNull(enabledApplicationsTypes);
    assertEquals(5, enabledApplicationsTypes.getData().size());
}
Also used : ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

ApplicationTypesEntity (io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Test (org.junit.Test)3 ApplicationTypeEntity (io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApplicationGrantTypeEntity (io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity)1 Application (io.gravitee.rest.api.model.settings.Application)1 ConfigService (io.gravitee.rest.api.service.ConfigService)1 ApplicationTypeService (io.gravitee.rest.api.service.configuration.application.ApplicationTypeService)1 ApplicationTypeNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationTypeNotFoundException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset.defaultCharset (java.nio.charset.Charset.defaultCharset)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Valid (javax.validation.Valid)1 Response (javax.ws.rs.core.Response)1 IOUtils (org.apache.commons.io.IOUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1