Skip to content

Commit 478027b

Browse files
author
zxBCN Valeriu_Tuguran,Constantin (IT EDP) EXTERNAL
committed
Fix sonar complaints.
1 parent c8dff78 commit 478027b

5 files changed

Lines changed: 21 additions & 16 deletions

File tree

api-project-component-v0/src/main/java/org/opendevstack/apiservice/project/controller/ComponentsResponseFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private ComponentsResponseFactory() {
1212
public static CreateComponentResponse error(String projectId) {
1313
CreateComponentResponse response = new CreateComponentResponse();
1414
response.setErrorCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
15-
response.setMessage("Failed to create component for project '" + projectId);
15+
response.setMessage("Failed to create component for project '" + projectId + "'");
1616
return response;
1717
}
1818

@@ -23,7 +23,7 @@ public static CreateComponentResponse entityCreated(String projectId, String com
2323
return response;
2424
}
2525

26-
public static ResponseEntity toResponseEntity(CreateComponentResponse response) {
27-
return new ResponseEntity(response, HttpStatus.valueOf(response.getErrorCode()));
26+
public static ResponseEntity<CreateComponentResponse> toResponseEntity(CreateComponentResponse response) {
27+
return new ResponseEntity<>(response, HttpStatus.valueOf(response.getErrorCode()));
2828
}
2929
}

api-project-component-v0/src/main/java/org/opendevstack/apiservice/project/service/ComponentsService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public boolean isHealthy() {
3232
}
3333

3434
public Component getProjectComponent(String projectId, String componentId) {
35+
log.info("Get component with id '" + componentId + "' for project '" + projectId + "'");
3536
return null;
3637
}
3738

3839
public Component createProjectComponent(String projectId, CreateComponentRequest createComponentRequest) {
40+
log.info("Creating component for project '" + projectId + "'" + " with request: " + createComponentRequest);
3941
return null;
4042
}
4143
}

api-project-component-v0/src/test/java/org/opendevstack/apiservice/project/controller/ProjectComponentsControllerTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,37 @@ void setup() {
3434
@Test
3535
void testCreateProjectComponent_whenSuccess_thenReturnOk() throws Exception {
3636
Component testComponent = buildTestComponent();
37+
String testProjectId = "testProjectId";
3738
CreateComponentRequest testCreateComponentRequest = buildTestCreateComponentRequest();
38-
CreateComponentResponse testServiceResponseSuccess = buildTestCreateComponentResponseSuccess();
39+
CreateComponentResponse testServiceResponseSuccess = buildTestCreateComponentResponseSuccess(testComponent.getName(),
40+
testProjectId);
3941

4042
when(componentsService.createProjectComponent(anyString(), any(CreateComponentRequest.class)))
4143
.thenReturn(testComponent);
4244

43-
ResponseEntity<CreateComponentResponse> response = projectComponentsController.createProjectComponent("testId",
45+
ResponseEntity<CreateComponentResponse> response = projectComponentsController.createProjectComponent(testProjectId,
4446
testCreateComponentRequest);
4547

4648
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
4749
assertThat(response.getBody()).isNotNull();
48-
assertThat(response.getBody().equals(testServiceResponseSuccess));
50+
assertThat(response.getBody()).isEqualTo(testServiceResponseSuccess);
4951
}
5052

5153
@Test
5254
void testCreateProjectComponent_whenFailure_thenReturnErrorResponse() throws Exception {
5355
CreateComponentRequest testCreateComponentRequest = buildTestCreateComponentRequest();
54-
CreateComponentResponse testServiceResponseFailure = buildTestCreateComponentResponseFailure();
56+
String testProjectId = "testProjectId";
57+
CreateComponentResponse testServiceResponseFailure = buildTestCreateComponentResponseFailure(testProjectId);
5558

5659
when(componentsService.createProjectComponent(anyString(), any(CreateComponentRequest.class)))
5760
.thenReturn(null);
5861

59-
ResponseEntity<CreateComponentResponse> response = projectComponentsController.createProjectComponent("projectId",
62+
ResponseEntity<CreateComponentResponse> response = projectComponentsController.createProjectComponent(testProjectId,
6063
testCreateComponentRequest);
6164

6265
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
6366
assertThat(response.getBody()).isNotNull();
64-
assertThat(response.getBody().equals(testServiceResponseFailure));
67+
assertThat(response.getBody()).isEqualTo(testServiceResponseFailure);
6568
}
6669

6770
@Test
@@ -76,7 +79,7 @@ void testGetProjectComponent_whenSuccess_thenReturnOk() throws Exception {
7679

7780
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
7881
assertThat(response.getBody()).isNotNull();
79-
assertThat(response.getBody().equals(testComponent));
82+
assertThat(response.getBody()).isEqualTo(testComponent);
8083
}
8184

8285
@Test

api-project-component-v0/src/test/java/org/opendevstack/apiservice/project/service/ComponentsServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void testGetProjectComponent_whenNoComponentFound_thenReturnNull() throws Except
4646
.thenReturn(null);
4747

4848
Component retrievedComponent = componentsService.getProjectComponent("testId", "testId");
49-
assertThat(retrievedComponent).isEqualTo(null);
49+
assertThat(retrievedComponent).isNull();
5050
}
5151

5252
@Test
@@ -70,6 +70,6 @@ void testCreateProjectComponent_whenFailure_thenReturnNull() throws Exception {
7070
.thenReturn(null);
7171

7272
Component retrievedComponent = componentsService.createProjectComponent("testId", testRequest);
73-
assertThat(retrievedComponent).isEqualTo(null);
73+
assertThat(retrievedComponent).isNull();
7474
}
7575
}

api-project-component-v0/src/test/java/org/opendevstack/apiservice/project/util/TestHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public static CreateComponentRequest buildTestCreateComponentRequest() {
2424
return request;
2525
}
2626

27-
public static CreateComponentResponse buildTestCreateComponentResponseSuccess() {
27+
public static CreateComponentResponse buildTestCreateComponentResponseSuccess(String componentName, String projectId) {
2828
CreateComponentResponse response = new CreateComponentResponse();
2929
response.setErrorCode(HttpStatus.CREATED.value());
30-
response.setMessage("success");
30+
response.setMessage(componentName + " component created successfully in project " + projectId);
3131
return response;
3232
}
3333

34-
public static CreateComponentResponse buildTestCreateComponentResponseFailure() {
34+
public static CreateComponentResponse buildTestCreateComponentResponseFailure(String projectId) {
3535
CreateComponentResponse response = new CreateComponentResponse();
3636
response.setErrorCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
37-
response.setMessage("failure");
37+
response.setMessage("Failed to create component for project '" + projectId + "'");
3838
return response;
3939
}
4040
}

0 commit comments

Comments
 (0)