use of io.gravitee.management.model.NewViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_CreateTest method shouldCreate2Views.
@Test
public void shouldCreate2Views() throws TechnicalException {
NewViewEntity v1 = new NewViewEntity();
v1.setName("v1");
NewViewEntity v2 = new NewViewEntity();
v2.setName("v2");
when(mockViewRepository.create(any())).thenReturn(new View());
List<ViewEntity> views = viewService.create(Arrays.asList(v1, v2));
assertNotNull("result is null", views);
assertFalse("result is empty", views.isEmpty());
assertEquals("result size is 2", 2, views.size());
verify(mockAuditService, times(2)).createPortalAuditLog(any(), eq(VIEW_CREATED), any(), isNull(), any());
verify(mockViewRepository, times(1)).create(argThat(new ArgumentMatcher<View>() {
@Override
public boolean matches(Object arg) {
return arg instanceof View && ((View) arg).getName().equals("v1");
}
}));
verify(mockViewRepository, times(1)).create(argThat(new ArgumentMatcher<View>() {
@Override
public boolean matches(Object arg) {
return arg instanceof View && ((View) arg).getName().equals("v2");
}
}));
}
use of io.gravitee.management.model.NewViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewServiceImpl method create.
@Override
public List<ViewEntity> create(final List<NewViewEntity> viewEntities) {
// First we prevent the duplicate view name
final List<String> viewNames = viewEntities.stream().map(NewViewEntity::getName).collect(Collectors.toList());
final Optional<ViewEntity> optionalView = findAll().stream().filter(view -> viewNames.contains(view.getName())).findAny();
if (optionalView.isPresent()) {
throw new DuplicateViewNameException(optionalView.get().getName());
}
final List<ViewEntity> savedViews = new ArrayList<>(viewEntities.size());
viewEntities.forEach(viewEntity -> {
try {
View view = convert(viewEntity);
savedViews.add(convert(viewRepository.create(view)));
auditService.createPortalAuditLog(Collections.singletonMap(VIEW, view.getId()), VIEW_CREATED, new Date(), null, view);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create view {}", viewEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to create view " + viewEntity.getName(), ex);
}
});
return savedViews;
}
use of io.gravitee.management.model.NewViewEntity in project gravitee-management-rest-api by gravitee-io.
the class ViewService_CreateTest method shouldNotCreateExistingView.
@Test(expected = DuplicateViewNameException.class)
public void shouldNotCreateExistingView() throws TechnicalException {
View v1 = new View();
NewViewEntity nv1 = new NewViewEntity();
v1.setName("v1");
nv1.setName("v1");
when(mockViewRepository.findAll()).thenReturn(Collections.singleton(v1));
try {
viewService.create(singletonList(nv1));
} catch (DuplicateViewNameException e) {
verify(mockViewRepository, never()).create(any());
throw e;
}
Assert.fail("should throw DuplicateViewNameException");
}
Aggregations