use of cn.taketoday.web.handler.result.HttpStatusReturnValueHandler in project today-infrastructure by TAKETODAY.
the class ReturnValueHandlerManagerTests method addHandler.
@Test
void addHandler() {
ReturnValueHandlerManager manager = new ReturnValueHandlerManager();
HttpStatusReturnValueHandler returnValueHandler = new HttpStatusReturnValueHandler();
manager.addHandlers(returnValueHandler);
assertThat(manager.getHandlers()).hasSize(1);
HttpStatusReturnValueHandler highestValueHandler = new HttpStatusReturnValueHandler();
manager.addHandlers(List.of(highestValueHandler));
assertThat(manager.getHandlers()).hasSize(2);
assertThat(manager.getByReturnValue(HttpStatus.OK)).isNotNull();
assertThat(manager.getByReturnValue("")).isNull();
assertThat(manager.getByReturnValue(null)).isNull();
assertThat(manager.getHandler("")).isNull();
// getHandler(handler)
HandlerMethod handler = Mockito.mock(HandlerMethod.class);
Mockito.when(handler.isReturn(HttpStatus.class)).thenReturn(true);
ActionMappingAnnotationHandler annotationHandler = new ActionMappingAnnotationHandler(handler, null, Object.class) {
@Override
public Object getHandlerObject() {
return null;
}
};
assertThat(manager.getHandler(annotationHandler)).isNotNull();
// obtainHandler
assertThat(manager.obtainHandler(annotationHandler)).isEqualTo(returnValueHandler).isNotNull();
// sort
// returnValueHandler.setOrder(2);
// highestValueHandler.setOrder(1);
assertThat(manager.obtainHandler(annotationHandler)).isEqualTo(highestValueHandler).isNotNull();
// returnValueHandler.setOrder(1);
// highestValueHandler.setOrder(2);
assertThat(manager.obtainHandler(annotationHandler)).isEqualTo(returnValueHandler).isNotNull();
assertThatThrownBy(() -> manager.obtainHandler("")).isInstanceOf(ReturnValueHandlerNotFoundException.class).hasMessageStartingWith("No ReturnValueHandler for handler");
}
use of cn.taketoday.web.handler.result.HttpStatusReturnValueHandler in project today-framework by TAKETODAY.
the class ReturnValueHandlerManagerTests method contains.
@Test
void contains() {
ReturnValueHandlerManager manager = new ReturnValueHandlerManager();
HttpStatusReturnValueHandler returnValueHandler = new HttpStatusReturnValueHandler();
manager.addHandlers(returnValueHandler);
assertThat(manager.contains(null)).isFalse();
assertThat(manager.contains(String.class)).isFalse();
assertThat(manager.contains(HttpStatusReturnValueHandler.class)).isTrue();
assertThat(manager.get(HttpStatusReturnValueHandler.class)).isNotNull();
assertThat(manager.get((Class<?>) null)).isNull();
}
use of cn.taketoday.web.handler.result.HttpStatusReturnValueHandler in project today-framework by TAKETODAY.
the class ReturnValueHandlerManagerTests method addHandler.
@Test
void addHandler() {
ReturnValueHandlerManager manager = new ReturnValueHandlerManager();
HttpStatusReturnValueHandler returnValueHandler = new HttpStatusReturnValueHandler();
manager.addHandlers(returnValueHandler);
assertThat(manager.getHandlers()).hasSize(1);
HttpStatusReturnValueHandler highestValueHandler = new HttpStatusReturnValueHandler();
manager.addHandlers(List.of(highestValueHandler));
assertThat(manager.getHandlers()).hasSize(2);
assertThat(manager.getByReturnValue(HttpStatus.OK)).isNotNull();
assertThat(manager.getByReturnValue("")).isNull();
assertThat(manager.getByReturnValue(null)).isNull();
assertThat(manager.getHandler("")).isNull();
// getHandler(handler)
HandlerMethod handler = Mockito.mock(HandlerMethod.class);
Mockito.when(handler.isReturn(HttpStatus.class)).thenReturn(true);
ActionMappingAnnotationHandler annotationHandler = new ActionMappingAnnotationHandler(handler, null, Object.class) {
@Override
public Object getHandlerObject() {
return null;
}
};
assertThat(manager.getHandler(annotationHandler)).isNotNull();
// obtainHandler
assertThat(manager.obtainHandler(annotationHandler)).isEqualTo(returnValueHandler).isNotNull();
// sort
// returnValueHandler.setOrder(2);
// highestValueHandler.setOrder(1);
assertThat(manager.obtainHandler(annotationHandler)).isEqualTo(highestValueHandler).isNotNull();
// returnValueHandler.setOrder(1);
// highestValueHandler.setOrder(2);
assertThat(manager.obtainHandler(annotationHandler)).isEqualTo(returnValueHandler).isNotNull();
assertThatThrownBy(() -> manager.obtainHandler("")).isInstanceOf(ReturnValueHandlerNotFoundException.class).hasMessageStartingWith("No ReturnValueHandler for handler");
}
use of cn.taketoday.web.handler.result.HttpStatusReturnValueHandler in project today-infrastructure by TAKETODAY.
the class ReturnValueHandlerManagerTests method contains.
@Test
void contains() {
ReturnValueHandlerManager manager = new ReturnValueHandlerManager();
HttpStatusReturnValueHandler returnValueHandler = new HttpStatusReturnValueHandler();
manager.addHandlers(returnValueHandler);
assertThat(manager.contains(null)).isFalse();
assertThat(manager.contains(String.class)).isFalse();
assertThat(manager.contains(HttpStatusReturnValueHandler.class)).isTrue();
assertThat(manager.get(HttpStatusReturnValueHandler.class)).isNotNull();
assertThat(manager.get((Class<?>) null)).isNull();
}
Aggregations