Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions event-bus-seedwork-node/node-event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CustomDomainEvent, DomainEvent } from '../domain-seedwork/domain-event'
import { EventBus } from '../domain-seedwork/event-bus';
import api, { trace,TimeInput, SpanStatusCode } from '@opentelemetry/api';
import { SemanticAttributes } from "@opentelemetry/semantic-conventions";
import { off } from 'process';

class BroadCaster {
private eventEmitter: EventEmitter;
Expand All @@ -18,6 +19,11 @@ class BroadCaster {
public on(event: string, listener: any) {
this.eventEmitter.on(event, listener);
}

public removeAllListeners() {
this.eventEmitter.removeAllListeners();
console.log(`pending listeners: ${this.eventEmitter.eventNames()}`)
}
}

class NodeEventBusImpl implements EventBus {
Expand All @@ -28,6 +34,12 @@ class NodeEventBusImpl implements EventBus {
this.broadcaster = new BroadCaster();
}

removeAllListeners() {
console.log('Removing all listeners');
this.broadcaster.removeAllListeners();
console.log('All listeners removed');
}

async dispatch<T extends DomainEvent>(event: new(...args:any) => T, data: any): Promise<void> {
console.log(`Dispatching node event ${event.constructor.name} with data ${JSON.stringify(data)}`);

Expand All @@ -52,7 +64,7 @@ class NodeEventBusImpl implements EventBus {
}
});
}

register<EventProps,T extends CustomDomainEvent<EventProps>>(event:new(...args:any) => T, func:(payload:T['payload']) => Promise<void>): void {
console.log(`Registering node event handler for: ${event.name}`);

Expand Down Expand Up @@ -84,7 +96,7 @@ class NodeEventBusImpl implements EventBus {
} catch(e) {
span.recordException(e);
span.setStatus({code: SpanStatusCode.ERROR, message: `NodeEventBus: Error executing ${event.name}`});
console.error(`Error handling node event ${event.name} with data ${rawPayload}`);
console.error(`Error handling node event ${event.name} with data ${JSON.stringify(rawPayload)}`);
console.error(e);
} finally {
span.end();
Expand Down
5 changes: 5 additions & 0 deletions features/ike.feature1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Test IW
Scenario: Test IW
Given IwTheTest not working
When IwTheTest is not working
Then IwTheTest does not work
10 changes: 5 additions & 5 deletions features/service-ticket.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Feature: Create a service ticket

Background:
Given OwenTheOwner creates Atlantis community
And he creates CommunityManager role in Atlantis community with following permissions:
Background:
Given OwenTheOwner creates Atlantis community
And he creates CommunityManager role in Atlantis community with following permissions:
| communityPermissions | canManageRolesAndPermissions, canManageSiteContent, canManageMembers |
| serviceTicketPermissions | canManageTickets |
| servicePermissions | canManageServices |
Expand Down Expand Up @@ -41,8 +41,8 @@ Background:



Scenario: Setup
Given test setup
Scenario: Setup Service Ticket
Given test setup
# Given SamTheSystem creates community Palms
# And SamTheSystem creates property Cottage in Atlantis
# And he creates property Villa in Atlantis
Expand Down
10 changes: 5 additions & 5 deletions features/split-steps.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Feature: Create a service ticket

Background:
Given OttoTheOwner registers with Owner Community
And he creates community named Palms
Background:
Given OttoTheOwner registers with Owner Community
And he creates community named Palms
# And he creates CommunityManager role in Atlantis community with following permissions:
# | communityPermissions | canManageRolesAndPermissions, canManageSiteContent, canManageMembers |
# | serviceTicketPermissions | canManageTickets |
Expand Down Expand Up @@ -42,8 +42,8 @@ Background:



Scenario: Setup
Given test setup
Scenario: Setup Split
Given test setup
# Given SamTheSystem creates community Palms
# And SamTheSystem creates property Cottage in Atlantis
# And he creates property Villa in Atlantis
Expand Down
5 changes: 5 additions & 0 deletions features/step-definitions/iw.steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Given, Then, When } from "@cucumber/cucumber";

Given('{actor} not working', function(actor){});
When('{actor} not is working', function(actor){});
Then('{actor} does not work', function(actor){});
16 changes: 13 additions & 3 deletions features/step-definitions/service-ticket.steps.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import { Given, When, DataTable } from '@cucumber/cucumber';
import { Actor } from '@serenity-js/core';
import { Actor, Wait } from '@serenity-js/core';
import { CreateRole } from '../../screenplay/tasks/create-role';
import { CreateCommunity } from '../../screenplay/tasks/create-community';
import { Register } from '../../screenplay/tasks/register';
import { CreateProperty } from '../../screenplay/tasks/create-property';
import { LogDataSources } from '../../screenplay/tasks/log-data-sources';
import { CommunityInDb } from '../../screenplay/questions/community-in-db';
import { Ensure, isPresent } from '@serenity-js/assertions';
import { RoleForCommunityInDb } from '../../screenplay/questions/role-for-community-in-db';

Given('test setup', async function(){});

Given('{actor} creates {word} community', async function(actor: Actor, communityName: string){
await actor
.attemptsTo(
Register.asUser()
, CreateCommunity.named(communityName)
, await CreateCommunity.named(communityName)
// , Wait.until((await CommunityInDb(communityName)), isPresent())
// , Wait.until((await RoleForCommunityInDb(communityName, 'admin')), isPresent())
, Ensure.eventually((await RoleForCommunityInDb(communityName, 'admin')), isPresent())
// , LogDataSources()
,LogDataSources('service-ticket-steps::{actor}'),
);
});

When('{pronoun} creates {word} role in {word} community with following permissions:', async function(actor: Actor, roleName: string, communityName: string, dataTable: DataTable){
console.log(` ^^ actor: ${actor.name}`)
LogDataSources('service-ticket-steps::{pronoun}'),
console.log(`+++ after log data sources`)
await actor
.attemptsTo(
CreateRole
Expand All @@ -27,8 +37,8 @@ Given('{actor} creates {word} community', async function(actor: Actor, community
, CreateProperty
.inCommunity(communityName)
.asNewPropertyNamed('property1')
// , LogDataSources()
);
console.log(`@@@ after tasks`)
});


Expand Down
2 changes: 2 additions & 0 deletions features/step-definitions/split-steps.steps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Given, When } from '@cucumber/cucumber';
import { Actor } from '@serenity-js/core';
import { Register } from '../../screenplay/tasks/register';
import { CreateCommunity } from '../../screenplay/tasks/create-community';

Given('{actor} registers with Owner Community', async function(actor: Actor){
await actor
.attemptsTo(
Register.asUser(),
await CreateCommunity.named('other-community'),
);
});

Expand Down
21 changes: 19 additions & 2 deletions features/support/serenity.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterAll, BeforeAll, setDefaultTimeout, defineParameterType, Before } from '@cucumber/cucumber';
import { AfterAll, BeforeAll, setDefaultTimeout, defineParameterType, Before, After } from '@cucumber/cucumber';
import { ConsoleReporter } from '@serenity-js/console-reporter';
import { actorCalled, actorInTheSpotlight, ArtifactArchiver, configure, Duration } from '@serenity-js/core';
import { SerenityBDDReporter } from '@serenity-js/serenity-bdd';
Expand Down Expand Up @@ -28,10 +28,27 @@ const timeouts = {

// let browser: playwright.Browser;

Before(() => {
Before(function logScenarioNameBefore(scenario) {
console.log(`*** BEFORE Scenario : ${scenario.pickle.name} **************************************`);
InteractWithTheDomain.init();
});

After(function logScenarioNameBefore(scenario) {
InteractWithTheDomain.close();
console.log(`*** AFTER Scenario : ${scenario.pickle.name} **************************************`);
});

const { AfterStep, BeforeStep } = require('@cucumber/cucumber');

BeforeStep(async function logStepNameBefore(step) {
console.log(`=== BEFORE Step : ${step.pickleStep.text} ======================================`);
InteractWithTheDomain.asReadOnly().logDatabase('BeforeStep');
});

AfterStep(async function logStepNameAfter(step) {
console.log(`=== AFTER Step : ${step.pickleStep.text} ======================================`);
});

BeforeAll(async () => {
// InteractWithTheDomain.init();
// Launch the browser once before all the tests
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions features/test2.feature1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Feature: Test MG2
Scenario: Test MG2
Given Mg2TheTest working
28 changes: 19 additions & 9 deletions screenplay/abilities/domain/interact-with-the-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { RoleProps } from '../../../domain/contexts/community/role';
import { MemberRepository } from '../../../domain/contexts/community/member.repository';
import { Member, MemberEntityReference, MemberProps } from '../../../domain/contexts/community/member';
import { DomainExecutionContext } from '../../../domain/contexts/execution-context';
import { getDomainInfrastructureImplInstanceBDD } from './io/domain-infrastructure-impl-instance-bdd';
// import { getDomainInfrastructureImplInstanceBDD } from './io/domain-infrastructure-impl-instance-bdd';
import { DomainInfrastructureImplBDD } from './io/domain-infrastructure-impl-instance-bdd';
import InitializeDomainBDD from './io/test/initialize-domain-bdd';
import { ReadOnlyContext, SystemExecutionContext } from '../../../domain/contexts/execution-context';
import { PassportImpl } from '../../../domain/contexts/iam/passport';
Expand All @@ -22,6 +23,7 @@ import { NotepadType } from '../../actors';
import { MemoryCognitiveSearchImpl } from '../../../infrastructure-impl/cognitive-search/in-memory/infrastructure';
import { PropertyRepository } from '../../../domain/contexts/property/property.repository';
import { PropertyProps } from '../../../domain/contexts/property/property';
import { InProcEventBusInstance, NodeEventBusInstance } from '../../../event-bus-seedwork-node';

export interface InteractWithTheDomainAsUnregisteredUser {
registerAsUser: (actor: Actor) => Promise<InteractWithTheDomainAsRegisteredUser>;
Expand Down Expand Up @@ -51,8 +53,8 @@ export interface InteractWithTheDomainAsReadOnly {
readMemberDb: (func:(db: ReadOnlyMemoryStore<MemberProps>) => Promise<void>) => Promise<void>;
readUserDb: (func:(db: ReadOnlyMemoryStore<UserProps>) => Promise<void>) => Promise<void>;
readPropertyDb: (func:(db: ReadOnlyMemoryStore<PropertyProps>) => Promise<void>) => Promise<void>;
logSearchDatabase: () => Promise<void>;
logDatabase: () => Promise<void>;
logSearchDatabase: (description: string) => Promise<void>;
logDatabase: (description: string) => Promise<void>;
}

export class InteractWithTheDomain extends Ability
Expand All @@ -72,14 +74,22 @@ export class InteractWithTheDomain extends Ability
// if(this._initialized === false) {
this.startWithEmptyDatabase();
this.startWithEmptySearchDatabase();
InitializeDomainBDD(getDomainInfrastructureImplInstanceBDD(
InitializeDomainBDD(new DomainInfrastructureImplBDD(
InteractWithTheDomain._database,
InteractWithTheDomain._searchDatabase
));
// InitializeDomainBDD(getDomainInfrastructureImplInstanceBDD(
// InteractWithTheDomain._database,
// InteractWithTheDomain._searchDatabase
// ));
// this._initialized = true;
// }
}

public static close() {
NodeEventBusInstance.removeAllListeners();
}

private static using(context: DomainExecutionContext) {
// this.init();
return new InteractWithTheDomain(context);
Expand Down Expand Up @@ -217,7 +227,7 @@ export class InteractWithTheDomain extends Ability

public async createCommunity(communityName: string): Promise<CommunityProps> {
let community: CommunityProps;
InteractWithTheDomain._database.CommunityUnitOfWork.withTransaction(this.context, async (repo) => {
await InteractWithTheDomain._database.CommunityUnitOfWork.withTransaction(this.context, async (repo) => {
const user: UserEntityReference = await this.getOrCreateUserForActor(actorInTheSpotlight());
const communityToBeSaved = await repo.getNewInstance(communityName, user);
const savedCommunity = await repo.save(communityToBeSaved);
Expand Down Expand Up @@ -275,13 +285,13 @@ export class InteractWithTheDomain extends Ability
return await func(InteractWithTheDomain._database.PropertyMemoryStore);
}

public async logSearchDatabase() {
console.log('===> Memory Search Database ************');
public async logSearchDatabase(description: string) {
console.log(`===> Memory Search Database : ${description} ************`);
InteractWithTheDomain._searchDatabase.logSearchCollectionIndexMap();
}

public async logDatabase() {
console.log('===> Memory Database ************');
public async logDatabase(description: string) {
console.log(`===> Memory Database : ${description} ************`);
await InteractWithTheDomain.asReadOnly().readCommunityDb(async (db) => {
console.log('===> database > community : ', JSON.stringify(db));
});
Expand Down
Loading