Skip to content

Commit f0652de

Browse files
committed
added tests for production decomposition
1 parent e396675 commit f0652de

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
Include SourceControl.Git
2+
3+
Class UnitTest.SourceControl.Git.ProductionDecomposition Extends %UnitTest.TestCase
4+
{
5+
6+
Parameter ProductionName = "UnitTest.SampleProduction";
7+
8+
Property SourceControlGlobal [ MultiDimensional ];
9+
10+
Property InitialExtension As %String [ InitialExpression = {##class(%Studio.SourceControl.Interface).SourceControlClassGet()} ];
11+
12+
Method TestDecomposeExistingProduction()
13+
{
14+
do $System.OBJ.Delete(..#ProductionName)
15+
set settings = ##class(SourceControl.Git.Settings).%New()
16+
set settings.decomposeProductions = 0
17+
$$$ThrowOnError(settings.%Save())
18+
$$$ThrowOnError(##class(SourceControl.Git.Production).CreateProduction(..#ProductionName))
19+
do ..ReplaceProductionDefinition("ProductionDefinition1")
20+
$$$ThrowOnError(##class(SourceControl.Git.Utils).AddToSourceControl(..#ProductionName_".cls"))
21+
do $$$AssertTrue(##class(SourceControl.Git.Utils).IsInSourceControl(..#ProductionName_".cls"))
22+
$$$ThrowOnError(##class(SourceControl.Git.Utils).Commit(..#ProductionName_".cls"))
23+
24+
set settings.decomposeProductions = 1
25+
$$$ThrowOnError(settings.%Save())
26+
do ##class(SourceControl.Git.API).BaselineProductions()
27+
do ##class(SourceControl.Git.Utils).RunGitCommand("add",,,".")
28+
do ##class(SourceControl.Git.Utils).RunGitCommand("commit",,,"-m","decomposing production from unit test")
29+
do $$$AssertTrue(##class(SourceControl.Git.Utils).IsInSourceControl("UnitTest.SampleProduction||ProductionSettings-UnitTest.SampleProduction.PTD"))
30+
do $$$AssertTrue(##class(SourceControl.Git.Utils).IsInSourceControl("UnitTest.SampleProduction||Settings-a|Ens.Activity.Operation.Local.PTD"))
31+
do $$$AssertNotTrue(##class(SourceControl.Git.Utils).IsInSourceControl(..#ProductionName_".cls"))
32+
33+
set settings.decomposeProductions = 0
34+
$$$ThrowOnError(settings.%Save())
35+
do ##class(SourceControl.Git.API).BaselineProductions()
36+
do ##class(SourceControl.Git.Utils).RunGitCommand("add",,,".")
37+
do ##class(SourceControl.Git.Utils).RunGitCommand("commit",,,"-m","recomposing production from unit test")
38+
do $$$AssertNotTrue(##class(SourceControl.Git.Utils).IsInSourceControl("UnitTest.SampleProduction||ProductionSettings-UnitTest.SampleProduction.PTD"))
39+
do $$$AssertNotTrue(##class(SourceControl.Git.Utils).IsInSourceControl("UnitTest.SampleProduction||Settings-a|Ens.Activity.Operation.Local.PTD"))
40+
do $$$AssertTrue(##class(SourceControl.Git.Utils).IsInSourceControl(..#ProductionName_".cls"))
41+
}
42+
43+
Method TestEditProduction()
44+
{
45+
new %session, %request, %SourceControl
46+
set %session = ##class(%CSP.Session).%New("dummysession")
47+
set %request = ##class(%CSP.Request).%New()
48+
set %request.Data("pageclass",1) = "EnsPortal.dummy"
49+
do $System.OBJ.Delete(..#ProductionName)
50+
$$$ThrowOnError(##class(SourceControl.Git.Utils).NewBranch("branch1"))
51+
$$$ThrowOnError(##class(SourceControl.Git.Utils).SwitchBranch("branch1"))
52+
$$$ThrowOnError(##class(SourceControl.Git.Production).CreateProduction(..#ProductionName))
53+
do ##class(%Studio.SourceControl.Interface).SourceControlCreate()
54+
$$$ThrowOnError(##class(SourceControl.Git.Utils).AddToSourceControl(..#ProductionName_".cls"))
55+
56+
do $$$LogMessage("with production decomposition enabled, the production class should not be in source control.")
57+
do $$$AssertNotTrue(##class(SourceControl.Git.Utils).IsInSourceControl(..#ProductionName_".cls"))
58+
do $$$LogMessage("initial creation of a production should export production settings and add to source control.")
59+
$$$ThrowOnError(%SourceControl.OnBeforeSave(..#ProductionName_".cls"))
60+
$$$ThrowOnError(%SourceControl.OnAfterSave(..#ProductionName_".cls"))
61+
do $$$AssertTrue(##class(SourceControl.Git.Utils).IsInSourceControl("UnitTest.SampleProduction||ProductionSettings-UnitTest.SampleProduction.PTD"))
62+
63+
do $$$LogMessage("adding a production item")
64+
$$$ThrowOnError(%SourceControl.OnBeforeSave(..#ProductionName_".cls"))
65+
do ..ReplaceProductionDefinition("ProductionDefinition1")
66+
$$$ThrowOnError(%SourceControl.OnAfterSave(..#ProductionName_".cls"))
67+
do $$$AssertTrue(##class(SourceControl.Git.Utils).IsInSourceControl("UnitTest.SampleProduction||Settings-a|Ens.Activity.Operation.Local.PTD"))
68+
69+
do $$$LogMessage("committing changes to production settings")
70+
do ##class(SourceControl.Git.Utils).RunGitCommand("add",,,".")
71+
do ##class(SourceControl.Git.Utils).Commit("UnitTest.SampleProduction||ProductionSettings-UnitTest.SampleProduction.PTD")
72+
do ##class(SourceControl.Git.Utils).Commit("UnitTest.SampleProduction||Settings-a|Ens.Activity.Operation.Local.PTD")
73+
74+
do $$$LogMessage("switching to a new branch")
75+
$$$ThrowOnError(##class(SourceControl.Git.Utils).NewBranch("branch2"))
76+
$$$ThrowOnError(##class(SourceControl.Git.Utils).SwitchBranch("branch2"))
77+
78+
do $$$LogMessage("modifying an existing item and adding a new item")
79+
$$$ThrowOnError(%SourceControl.OnBeforeSave(..#ProductionName_".cls"))
80+
set production = ##class(Ens.Config.Production).%OpenId(..#ProductionName)
81+
set production.Items.GetAt(1).Enabled = 0
82+
do ..ReplaceProductionDefinition("ProductionDefinition2")
83+
$$$ThrowOnError(%SourceControl.OnAfterSave(..#ProductionName_".cls"))
84+
do $$$AssertTrue(##class(SourceControl.Git.Utils).IsInSourceControl("UnitTest.SampleProduction||Settings-b|Ens.Activity.Operation.Local.PTD"))
85+
do ##class(SourceControl.Git.Utils).RunGitCommand("add",,,".")
86+
do ##class(SourceControl.Git.Utils).Commit("UnitTest.SampleProduction||Settings-a|Ens.Activity.Operation.Local.PTD")
87+
do ##class(SourceControl.Git.Utils).Commit("UnitTest.SampleProduction||Settings-b|Ens.Activity.Operation.Local.PTD")
88+
$$$ThrowOnError(production.%Reload())
89+
do $$$AssertEquals(production.Items.Count(), 2)
90+
91+
do $$$LogMessage("switching back to the original branch")
92+
$$$ThrowOnError(##class(SourceControl.Git.Utils).SwitchBranch("branch1"))
93+
$$$ThrowOnError(production.%Reload())
94+
do $$$AssertEquals(production.Items.Count(), 1)
95+
do $$$AssertEquals(production.Items.GetAt(1).Settings.GetAt(1).Name, "RecordStatsInterval")
96+
do $$$AssertEquals(production.Items.GetAt(1).Settings.GetAt(1).Value, 61)
97+
}
98+
99+
ClassMethod ReplaceProductionDefinition(pXDataName)
100+
{
101+
new %SourceControl
102+
set productionClass = ##class(%Dictionary.ClassDefinition).%OpenId(..#ProductionName)
103+
do productionClass.XDatas.Clear()
104+
set productionXData = ##class(%Dictionary.XDataDefinition).%New()
105+
set xdata = ##class(%Dictionary.XDataDefinition).IDKEYOpen($classname(),pXDataName,,.st)
106+
$$$ThrowOnError(st)
107+
set productionXData = xdata.%ConstructClone(1)
108+
set productionXData.Name = "ProductionDefinition"
109+
set st = productionClass.XDatas.Insert(productionXData)
110+
$$$ThrowOnError(st)
111+
set st = productionClass.%Save()
112+
$$$ThrowOnError(st)
113+
set st = $System.OBJ.Compile(..#ProductionName)
114+
$$$ThrowOnError(st)
115+
set st = ##class(Ens.Production).Update()
116+
$$$ThrowOnError(st)
117+
}
118+
119+
XData ProductionDefinition1
120+
{
121+
<Production Name="UnitTest.SampleProduction" LogGeneralTraceEvents="false">
122+
<Item Name="a" Category="" ClassName="Ens.Activity.Operation.Local" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
123+
</Item>
124+
</Production>
125+
}
126+
127+
XData ProductionDefinition2
128+
{
129+
<Production Name="UnitTest.SampleProduction" LogGeneralTraceEvents="false">
130+
<Item Name="a" Category="" ClassName="Ens.Activity.Operation.Local" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
131+
<Setting Target="Host" Name="RecordStatsInterval">61</Setting>
132+
</Item>
133+
<Item Name="b" Category="" ClassName="Ens.Activity.Operation.Local" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
134+
</Item>
135+
</Production>
136+
}
137+
138+
Method OnBeforeAllTests() As %Status
139+
{
140+
merge ..SourceControlGlobal = ^SYS("SourceControl")
141+
return $$$OK
142+
}
143+
144+
Method OnBeforeOneTest() As %Status
145+
{
146+
kill ^SYS("SourceControl")
147+
do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("SourceControl.Git.Extension")
148+
set settings = ##class(SourceControl.Git.Settings).%New()
149+
set settings.decomposeProductions = 1
150+
Set settings.namespaceTemp = ##class(%Library.File).TempFilename()_"dir"
151+
Set settings.Mappings("PTD","*")="ptd/"
152+
$$$ThrowOnError(settings.%Save())
153+
// using work queue manager ensures proper OS user context/file ownership
154+
set workMgr = $System.WorkMgr.%New("")
155+
$$$ThrowOnError(workMgr.Queue("##class(SourceControl.Git.Utils).Init"))
156+
$$$ThrowOnError(workMgr.WaitForComplete())
157+
quit $$$OK
158+
}
159+
160+
Method %OnClose() As %Status
161+
{
162+
do ##class(%Studio.SourceControl.Interface).SourceControlClassSet(..InitialExtension)
163+
kill ^SYS("SourceControl")
164+
merge ^SYS("SourceControl") = ..SourceControlGlobal
165+
do $System.OBJ.Delete(..#ProductionName)
166+
quit $$$OK
167+
}
168+
169+
}

0 commit comments

Comments
 (0)