@@ -50,7 +50,7 @@ void tear_down() throws Exception {
5050 }
5151
5252 @ Test
53- void build_resolves_defaults_from_flavor_when_request_fields_are_missing () throws ProjectExistenceServiceException {
53+ void build_for_creation_resolves_defaults_from_flavor_when_request_fields_are_missing () throws ProjectExistenceServiceException {
5454 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
5555 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
5656 CreateProjectRequest request = build_request ("DLSS" , null , "KEY01" );
@@ -59,7 +59,7 @@ void build_resolves_defaults_from_flavor_when_request_fields_are_missing() throw
5959
6060 when (projectExistenceService .isProjectFound ("KEY01" )).thenReturn (false );
6161
62- ProjectCreationCommand result = sut .build (request , clientApp );
62+ ProjectCreationCommand result = sut .buildForCreation (request , clientApp );
6363
6464 assertEquals ("DLSS" , result .getProjectFlavor ());
6565 assertEquals ("CI-001" , result .getConfigurationItem ());
@@ -69,84 +69,84 @@ void build_resolves_defaults_from_flavor_when_request_fields_are_missing() throw
6969 }
7070
7171 @ Test
72- void build_resolves_flavor_from_configuration_item_when_flavor_is_not_provided () throws ProjectExistenceServiceException {
72+ void build_for_creation_resolves_flavor_from_configuration_item_when_flavor_is_not_provided () throws ProjectExistenceServiceException {
7373 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
7474 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
7575 CreateProjectRequest request = build_request (null , "CI-001" , "KEY01" );
7676
7777 when (projectExistenceService .isProjectFound ("KEY01" )).thenReturn (false );
7878
79- ProjectCreationCommand result = sut .build (request , clientApp );
79+ ProjectCreationCommand result = sut .buildForCreation (request , clientApp );
8080
8181 assertEquals ("DLSS" , result .getProjectFlavor ());
8282 assertEquals ("CI-001" , result .getConfigurationItem ());
8383 }
8484
8585 @ Test
86- void build_generates_project_key_when_request_project_key_is_null () throws ProjectExistenceServiceException , org .opendevstack .apiservice .serviceproject .exception .ProjectKeyGenerationException {
86+ void build_for_creation_generates_project_key_when_request_project_key_is_null () throws ProjectExistenceServiceException , org .opendevstack .apiservice .serviceproject .exception .ProjectKeyGenerationException {
8787 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
8888 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
8989 CreateProjectRequest request = build_request ("DLSS" , null , null );
9090
9191 when (generateProjectKeyService .generateProjectKey ("DLSS%06d" )).thenReturn ("DLSS000001" );
9292 when (projectExistenceService .isProjectFound ("DLSS000001" )).thenReturn (false );
9393
94- ProjectCreationCommand result = sut .build (request , clientApp );
94+ ProjectCreationCommand result = sut .buildForCreation (request , clientApp );
9595
9696 assertEquals ("DLSS000001" , result .getProjectKey ());
9797 verify (generateProjectKeyService ).generateProjectKey ("DLSS%06d" );
9898 }
9999
100100 @ Test
101- void build_throws_project_already_exists_exception_when_project_key_already_exists () throws ProjectExistenceServiceException {
101+ void build_for_creation_throws_project_already_exists_exception_when_project_key_already_exists () throws ProjectExistenceServiceException {
102102 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
103103 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
104104 CreateProjectRequest request = build_request ("DLSS" , null , "KEY01" );
105105
106106 when (projectExistenceService .isProjectFound ("KEY01" )).thenReturn (true );
107107
108108 ProjectAlreadyExistsException ex = assertThrows (ProjectAlreadyExistsException .class ,
109- () -> sut .build (request , clientApp ));
109+ () -> sut .buildForCreation (request , clientApp ));
110110 assertEquals (ErrorKey .PROJECT_ALREADY_EXISTS , ex .getErrorKey ());
111111 }
112112
113113 @ Test
114- void build_throws_validation_exception_when_flavor_and_config_item_are_missing () {
114+ void build_for_creation_throws_validation_exception_when_flavor_and_config_item_are_missing () {
115115 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
116116 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
117117 CreateProjectRequest request = build_request (null , null , "KEY01" );
118118
119119 ProjectValidationException ex = assertThrows (ProjectValidationException .class ,
120- () -> sut .build (request , clientApp ));
120+ () -> sut .buildForCreation (request , clientApp ));
121121 assertEquals (ErrorKey .BAD_REQUEST_FLAVOR_CONFIG_ITEM , ex .getErrorKey ());
122122 }
123123
124124 @ Test
125- void build_throws_validation_exception_when_configuration_item_matches_multiple_flavors () {
125+ void build_for_creation_throws_validation_exception_when_configuration_item_matches_multiple_flavors () {
126126 ClientAppEntity clientApp = build_client_app (List .of (
127127 build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" ),
128128 build_flavor ("AMP" , "CI-001" , new String [] {}, "eu" , "owner2" )));
129129 CreateProjectRequest request = build_request (null , "CI-001" , "KEY01" );
130130
131131 ProjectValidationException ex = assertThrows (ProjectValidationException .class ,
132- () -> sut .build (request , clientApp ));
132+ () -> sut .buildForCreation (request , clientApp ));
133133 assertEquals (ErrorKey .INVALID_CONFIG_ITEM , ex .getErrorKey ());
134134 }
135135
136136 @ Test
137- void build_throws_project_key_generation_exception_when_generation_fails () throws Exception {
137+ void build_for_creation_throws_project_key_generation_exception_when_generation_fails () throws Exception {
138138 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
139139 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
140140 CreateProjectRequest request = build_request ("DLSS" , null , null );
141141
142142 when (generateProjectKeyService .generateProjectKey ("DLSS%06d" ))
143143 .thenThrow (new org .opendevstack .apiservice .serviceproject .exception .ProjectKeyGenerationException ("fail" ));
144144
145- assertThrows (ProjectCreationException .class , () -> sut .build (request , clientApp ));
145+ assertThrows (ProjectCreationException .class , () -> sut .buildForCreation (request , clientApp ));
146146 }
147147
148148 @ Test
149- void build_throws_project_already_exists_exception_when_project_name_already_exists () throws Exception {
149+ void build_for_creation_throws_project_already_exists_exception_when_project_name_already_exists () throws Exception {
150150 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
151151 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
152152 CreateProjectRequest request = build_request ("DLSS" , null , "KEY01" );
@@ -155,11 +155,11 @@ void build_throws_project_already_exists_exception_when_project_name_already_exi
155155 when (projectExistenceService .isProjectFound ("KEY01" )).thenReturn (false );
156156 when (projectExistenceService .isProjectFoundByName ("Existing Project" )).thenReturn (true );
157157
158- assertThrows (ProjectAlreadyExistsException .class , () -> sut .build (request , clientApp ));
158+ assertThrows (ProjectAlreadyExistsException .class , () -> sut .buildForCreation (request , clientApp ));
159159 }
160160
161161 @ Test
162- void build_throws_project_creation_exception_when_project_name_check_fails () throws Exception {
162+ void build_for_creation_throws_project_creation_exception_when_project_name_check_fails () throws Exception {
163163 ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
164164 ClientAppEntity clientApp = build_client_app (List .of (flavor ));
165165 CreateProjectRequest request = build_request ("DLSS" , null , "KEY01" );
@@ -169,7 +169,39 @@ void build_throws_project_creation_exception_when_project_name_check_fails() thr
169169 when (projectExistenceService .isProjectFoundByName ("Any Project" ))
170170 .thenThrow (new ProjectExistenceServiceException ("lookup failed" ));
171171
172- assertThrows (ProjectCreationException .class , () -> sut .build (request , clientApp ));
172+ assertThrows (ProjectCreationException .class , () -> sut .buildForCreation (request , clientApp ));
173+ }
174+
175+ @ Test
176+ void build_for_registration_resolves_defaults_from_flavor_when_request_fields_are_missing () throws ProjectExistenceServiceException {
177+ ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
178+ ClientAppEntity clientApp = build_client_app (List .of (flavor ));
179+ CreateProjectRequest request = build_request ("DLSS" , null , "KEY01" );
180+ request .setOwner (null );
181+ request .setLocation (null );
182+
183+ when (projectExistenceService .isProjectFoundInCollection ("KEY01" )).thenReturn (false );
184+
185+ ProjectCreationCommand result = sut .buildForRegistration (request , clientApp );
186+
187+ assertEquals ("DLSS" , result .getProjectFlavor ());
188+ assertEquals ("CI-001" , result .getConfigurationItem ());
189+ assertEquals ("owner1" , result .getOwner ());
190+ assertEquals ("eu" , result .getLocation ());
191+ assertEquals ("KEY01" , result .getProjectKey ());
192+ }
193+
194+ @ Test
195+ void build_for_registration_throws_project_already_exists_exception_when_project_key_already_exists () throws ProjectExistenceServiceException {
196+ ClientAppProjectFlavorEntity flavor = build_flavor ("DLSS" , "CI-001" , new String [] {}, "eu" , "owner1" );
197+ ClientAppEntity clientApp = build_client_app (List .of (flavor ));
198+ CreateProjectRequest request = build_request ("DLSS" , null , "KEY01" );
199+
200+ when (projectExistenceService .isProjectFoundInCollection ("KEY01" )).thenReturn (true );
201+
202+ ProjectAlreadyExistsException ex = assertThrows (ProjectAlreadyExistsException .class ,
203+ () -> sut .buildForRegistration (request , clientApp ));
204+ assertEquals (ErrorKey .PROJECT_ALREADY_EXISTS , ex .getErrorKey ());
173205 }
174206
175207 private CreateProjectRequest build_request (String flavor , String configItem , String projectKey ) {
0 commit comments