diff --git a/code/example-spring-boot-demo/src/main/kotlin/com/example/demo/pipeline/filters/ResponseHeaderFilter.kt b/code/example-spring-boot-demo/src/main/kotlin/com/example/demo/pipeline/filters/ResponseHeaderFilter.kt index 66c85ff..dd84966 100644 --- a/code/example-spring-boot-demo/src/main/kotlin/com/example/demo/pipeline/filters/ResponseHeaderFilter.kt +++ b/code/example-spring-boot-demo/src/main/kotlin/com/example/demo/pipeline/filters/ResponseHeaderFilter.kt @@ -1,5 +1,6 @@ package com.example.demo.pipeline.filters +import com.example.demo.RequestScopedComponent import com.example.demo.pipeline.handlerinterceptors.ExampleHandlerInterceptor import org.slf4j.LoggerFactory import org.springframework.stereotype.Component @@ -14,7 +15,9 @@ import javax.servlet.http.HttpServletResponse import javax.servlet.http.HttpServletResponseWrapper @Component -class ResponseHeaderFilter : HttpFilter() { +class ResponseHeaderFilter( + val requestScopedComponent: RequestScopedComponent +) : HttpFilter() { companion object { private val logger = LoggerFactory.getLogger(ResponseHeaderFilter::class.java) @@ -27,6 +30,7 @@ class ResponseHeaderFilter : HttpFilter() { ) { val start = System.nanoTime() val wrappedResponse = ResponseWrapper(response) + requestScopedComponent.path = request.requestURI try { chain.doFilter(request, wrappedResponse) } finally { diff --git a/code/tic-tac-tow-service/.editorconfig b/code/tic-tac-tow-service/.editorconfig new file mode 100644 index 0000000..268ff78 --- /dev/null +++ b/code/tic-tac-tow-service/.editorconfig @@ -0,0 +1,628 @@ +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = false +max_line_length = 120 +tab_width = 4 +ij_continuation_indent_size = 4 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = false +ij_smart_tabs = false +ij_visual_guides = none +ij_wrap_on_typing = false + +[*.java] +ij_java_align_consecutive_assignments = false +ij_java_align_consecutive_variable_declarations = false +ij_java_align_group_field_declarations = false +ij_java_align_multiline_annotation_parameters = false +ij_java_align_multiline_array_initializer_expression = false +ij_java_align_multiline_assignment = false +ij_java_align_multiline_binary_operation = false +ij_java_align_multiline_chained_methods = false +ij_java_align_multiline_extends_list = false +ij_java_align_multiline_for = true +ij_java_align_multiline_method_parentheses = false +ij_java_align_multiline_parameters = true +ij_java_align_multiline_parameters_in_calls = false +ij_java_align_multiline_parenthesized_expression = false +ij_java_align_multiline_records = true +ij_java_align_multiline_resources = true +ij_java_align_multiline_ternary_operation = false +ij_java_align_multiline_text_blocks = false +ij_java_align_multiline_throws_list = false +ij_java_align_subsequent_simple_methods = false +ij_java_align_throws_keyword = false +ij_java_annotation_parameter_wrap = off +ij_java_array_initializer_new_line_after_left_brace = false +ij_java_array_initializer_right_brace_on_new_line = false +ij_java_array_initializer_wrap = off +ij_java_assert_statement_colon_on_next_line = false +ij_java_assert_statement_wrap = off +ij_java_assignment_wrap = off +ij_java_binary_operation_sign_on_next_line = false +ij_java_binary_operation_wrap = off +ij_java_blank_lines_after_anonymous_class_header = 0 +ij_java_blank_lines_after_class_header = 0 +ij_java_blank_lines_after_imports = 1 +ij_java_blank_lines_after_package = 1 +ij_java_blank_lines_around_class = 1 +ij_java_blank_lines_around_field = 0 +ij_java_blank_lines_around_field_in_interface = 0 +ij_java_blank_lines_around_initializer = 1 +ij_java_blank_lines_around_method = 1 +ij_java_blank_lines_around_method_in_interface = 1 +ij_java_blank_lines_before_class_end = 0 +ij_java_blank_lines_before_imports = 1 +ij_java_blank_lines_before_method_body = 0 +ij_java_blank_lines_before_package = 0 +ij_java_block_brace_style = end_of_line +ij_java_block_comment_add_space = false +ij_java_block_comment_at_first_column = true +ij_java_builder_methods = none +ij_java_call_parameters_new_line_after_left_paren = false +ij_java_call_parameters_right_paren_on_new_line = false +ij_java_call_parameters_wrap = off +ij_java_case_statement_on_separate_line = true +ij_java_catch_on_new_line = false +ij_java_class_annotation_wrap = split_into_lines +ij_java_class_brace_style = end_of_line +ij_java_class_count_to_use_import_on_demand = 5 +ij_java_class_names_in_javadoc = 1 +ij_java_do_not_indent_top_level_class_members = false +ij_java_do_not_wrap_after_single_annotation = false +ij_java_do_while_brace_force = never +ij_java_doc_add_blank_line_after_description = true +ij_java_doc_add_blank_line_after_param_comments = false +ij_java_doc_add_blank_line_after_return = false +ij_java_doc_add_p_tag_on_empty_lines = true +ij_java_doc_align_exception_comments = true +ij_java_doc_align_param_comments = true +ij_java_doc_do_not_wrap_if_one_line = false +ij_java_doc_enable_formatting = true +ij_java_doc_enable_leading_asterisks = true +ij_java_doc_indent_on_continuation = false +ij_java_doc_keep_empty_lines = true +ij_java_doc_keep_empty_parameter_tag = true +ij_java_doc_keep_empty_return_tag = true +ij_java_doc_keep_empty_throws_tag = true +ij_java_doc_keep_invalid_tags = true +ij_java_doc_param_description_on_new_line = false +ij_java_doc_preserve_line_breaks = false +ij_java_doc_use_throws_not_exception_tag = true +ij_java_else_on_new_line = false +ij_java_enum_constants_wrap = off +ij_java_extends_keyword_wrap = off +ij_java_extends_list_wrap = off +ij_java_field_annotation_wrap = split_into_lines +ij_java_finally_on_new_line = false +ij_java_for_brace_force = never +ij_java_for_statement_new_line_after_left_paren = false +ij_java_for_statement_right_paren_on_new_line = false +ij_java_for_statement_wrap = off +ij_java_generate_final_locals = false +ij_java_generate_final_parameters = false +ij_java_if_brace_force = never +ij_java_imports_layout = *,|,javax.**,java.**,|,$* +ij_java_indent_case_from_switch = true +ij_java_insert_inner_class_imports = false +ij_java_insert_override_annotation = true +ij_java_keep_blank_lines_before_right_brace = 2 +ij_java_keep_blank_lines_between_package_declaration_and_header = 2 +ij_java_keep_blank_lines_in_code = 2 +ij_java_keep_blank_lines_in_declarations = 2 +ij_java_keep_builder_methods_indents = false +ij_java_keep_control_statement_in_one_line = true +ij_java_keep_first_column_comment = true +ij_java_keep_indents_on_empty_lines = false +ij_java_keep_line_breaks = true +ij_java_keep_multiple_expressions_in_one_line = false +ij_java_keep_simple_blocks_in_one_line = false +ij_java_keep_simple_classes_in_one_line = false +ij_java_keep_simple_lambdas_in_one_line = false +ij_java_keep_simple_methods_in_one_line = false +ij_java_label_indent_absolute = false +ij_java_label_indent_size = 0 +ij_java_lambda_brace_style = end_of_line +ij_java_layout_static_imports_separately = true +ij_java_line_comment_add_space = false +ij_java_line_comment_at_first_column = true +ij_java_method_annotation_wrap = split_into_lines +ij_java_method_brace_style = end_of_line +ij_java_method_call_chain_wrap = off +ij_java_method_parameters_new_line_after_left_paren = false +ij_java_method_parameters_right_paren_on_new_line = false +ij_java_method_parameters_wrap = off +ij_java_modifier_list_wrap = false +ij_java_names_count_to_use_import_on_demand = 3 +ij_java_new_line_after_lparen_in_record_header = false +ij_java_packages_to_use_import_on_demand = java.awt.*,javax.swing.* +ij_java_parameter_annotation_wrap = off +ij_java_parentheses_expression_new_line_after_left_paren = false +ij_java_parentheses_expression_right_paren_on_new_line = false +ij_java_place_assignment_sign_on_next_line = false +ij_java_prefer_longer_names = true +ij_java_prefer_parameters_wrap = false +ij_java_record_components_wrap = normal +ij_java_repeat_synchronized = true +ij_java_replace_instanceof_and_cast = false +ij_java_replace_null_check = true +ij_java_replace_sum_lambda_with_method_ref = true +ij_java_resource_list_new_line_after_left_paren = false +ij_java_resource_list_right_paren_on_new_line = false +ij_java_resource_list_wrap = off +ij_java_rparen_on_new_line_in_record_header = false +ij_java_space_after_closing_angle_bracket_in_type_argument = false +ij_java_space_after_colon = true +ij_java_space_after_comma = true +ij_java_space_after_comma_in_type_arguments = true +ij_java_space_after_for_semicolon = true +ij_java_space_after_quest = true +ij_java_space_after_type_cast = true +ij_java_space_before_annotation_array_initializer_left_brace = false +ij_java_space_before_annotation_parameter_list = false +ij_java_space_before_array_initializer_left_brace = false +ij_java_space_before_catch_keyword = true +ij_java_space_before_catch_left_brace = true +ij_java_space_before_catch_parentheses = true +ij_java_space_before_class_left_brace = true +ij_java_space_before_colon = true +ij_java_space_before_colon_in_foreach = true +ij_java_space_before_comma = false +ij_java_space_before_do_left_brace = true +ij_java_space_before_else_keyword = true +ij_java_space_before_else_left_brace = true +ij_java_space_before_finally_keyword = true +ij_java_space_before_finally_left_brace = true +ij_java_space_before_for_left_brace = true +ij_java_space_before_for_parentheses = true +ij_java_space_before_for_semicolon = false +ij_java_space_before_if_left_brace = true +ij_java_space_before_if_parentheses = true +ij_java_space_before_method_call_parentheses = false +ij_java_space_before_method_left_brace = true +ij_java_space_before_method_parentheses = false +ij_java_space_before_opening_angle_bracket_in_type_parameter = false +ij_java_space_before_quest = true +ij_java_space_before_switch_left_brace = true +ij_java_space_before_switch_parentheses = true +ij_java_space_before_synchronized_left_brace = true +ij_java_space_before_synchronized_parentheses = true +ij_java_space_before_try_left_brace = true +ij_java_space_before_try_parentheses = true +ij_java_space_before_type_parameter_list = false +ij_java_space_before_while_keyword = true +ij_java_space_before_while_left_brace = true +ij_java_space_before_while_parentheses = true +ij_java_space_inside_one_line_enum_braces = false +ij_java_space_within_empty_array_initializer_braces = false +ij_java_space_within_empty_method_call_parentheses = false +ij_java_space_within_empty_method_parentheses = false +ij_java_spaces_around_additive_operators = true +ij_java_spaces_around_assignment_operators = true +ij_java_spaces_around_bitwise_operators = true +ij_java_spaces_around_equality_operators = true +ij_java_spaces_around_lambda_arrow = true +ij_java_spaces_around_logical_operators = true +ij_java_spaces_around_method_ref_dbl_colon = false +ij_java_spaces_around_multiplicative_operators = true +ij_java_spaces_around_relational_operators = true +ij_java_spaces_around_shift_operators = true +ij_java_spaces_around_type_bounds_in_type_parameters = true +ij_java_spaces_around_unary_operator = false +ij_java_spaces_within_angle_brackets = false +ij_java_spaces_within_annotation_parentheses = false +ij_java_spaces_within_array_initializer_braces = false +ij_java_spaces_within_braces = false +ij_java_spaces_within_brackets = false +ij_java_spaces_within_cast_parentheses = false +ij_java_spaces_within_catch_parentheses = false +ij_java_spaces_within_for_parentheses = false +ij_java_spaces_within_if_parentheses = false +ij_java_spaces_within_method_call_parentheses = false +ij_java_spaces_within_method_parentheses = false +ij_java_spaces_within_parentheses = false +ij_java_spaces_within_record_header = false +ij_java_spaces_within_switch_parentheses = false +ij_java_spaces_within_synchronized_parentheses = false +ij_java_spaces_within_try_parentheses = false +ij_java_spaces_within_while_parentheses = false +ij_java_special_else_if_treatment = true +ij_java_subclass_name_suffix = Impl +ij_java_ternary_operation_signs_on_next_line = false +ij_java_ternary_operation_wrap = off +ij_java_test_name_suffix = Test +ij_java_throws_keyword_wrap = off +ij_java_throws_list_wrap = off +ij_java_use_external_annotations = false +ij_java_use_fq_class_names = false +ij_java_use_relative_indents = false +ij_java_use_single_class_imports = true +ij_java_variable_annotation_wrap = off +ij_java_visibility = public +ij_java_while_brace_force = never +ij_java_while_on_new_line = false +ij_java_wrap_comments = false +ij_java_wrap_first_method_in_call_chain = false +ij_java_wrap_long_lines = false + +[*.properties] +ij_properties_align_group_field_declarations = false +ij_properties_keep_blank_lines = false +ij_properties_key_value_delimiter = equals +ij_properties_spaces_around_key_value_delimiter = false + +[.editorconfig] +ij_editorconfig_align_group_field_declarations = false +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false +ij_editorconfig_spaces_around_assignment_operators = true + +[{*.ant,*.fxml,*.jhm,*.jnlp,*.jrxml,*.jspx,*.pom,*.rng,*.tagx,*.tld,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul}] +ij_xml_align_attributes = true +ij_xml_align_text = false +ij_xml_attribute_wrap = normal +ij_xml_block_comment_add_space = false +ij_xml_block_comment_at_first_column = true +ij_xml_keep_blank_lines = 2 +ij_xml_keep_indents_on_empty_lines = false +ij_xml_keep_line_breaks = true +ij_xml_keep_line_breaks_in_text = true +ij_xml_keep_whitespaces = false +ij_xml_keep_whitespaces_around_cdata = preserve +ij_xml_keep_whitespaces_inside_cdata = false +ij_xml_line_comment_at_first_column = true +ij_xml_space_after_tag_name = false +ij_xml_space_around_equals_in_attribute = false +ij_xml_space_inside_empty_tag = false +ij_xml_text_wrap = normal +ij_xml_use_custom_settings = false + +[{*.bash,*.sh,*.zsh}] +indent_size = 2 +tab_width = 2 +ij_shell_binary_ops_start_line = false +ij_shell_keep_column_alignment_padding = false +ij_shell_minify_program = false +ij_shell_redirect_followed_by_space = false +ij_shell_switch_cases_indented = false +ij_shell_use_unix_line_separator = true + +[{*.gant,*.groovy,*.gy}] +ij_groovy_align_group_field_declarations = false +ij_groovy_align_multiline_array_initializer_expression = false +ij_groovy_align_multiline_assignment = false +ij_groovy_align_multiline_binary_operation = false +ij_groovy_align_multiline_chained_methods = false +ij_groovy_align_multiline_extends_list = false +ij_groovy_align_multiline_for = true +ij_groovy_align_multiline_list_or_map = true +ij_groovy_align_multiline_method_parentheses = false +ij_groovy_align_multiline_parameters = true +ij_groovy_align_multiline_parameters_in_calls = false +ij_groovy_align_multiline_resources = true +ij_groovy_align_multiline_ternary_operation = false +ij_groovy_align_multiline_throws_list = false +ij_groovy_align_named_args_in_map = true +ij_groovy_align_throws_keyword = false +ij_groovy_array_initializer_new_line_after_left_brace = false +ij_groovy_array_initializer_right_brace_on_new_line = false +ij_groovy_array_initializer_wrap = off +ij_groovy_assert_statement_wrap = off +ij_groovy_assignment_wrap = off +ij_groovy_binary_operation_wrap = off +ij_groovy_blank_lines_after_class_header = 0 +ij_groovy_blank_lines_after_imports = 1 +ij_groovy_blank_lines_after_package = 1 +ij_groovy_blank_lines_around_class = 1 +ij_groovy_blank_lines_around_field = 0 +ij_groovy_blank_lines_around_field_in_interface = 0 +ij_groovy_blank_lines_around_method = 1 +ij_groovy_blank_lines_around_method_in_interface = 1 +ij_groovy_blank_lines_before_imports = 1 +ij_groovy_blank_lines_before_method_body = 0 +ij_groovy_blank_lines_before_package = 0 +ij_groovy_block_brace_style = end_of_line +ij_groovy_block_comment_add_space = false +ij_groovy_block_comment_at_first_column = true +ij_groovy_call_parameters_new_line_after_left_paren = false +ij_groovy_call_parameters_right_paren_on_new_line = false +ij_groovy_call_parameters_wrap = off +ij_groovy_catch_on_new_line = false +ij_groovy_class_annotation_wrap = split_into_lines +ij_groovy_class_brace_style = end_of_line +ij_groovy_class_count_to_use_import_on_demand = 5 +ij_groovy_do_while_brace_force = never +ij_groovy_else_on_new_line = false +ij_groovy_enum_constants_wrap = off +ij_groovy_extends_keyword_wrap = off +ij_groovy_extends_list_wrap = off +ij_groovy_field_annotation_wrap = split_into_lines +ij_groovy_finally_on_new_line = false +ij_groovy_for_brace_force = never +ij_groovy_for_statement_new_line_after_left_paren = false +ij_groovy_for_statement_right_paren_on_new_line = false +ij_groovy_for_statement_wrap = off +ij_groovy_if_brace_force = never +ij_groovy_import_annotation_wrap = 2 +ij_groovy_imports_layout = *,|,javax.**,java.**,|,$* +ij_groovy_indent_case_from_switch = true +ij_groovy_indent_label_blocks = true +ij_groovy_insert_inner_class_imports = false +ij_groovy_keep_blank_lines_before_right_brace = 2 +ij_groovy_keep_blank_lines_in_code = 2 +ij_groovy_keep_blank_lines_in_declarations = 2 +ij_groovy_keep_control_statement_in_one_line = true +ij_groovy_keep_first_column_comment = true +ij_groovy_keep_indents_on_empty_lines = false +ij_groovy_keep_line_breaks = true +ij_groovy_keep_multiple_expressions_in_one_line = false +ij_groovy_keep_simple_blocks_in_one_line = false +ij_groovy_keep_simple_classes_in_one_line = true +ij_groovy_keep_simple_lambdas_in_one_line = true +ij_groovy_keep_simple_methods_in_one_line = true +ij_groovy_label_indent_absolute = false +ij_groovy_label_indent_size = 0 +ij_groovy_lambda_brace_style = end_of_line +ij_groovy_layout_static_imports_separately = true +ij_groovy_line_comment_add_space = false +ij_groovy_line_comment_at_first_column = true +ij_groovy_method_annotation_wrap = split_into_lines +ij_groovy_method_brace_style = end_of_line +ij_groovy_method_call_chain_wrap = off +ij_groovy_method_parameters_new_line_after_left_paren = false +ij_groovy_method_parameters_right_paren_on_new_line = false +ij_groovy_method_parameters_wrap = off +ij_groovy_modifier_list_wrap = false +ij_groovy_names_count_to_use_import_on_demand = 3 +ij_groovy_packages_to_use_import_on_demand = java.awt.*,javax.swing.* +ij_groovy_parameter_annotation_wrap = off +ij_groovy_parentheses_expression_new_line_after_left_paren = false +ij_groovy_parentheses_expression_right_paren_on_new_line = false +ij_groovy_prefer_parameters_wrap = false +ij_groovy_resource_list_new_line_after_left_paren = false +ij_groovy_resource_list_right_paren_on_new_line = false +ij_groovy_resource_list_wrap = off +ij_groovy_space_after_assert_separator = true +ij_groovy_space_after_colon = true +ij_groovy_space_after_comma = true +ij_groovy_space_after_comma_in_type_arguments = true +ij_groovy_space_after_for_semicolon = true +ij_groovy_space_after_quest = true +ij_groovy_space_after_type_cast = true +ij_groovy_space_before_annotation_parameter_list = false +ij_groovy_space_before_array_initializer_left_brace = false +ij_groovy_space_before_assert_separator = false +ij_groovy_space_before_catch_keyword = true +ij_groovy_space_before_catch_left_brace = true +ij_groovy_space_before_catch_parentheses = true +ij_groovy_space_before_class_left_brace = true +ij_groovy_space_before_closure_left_brace = true +ij_groovy_space_before_colon = true +ij_groovy_space_before_comma = false +ij_groovy_space_before_do_left_brace = true +ij_groovy_space_before_else_keyword = true +ij_groovy_space_before_else_left_brace = true +ij_groovy_space_before_finally_keyword = true +ij_groovy_space_before_finally_left_brace = true +ij_groovy_space_before_for_left_brace = true +ij_groovy_space_before_for_parentheses = true +ij_groovy_space_before_for_semicolon = false +ij_groovy_space_before_if_left_brace = true +ij_groovy_space_before_if_parentheses = true +ij_groovy_space_before_method_call_parentheses = false +ij_groovy_space_before_method_left_brace = true +ij_groovy_space_before_method_parentheses = false +ij_groovy_space_before_quest = true +ij_groovy_space_before_record_parentheses = false +ij_groovy_space_before_switch_left_brace = true +ij_groovy_space_before_switch_parentheses = true +ij_groovy_space_before_synchronized_left_brace = true +ij_groovy_space_before_synchronized_parentheses = true +ij_groovy_space_before_try_left_brace = true +ij_groovy_space_before_try_parentheses = true +ij_groovy_space_before_while_keyword = true +ij_groovy_space_before_while_left_brace = true +ij_groovy_space_before_while_parentheses = true +ij_groovy_space_in_named_argument = true +ij_groovy_space_in_named_argument_before_colon = false +ij_groovy_space_within_empty_array_initializer_braces = false +ij_groovy_space_within_empty_method_call_parentheses = false +ij_groovy_spaces_around_additive_operators = true +ij_groovy_spaces_around_assignment_operators = true +ij_groovy_spaces_around_bitwise_operators = true +ij_groovy_spaces_around_equality_operators = true +ij_groovy_spaces_around_lambda_arrow = true +ij_groovy_spaces_around_logical_operators = true +ij_groovy_spaces_around_multiplicative_operators = true +ij_groovy_spaces_around_regex_operators = true +ij_groovy_spaces_around_relational_operators = true +ij_groovy_spaces_around_shift_operators = true +ij_groovy_spaces_within_annotation_parentheses = false +ij_groovy_spaces_within_array_initializer_braces = false +ij_groovy_spaces_within_braces = true +ij_groovy_spaces_within_brackets = false +ij_groovy_spaces_within_cast_parentheses = false +ij_groovy_spaces_within_catch_parentheses = false +ij_groovy_spaces_within_for_parentheses = false +ij_groovy_spaces_within_gstring_injection_braces = false +ij_groovy_spaces_within_if_parentheses = false +ij_groovy_spaces_within_list_or_map = false +ij_groovy_spaces_within_method_call_parentheses = false +ij_groovy_spaces_within_method_parentheses = false +ij_groovy_spaces_within_parentheses = false +ij_groovy_spaces_within_switch_parentheses = false +ij_groovy_spaces_within_synchronized_parentheses = false +ij_groovy_spaces_within_try_parentheses = false +ij_groovy_spaces_within_tuple_expression = false +ij_groovy_spaces_within_while_parentheses = false +ij_groovy_special_else_if_treatment = true +ij_groovy_ternary_operation_wrap = off +ij_groovy_throws_keyword_wrap = off +ij_groovy_throws_list_wrap = off +ij_groovy_use_flying_geese_braces = false +ij_groovy_use_fq_class_names = false +ij_groovy_use_fq_class_names_in_javadoc = true +ij_groovy_use_relative_indents = false +ij_groovy_use_single_class_imports = true +ij_groovy_variable_annotation_wrap = off +ij_groovy_while_brace_force = never +ij_groovy_while_on_new_line = false +ij_groovy_wrap_chain_calls_after_dot = false +ij_groovy_wrap_long_lines = false + +[{*.har,*.json}] +indent_size = 2 +ij_json_keep_blank_lines_in_code = 0 +ij_json_keep_indents_on_empty_lines = false +ij_json_keep_line_breaks = true +ij_json_space_after_colon = true +ij_json_space_after_comma = true +ij_json_space_before_colon = true +ij_json_space_before_comma = false +ij_json_spaces_within_braces = false +ij_json_spaces_within_brackets = false +ij_json_wrap_long_lines = false + +[{*.htm,*.html,*.sht,*.shtm,*.shtml}] +ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3 +ij_html_align_attributes = true +ij_html_align_text = false +ij_html_attribute_wrap = normal +ij_html_block_comment_add_space = false +ij_html_block_comment_at_first_column = true +ij_html_do_not_align_children_of_min_lines = 0 +ij_html_do_not_break_if_inline_tags = title,h1,h2,h3,h4,h5,h6,p +ij_html_do_not_indent_children_of_tags = html,body,thead,tbody,tfoot +ij_html_enforce_quotes = false +ij_html_inline_tags = a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var +ij_html_keep_blank_lines = 2 +ij_html_keep_indents_on_empty_lines = false +ij_html_keep_line_breaks = true +ij_html_keep_line_breaks_in_text = true +ij_html_keep_whitespaces = false +ij_html_keep_whitespaces_inside = span,pre,textarea +ij_html_line_comment_at_first_column = true +ij_html_new_line_after_last_attribute = never +ij_html_new_line_before_first_attribute = never +ij_html_quote_style = double +ij_html_remove_new_line_before_tags = br +ij_html_space_after_tag_name = false +ij_html_space_around_equality_in_attribute = false +ij_html_space_inside_empty_tag = false +ij_html_text_wrap = normal + +[{*.kt,*.kts}] +ij_kotlin_align_in_columns_case_branch = false +ij_kotlin_align_multiline_binary_operation = false +ij_kotlin_align_multiline_extends_list = false +ij_kotlin_align_multiline_method_parentheses = false +ij_kotlin_align_multiline_parameters = true +ij_kotlin_align_multiline_parameters_in_calls = false +ij_kotlin_allow_trailing_comma = false +ij_kotlin_allow_trailing_comma_on_call_site = false +ij_kotlin_assignment_wrap = normal +ij_kotlin_blank_lines_after_class_header = 0 +ij_kotlin_blank_lines_around_block_when_branches = 0 +ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1 +ij_kotlin_block_comment_add_space = false +ij_kotlin_block_comment_at_first_column = true +ij_kotlin_call_parameters_new_line_after_left_paren = true +ij_kotlin_call_parameters_right_paren_on_new_line = true +ij_kotlin_call_parameters_wrap = on_every_item +ij_kotlin_catch_on_new_line = false +ij_kotlin_class_annotation_wrap = split_into_lines +ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL +ij_kotlin_continuation_indent_for_chained_calls = false +ij_kotlin_continuation_indent_for_expression_bodies = false +ij_kotlin_continuation_indent_in_argument_lists = false +ij_kotlin_continuation_indent_in_elvis = false +ij_kotlin_continuation_indent_in_if_conditions = false +ij_kotlin_continuation_indent_in_parameter_lists = false +ij_kotlin_continuation_indent_in_supertype_lists = false +ij_kotlin_else_on_new_line = false +ij_kotlin_enum_constants_wrap = off +ij_kotlin_extends_list_wrap = normal +ij_kotlin_field_annotation_wrap = split_into_lines +ij_kotlin_finally_on_new_line = false +ij_kotlin_if_rparen_on_new_line = true +ij_kotlin_import_nested_classes = false +ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^ +ij_kotlin_insert_whitespaces_in_simple_one_line_method = true +ij_kotlin_keep_blank_lines_before_right_brace = 2 +ij_kotlin_keep_blank_lines_in_code = 2 +ij_kotlin_keep_blank_lines_in_declarations = 2 +ij_kotlin_keep_first_column_comment = true +ij_kotlin_keep_indents_on_empty_lines = false +ij_kotlin_keep_line_breaks = true +ij_kotlin_lbrace_on_next_line = false +ij_kotlin_line_comment_add_space = false +ij_kotlin_line_comment_at_first_column = true +ij_kotlin_method_annotation_wrap = split_into_lines +ij_kotlin_method_call_chain_wrap = normal +ij_kotlin_method_parameters_new_line_after_left_paren = true +ij_kotlin_method_parameters_right_paren_on_new_line = true +ij_kotlin_method_parameters_wrap = on_every_item +ij_kotlin_name_count_to_use_star_import = 5 +ij_kotlin_name_count_to_use_star_import_for_members = 3 +ij_kotlin_packages_to_use_import_on_demand = java.util.*,kotlinx.android.synthetic.**,io.ktor.** +ij_kotlin_parameter_annotation_wrap = off +ij_kotlin_space_after_comma = true +ij_kotlin_space_after_extend_colon = true +ij_kotlin_space_after_type_colon = true +ij_kotlin_space_before_catch_parentheses = true +ij_kotlin_space_before_comma = false +ij_kotlin_space_before_extend_colon = true +ij_kotlin_space_before_for_parentheses = true +ij_kotlin_space_before_if_parentheses = true +ij_kotlin_space_before_lambda_arrow = true +ij_kotlin_space_before_type_colon = false +ij_kotlin_space_before_when_parentheses = true +ij_kotlin_space_before_while_parentheses = true +ij_kotlin_spaces_around_additive_operators = true +ij_kotlin_spaces_around_assignment_operators = true +ij_kotlin_spaces_around_equality_operators = true +ij_kotlin_spaces_around_function_type_arrow = true +ij_kotlin_spaces_around_logical_operators = true +ij_kotlin_spaces_around_multiplicative_operators = true +ij_kotlin_spaces_around_range = false +ij_kotlin_spaces_around_relational_operators = true +ij_kotlin_spaces_around_unary_operator = false +ij_kotlin_spaces_around_when_arrow = true +ij_kotlin_variable_annotation_wrap = off +ij_kotlin_while_on_new_line = false +ij_kotlin_wrap_elvis_expressions = 1 +ij_kotlin_wrap_expression_body_functions = 1 +ij_kotlin_wrap_first_method_in_call_chain = false +ktlint_disabled_rules=trailing-comma-on-call-site, trailing-comma-on-declaration-site + +[{*.markdown,*.md}] +ij_markdown_force_one_space_after_blockquote_symbol = true +ij_markdown_force_one_space_after_header_symbol = true +ij_markdown_force_one_space_after_list_bullet = true +ij_markdown_force_one_space_between_words = true +ij_markdown_keep_indents_on_empty_lines = false +ij_markdown_max_lines_around_block_elements = 1 +ij_markdown_max_lines_around_header = 1 +ij_markdown_max_lines_between_paragraphs = 1 +ij_markdown_min_lines_around_block_elements = 1 +ij_markdown_min_lines_around_header = 1 +ij_markdown_min_lines_between_paragraphs = 1 + +[{*.yaml,*.yml}] +indent_size = 2 +ij_yaml_align_values_properties = do_not_align +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_block_mapping_on_new_line = false +ij_yaml_indent_sequence_value = true +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = false +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = true +ij_yaml_spaces_within_brackets = true diff --git a/code/tic-tac-tow-service/build.gradle.kts b/code/tic-tac-tow-service/build.gradle.kts index 9ef3e3d..e47031a 100644 --- a/code/tic-tac-tow-service/build.gradle.kts +++ b/code/tic-tac-tow-service/build.gradle.kts @@ -5,6 +5,7 @@ plugins { id("io.spring.dependency-management") version "1.0.14.RELEASE" kotlin("jvm") version "1.6.21" kotlin("plugin.spring") version "1.6.21" + java } group = "pt.isel.daw" @@ -15,6 +16,8 @@ repositories { mavenCentral() } +val ktlint by configurations.creating + dependencies { implementation("org.springframework.boot:spring-boot-starter-validation") implementation("org.springframework.boot:spring-boot-starter-web") @@ -31,6 +34,8 @@ dependencies { testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation(kotlin("test")) + + ktlint("com.pinterest:ktlint:0.47.1") } tasks.withType { @@ -43,3 +48,22 @@ tasks.withType { tasks.withType { useJUnitPlatform() } + +// from https://pinterest.github.io/ktlint/install/integrations/#custom-gradle-integration-with-kotlin-dsl +val outputDir = "${project.buildDir}/reports/ktlint/" +val inputFiles = project.fileTree(mapOf("dir" to "src", "include" to "**/*.kt")) + +val ktlintCheck by tasks.creating(JavaExec::class) { + inputs.files(inputFiles) + outputs.dir(outputDir) + + description = "Check Kotlin code style." + classpath = ktlint + mainClass.set("com.pinterest.ktlint.Main") + // see https://pinterest.github.io/ktlint/install/cli/#command-line-usage for more information + args = listOf("src/**/*.kt") +} + +tasks.named("check") { + dependsOn(ktlintCheck) +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/Clock.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/Clock.kt index b8e8cc2..bf15371 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/Clock.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/Clock.kt @@ -9,4 +9,4 @@ interface Clock { object RealClock : Clock { // To only have second precision override fun now(): Instant = Instant.ofEpochSecond(Instant.now().epochSecond) -} +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/utils.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/Either.kt similarity index 100% rename from code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/utils.kt rename to code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/Either.kt diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/TicTacTowApplication.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/TicTacTowApplication.kt index a8b0f98..4d04c0c 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/TicTacTowApplication.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/TicTacTowApplication.kt @@ -7,5 +7,5 @@ import org.springframework.boot.runApplication class TicTacTowApplication fun main(args: Array) { - runApplication(*args) -} + runApplication(*args) +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Board.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Board.kt index 851f7d9..fbc34aa 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Board.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Board.kt @@ -5,8 +5,7 @@ data class Board( ) { init { require( - cells.size == 3 && - cells.all { it.size == 3 } + cells.size == 3 && cells.all { it.size == 3 } ) } @@ -21,17 +20,19 @@ data class Board( fun hasWon(state: State): Boolean { require(state != State.EMPTY) // TODO can be optimized - return cells.any { row -> row.all { it == state } } - || (0..2).any { col -> cells.all { row -> row[col] == state } } - || cells[0][0] == state && cells[1][1] == state && cells[2][2] == state - || cells[0][2] == state && cells[1][1] == state && cells[2][0] == state + return cells.any { row -> row.all { it == state } } || + (0..2).any { col -> cells.all { row -> row[col] == state } } || + cells[0][0] == state && cells[1][1] == state && cells[2][2] == state || + cells[0][2] == state && cells[1][1] == state && cells[2][0] == state } companion object { - fun create() = Board(Array(3) { - Array(3) { State.EMPTY } - }) + fun create() = Board( + Array(3) { + Array(3) { State.EMPTY } + } + ) fun fromString(s: String): Board { require(s.length == 9) @@ -88,10 +89,9 @@ data class Board( return true } - fun isFull(): Boolean = cells.all { row -> row.all {it != State.EMPTY} } + fun isFull(): Boolean = cells.all { row -> row.all { it != State.EMPTY } } override fun hashCode(): Int { return cells.contentDeepHashCode() } - } \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/GameLogic.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/GameLogic.kt index 7b8b68c..df20686 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/GameLogic.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/GameLogic.kt @@ -124,4 +124,4 @@ sealed class RoundResult { private fun Game.isPlayerX(player: User) = this.playerX.id == player.id -private fun Game.isPlayerO(player: User) = this.playerO.id == player.id +private fun Game.isPlayerO(player: User) = this.playerO.id == player.id \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/PasswordValidationInfo.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/PasswordValidationInfo.kt index 620ffad..8e23b96 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/PasswordValidationInfo.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/PasswordValidationInfo.kt @@ -1,7 +1,5 @@ package pt.isel.daw.tictactow.domain -data class PasswordValidationInfo ( +data class PasswordValidationInfo( val validationInfo: String -) - - +) \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Round.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Round.kt index 1d97e9c..5ec3eee 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Round.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/Round.kt @@ -3,4 +3,4 @@ package pt.isel.daw.tictactow.domain class Round( val position: Position, val player: User, -) +) \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/UserLogic.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/UserLogic.kt index 69716bd..58f8c6f 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/UserLogic.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/domain/UserLogic.kt @@ -3,7 +3,7 @@ package pt.isel.daw.tictactow.domain import java.security.SecureRandom import java.util.* -class UserLogic{ +class UserLogic { fun generateToken(): String = ByteArray(TOKEN_BYTE_SIZE).let { byteArray -> @@ -24,4 +24,4 @@ class UserLogic{ companion object { private const val TOKEN_BYTE_SIZE = 256 / 8 } -} +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/GamesRepository.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/GamesRepository.kt index 29d0911..c1d3f6a 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/GamesRepository.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/GamesRepository.kt @@ -4,9 +4,7 @@ import pt.isel.daw.tictactow.domain.Game import java.util.UUID interface GamesRepository { - fun insert(game: Game) fun getById(id: UUID): Game? fun update(game: Game) - } \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/Transaction.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/Transaction.kt index fcee6e2..6c10850 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/Transaction.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/Transaction.kt @@ -7,4 +7,4 @@ interface Transaction { val gamesRepository: GamesRepository fun rollback() -} +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiGamesRepository.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiGamesRepository.kt index a27ca20..f503118 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiGamesRepository.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiGamesRepository.kt @@ -80,8 +80,5 @@ class GameDbModel( @Nested("playerO") val playerO: User, ) { - fun toGame() = Game( - id, state, board, created, updated, deadline, - playerX, playerO - ) -} + fun toGame() = Game(id, state, board, created, updated, deadline, playerX, playerO) +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransaction.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransaction.kt index 2264f9e..be43bcf 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransaction.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransaction.kt @@ -16,6 +16,4 @@ class JdbiTransaction( override fun rollback() { handle.rollback() } -} - - +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransactionManager.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransactionManager.kt index 77bb28d..5bd5213 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransactionManager.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiTransactionManager.kt @@ -13,4 +13,4 @@ class JdbiTransactionManager( val transaction = JdbiTransaction(handle) block(transaction) } -} +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiUsersRepository.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiUsersRepository.kt index b1a76f7..1501c45 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiUsersRepository.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/JdbiUsersRepository.kt @@ -18,7 +18,11 @@ class JdbiUsersRepository( .singleOrNull() override fun storeUser(username: String, passwordValidation: PasswordValidationInfo): Boolean = - handle.createUpdate("insert into dbo.Users (username, password_validation) values (:username, :password_validation)") + handle.createUpdate( + """ + insert into dbo.Users (username, password_validation) values (:username, :password_validation) + """ + ) .bind("username", username) .bind("password_validation", passwordValidation.validationInfo) .execute() == 1 @@ -37,15 +41,16 @@ class JdbiUsersRepository( } override fun getUserByTokenValidationInfo(tokenValidationInfo: TokenValidationInfo): User? = - handle.createQuery(""" + handle.createQuery( + """ select id, username, password_validation from dbo.Users as users inner join dbo.Tokens as tokens on users.id = tokens.user_id where token_validation = :validation_information - """) + """ + ) .bind("validation_information", tokenValidationInfo.validationInfo) .mapTo() .singleOrNull() - -} +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/utils.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/Utils.kt similarity index 100% rename from code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/utils.kt rename to code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/Utils.kt diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/mappers/InstantMapper.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/mappers/InstantMapper.kt index eba5e0d..386e6e0 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/mappers/InstantMapper.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/repository/jdbi/mappers/InstantMapper.kt @@ -7,7 +7,6 @@ import java.time.Instant class InstantMapper : ColumnMapper { override fun map(rs: ResultSet, columnNumber: Int, ctx: StatementContext): Instant { - return Instant.ofEpochSecond(rs.getLong(columnNumber)) + return Instant.ofEpochSecond(rs.getLong(columnNumber)) } - } \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/service/UsersService.kt b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/service/UsersService.kt index 93d0f99..aff46ad 100644 --- a/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/service/UsersService.kt +++ b/code/tic-tac-tow-service/src/main/kotlin/pt/isel/daw/tictactow/service/UsersService.kt @@ -27,7 +27,6 @@ class UsersService( ) { fun createUser(username: String, password: String): UserCreationResult { - if (!userLogic.isSafePassword(password)) { return Either.Left(UserCreationError.InsecurePassword) } @@ -64,7 +63,7 @@ class UsersService( } fun getUserByToken(token: String): User? { - if(!userLogic.canBeToken(token)) { + if (!userLogic.canBeToken(token)) { return null } return transactionManager.run { @@ -78,4 +77,4 @@ class UsersService( passwordEncoder.encode("changeit") return Either.Left(TokenCreationError.UserOrPasswordAreInvalid) } -} +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/TicTacTowApplicationTests.kt b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/TicTacTowApplicationTests.kt index 96c9877..a4b136b 100644 --- a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/TicTacTowApplicationTests.kt +++ b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/TicTacTowApplicationTests.kt @@ -6,8 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest @SpringBootTest class TicTacTowApplicationTests { - @Test - fun contextLoads() { - } - -} + @Test + fun contextLoads() { + } +} \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/domain/GameLogicTests.kt b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/domain/GameLogicTests.kt index 082f3b8..0aefe4e 100644 --- a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/domain/GameLogicTests.kt +++ b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/domain/GameLogicTests.kt @@ -1,6 +1,7 @@ package pt.isel.daw.tictactow.domain -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test import pt.isel.daw.tictactow.Clock import pt.isel.daw.tictactow.RealClock @@ -67,7 +68,6 @@ class GameLogicTests { @Test fun `cannot play twice`() { - // given: a game var game = gameLogic.createNewGame(alice, bob) @@ -104,27 +104,26 @@ class GameLogicTests { @Test fun `alice wins`() { - // given: a game and a list of rounds val game = gameLogic.createNewGame(alice, bob) val rounds = listOf( - Round(Position(1,1), alice), - Round(Position(0,1), bob), + Round(Position(1, 1), alice), + Round(Position(0, 1), bob), - Round(Position(0,0), alice), - Round(Position(2,2), bob), + Round(Position(0, 0), alice), + Round(Position(2, 2), bob), - Round(Position(2,0), alice), - Round(Position(0,2), bob), + Round(Position(2, 0), alice), + Round(Position(0, 2), bob), - Round(Position(1,0), alice), + Round(Position(1, 0), alice), ) // when: the rounds are applied val result = play(gameLogic, game, rounds) // then: alice wins - when(result){ + when (result) { is RoundResult.YouWon -> { assertEquals(Game.State.PLAYER_X_WON, result.game.state) } @@ -134,30 +133,29 @@ class GameLogicTests { @Test fun `test draw game`() { - // given: a game and a list of rounds val game = gameLogic.createNewGame(alice, bob) val rounds = listOf( - Round(Position(0,0), alice), - Round(Position(1,1), bob), + Round(Position(0, 0), alice), + Round(Position(1, 1), bob), - Round(Position(2,0), alice), - Round(Position(1,0), bob), + Round(Position(2, 0), alice), + Round(Position(1, 0), bob), - Round(Position(1,2), alice), - Round(Position(0,1), bob), + Round(Position(1, 2), alice), + Round(Position(0, 1), bob), - Round(Position(2,1), alice), - Round(Position(2,2), bob), + Round(Position(2, 1), alice), + Round(Position(2, 2), bob), - Round(Position(0,2), alice), + Round(Position(0, 2), alice), ) // when: the rounds are applied val result = play(gameLogic, game, rounds) // then: it's a draw - when(result){ + when (result) { is RoundResult.Draw -> { assertEquals(Game.State.DRAW, result.game.state) } @@ -167,7 +165,6 @@ class GameLogicTests { @Test fun `timeout test`() { - // given: a game logic, a game and a list of rounds val testClock = TestClock() val timeout = Duration.ofMinutes(5) @@ -176,20 +173,20 @@ class GameLogicTests { // when: alice plays testClock.advance(timeout.minusMinutes(1)) - var result = gameLogic.applyRound(game, Round(Position(1,1), alice)) + var result = gameLogic.applyRound(game, Round(Position(1, 1), alice)) // then: round is accepted - game = when(result) { + game = when (result) { is RoundResult.OthersTurn -> result.game else -> fail("Unexpected result $result") } // when: bob plays testClock.advance(timeout.plusSeconds(1)) - result = gameLogic.applyRound(game, Round(Position(1,1), bob)) + result = gameLogic.applyRound(game, Round(Position(1, 1), bob)) // then: round is not accepted and alice won - game = when(result) { + game = when (result) { is RoundResult.TooLate -> result.game else -> fail("Unexpected result $result") } @@ -217,7 +214,7 @@ class GameLogicTests { // our test players private val alice = User(1, "alice", PasswordValidationInfo("")) - private val bob = User(2, "alice", PasswordValidationInfo("")) + private val bob = User(2, "alice", PasswordValidationInfo("")) } class TestClock : Clock { @@ -230,5 +227,4 @@ class GameLogicTests { now += duration } } - } \ No newline at end of file diff --git a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/repository/GameRepositoryTests.kt b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/repository/GameRepositoryTests.kt index 99cae93..01eeac4 100644 --- a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/repository/GameRepositoryTests.kt +++ b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/repository/GameRepositoryTests.kt @@ -1,15 +1,15 @@ package pt.isel.daw.tictactow.repository +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Test import pt.isel.daw.tictactow.RealClock +import pt.isel.daw.tictactow.domain.GameLogic import pt.isel.daw.tictactow.domain.PasswordValidationInfo import pt.isel.daw.tictactow.repository.jdbi.JdbiGamesRepository import pt.isel.daw.tictactow.repository.jdbi.JdbiUsersRepository -import pt.isel.daw.tictactow.domain.GameLogic import pt.isel.daw.tictactow.utils.testWithHandleAndRollback import java.time.Duration -import kotlin.test.assertEquals -import kotlin.test.fail class GameRepositoryTests { diff --git a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/utils/JdbiTestUtils.kt b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/utils/JdbiTestUtils.kt index 9300d73..bbb53f7 100644 --- a/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/utils/JdbiTestUtils.kt +++ b/code/tic-tac-tow-service/src/test/kotlin/pt/isel/daw/tictactow/utils/JdbiTestUtils.kt @@ -19,7 +19,8 @@ fun testWithHandleAndRollback(block: (Handle) -> Unit) = jdbi.useTransaction Unit) = jdbi.useTransaction { handle -> +fun testWithTransactionManagerAndRollback(block: (TransactionManager) -> Unit) = jdbi.useTransaction +{ handle -> val transaction = JdbiTransaction(handle) @@ -34,4 +35,4 @@ fun testWithTransactionManagerAndRollback(block: (TransactionManager) -> Unit) = // finally, we rollback everything handle.rollback() -} +} \ No newline at end of file