-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-structurizr-conversion.js
More file actions
142 lines (128 loc) · 4.01 KB
/
test-structurizr-conversion.js
File metadata and controls
142 lines (128 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Test script to verify Structurizr import/export functionality
* Run with: node test-structurizr-conversion.js
*/
// Sample BAC4 model
const sampleBac4Model = {
metadata: {
name: 'Test E-Commerce System',
version: '1.0',
author: 'Test User'
},
systems: [
{
id: 'system-1',
type: 'system',
name: 'E-Commerce Platform',
description: 'Main e-commerce system',
technology: 'Java Spring',
tags: ['Core'],
position: { x: 100, y: 100 }
}
],
externalSystems: [
{
id: 'externalSystem-1',
type: 'externalSystem',
name: 'Payment Gateway',
description: 'Third-party payment processor',
technology: '',
tags: ['External'],
position: { x: 400, y: 100 }
}
],
people: [
{
id: 'person-1',
type: 'person',
name: 'Customer',
description: 'Online shopper',
technology: '',
tags: [],
position: { x: 100, y: 300 }
}
],
containers: [],
components: [],
relationships: [
{
id: 'rel-1',
from: 'person-1',
to: 'system-1',
description: 'Places orders',
technology: 'HTTPS',
arrowDirection: 'right',
lineStyle: 'solid',
animated: false
},
{
id: 'rel-2',
from: 'system-1',
to: 'externalSystem-1',
description: 'Processes payments',
technology: 'REST API',
arrowDirection: 'right',
lineStyle: 'solid',
animated: false
}
]
};
// Import the conversion functions
import { exportToStructurizr, importFromStructurizr } from './src/utils/structurizrUtils.js';
console.log('🧪 Testing Structurizr Conversion\n');
console.log('='.repeat(50));
// Test export
console.log('\n1️⃣ Testing BAC4 → Structurizr Export');
console.log('-'.repeat(50));
try {
const structurizrWorkspace = exportToStructurizr(sampleBac4Model);
console.log('✅ Export successful!');
console.log('\nStructurizr Workspace Structure:');
console.log(' - Name:', structurizrWorkspace.name);
console.log(' - Version:', structurizrWorkspace.version);
console.log(' - People:', structurizrWorkspace.model.people.length);
console.log(' - Systems:', structurizrWorkspace.model.softwareSystems.length);
console.log(' - Views:', Object.keys(structurizrWorkspace.views).length);
// Test import
console.log('\n2️⃣ Testing Structurizr → BAC4 Import');
console.log('-'.repeat(50));
const importedModel = importFromStructurizr(structurizrWorkspace);
console.log('✅ Import successful!');
console.log('\nImported BAC4 Model Structure:');
console.log(' - Name:', importedModel.metadata.name);
console.log(' - People:', importedModel.people.length);
console.log(' - Systems:', importedModel.systems.length);
console.log(' - External Systems:', importedModel.externalSystems.length);
console.log(' - Relationships:', importedModel.relationships.length);
// Verify round-trip conversion preserves data
console.log('\n3️⃣ Verifying Round-Trip Conversion');
console.log('-'.repeat(50));
const originalCount = {
people: sampleBac4Model.people.length,
systems: sampleBac4Model.systems.length,
externalSystems: sampleBac4Model.externalSystems.length,
relationships: sampleBac4Model.relationships.length
};
const importedCount = {
people: importedModel.people.length,
systems: importedModel.systems.length,
externalSystems: importedModel.externalSystems.length,
relationships: importedModel.relationships.length
};
const allMatch = Object.keys(originalCount).every(
key => originalCount[key] === importedCount[key]
);
if (allMatch) {
console.log('✅ All elements preserved correctly!');
} else {
console.log('⚠️ Element counts differ:');
console.log(' Original:', originalCount);
console.log(' Imported:', importedCount);
}
console.log('\n' + '='.repeat(50));
console.log('✨ All tests passed!\n');
} catch (error) {
console.error('❌ Test failed:', error.message);
console.error(error.stack);
process.exit(1);
}