Fix coverage with several contract classes; table annotation and file path checks; clean task dir on write

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
This commit is contained in:
Kral
2026-10-03 08:44:35 +02:00
parent fb576b0954
commit 03ab36149e
388 changed files with 28620 additions and 339 deletions

View File

@@ -0,0 +1,11 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Manager'
define view entity {{P}}I_MANAGER
as select from {{p}}emp
{
key emp_id as mgr_id,
emp_name as mgr_name,
department as mgr_dept
}
where
is_manager <> 'X'

View File

@@ -0,0 +1,13 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Employee'
define view entity {{P}}I_EMPLOYEE
as select from {{p}}emp
association [0..1] to {{P}}I_MANAGER as _Manager
on $projection.manager_id <> _Manager.mgr_id
{
key emp_id as emp_id,
manager_id as manager_id,
emp_name as emp_name,
department as department,
_Manager
}

View File

@@ -0,0 +1,11 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Manager'
define view entity {{P}}I_MANAGER
as select from {{p}}emp
{
key emp_id as mgr_id,
emp_name as mgr_name,
department as mgr_dept
}
where
is_manager = 'Z'

View File

@@ -0,0 +1,29 @@
{
"id": "G0109",
"pool": "eval",
"object_type": "DDLS",
"category": "B",
"attempts": [
{
"stage": "validate",
"oracle": 0,
"null": 0
},
{
"stage": "validate",
"oracle": 85.0,
"null": 0
},
{
"stage": "validate",
"oracle": 100.0,
"null": 0,
"mutation": {
"valid": 3,
"killed": 3,
"ok": true
}
}
],
"accepted": true
}

View File

@@ -0,0 +1,92 @@
CLASS {{p}}t31_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
CLASS-DATA go_env TYPE REF TO if_cds_test_environment.
CLASS-METHODS class_setup.
CLASS-METHODS class_teardown.
METHODS setup.
METHODS employees_shown FOR TESTING.
METHODS employee_values FOR TESTING.
METHODS manager_id_shown FOR TESTING.
METHODS managers_shown FOR TESTING.
METHODS manager_values FOR TESTING.
METHODS path_reads_manager FOR TESTING.
METHODS path_manager_dept FOR TESTING.
METHODS path_only_managers FOR TESTING.
ENDCLASS.
CLASS {{p}}t31_hidden IMPLEMENTATION.
METHOD class_setup.
go_env = cl_cds_test_environment=>create( i_for_entity = '{{P}}I_EMPLOYEE' ).
ENDMETHOD.
METHOD class_teardown.
go_env->destroy( ).
ENDMETHOD.
METHOD setup.
DATA lt_emp TYPE STANDARD TABLE OF {{p}}emp WITH EMPTY KEY.
go_env->clear_doubles( ).
lt_emp = VALUE #(
( emp_id = 'E1' manager_id = '' emp_name = 'Anna' department = 'IT' is_manager = 'X' )
( emp_id = 'E2' manager_id = 'E1' emp_name = 'Ben' department = 'HR' is_manager = 'X' )
( emp_id = 'E3' manager_id = 'E1' emp_name = 'Cara' department = 'IT' is_manager = '' )
( emp_id = 'E4' manager_id = 'E2' emp_name = 'Dan' department = 'HR' is_manager = '' )
( emp_id = 'E5' manager_id = 'E2' emp_name = 'Eve' department = 'IT' is_manager = '' )
( emp_id = 'E6' manager_id = 'E3' emp_name = 'Fay' department = 'IT' is_manager = '' ) ).
go_env->insert_test_data( lt_emp ).
ENDMETHOD.
METHOD employees_shown.
SELECT COUNT(*) FROM {{p}}i_employee INTO @DATA(lv_count).
cl_abap_unit_assert=>assert_equals( exp = 6 act = lv_count ).
ENDMETHOD.
METHOD employee_values.
SELECT SINGLE emp_name, department FROM {{p}}i_employee WHERE emp_id = 'E3'
INTO @DATA(ls_emp).
cl_abap_unit_assert=>assert_equals( exp = 'Cara' act = ls_emp-emp_name ).
cl_abap_unit_assert=>assert_equals( exp = 'IT' act = ls_emp-department ).
ENDMETHOD.
METHOD manager_id_shown.
SELECT SINGLE manager_id FROM {{p}}i_employee WHERE emp_id = 'E4'
INTO @DATA(lv_manager).
cl_abap_unit_assert=>assert_equals( exp = 'E2' act = lv_manager ).
ENDMETHOD.
METHOD managers_shown.
SELECT COUNT(*) FROM {{p}}i_manager INTO @DATA(lv_count).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_count ).
ENDMETHOD.
METHOD manager_values.
SELECT SINGLE mgr_name, mgr_dept FROM {{p}}i_manager WHERE mgr_id = 'E2'
INTO @DATA(ls_mgr).
cl_abap_unit_assert=>assert_equals( exp = 'Ben' act = ls_mgr-mgr_name ).
cl_abap_unit_assert=>assert_equals( exp = 'HR' act = ls_mgr-mgr_dept ).
ENDMETHOD.
METHOD path_reads_manager.
SELECT FROM {{p}}i_employee\_manager
FIELDS mgr_name
WHERE mgr_name <> ''
INTO TABLE @DATA(lt_mgr).
cl_abap_unit_assert=>assert_equals( exp = 4 act = lines( lt_mgr ) ).
ENDMETHOD.
METHOD path_manager_dept.
SELECT COUNT(*) FROM {{p}}i_employee\_manager
WHERE mgr_dept = 'IT'
INTO @DATA(lv_count).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_count ).
ENDMETHOD.
METHOD path_only_managers.
SELECT COUNT(*) FROM {{p}}i_employee\_manager
WHERE mgr_id = 'E3'
INTO @DATA(lv_count).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_count ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,44 @@
{
"task": "G0109",
"mutants": [
{
"object": "{{P}}I_MANAGER",
"mutant": "line 11: = -> <> (eq)",
"status": "killed",
"hidden": "3/8",
"failed_tests": [
"MANAGERS_SHOWN",
"MANAGER_VALUES",
"PATH_MANAGER_DEPT",
"PATH_ONLY_MANAGERS",
"PATH_READS_MANAGER"
]
},
{
"object": "{{P}}I_EMPLOYEE",
"mutant": "line 6: = -> <> (eq)",
"status": "killed",
"hidden": "6/8",
"failed_tests": [
"PATH_MANAGER_DEPT",
"PATH_READS_MANAGER"
]
},
{
"object": "{{P}}I_MANAGER",
"mutant": "line 11: 'X' -> 'Z' (lit)",
"status": "killed",
"hidden": "4/8",
"failed_tests": [
"MANAGERS_SHOWN",
"MANAGER_VALUES",
"PATH_MANAGER_DEPT",
"PATH_READS_MANAGER"
]
}
],
"valid": 3,
"killed": 3,
"kill_rate": 1.0,
"ok": true
}

View File

@@ -0,0 +1,13 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Employee'
define view entity {{P}}I_EMPLOYEE
as select from {{p}}emp
association [0..1] to {{P}}I_MANAGER as _Manager
on $projection.manager_id = _Manager.mgr_id
{
key emp_id as emp_id,
manager_id as manager_id,
emp_name as emp_name,
department as department,
_Manager
}

View File

@@ -0,0 +1,11 @@
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Manager'
define view entity {{P}}I_MANAGER
as select from {{p}}emp
{
key emp_id as mgr_id,
emp_name as mgr_name,
department as mgr_dept
}
where
is_manager = 'X'

View File

@@ -0,0 +1,47 @@
CLASS {{p}}t31_test DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
CLASS-DATA go_env TYPE REF TO if_cds_test_environment.
CLASS-METHODS class_setup.
CLASS-METHODS class_teardown.
METHODS setup.
METHODS manager_of_employee FOR TESTING.
METHODS manager_view_shown FOR TESTING.
ENDCLASS.
CLASS {{p}}t31_test IMPLEMENTATION.
METHOD class_setup.
go_env = cl_cds_test_environment=>create( i_for_entity = '{{P}}I_EMPLOYEE' ).
ENDMETHOD.
METHOD class_teardown.
go_env->destroy( ).
ENDMETHOD.
METHOD setup.
DATA lt_emp TYPE STANDARD TABLE OF {{p}}emp WITH EMPTY KEY.
go_env->clear_doubles( ).
lt_emp = VALUE #(
( emp_id = 'E1' manager_id = '' emp_name = 'Anna' department = 'IT' is_manager = 'X' )
( emp_id = 'E2' manager_id = 'E1' emp_name = 'Ben' department = 'HR' is_manager = 'X' )
( emp_id = 'E3' manager_id = 'E1' emp_name = 'Cara' department = 'IT' is_manager = '' )
( emp_id = 'E4' manager_id = 'E2' emp_name = 'Dan' department = 'HR' is_manager = '' )
( emp_id = 'E5' manager_id = 'E2' emp_name = 'Eve' department = 'IT' is_manager = '' )
( emp_id = 'E6' manager_id = 'E3' emp_name = 'Fay' department = 'IT' is_manager = '' ) ).
go_env->insert_test_data( lt_emp ).
ENDMETHOD.
METHOD manager_of_employee.
SELECT FROM {{p}}i_employee\_manager
FIELDS mgr_name
WHERE mgr_name <> ''
INTO TABLE @DATA(lt_mgr).
cl_abap_unit_assert=>assert_equals( exp = 4 act = lines( lt_mgr ) ).
ENDMETHOD.
METHOD manager_view_shown.
SELECT COUNT(*) FROM {{p}}i_manager INTO @DATA(lv_count).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_count ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,13 @@
@EndUserText.label : 'Employee'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table {{p}}emp {
key client : abap.clnt not null;
key emp_id : abap.char(10) not null;
manager_id : abap.char(10);
emp_name : abap.char(40);
department : abap.char(10);
is_manager : abap.char(1);
}

View File

@@ -0,0 +1,23 @@
CLASS {{p}}seed_data DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS {{p}}seed_data IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA lt_emp TYPE STANDARD TABLE OF {{p}}emp WITH EMPTY KEY.
lt_emp = VALUE #(
( emp_id = 'E1' manager_id = '' emp_name = 'Anna' department = 'IT' is_manager = 'X' )
( emp_id = 'E2' manager_id = 'E1' emp_name = 'Ben' department = 'HR' is_manager = 'X' )
( emp_id = 'E3' manager_id = 'E1' emp_name = 'Cara' department = 'IT' is_manager = '' )
( emp_id = 'E4' manager_id = 'E2' emp_name = 'Dan' department = 'HR' is_manager = '' )
( emp_id = 'E5' manager_id = 'E2' emp_name = 'Eve' department = 'IT' is_manager = '' )
( emp_id = 'E6' manager_id = 'E3' emp_name = 'Fay' department = 'IT' is_manager = '' ) ).
DELETE FROM {{p}}emp.
INSERT {{p}}emp FROM TABLE @lt_emp.
out->write( 'Seed data for employees inserted.' ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,51 @@
# 1. Goal
A personnel system stores employees. Each employee can have a manager, who is
also an employee. A report reads the manager data of the employees. The data
must be in the database, in CDS views. The report uses an association in an
ABAP SQL path expression.
# 2. Open questions
None.
# 3. Context
- Table {{P}}EMP (employee), package $TMP. Key: EMP_ID (CHAR 10).
Fields: MANAGER_ID (CHAR 10, the EMP_ID of the manager), EMP_NAME (CHAR 40),
DEPARTMENT (CHAR 10), IS_MANAGER (CHAR 1, 'X' for a manager).
- The table is filled by the seed class {{P}}SEED_DATA.
# 4. Contract
- Create the CDS view entity {{P}}I_MANAGER in package $TMP.
Scalar elements: MGR_ID (key), MGR_NAME, MGR_DEPT.
- Create the CDS view entity {{P}}I_EMPLOYEE in package $TMP.
Scalar elements: EMP_ID (key), MANAGER_ID, EMP_NAME, DEPARTMENT.
- {{P}}I_EMPLOYEE also has the exposed association _MANAGER. _MANAGER is an
element of the view. It is not a scalar element.
- Both views have no authorization check (#NOT_REQUIRED).
# 5. Business rules
1. {{P}}I_MANAGER shows one row for each row of {{P}}EMP with IS_MANAGER = 'X'.
MGR_ID, MGR_NAME and MGR_DEPT have the values of EMP_ID, EMP_NAME and
DEPARTMENT of that employee.
2. {{P}}I_EMPLOYEE shows one row for each row of {{P}}EMP. EMP_ID, MANAGER_ID,
EMP_NAME and DEPARTMENT have the values of the employee.
3. The association _MANAGER leads from an employee to the manager of the
employee. The manager is the row of {{P}}I_MANAGER whose MGR_ID is the
MANAGER_ID of the employee. An employee whose MANAGER_ID is empty or has no
such row has no manager.
4. _MANAGER is part of the public interface of {{P}}I_EMPLOYEE. An ABAP SQL
statement reads the manager data with the path expression
{{P}}I_EMPLOYEE\_MANAGER. Example:
SELECT FROM {{P}}I_EMPLOYEE\_MANAGER FIELDS mgr_name
INTO TABLE @DATA(lt_name).
The elements of the path expression are the elements of the manager, not
the elements of the employee.
# 6. Constraints
- Release target: 8.16.
- Out of scope: do not change {{P}}EMP.
- Use ABAP SQL and CDS only.
# 7. Acceptance
- Both views are active and have no syntax error.
- The hidden tests pass.
- Write ABAP Unit tests with CL_CDS_TEST_ENVIRONMENT in a global test class.

View File

@@ -0,0 +1,80 @@
{
"id": "G0109",
"category": "B",
"object_type": "DDLS",
"difficulty": 2,
"release_target": "v816",
"expected_outcome": "implement",
"budget": {
"max_tool_calls": 40,
"max_activations": 10
},
"seed": [
{
"type": "TABL",
"name": "{{P}}EMP",
"file": "seed/emp.tabl.asabap",
"description": "Employee"
},
{
"type": "CLAS",
"name": "{{P}}SEED_DATA",
"file": "seed/seed_data.clas.abap",
"description": "Seed data for employees",
"run": true
}
],
"contract": [
{
"type": "DDLS",
"name": "{{P}}I_MANAGER",
"fields": [
"MGR_ID",
"MGR_NAME",
"MGR_DEPT"
]
},
{
"type": "DDLS",
"name": "{{P}}I_EMPLOYEE",
"fields": [
"EMP_ID",
"MANAGER_ID",
"EMP_NAME",
"DEPARTMENT"
]
}
],
"out_of_scope": [
"{{P}}EMP"
],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}T31_HIDDEN",
"file": "hidden/t31_hidden.clas.abap",
"description": "T31 hidden tests"
}
],
"reference": [
{
"type": "DDLS",
"name": "{{P}}I_MANAGER",
"file": "reference/i_manager.ddls.asddls",
"description": "Managers"
},
{
"type": "DDLS",
"name": "{{P}}I_EMPLOYEE",
"file": "reference/i_employee.ddls.asddls",
"description": "Employees with exposed manager association"
},
{
"type": "CLAS",
"name": "{{P}}T31_TEST",
"file": "reference/t31_test.clas.abap",
"description": "T31 own tests"
}
],
"craft_checks": []
}