Skip to content

Commit

Permalink
feat: add mfe type
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Apr 16, 2024
1 parent 051aabd commit 3477ace
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 122 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
</goals>
<configuration>
<url>
https://raw.githubusercontent.com/onecx/onecx-product-store-svc/feat/remote_components/src/main/openapi/onecx-product-store-internal.yaml
https://raw.githubusercontent.com/onecx/onecx-product-store-svc/main/src/main/openapi/onecx-product-store-internal.yaml
</url>
<outputDirectory>target/tmp/openapi</outputDirectory>
<outputFileName>onecx-product-store-internal.yaml</outputFileName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ public Response getMicrofrontend(String id) {
}
}

@Override
public Response getMicrofrontendByAppId(String appId) {
try (Response response = client.getMicrofrontendByAppId(appId)) {
MicrofrontendDTO result = mapper.mapMfe(response.readEntity(Microfrontend.class));
return Response.status(response.getStatus()).entity(result).build();
}
}

@Override
public Response searchMicrofrontends(MfeAndMsSearchCriteriaDTO microfrontendSearchCriteriaDTO) {

Expand Down
51 changes: 24 additions & 27 deletions src/main/openapi/onecx-product-store-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ info:
servers:
- url: "http://onecx-product-store-bff:8080"
tags:
- name: OneCX Product Store
- name: Microfrontends
paths:
/microfrontends:
post:
Expand Down Expand Up @@ -78,31 +78,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetailResponse'
/microfrontends/appId/{appId}:
get:
x-onecx:
permissions:
microfrontend:
- read
tags:
- Microfrontends
description: Return micro-frontend by its appId
operationId: getMicrofrontendByAppId
parameters:
- name: appId
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Microfrontend'
"404":
description: Not Found
/microfrontends/{id}:
get:
x-onecx:
Expand Down Expand Up @@ -750,6 +725,8 @@ components:
uniqueItems: true
items:
type: string
undeployed:
type: boolean
UpdateProductRequest:
type: object
required:
Expand All @@ -776,6 +753,8 @@ components:
uniqueItems: true
items:
type: string
undeployed:
type: boolean
Product:
type: object
required:
Expand Down Expand Up @@ -817,6 +796,8 @@ components:
uniqueItems: true
items:
type: string
undeployed:
type: boolean
ProductAndWorkspaces:
type: object
allOf:
Expand Down Expand Up @@ -849,10 +830,12 @@ components:
description: name of the product used for displaying to user.
classifications:
type: array
description: like tags for grouing and labeling. Used in frontend to enable filtering.
description: like tags for grouping and labeling. Used in frontend to enable filtering.
uniqueItems: true
items:
type: string
undeployed:
type: boolean
OffsetDateTime:
format: date-time
type: string
Expand Down Expand Up @@ -945,6 +928,8 @@ components:
type: string
operator:
type: boolean
deprecated:
type: boolean
type:
$ref: "#/components/schemas/MicrofrontendType"
classifications:
Expand Down Expand Up @@ -1024,6 +1009,8 @@ components:
type: string
exposedModule:
type: string
deprecated:
type: boolean
type:
$ref: "#/components/schemas/MicrofrontendType"
endpoints:
Expand Down Expand Up @@ -1083,6 +1070,8 @@ components:
type: string
exposedModule:
type: string
deprecated:
type: boolean
type:
$ref: "#/components/schemas/MicrofrontendType"
endpoints:
Expand Down Expand Up @@ -1157,6 +1146,8 @@ components:
type: string
exposedModule:
type: string
deprecated:
type: boolean
type:
$ref: "#/components/schemas/MicrofrontendType"
endpoints:
Expand Down Expand Up @@ -1204,6 +1195,8 @@ components:
type: string
operator:
type: boolean
undeployed:
type: boolean
UpdateMicroserviceRequest:
type: object
properties:
Expand All @@ -1219,6 +1212,8 @@ components:
type: string
type:
type: string
undeployed:
type: boolean
CreateMicroserviceRequest:
required:
- productName
Expand All @@ -1237,6 +1232,8 @@ components:
type: string
type:
type: string
undeployed:
type: boolean
MicroservicePageResult:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,92 +120,6 @@ void getMicrofrontend_shouldReturnMicrofrontend() {

}

/**
* Scenario: Receives microfrontend (mfe) by app-id successfully.
* Given
* When I query GET endpoint with an existing id
* Then I get a 'OK' response code back
* AND associated mfe is returned
*/
@Test
void getMicrofrontendByAppId_shouldReturnMicrofrontend() {

OffsetDateTime offsetDateTime = OffsetDateTime.parse("2023-11-30T13:53:03.688710200+01:00");
OffsetDateTimeMapper mapper = new OffsetDateTimeMapper();
Set<String> classificationSet = new HashSet<>();
classificationSet.add("some");
classificationSet.add("another");
List<UIEndpoint> uiEndpointSet = new ArrayList<>();
UIEndpoint uiEndpointItem = new UIEndpoint();
uiEndpointItem.setName("Search");
uiEndpointItem.setPath("/search");
uiEndpointSet.add(uiEndpointItem);

Microfrontend data = createMicrofrontend("7a0ee705-8fd0-47b0-8205-b2a5f6540b9e", offsetDateTime, "csommer",
offsetDateTime, "csommer", 1, false, "App-ID", "1.0.0",
"AppName", "some description", "", "https://localhost/mfe/core/ah-mgmt/",
"https://localhost/mfe/core/ah-mgmt/remoteEntry.js", "ProductName", classificationSet,
"[email protected]", "sun", "some notes", "/AnnouncementManagementModule", uiEndpointSet);

// create mock rest endpoint
mockServerClient
.when(request().withPath(PRODUCT_STORE_SVC_INTERNAL_API_BASE_PATH + "/appId/" + data.getAppId())
.withMethod(HttpMethod.GET))
.respond(httpRequest -> response().withStatusCode(Response.Status.OK.getStatusCode())
.withContentType(MediaType.APPLICATION_JSON)
.withBody(JsonBody.json(data)));

var response = given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
.header(APM_HEADER_PARAM, ADMIN)
.contentType(APPLICATION_JSON)
.get("appId/" + data.getAppId())
.then()
.statusCode(Response.Status.OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract().as(MicrofrontendDTO.class);

Assertions.assertEquals(data.getId(), response.getId());
Assertions.assertEquals(data.getCreationUser(), response.getCreationUser());
Assertions.assertEquals(mapper.map(data.getCreationDate()), mapper.map(response.getCreationDate()));
Assertions.assertEquals(mapper.map(data.getModificationDate()), mapper.map(response.getModificationDate()));
Assertions.assertEquals(data.getModificationUser(), response.getModificationUser());
Assertions.assertEquals(data.getModificationCount(), response.getModificationCount());
Assertions.assertEquals(data.getOperator(), response.getOperator());
Assertions.assertEquals(data.getAppId(), response.getAppId());
Assertions.assertEquals(data.getAppVersion(), response.getAppVersion());
Assertions.assertEquals(data.getAppName(), response.getAppName());
Assertions.assertEquals(data.getDescription(), response.getDescription());
Assertions.assertEquals(data.getRemoteBaseUrl(), response.getRemoteBaseUrl());
Assertions.assertEquals(data.getRemoteEntry(), response.getRemoteEntry());
Assertions.assertEquals(data.getProductName(), response.getProductName());

Assertions.assertEquals(data.getContact(), response.getContact());
Assertions.assertEquals(data.getIconName(), response.getIconName());
Assertions.assertEquals(data.getNote(), response.getNote());
Assertions.assertEquals(data.getExposedModule(), response.getExposedModule());
Assertions.assertEquals(data.getEndpoints().size(), response.getEndpoints().size());
Assertions.assertEquals(data.getEndpoints().get(0).getName(), response.getEndpoints().get(0).getName());
Assertions.assertEquals(data.getEndpoints().get(0).getPath(), response.getEndpoints().get(0).getPath());

// create mock rest endpoint
mockServerClient
.when(request().withPath(PRODUCT_STORE_SVC_INTERNAL_API_BASE_PATH + "/appId/not-existing")
.withMethod(HttpMethod.GET))
.respond(httpRequest -> response().withStatusCode(Response.Status.NOT_FOUND.getStatusCode()));

//expect not found for non-existing appId
given()
.when()
.auth().oauth2(keycloakClient.getAccessToken(ADMIN))
.header(APM_HEADER_PARAM, ADMIN)
.contentType(APPLICATION_JSON)
.get("/appId/not-existing")
.then()
.statusCode(Response.Status.NOT_FOUND.getStatusCode());
}

/**
* Scenario: Receive 404 Not Found when microfrontend (mfe) is not existing in backend service.
* Given
Expand Down

0 comments on commit 3477ace

Please sign in to comment.