Skip to content

Commit

Permalink
Discover SAP system running on a JAVA stack (#2820)
Browse files Browse the repository at this point in the history
* Add sap system type in view

* Update factory and fix test

* Refactor type

* Refactor type

* Update existing story and add test

* Fix existing cypress test

* Refactor render of sap system type

* Address frontend comments

* Refactor frontend code

* Refactor test and story

* Add backend test for j2ee discovery
  • Loading branch information
EMaksy authored Jul 30, 2024
1 parent 51b28ac commit 9ed6d26
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 16 deletions.
1 change: 1 addition & 0 deletions assets/js/lib/test-utils/factories/sapSystems.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const roles = () =>
'GATEWAY',
'ICMAN',
'IGS',
'J2EE',
]);

export const sapSystemApplicationInstanceFactory = Factory.define(() => ({
Expand Down
13 changes: 12 additions & 1 deletion assets/js/pages/SapSystemsOverviewPage/SapSystemsOverview.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/no-unstable-nested-components */
import React, { useState } from 'react';
import { Link, useSearchParams } from 'react-router-dom';
import { filter } from 'lodash';
import { filter, uniq, flatMap } from 'lodash';

import { getEnsaVersionLabel } from '@lib/model/sapSystems';

Expand Down Expand Up @@ -77,6 +77,17 @@ function SapSystemsOverview({
title: 'Tenant',
key: 'tenant',
},
{
title: 'Type',
key: 'applicationInstances',
render: (content) =>
uniq(flatMap(content, ({ features }) => features.split('|')))
.filter((item) => item === 'J2EE' || item === 'ABAP')
.map((item) => (item === 'J2EE' ? 'JAVA' : item))
.toSorted()
.join('/'),
},

{
title: 'DB Address',
key: 'dbAddress',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MemoryRouter } from 'react-router-dom';
import {
clusterFactory,
hostFactory,
sapSystemApplicationInstanceFactory,
sapSystemFactory,
} from '@lib/test-utils/factories';

Expand All @@ -19,6 +20,7 @@ const enrichInstances = (systems, instanceType) =>
const cluster = clusterFactory.build();
return {
...instance,
features: 'ABAP',
host: {
...hostFactory.build({
id: instance.host_id,
Expand Down Expand Up @@ -49,6 +51,28 @@ const enrichedAbsentDatabaseInstances = enrichInstances(
'database_instances'
);

const sapSystemTypes = [
'ABAP',
'J2EE',
'ABAP|J2EE',
'J2EE|ABAP',
'SOME_SAP_SYSTEM_FEATURE|NOT_A_REAL_SYSTEM',
];

const sapSystemsWithCustomTypes = sapSystemTypes.map((type) => {
const sapSystemID = faker.string.uuid();
return sapSystemFactory.build({
id: sapSystemID,
application_instances: sapSystemApplicationInstanceFactory.buildList(2, {
sap_system_id: sapSystemID,
features: type,
}),
});
});
const sapSystemApplicationInstances = sapSystemsWithCustomTypes
.map((sapSystem) => sapSystem.application_instances)
.flat();

enrichedAbsentApplicationInstances[1].absent_at = faker.date
.past()
.toISOString();
Expand All @@ -71,10 +95,6 @@ export default {
control: { type: 'array' },
description: 'Application instances',
},
userAbilities: {
control: { type: 'array' },
description: 'User profile abilities',
},
databaseInstances: {
control: { type: 'array' },
description: 'Database instances',
Expand All @@ -87,6 +107,10 @@ export default {
defaultValue: { summary: false },
},
},
userAbilities: {
control: { type: 'array' },
description: 'User profile abilities',
},
onTagAdd: {
action: 'Add tag',
description: 'Called when a new tag is added',
Expand Down Expand Up @@ -140,3 +164,11 @@ export const UnauthorizedCleanUp = {
userAbilities: [],
},
};
export const SapSystemsWithDifferentTypes = {
args: {
userAbilities,
sapSystems: sapSystemsWithCustomTypes,
applicationInstances: sapSystemApplicationInstances,
databaseInstances: {},
},
};
100 changes: 96 additions & 4 deletions assets/js/pages/SapSystemsOverviewPage/SapSystemsOverview.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import userEvent from '@testing-library/user-event';
import {
clusterFactory,
hostFactory,
sapSystemApplicationInstanceFactory,
sapSystemFactory,
} from '@lib/test-utils/factories';
import { renderWithRouter } from '@lib/test-utils';
Expand Down Expand Up @@ -41,16 +42,25 @@ describe('SapSystemsOverviews component', () => {
});

it('should display the correct content for a SAP system main row', () => {
const sapSystem = sapSystemFactory.build({ ensa_version: 'ensa1' });
const {
const sapSystemType = 'ABAP';
const sapSystemID = faker.string.uuid();

const sapSystem = sapSystemFactory.build({
id: sapSystemID,
sid,
ensa_version: 'ensa1',
application_instances: sapSystemApplicationInstanceFactory.buildList(
2,
{ sap_system_id: sapSystemID, features: sapSystemType }
),
});
const {
tenant,
db_host: dbAddress,
application_instances: applicationInstances,
database_instances: databaseInstances,
database_id: databaseID,
database_sid: attachedRdbms,
sid,
} = sapSystem;

renderWithRouter(
Expand Down Expand Up @@ -80,13 +90,95 @@ describe('SapSystemsOverviews component', () => {
tenant
);
expect(mainRow.querySelector('td:nth-child(5)')).toHaveTextContent(
dbAddress
sapSystemType
);
expect(mainRow.querySelector('td:nth-child(6)')).toHaveTextContent(
dbAddress
);
expect(mainRow.querySelector('td:nth-child(7)')).toHaveTextContent(
'ENSA1'
);
});

it('should display the correct SAP system type JAVA or ABAP', () => {
const sapSystemTypes = [
'ABAP',
'J2EE',
'SOME_SAP_SYSTEM_FEATURE|NOT_A_REAL_SYSTEM',
];

const expectedSapSystemTypes = ['ABAP', 'JAVA', ''];

const sapSystems = sapSystemTypes.map((type) => {
const sapSystemID = faker.string.uuid();
return sapSystemFactory.build({
id: sapSystemID,
application_instances: sapSystemApplicationInstanceFactory.buildList(
2,
{ sap_system_id: sapSystemID, features: type }
),
});
});

const sapSystemApplicationInstances = sapSystems
.map((sapSystem) => sapSystem.application_instances)
.flat();

renderWithRouter(
<SapSystemsOverview
sapSystems={sapSystems}
userAbilities={userAbilities}
applicationInstances={sapSystemApplicationInstances}
databaseInstances={[]}
/>
);
const rows = screen.getByRole('table').querySelectorAll('tbody > tr');
expectedSapSystemTypes.forEach((expectedType, index) => {
const rowIndex = index * 2;
const sapSystemRow = rows[rowIndex];
expect(sapSystemRow.querySelector('td:nth-child(5)')).toHaveTextContent(
expectedType
);
});
});

it('should display the correct SAP system type JAVA and ABAP', () => {
const expectedSapSystemTypes = 'ABAP/JAVA';
const sapSystemID = faker.string.uuid();
const sapSystem = sapSystemFactory.build({
id: sapSystemID,
application_instances: [
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystemID,
features: 'ABAP',
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystemID,
features: 'J2EE',
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystemID,
features: 'SOME_SAP_SYSTEM_FEATURE|OTHER_SAP_APP',
}),
],
});

const { application_instances: applicationInstances } = sapSystem;

renderWithRouter(
<SapSystemsOverview
sapSystems={[sapSystem]}
userAbilities={userAbilities}
applicationInstances={applicationInstances}
databaseInstances={[]}
/>
);
const rows = screen.getByRole('table').querySelectorAll('tbody > tr');
expect(rows[0].querySelector('td:nth-child(5)')).toHaveTextContent(
expectedSapSystemTypes
);
});

it('should display the correct content for a SAP system instances', () => {
const sapSystem = sapSystemFactory.build();
const {
Expand Down
16 changes: 12 additions & 4 deletions lib/trento/sap_systems/sap_system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ defmodule Trento.SapSystems.SapSystem do
database_health: database_health
}
) do
if instances_have_abap?(instances) and instances_have_messageserver?(instances) do
if instances_have_abap_or_java?(instances) and instances_have_messageserver?(instances) do
%SapSystemRestored{
db_host: db_host,
health: health,
Expand All @@ -659,7 +659,7 @@ defmodule Trento.SapSystems.SapSystem do
database_health: database_health
}
) do
if instances_have_abap?(instances) and instances_have_messageserver?(instances) do
if instances_have_abap_or_java?(instances) and instances_have_messageserver?(instances) do
%SapSystemRestored{
health: health,
db_host: db_host,
Expand All @@ -683,7 +683,7 @@ defmodule Trento.SapSystems.SapSystem do
database_health: database_health
}
) do
if instances_have_abap?(instances) and instances_have_messageserver?(instances) do
if instances_have_abap_or_java?(instances) and instances_have_messageserver?(instances) do
%SapSystemRegistered{
sap_system_id: sap_system_id,
sid: sid,
Expand Down Expand Up @@ -794,7 +794,7 @@ defmodule Trento.SapSystems.SapSystem do
},
deregistered_at
) do
unless instances_have_abap?(instances) and instances_have_messageserver?(instances) do
unless instances_have_abap_or_java?(instances) and instances_have_messageserver?(instances) do
%SapSystemDeregistered{sap_system_id: sap_system_id, deregistered_at: deregistered_at}
end
end
Expand All @@ -814,6 +814,14 @@ defmodule Trento.SapSystems.SapSystem do
Enum.any?(instances, fn %{features: features} -> features =~ "ABAP" end)
end

defp instances_have_java?(instances) do
Enum.any?(instances, fn %{features: features} -> features =~ "J2EE" end)
end

defp instances_have_abap_or_java?(instances) do
instances_have_abap?(instances) or instances_have_java?(instances)
end

def instances_have_messageserver?(instances) do
Enum.any?(instances, fn %{features: features} -> features =~ "MESSAGESERVER" end)
end
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/cypress/e2e/sap_systems_overview.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ context('SAP Systems Overview', () => {
.within(() => {
cy.get('td').eq(2).contains(attachedDatabase.sid);
cy.get('td').eq(3).contains(attachedDatabase.tenant);
cy.get('td').eq(4).contains(attachedDatabase.dbAddress);

cy.get('td').eq(5).contains(attachedDatabase.dbAddress);
});
});
it(`should have a link to the attached HANA database with id: ${attachedDatabase.id}`, () => {
Expand Down
Loading

0 comments on commit 9ed6d26

Please sign in to comment.