Skip to content

Commit e72e15c

Browse files
Feature/update ods api service to use project info service
* [ods-api-to-projecs-info-service] - Add projects info service openApi configuration. * [ods-api-to-projecs-info-service] - Delete previous code. * [ods-api-to-projecs-info-service] - Update facade. * [ods-api-to-projecs-info-service] - Update facade. * [ods-api-to-projecs-info-service] - Use new ProjectsApi auto-generated client. * [ods-api-to-projecs-info-service] - Get token from request and use it for authorize into projectsInfoService. * [ods-api-to-projecs-info-service] - Set base path. * [ods-api-to-projecs-info-service] - Add Unit tests. * [ods-api-to-projecs-info-service] - Get rid of idToken, as projects-info-service does not need it. * [ods-api-to-projects-info-service] - Clean application configuration. * [ods-api-to-projects-info-service] - Add missing unit test.
1 parent cb08f8d commit e72e15c

69 files changed

Lines changed: 594 additions & 4258 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api-project-platform/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
<artifactId>spring-boot-starter-web</artifactId>
2121
</dependency>
2222

23+
<!-- Spring Boot Security -->
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-security</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
31+
</dependency>
32+
2333
<!-- Spring Boot Validation -->
2434
<dependency>
2535
<groupId>org.springframework.boot</groupId>
@@ -77,6 +87,10 @@
7787
<artifactId>spring-boot-starter-test</artifactId>
7888
<scope>test</scope>
7989
</dependency>
90+
<dependency>
91+
<groupId>org.springframework.security</groupId>
92+
<artifactId>spring-security-core</artifactId>
93+
</dependency>
8094
</dependencies>
8195

8296
<build>

api-project-platform/src/main/java/org/opendevstack/apiservice/projectplatform/facade/impl/ProjectsFacadeImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.opendevstack.apiservice.projectplatform.facade.impl;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.opendevstack.apiservice.externalservice.projectsinfoservice.exception.ProjectsInfoServiceException;
45
import org.opendevstack.apiservice.externalservice.projectsinfoservice.model.Platforms;
56
import org.opendevstack.apiservice.externalservice.projectsinfoservice.service.ProjectsInfoService;
@@ -10,6 +11,7 @@
1011
import org.springframework.stereotype.Component;
1112

1213
@Component
14+
@Slf4j
1315
public class ProjectsFacadeImpl implements ProjectsFacade {
1416

1517
private final ProjectsInfoService projectsInfoService;
@@ -30,4 +32,5 @@ public ProjectPlatforms getProjectPlatforms(String projectKey) throws ProjectPla
3032
throw new ProjectPlatformsException("Failed to retrieve project platforms", e);
3133
}
3234
}
35+
3336
}

api-project-platform/src/main/java/org/opendevstack/apiservice/projectplatform/mapper/ProjectPlatformsMapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public ProjectPlatforms toApiModel(Platforms externalPlatforms) {
3131
ProjectPlatforms apiPlatforms = new ProjectPlatforms();
3232

3333
// Map sections
34-
if (externalPlatforms.getSections() != null) {
34+
if (externalPlatforms.sections() != null) {
3535
apiPlatforms.setSections(
36-
externalPlatforms.getSections().stream()
36+
externalPlatforms.sections().stream()
3737
.map(this::toApiSection)
3838
.collect(Collectors.toList())
3939
);
@@ -55,13 +55,13 @@ private Section toApiSection(PlatformSection externalSection) {
5555
}
5656

5757
Section apiSection = new Section();
58-
apiSection.setSection(externalSection.getSection());
59-
apiSection.setTooltip(externalSection.getTooltip());
58+
apiSection.setSection(externalSection.section());
59+
apiSection.setTooltip(externalSection.tooltip());
6060

6161
// Map links
62-
if (externalSection.getLinks() != null) {
62+
if (externalSection.links() != null) {
6363
apiSection.setLinks(
64-
externalSection.getLinks().stream()
64+
externalSection.links().stream()
6565
.map(this::toApiLink)
6666
.collect(Collectors.toList())
6767
);
Lines changed: 45 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,82 @@
11
package org.opendevstack.apiservice.projectplatform.facade.impl;
22

3+
import org.junit.jupiter.api.AfterEach;
34
import org.junit.jupiter.api.BeforeEach;
45
import org.junit.jupiter.api.Test;
5-
import org.junit.jupiter.api.extension.ExtendWith;
6-
import org.mockito.Mock;
7-
import org.mockito.junit.jupiter.MockitoExtension;
86
import org.opendevstack.apiservice.externalservice.projectsinfoservice.exception.ProjectsInfoServiceException;
7+
import org.opendevstack.apiservice.externalservice.projectsinfoservice.model.PlatformSection;
98
import org.opendevstack.apiservice.externalservice.projectsinfoservice.model.Platforms;
109
import org.opendevstack.apiservice.externalservice.projectsinfoservice.service.ProjectsInfoService;
1110
import org.opendevstack.apiservice.projectplatform.exception.ProjectPlatformsException;
1211
import org.opendevstack.apiservice.projectplatform.mapper.ProjectPlatformsMapper;
13-
import org.opendevstack.apiservice.projectplatform.model.Link;
1412
import org.opendevstack.apiservice.projectplatform.model.ProjectPlatforms;
15-
import org.opendevstack.apiservice.projectplatform.model.Section;
13+
import org.springframework.security.core.context.SecurityContextHolder;
1614

1715
import java.util.List;
1816

19-
import static org.junit.jupiter.api.Assertions.*;
20-
import static org.mockito.Mockito.*;
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19+
import static org.mockito.Mockito.mock;
20+
import static org.mockito.Mockito.verify;
21+
import static org.mockito.Mockito.when;
2122

22-
@ExtendWith(MockitoExtension.class)
2323
class ProjectsFacadeImplTest {
2424

25-
@Mock
2625
private ProjectsInfoService projectsInfoService;
27-
28-
@Mock
2926
private ProjectPlatformsMapper mapper;
3027

31-
private ProjectsFacadeImpl facade;
28+
private ProjectsFacadeImpl sut;
3229

3330
@BeforeEach
34-
void setUp() {
35-
facade = new ProjectsFacadeImpl(projectsInfoService, mapper);
36-
}
37-
38-
@Test
39-
void givenAnyProjectKey_whenGetProjectPlatforms_thenGetMockProjectPlatforms() throws ProjectsInfoServiceException, ProjectPlatformsException {
40-
// Arrange
41-
String projectKey = "DEVSTACK";
31+
void setup() {
32+
projectsInfoService = mock(ProjectsInfoService.class);
33+
mapper = mock(ProjectPlatformsMapper.class);
4234

43-
// Create external service response
44-
Platforms externalPlatforms = new Platforms();
35+
sut = new ProjectsFacadeImpl(projectsInfoService, mapper);
4536

46-
// Create expected API response
47-
ProjectPlatforms expectedPlatforms = createExpectedProjectPlatforms();
37+
// Reset security context before each test
38+
SecurityContextHolder.clearContext();
39+
}
4840

49-
// Mock behavior
50-
when(projectsInfoService.getProjectPlatforms(projectKey)).thenReturn(externalPlatforms);
51-
when(mapper.toApiModel(externalPlatforms)).thenReturn(expectedPlatforms);
52-
53-
// Act
54-
ProjectPlatforms result = facade.getProjectPlatforms(projectKey);
55-
56-
// Assert
57-
assertNotNull(result, "Result should not be null");
58-
59-
List<Section> sections = result.getSections();
60-
assertNotNull(sections, "Sections should not be null");
61-
assertEquals(3, sections.size(), "There should be 3 sections");
62-
63-
// Validate first section
64-
Section appPlatformSection = sections.get(0);
65-
assertEquals("Project Shortcuts - Application Platform", appPlatformSection.getSection());
66-
assertEquals(4, appPlatformSection.getLinks().size());
67-
assertTrue(appPlatformSection.getLinks().stream().anyMatch(link -> link.getLabel().equals("JIRA")));
68-
assertTrue(appPlatformSection.getLinks().stream().allMatch(link -> link.getUrl().equals("https://www.google.com")));
69-
70-
// Validate second section
71-
Section dataPlatformSection = sections.get(1);
72-
assertEquals("Project Shortcuts - Data Platform", dataPlatformSection.getSection());
73-
assertEquals(2, dataPlatformSection.getLinks().size());
74-
75-
// Validate third section
76-
Section servicesSection = sections.get(2);
77-
assertEquals("Services", servicesSection.getSection());
78-
assertEquals(3, servicesSection.getLinks().size());
79-
80-
// Verify interactions
81-
verify(projectsInfoService, times(1)).getProjectPlatforms(projectKey);
82-
verify(mapper, times(1)).toApiModel(externalPlatforms);
41+
@AfterEach
42+
void cleanup() {
43+
SecurityContextHolder.clearContext();
8344
}
8445

8546
@Test
86-
void givenProjectsInfoServiceThrowsException_whenGetProjectPlatforms_thenRuntimeExceptionIsThrown() throws ProjectsInfoServiceException {
87-
// Arrange
88-
String projectKey = "DEVSTACK";
89-
when(projectsInfoService.getProjectPlatforms(projectKey))
90-
.thenThrow(new ProjectsInfoServiceException("Service error"));
47+
void getProjectPlatforms_whenGetProjectPlatforms_thenReturnMappedApiModel() throws Exception {
48+
//given
49+
String projectKey = "PROJ";
9150

92-
// Act & Assert
93-
ProjectPlatformsException exception = assertThrows(ProjectPlatformsException.class, () -> facade.getProjectPlatforms(projectKey));
51+
List<PlatformSection> sections = List.of();
52+
Platforms externalPlatforms = new Platforms(sections);
53+
when(projectsInfoService.getProjectPlatforms(projectKey)).thenReturn(externalPlatforms);
9454

95-
assertEquals("Failed to retrieve project platforms", exception.getMessage());
96-
verify(projectsInfoService, times(1)).getProjectPlatforms(projectKey);
97-
verify(mapper, never()).toApiModel(any());
98-
}
55+
ProjectPlatforms mapped = new ProjectPlatforms();
56+
when(mapper.toApiModel(externalPlatforms)).thenReturn(mapped);
9957

100-
private ProjectPlatforms createExpectedProjectPlatforms() {
101-
ProjectPlatforms platforms = new ProjectPlatforms();
58+
//when
59+
ProjectPlatforms result = sut.getProjectPlatforms(projectKey);
10260

103-
// Set sections
104-
Section appPlatformSection = new Section("Project Shortcuts - Application Platform", "tooltip", List.of(
105-
new Link("JIRA", "https://www.google.com", "tooltip", "type", "abbreviation", false),
106-
new Link("Bitbucket", "https://www.google.com", "tooltip", "type", "abbreviation", false),
107-
new Link("Confluence", "https://www.google.com", "tooltip", "type", "abbreviation", false),
108-
new Link("Jenkins", "https://www.google.com", "tooltip", "type", "abbreviation", false)
109-
));
61+
//then
62+
verify(projectsInfoService).getProjectPlatforms(projectKey);
63+
verify(mapper).toApiModel(externalPlatforms);
11064

111-
Section dataPlatformSection = new Section("Project Shortcuts - Data Platform", "tooltip", List.of(
112-
new Link("EKG", "https://www.google.com", "tooltip", "type", "abbreviation", false),
113-
new Link("EDGC", "https://www.google.com", "tooltip", "type", "abbreviation", false)
114-
));
65+
assertThat(result).isSameAs(mapped);
66+
}
11567

116-
Section servicesSection = new Section("Services", "tooltip", List.of(
117-
new Link("Service Onboarding", "https://www.google.com", "tooltip", "type", "abbreviation", false),
118-
new Link("Documentation", "https://www.google.com", "tooltip", "type", "abbreviation", false),
119-
new Link("Service Training", "https://www.google.com", "tooltip", "type", "abbreviation", false)
120-
));
68+
@Test
69+
void getProjectPlatforms_whenInfoServiceThrowsException_thenWrapInProjectPlatformsException() throws Exception {
70+
//given
71+
String projectKey = "PROJ";
12172

122-
platforms.setSections(List.of(appPlatformSection, dataPlatformSection, servicesSection));
73+
when(projectsInfoService.getProjectPlatforms(projectKey))
74+
.thenThrow(new ProjectsInfoServiceException("boom"));
12375

124-
return platforms;
76+
//when/then
77+
assertThatThrownBy(() -> sut.getProjectPlatforms(projectKey))
78+
.isInstanceOf(ProjectPlatformsException.class)
79+
.hasMessageContaining("Failed to retrieve project platforms");
12580
}
126-
}
12781

82+
}

0 commit comments

Comments
 (0)