Skip to content

Commit 43bc856

Browse files
committed
For #6902: test persistence API
1 parent af8d3da commit 43bc856

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Copyright (C) 2025 Orbeon, Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under the terms of the
5+
* GNU Lesser General Public License as published by the Free Software Foundation; either version
6+
* 2.1 of the License, or (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
* See the GNU Lesser General Public License for more details.
11+
*
12+
* The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
13+
*/
14+
package org.orbeon.oxf.fr.persistence.test
15+
16+
import org.orbeon.dom
17+
import org.orbeon.dom.Document
18+
import org.orbeon.oxf.externalcontext.SafeRequestContext
19+
import org.orbeon.oxf.fr.Version._
20+
import org.orbeon.oxf.fr.permission._
21+
import org.orbeon.oxf.fr.persistence.db._
22+
import org.orbeon.oxf.fr.persistence.http.{HttpAssert, HttpCall}
23+
import org.orbeon.oxf.fr.persistence.relational.Provider
24+
import org.orbeon.oxf.fr.persistence.relational.Provider._
25+
import org.orbeon.oxf.http.StatusCode
26+
import org.orbeon.oxf.test.{DocumentTestBase, ResourceManagerSupport, XFormsSupport, XMLSupport}
27+
import org.orbeon.oxf.util.{IndentedLogger, LoggerFactory}
28+
import org.orbeon.oxf.xml.dom.Converter._
29+
import org.scalatest.funspec.AnyFunSpecLike
30+
31+
class SingletonTest
32+
extends DocumentTestBase
33+
with AnyFunSpecLike
34+
with ResourceManagerSupport
35+
with XMLSupport
36+
with XFormsSupport {
37+
38+
private implicit val Logger: IndentedLogger = new IndentedLogger(LoggerFactory.createLogger(classOf[SingletonTest]), true)
39+
40+
private def createSingletonForm(provider: Provider, isSingleton: Boolean, formName: String)(implicit safeRequestCtx: SafeRequestContext): Unit = {
41+
val formURL = HttpCall.crudURLPrefix(provider, formName) + "form/form.xhtml"
42+
val form = HttpCall.XML(
43+
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">
44+
<xh:head>
45+
<xf:model id="fr-form-model">
46+
<xf:instance id="fr-form-metadata">
47+
<metadata>
48+
<application-name>{provider.entryName}</application-name>
49+
<form-name>{formName}</form-name>
50+
{if (isSingleton) <singleton>true</singleton> else null}
51+
</metadata>
52+
</xf:instance>
53+
</xf:model>
54+
</xh:head>
55+
</xh:html>.toDocument
56+
)
57+
HttpAssert.put(formURL, Unspecified, form, StatusCode.Created)
58+
}
59+
60+
describe("Singleton forms") {
61+
it("second PUT should succeed regular forms, fail for singleton forms") {
62+
withTestSafeRequestContext { implicit safeRequestCtx =>
63+
Connect.withOrbeonTables("singleton document creation") { (_, provider) =>
64+
val singletonSecondPut = List(
65+
true -> StatusCode.Conflict,
66+
false -> StatusCode.Created
67+
)
68+
for ((isSingleton, expectedStatus) <- singletonSecondPut) {
69+
val formName = s"singleton-$isSingleton"
70+
createSingletonForm(provider, isSingleton, formName)
71+
val dataURL1 = HttpCall.crudURLPrefix(provider, formName) + "data/1/data.xml"
72+
val dataURL2 = HttpCall.crudURLPrefix(provider, formName) + "data/2/data.xml"
73+
val formData = HttpCall.XML(<form/>.toDocument)
74+
HttpAssert.put(dataURL1, Specific(1), formData, StatusCode.Created)
75+
HttpAssert.put(dataURL2, Specific(1), formData, expectedStatus)
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)