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