Search in sources :

Example 6 with NewApplicationEntity

use of io.gravitee.rest.api.model.NewApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResourceTest method shouldCreateApplicationWithSimpleSettings.

@Test
public void shouldCreateApplicationWithSimpleSettings() {
    ApplicationInput input = new ApplicationInput().description(APPLICATION).groups(Arrays.asList(APPLICATION)).name(APPLICATION);
    SimpleApplicationSettings sas = new SimpleApplicationSettings().clientId(APPLICATION).type(APPLICATION);
    input.setSettings(new io.gravitee.rest.api.portal.rest.model.ApplicationSettings().app(sas));
    final Response response = target().request().post(Entity.json(input));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    ArgumentCaptor<NewApplicationEntity> captor = ArgumentCaptor.forClass(NewApplicationEntity.class);
    Mockito.verify(applicationService).create(captor.capture(), any());
    final NewApplicationEntity value = captor.getValue();
    assertNotNull(value);
    assertEquals(APPLICATION, value.getDescription());
    assertEquals(APPLICATION, value.getName());
    final Set<String> groups = value.getGroups();
    assertNotNull(groups);
    assertFalse(groups.isEmpty());
    assertTrue(groups.contains(APPLICATION));
    assertNull(value.getType());
    assertNull(value.getClientId());
    final ApplicationSettings settings = value.getSettings();
    assertNotNull(settings);
    final io.gravitee.rest.api.model.application.SimpleApplicationSettings app = settings.getApp();
    assertNotNull(app);
    assertEquals(APPLICATION, app.getClientId());
    assertEquals(APPLICATION, app.getType());
    assertNull(settings.getoAuthClient());
    Application createdApp = response.readEntity(Application.class);
    assertNotNull(createdApp);
    assertEquals("NEW", createdApp.getId());
}
Also used : NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) Response(javax.ws.rs.core.Response) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) Test(org.junit.Test)

Example 7 with NewApplicationEntity

use of io.gravitee.rest.api.model.NewApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResourceTest method shouldNotCreateApplication_emptyName.

@Test
public void shouldNotCreateApplication_emptyName() {
    final NewApplicationEntity appEntity = new NewApplicationEntity();
    appEntity.setName("");
    appEntity.setDescription("my description");
    ApplicationEntity returnedApp = new ApplicationEntity();
    returnedApp.setId("my-beautiful-application");
    doReturn(returnedApp).when(applicationService).create(any(NewApplicationEntity.class), Mockito.eq(JerseySpringTest.USER_NAME));
    final Response response = envTarget().request().post(Entity.json(appEntity));
    assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) JerseySpringTest(io.gravitee.rest.api.management.rest.JerseySpringTest) Test(org.junit.Test)

Example 8 with NewApplicationEntity

use of io.gravitee.rest.api.model.NewApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResourceTest method shouldCreateApplication.

@Test
public void shouldCreateApplication() {
    reset(applicationService);
    NewApplicationEntity newApplicationEntity = new NewApplicationEntity();
    newApplicationEntity.setName("My beautiful application");
    newApplicationEntity.setDescription("my description");
    ApplicationEntity createdApplication = new ApplicationEntity();
    createdApplication.setId("my-beautiful-application");
    doReturn(createdApplication).when(applicationService).create(any(NewApplicationEntity.class), Mockito.eq(USER_NAME));
    final Response response = envTarget().request().post(Entity.json(newApplicationEntity));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    assertEquals(envTarget().path("my-beautiful-application").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
}
Also used : Response(javax.ws.rs.core.Response) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) JerseySpringTest(io.gravitee.rest.api.management.rest.JerseySpringTest) Test(org.junit.Test)

Aggregations

NewApplicationEntity (io.gravitee.rest.api.model.NewApplicationEntity)8 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)6 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)4 JerseySpringTest (io.gravitee.rest.api.management.rest.JerseySpringTest)2 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)2 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)1 io.gravitee.rest.api.portal.rest.model (io.gravitee.rest.api.portal.rest.model)1 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)1