diff --git a/.gitignore b/.gitignore index 0bcec2d40..b9edd18c5 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ bin repairXMLFull.xml xml-with-props.xml +ml-development-tools/src/test/ml-modules +ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/generated diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 584292f54..459d75f90 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,6 +41,10 @@ Individual tests can be run in the following manner (replace `GraphsTest` with t ./gradlew marklogic-client-api:test --tests GraphsTest +Tests for the ml-development-tools Gradle plugin can be run via: + + ./gradlew ml-development-tools:test + You can also undeploy the test application if you do not wish to keep it around on your MarkLogic instance: ./gradlew mlUndeploy -i -Pconfirm=true diff --git a/Jenkinsfile b/Jenkinsfile index ec250d204..8243386cc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -50,8 +50,6 @@ def runAllTests(String type, String version, Boolean useReverseProxy){ export PATH=$GRADLE_USER_HOME:$JAVA_HOME/bin:$PATH cd java-client-api mkdir -p ml-development-tools/build/test-results/test - ./gradlew ml-development-tools:setupTestServer || true - ./gradlew ml-development-tools:generateTests || true ./gradlew ml-development-tools:test || true ''' diff --git a/ml-development-tools/build.gradle b/ml-development-tools/build.gradle index e42758f1e..d4934f1c1 100644 --- a/ml-development-tools/build.gradle +++ b/ml-development-tools/build.gradle @@ -75,20 +75,11 @@ compileTestKotlin { kotlinOptions.jvmTarget = '1.8' } -task setupTestServer(type: JavaExec) { - classpath = sourceSets.test.runtimeClasspath - main = 'com.marklogic.client.test.dbfunction.FntestconfKt' - args = [ 'setup' ] -} task generateTests(type: JavaExec) { - dependsOn setupTestServer classpath = sourceSets.test.runtimeClasspath main = 'com.marklogic.client.test.dbfunction.FntestgenKt' args = [ './src/test/', 'latest' ] } -task teardownTestServer(type: JavaExec) { - dependsOn test - classpath = sourceSets.test.runtimeClasspath - main = 'com.marklogic.client.test.dbfunction.FntestconfKt' - args = [ 'teardown' ] -} + +// Allows running "./gradlew test" without having to remember to generate the tests first. +test.dependsOn generateTests diff --git a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/DBFunctionTestUtil.java b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/DBFunctionTestUtil.java index 6c06749a6..a0968a06b 100644 --- a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/DBFunctionTestUtil.java +++ b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/DBFunctionTestUtil.java @@ -40,7 +40,7 @@ private static DatabaseClient makeRestClientImpl(DatabaseClientFactory.DigestAut return makeClientImpl(auth, "8012", false); } private static DatabaseClient makeTestClientImpl(DatabaseClientFactory.DigestAuthContext auth) { - return makeClientImpl(auth, "8016", true); + return makeClientImpl(auth, "8013", true); } private static DatabaseClient makeClientImpl( DatabaseClientFactory.DigestAuthContext auth, String defaultPort, boolean withCheck diff --git a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/AnyDocumentBundle.java b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/AnyDocumentBundle.java index abff1ed0f..53d2c0944 100644 --- a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/AnyDocumentBundle.java +++ b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/AnyDocumentBundle.java @@ -2,8 +2,8 @@ // IMPORTANT: Do not edit. This file is generated. -import java.util.stream.Stream; import com.marklogic.client.io.Format; +import java.util.stream.Stream; import com.marklogic.client.DatabaseClient; @@ -48,40 +48,55 @@ final class AnyDocumentBundleImpl implements AnyDocumentBundle { private DatabaseClient dbClient; private BaseProxy baseProxy; - private BaseProxy.DBFunctionRequest req_sendReceiveManyDocs; - private BaseProxy.DBFunctionRequest req_sendReceiveRequiredDoc; private BaseProxy.DBFunctionRequest req_sendReceiveOptionalDoc; private BaseProxy.DBFunctionRequest req_sendReceiveAnyDocs; + private BaseProxy.DBFunctionRequest req_sendReceiveRequiredDoc; + private BaseProxy.DBFunctionRequest req_sendReceiveManyDocs; private BaseProxy.DBFunctionRequest req_sendReceiveMappedDoc; private AnyDocumentBundleImpl(DatabaseClient dbClient, JSONWriteHandle servDecl) { this.dbClient = dbClient; this.baseProxy = new BaseProxy("/dbf/test/anyDocument/", servDecl); - this.req_sendReceiveManyDocs = this.baseProxy.request( - "sendReceiveManyDocs.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_MIXED); - this.req_sendReceiveRequiredDoc = this.baseProxy.request( - "sendReceiveRequiredDoc.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_MIXED); this.req_sendReceiveOptionalDoc = this.baseProxy.request( "sendReceiveOptionalDoc.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_MIXED); this.req_sendReceiveAnyDocs = this.baseProxy.request( "sendReceiveAnyDocs.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_MIXED); + this.req_sendReceiveRequiredDoc = this.baseProxy.request( + "sendReceiveRequiredDoc.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_MIXED); + this.req_sendReceiveManyDocs = this.baseProxy.request( + "sendReceiveManyDocs.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_MIXED); this.req_sendReceiveMappedDoc = this.baseProxy.request( "sendReceiveMappedDoc.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_MIXED); } @Override - public Stream sendReceiveManyDocs(Stream uris, Stream docs) { - return sendReceiveManyDocs( - this.req_sendReceiveManyDocs.on(this.dbClient), uris, docs + public com.marklogic.client.io.InputStreamHandle sendReceiveOptionalDoc(String uri, com.marklogic.client.io.InputStreamHandle doc) { + return sendReceiveOptionalDoc( + this.req_sendReceiveOptionalDoc.on(this.dbClient), uri, doc ); } - private Stream sendReceiveManyDocs(BaseProxy.DBFunctionRequest request, Stream uris, Stream docs) { + private com.marklogic.client.io.InputStreamHandle sendReceiveOptionalDoc(BaseProxy.DBFunctionRequest request, String uri, com.marklogic.client.io.InputStreamHandle doc) { return request .withParams( - BaseProxy.atomicParam("uris", false, BaseProxy.StringType.fromString(uris)), - BaseProxy.documentParam("docs", false, docs) - ).responseMultiple(false, Format.UNKNOWN) + BaseProxy.atomicParam("uri", true, BaseProxy.StringType.fromString(uri)), + BaseProxy.documentParam("doc", true, doc) + ).responseSingle(true, Format.UNKNOWN) + .asHandle(new com.marklogic.client.io.InputStreamHandle()); + } + + @Override + public Stream sendReceiveAnyDocs(Stream uris, Stream docs) { + return sendReceiveAnyDocs( + this.req_sendReceiveAnyDocs.on(this.dbClient), uris, docs + ); + } + private Stream sendReceiveAnyDocs(BaseProxy.DBFunctionRequest request, Stream uris, Stream docs) { + return request + .withParams( + BaseProxy.atomicParam("uris", true, BaseProxy.StringType.fromString(uris)), + BaseProxy.documentParam("docs", true, docs) + ).responseMultiple(true, Format.UNKNOWN) .asStreamOfHandles(null, new com.marklogic.client.io.InputStreamHandle()); } @@ -101,32 +116,17 @@ private com.marklogic.client.io.InputStreamHandle sendReceiveRequiredDoc(BasePro } @Override - public com.marklogic.client.io.InputStreamHandle sendReceiveOptionalDoc(String uri, com.marklogic.client.io.InputStreamHandle doc) { - return sendReceiveOptionalDoc( - this.req_sendReceiveOptionalDoc.on(this.dbClient), uri, doc - ); - } - private com.marklogic.client.io.InputStreamHandle sendReceiveOptionalDoc(BaseProxy.DBFunctionRequest request, String uri, com.marklogic.client.io.InputStreamHandle doc) { - return request - .withParams( - BaseProxy.atomicParam("uri", true, BaseProxy.StringType.fromString(uri)), - BaseProxy.documentParam("doc", true, doc) - ).responseSingle(true, Format.UNKNOWN) - .asHandle(new com.marklogic.client.io.InputStreamHandle()); - } - - @Override - public Stream sendReceiveAnyDocs(Stream uris, Stream docs) { - return sendReceiveAnyDocs( - this.req_sendReceiveAnyDocs.on(this.dbClient), uris, docs + public Stream sendReceiveManyDocs(Stream uris, Stream docs) { + return sendReceiveManyDocs( + this.req_sendReceiveManyDocs.on(this.dbClient), uris, docs ); } - private Stream sendReceiveAnyDocs(BaseProxy.DBFunctionRequest request, Stream uris, Stream docs) { + private Stream sendReceiveManyDocs(BaseProxy.DBFunctionRequest request, Stream uris, Stream docs) { return request .withParams( - BaseProxy.atomicParam("uris", true, BaseProxy.StringType.fromString(uris)), - BaseProxy.documentParam("docs", true, docs) - ).responseMultiple(true, Format.UNKNOWN) + BaseProxy.atomicParam("uris", false, BaseProxy.StringType.fromString(uris)), + BaseProxy.documentParam("docs", false, docs) + ).responseMultiple(false, Format.UNKNOWN) .asStreamOfHandles(null, new com.marklogic.client.io.InputStreamHandle()); } @@ -150,40 +150,40 @@ private com.marklogic.client.io.StringHandle sendReceiveMappedDoc(BaseProxy.DBFu } /** - * Invokes the sendReceiveManyDocs operation on the database server + * Invokes the sendReceiveOptionalDoc operation on the database server * - * @param uris provides input - * @param docs provides input + * @param uri provides input + * @param doc provides input * @return as output */ - Stream sendReceiveManyDocs(Stream uris, Stream docs); + com.marklogic.client.io.InputStreamHandle sendReceiveOptionalDoc(String uri, com.marklogic.client.io.InputStreamHandle doc); /** - * Invokes the sendReceiveRequiredDoc operation on the database server + * Invokes the sendReceiveAnyDocs operation on the database server * - * @param uri provides input - * @param doc provides input + * @param uris provides input + * @param docs provides input * @return as output */ - com.marklogic.client.io.InputStreamHandle sendReceiveRequiredDoc(String uri, com.marklogic.client.io.InputStreamHandle doc); + Stream sendReceiveAnyDocs(Stream uris, Stream docs); /** - * Invokes the sendReceiveOptionalDoc operation on the database server + * Invokes the sendReceiveRequiredDoc operation on the database server * * @param uri provides input * @param doc provides input * @return as output */ - com.marklogic.client.io.InputStreamHandle sendReceiveOptionalDoc(String uri, com.marklogic.client.io.InputStreamHandle doc); + com.marklogic.client.io.InputStreamHandle sendReceiveRequiredDoc(String uri, com.marklogic.client.io.InputStreamHandle doc); /** - * Invokes the sendReceiveAnyDocs operation on the database server + * Invokes the sendReceiveManyDocs operation on the database server * * @param uris provides input * @param docs provides input * @return as output */ - Stream sendReceiveAnyDocs(Stream uris, Stream docs); + Stream sendReceiveManyDocs(Stream uris, Stream docs); /** * Invokes the sendReceiveMappedDoc operation on the database server diff --git a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/DecoratorBaseBundle.java b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/DecoratorBaseBundle.java index ee85839c8..e135a3317 100644 --- a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/DecoratorBaseBundle.java +++ b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/DecoratorBaseBundle.java @@ -24,7 +24,7 @@ public interface DecoratorBaseBundle { * @return an object for executing database operations */ static DecoratorBaseBundle on(DatabaseClient db) { - return on(db, null); + return on(db, null); } /** * Creates a DecoratorBaseBundle object for executing operations on the database server. @@ -54,21 +54,21 @@ private DecoratorBaseBundleImpl(DatabaseClient dbClient, JSONWriteHandle servDec this.baseProxy = new BaseProxy("/dbf/test/decoratorBase/", servDecl); this.req_docify = this.baseProxy.request( - "docify.sjs", BaseProxy.ParameterValuesKind.SINGLE_ATOMIC); + "docify.sjs", BaseProxy.ParameterValuesKind.SINGLE_ATOMIC); } @Override public com.fasterxml.jackson.databind.JsonNode docify(String value) { return docify( - this.req_docify.on(this.dbClient), value - ); + this.req_docify.on(this.dbClient), value + ); } private com.fasterxml.jackson.databind.JsonNode docify(BaseProxy.DBFunctionRequest request, String value) { - return BaseProxy.JsonDocumentType.toJsonNode( - request - .withParams( - BaseProxy.atomicParam("value", true, BaseProxy.StringType.fromString(value)) - ).responseSingle(true, Format.JSON) + return BaseProxy.JsonDocumentType.toJsonNode( + request + .withParams( + BaseProxy.atomicParam("value", true, BaseProxy.StringType.fromString(value)) + ).responseSingle(true, Format.JSON) ); } } @@ -76,12 +76,12 @@ private com.fasterxml.jackson.databind.JsonNode docify(BaseProxy.DBFunctionReque return new DecoratorBaseBundleImpl(db, serviceDeclaration); } - /** - * Invokes the docify operation on the database server - * - * @param value provides input - * @return as output - */ + /** + * Invokes the docify operation on the database server + * + * @param value provides input + * @return as output + */ com.fasterxml.jackson.databind.JsonNode docify(String value); } diff --git a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/SessionsBundle.java b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/SessionsBundle.java index 73c26702b..1f0ef0aaa 100644 --- a/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/SessionsBundle.java +++ b/ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/positive/SessionsBundle.java @@ -47,33 +47,33 @@ final class SessionsBundleImpl implements SessionsBundle { private DatabaseClient dbClient; private BaseProxy baseProxy; - private BaseProxy.DBFunctionRequest req_beginTransactionNoSession; + private BaseProxy.DBFunctionRequest req_beginTransaction; + private BaseProxy.DBFunctionRequest req_getSessionField; private BaseProxy.DBFunctionRequest req_checkTransaction; - private BaseProxy.DBFunctionRequest req_sleepify; private BaseProxy.DBFunctionRequest req_rollbackTransaction; + private BaseProxy.DBFunctionRequest req_sleepify; private BaseProxy.DBFunctionRequest req_setSessionField; - private BaseProxy.DBFunctionRequest req_getSessionField; - private BaseProxy.DBFunctionRequest req_beginTransaction; + private BaseProxy.DBFunctionRequest req_beginTransactionNoSession; private BaseProxy.DBFunctionRequest req_setSessionFieldNoSession; private SessionsBundleImpl(DatabaseClient dbClient, JSONWriteHandle servDecl) { this.dbClient = dbClient; this.baseProxy = new BaseProxy("/dbf/test/sessions/", servDecl); - this.req_beginTransactionNoSession = this.baseProxy.request( - "beginTransactionNoSession.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_ATOMICS); + this.req_beginTransaction = this.baseProxy.request( + "beginTransaction.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_ATOMICS); + this.req_getSessionField = this.baseProxy.request( + "getSessionField.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_ATOMICS); this.req_checkTransaction = this.baseProxy.request( "checkTransaction.sjs", BaseProxy.ParameterValuesKind.SINGLE_ATOMIC); - this.req_sleepify = this.baseProxy.request( - "sleepify.sjs", BaseProxy.ParameterValuesKind.SINGLE_ATOMIC); this.req_rollbackTransaction = this.baseProxy.request( "rollbackTransaction.sjs", BaseProxy.ParameterValuesKind.NONE); + this.req_sleepify = this.baseProxy.request( + "sleepify.sjs", BaseProxy.ParameterValuesKind.SINGLE_ATOMIC); this.req_setSessionField = this.baseProxy.request( "setSessionField.sjs", BaseProxy.ParameterValuesKind.SINGLE_ATOMIC); - this.req_getSessionField = this.baseProxy.request( - "getSessionField.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_ATOMICS); - this.req_beginTransaction = this.baseProxy.request( - "beginTransaction.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_ATOMICS); + this.req_beginTransactionNoSession = this.baseProxy.request( + "beginTransactionNoSession.sjs", BaseProxy.ParameterValuesKind.MULTIPLE_ATOMICS); this.req_setSessionFieldNoSession = this.baseProxy.request( "setSessionFieldNoSession.sjs", BaseProxy.ParameterValuesKind.SINGLE_ATOMIC); } @@ -83,13 +83,14 @@ public SessionState newSessionState() { } @Override - public void beginTransactionNoSession(String uri, String text) { - beginTransactionNoSession( - this.req_beginTransactionNoSession.on(this.dbClient), uri, text + public void beginTransaction(SessionState transaction, String uri, String text) { + beginTransaction( + this.req_beginTransaction.on(this.dbClient), transaction, uri, text ); } - private void beginTransactionNoSession(BaseProxy.DBFunctionRequest request, String uri, String text) { + private void beginTransaction(BaseProxy.DBFunctionRequest request, SessionState transaction, String uri, String text) { request + .withSession("transaction", transaction, false) .withParams( BaseProxy.atomicParam("uri", false, BaseProxy.StringType.fromString(uri)), BaseProxy.atomicParam("text", false, BaseProxy.StringType.fromString(text)) @@ -97,33 +98,34 @@ private void beginTransactionNoSession(BaseProxy.DBFunctionRequest request, Stri } @Override - public Boolean checkTransaction(SessionState transaction, String uri) { - return checkTransaction( - this.req_checkTransaction.on(this.dbClient), transaction, uri + public Boolean getSessionField(SessionState timestamper, String fieldName, Long fieldValue) { + return getSessionField( + this.req_getSessionField.on(this.dbClient), timestamper, fieldName, fieldValue ); } - private Boolean checkTransaction(BaseProxy.DBFunctionRequest request, SessionState transaction, String uri) { + private Boolean getSessionField(BaseProxy.DBFunctionRequest request, SessionState timestamper, String fieldName, Long fieldValue) { return BaseProxy.BooleanType.toBoolean( request - .withSession("transaction", transaction, true) + .withSession("timestamper", timestamper, false) .withParams( - BaseProxy.atomicParam("uri", false, BaseProxy.StringType.fromString(uri)) + BaseProxy.atomicParam("fieldName", false, BaseProxy.StringType.fromString(fieldName)), + BaseProxy.atomicParam("fieldValue", false, BaseProxy.UnsignedLongType.fromLong(fieldValue)) ).responseSingle(false, null) ); } @Override - public Boolean sleepify(SessionState sleeper, Integer sleeptime) { - return sleepify( - this.req_sleepify.on(this.dbClient), sleeper, sleeptime + public Boolean checkTransaction(SessionState transaction, String uri) { + return checkTransaction( + this.req_checkTransaction.on(this.dbClient), transaction, uri ); } - private Boolean sleepify(BaseProxy.DBFunctionRequest request, SessionState sleeper, Integer sleeptime) { + private Boolean checkTransaction(BaseProxy.DBFunctionRequest request, SessionState transaction, String uri) { return BaseProxy.BooleanType.toBoolean( request - .withSession("sleeper", sleeper, false) + .withSession("transaction", transaction, true) .withParams( - BaseProxy.atomicParam("sleeptime", false, BaseProxy.UnsignedIntegerType.fromInteger(sleeptime)) + BaseProxy.atomicParam("uri", false, BaseProxy.StringType.fromString(uri)) ).responseSingle(false, null) ); } @@ -140,47 +142,45 @@ private void rollbackTransaction(BaseProxy.DBFunctionRequest request, SessionSta } @Override - public Long setSessionField(SessionState timestamper, String fieldName) { - return setSessionField( - this.req_setSessionField.on(this.dbClient), timestamper, fieldName + public Boolean sleepify(SessionState sleeper, Integer sleeptime) { + return sleepify( + this.req_sleepify.on(this.dbClient), sleeper, sleeptime ); } - private Long setSessionField(BaseProxy.DBFunctionRequest request, SessionState timestamper, String fieldName) { - return BaseProxy.UnsignedLongType.toLong( + private Boolean sleepify(BaseProxy.DBFunctionRequest request, SessionState sleeper, Integer sleeptime) { + return BaseProxy.BooleanType.toBoolean( request - .withSession("timestamper", timestamper, false) + .withSession("sleeper", sleeper, false) .withParams( - BaseProxy.atomicParam("fieldName", false, BaseProxy.StringType.fromString(fieldName)) + BaseProxy.atomicParam("sleeptime", false, BaseProxy.UnsignedIntegerType.fromInteger(sleeptime)) ).responseSingle(false, null) ); } @Override - public Boolean getSessionField(SessionState timestamper, String fieldName, Long fieldValue) { - return getSessionField( - this.req_getSessionField.on(this.dbClient), timestamper, fieldName, fieldValue + public Long setSessionField(SessionState timestamper, String fieldName) { + return setSessionField( + this.req_setSessionField.on(this.dbClient), timestamper, fieldName ); } - private Boolean getSessionField(BaseProxy.DBFunctionRequest request, SessionState timestamper, String fieldName, Long fieldValue) { - return BaseProxy.BooleanType.toBoolean( + private Long setSessionField(BaseProxy.DBFunctionRequest request, SessionState timestamper, String fieldName) { + return BaseProxy.UnsignedLongType.toLong( request .withSession("timestamper", timestamper, false) .withParams( - BaseProxy.atomicParam("fieldName", false, BaseProxy.StringType.fromString(fieldName)), - BaseProxy.atomicParam("fieldValue", false, BaseProxy.UnsignedLongType.fromLong(fieldValue)) + BaseProxy.atomicParam("fieldName", false, BaseProxy.StringType.fromString(fieldName)) ).responseSingle(false, null) ); } @Override - public void beginTransaction(SessionState transaction, String uri, String text) { - beginTransaction( - this.req_beginTransaction.on(this.dbClient), transaction, uri, text + public void beginTransactionNoSession(String uri, String text) { + beginTransactionNoSession( + this.req_beginTransactionNoSession.on(this.dbClient), uri, text ); } - private void beginTransaction(BaseProxy.DBFunctionRequest request, SessionState transaction, String uri, String text) { + private void beginTransactionNoSession(BaseProxy.DBFunctionRequest request, String uri, String text) { request - .withSession("transaction", transaction, false) .withParams( BaseProxy.atomicParam("uri", false, BaseProxy.StringType.fromString(uri)), BaseProxy.atomicParam("text", false, BaseProxy.StringType.fromString(text)) @@ -212,31 +212,33 @@ private void setSessionFieldNoSession(BaseProxy.DBFunctionRequest request, Strin SessionState newSessionState(); /** - * Invokes the beginTransactionNoSession operation on the database server + * Invokes the beginTransaction operation on the database server * + * @param transaction provides input * @param uri provides input * @param text provides input * */ - void beginTransactionNoSession(String uri, String text); + void beginTransaction(SessionState transaction, String uri, String text); /** - * Invokes the checkTransaction operation on the database server + * Invokes the getSessionField operation on the database server * - * @param transaction provides input - * @param uri provides input + * @param timestamper provides input + * @param fieldName provides input + * @param fieldValue provides input * @return as output */ - Boolean checkTransaction(SessionState transaction, String uri); + Boolean getSessionField(SessionState timestamper, String fieldName, Long fieldValue); /** - * Invokes the sleepify operation on the database server + * Invokes the checkTransaction operation on the database server * - * @param sleeper provides input - * @param sleeptime provides input + * @param transaction provides input + * @param uri provides input * @return as output */ - Boolean sleepify(SessionState sleeper, Integer sleeptime); + Boolean checkTransaction(SessionState transaction, String uri); /** * Invokes the rollbackTransaction operation on the database server @@ -247,33 +249,31 @@ private void setSessionFieldNoSession(BaseProxy.DBFunctionRequest request, Strin void rollbackTransaction(SessionState transaction); /** - * Invokes the setSessionField operation on the database server + * Invokes the sleepify operation on the database server * - * @param timestamper provides input - * @param fieldName provides input + * @param sleeper provides input + * @param sleeptime provides input * @return as output */ - Long setSessionField(SessionState timestamper, String fieldName); + Boolean sleepify(SessionState sleeper, Integer sleeptime); /** - * Invokes the getSessionField operation on the database server + * Invokes the setSessionField operation on the database server * * @param timestamper provides input * @param fieldName provides input - * @param fieldValue provides input * @return as output */ - Boolean getSessionField(SessionState timestamper, String fieldName, Long fieldValue); + Long setSessionField(SessionState timestamper, String fieldName); /** - * Invokes the beginTransaction operation on the database server + * Invokes the beginTransactionNoSession operation on the database server * - * @param transaction provides input * @param uri provides input * @param text provides input * */ - void beginTransaction(SessionState transaction, String uri, String text); + void beginTransactionNoSession(String uri, String text); /** * Invokes the setSessionFieldNoSession operation on the database server diff --git a/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestconf.kt b/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestconf.kt deleted file mode 100644 index 8f8410110..000000000 --- a/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestconf.kt +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2022 MarkLogic Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.marklogic.client.test.dbfunction - -import com.fasterxml.jackson.databind.ObjectWriter -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import com.marklogic.client.DatabaseClientFactory -import com.marklogic.client.io.DocumentMetadataHandle -import com.marklogic.client.io.InputStreamHandle -import okhttp3.MediaType.Companion.toMediaTypeOrNull -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.RequestBody.Companion.toRequestBody - -const val contentDbName = "DBFUnitTest" -const val modulesDbName = "DBFUnitTestModules" -const val serverName = "DBFUnitTest" -val host = System.getenv("TEST_HOST") ?: "localhost" -val serverPort = System.getenv("TEST_PORT")?.toInt() ?: 8016 - -fun main(args: Array) { - val mapper = jacksonObjectMapper() - val serializer = mapper.writerWithDefaultPrettyPrinter() - -/* TODO: -skip - setup operations where result is present - teardown where result is absent -amp the test inspector to add header -create roles and users -parameterize the port, user name, etc - */ - when(val operation = if (args.isNotEmpty()) args[0] else "setup") { - "setup" -> dbfTestSetup(serializer) - "teardown" -> dbfTestTeardown(serializer) - else -> throw java.lang.IllegalArgumentException("unknown operation: $operation") - } -} -fun dbfTestSetup(serializer: ObjectWriter) { - setupServer(serializer) - setupModules() -} -fun dbfTestTeardown(serializer: ObjectWriter) { - teardownServer(serializer) -} -fun setupServer(serializer: ObjectWriter) { - val dbClient = DatabaseClientFactory.newClient( - host, - 8002, - DatabaseClientFactory.DigestAuthContext("admin", "admin") - ) - - val client = dbClient.clientImplementation as OkHttpClient - - for (dbName in listOf(contentDbName, modulesDbName)) { - createEntity( - client, serializer, "databases", "database", dbName, - mapOf("database-name" to dbName) - ) - - val forestName = "$dbName-1" - createEntity( - client, serializer, "forests", "forest", forestName, - mapOf("forest-name" to forestName, "database" to dbName) - ) - } - - val userName = "rest-reader" - if (!existsEntity(client, "users", "user", userName)) { - createEntity( - client, serializer, "users", "user", userName, - mapOf( - "user-name" to userName, - "password" to "x", - "role" to listOf(userName) - ) - ) - } - - createEntity( - client, serializer, "servers?group-id=Default&server-type=http", "appserver", serverName, - mapOf( - "server-name" to serverName, - "root" to "/", - "port" to serverPort, - "content-database" to contentDbName, - "modules-database" to modulesDbName - ) - ) - - dbClient.release() -} -fun existsEntity(client: OkHttpClient, address: String, name: String, instanceName: String) : Boolean { - val response = client.newCall( - Request.Builder() - .url("""http://${host}:8002/manage/v2/${address}/${instanceName}""") - .get() - .build() - ).execute() - val status = response.code - if (status < 400) return true - if (status == 404) return false - throw RuntimeException("""Could not create $instanceName ${name}: $status""") -} -fun createEntity(client: OkHttpClient, serializer: ObjectWriter, address: String, name: String, - instanceName: String, instancedef: Map) { - val response = client.newCall( - Request.Builder() - .url("""http://${host}:8002/manage/v2/${address}""") - .post( - serializer.writeValueAsString(instancedef).toRequestBody("application/json".toMediaTypeOrNull()) - ) - .build() - ).execute() - if (response.code >= 400) { - throw RuntimeException("""Could not create $instanceName ${name}: ${response.code}""") - } -} -fun setupModules() { - val dbClient = DatabaseClientFactory.newClient( - host, - 8000, - "DBFUnitTestModules", - DatabaseClientFactory.DigestAuthContext("admin", "admin") - ) - - val docMgr = dbClient.newJSONDocumentManager() - - val docMeta = DocumentMetadataHandle() - - val docPerm = docMeta.permissions - docPerm.add("rest-reader", DocumentMetadataHandle.Capability.EXECUTE) - - for (scriptName in listOf("testInspector")) { - val scriptPath = """./${scriptName}.sjs""" - val scriptUri = """/dbf/test/${scriptName}.sjs""" - - val inspectorStream = DBFunctionTestUtil.getResourceAsStream(scriptPath) - - docMgr.write(scriptUri, docMeta, InputStreamHandle(inspectorStream)) - } - - dbClient.release() -} -fun teardownServer(serializer: ObjectWriter) { - val dbClient = DatabaseClientFactory.newClient( - host, - 8002, - DatabaseClientFactory.DigestAuthContext("admin", "admin") - ) - - val client = dbClient.clientImplementation as OkHttpClient - - val response = client.newCall( - Request.Builder() - .url("""http://${host}:8002/manage/v2/servers/$serverName/properties?group-id=Default""") - .put(serializer.writeValueAsString( - mapOf("content-database" to 0, "modules-database" to 0) - ).toRequestBody("application/json".toMediaTypeOrNull()) - ) - .build() - ).execute() - if (response.code >= 400) { - throw RuntimeException("""Could not detach $serverName appserver: ${response.code}""") - } - - for (dbName in listOf(contentDbName, modulesDbName)) { - deleteEntity(client, """databases/${dbName}?forest-delete=data""", "database", dbName) - } - - deleteEntity(client, """servers/$serverName?group-id=Default""", "appserver", serverName) - - dbClient.release() -} -fun deleteEntity(client: OkHttpClient, address: String, name: String, instanceName: String) { - val response = client.newCall( - Request.Builder() - .url("""http://${host}:8002/manage/v2/${address}""") - .delete() - .build() - ).execute() - if (response.code >= 400) { - throw RuntimeException("""Could not delete $instanceName ${name}: ${response.code}""") - } -} diff --git a/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt b/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt index 97ce2b7f4..e248d4dad 100644 --- a/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt +++ b/ml-development-tools/src/test/kotlin/com/marklogic/client/test/dbfunction/fntestgen.kt @@ -565,13 +565,13 @@ fun dbfTestGenerate(testDir: String, release: String) { val db = DatabaseClientFactory.newClient( host, 8000, - "DBFUnitTest", + "java-dev-tools-content", DatabaseClientFactory.DigestAuthContext("admin", "admin") ) val modDb = DatabaseClientFactory.newClient( host, 8000, - "DBFUnitTestModules", + "java-unittest-modules", DatabaseClientFactory.DigestAuthContext("admin", "admin") ) diff --git a/test-app/src/main/ml-config/databases/dev-tools-content.json b/test-app/src/main/ml-config/databases/dev-tools-content.json new file mode 100644 index 000000000..5b356824a --- /dev/null +++ b/test-app/src/main/ml-config/databases/dev-tools-content.json @@ -0,0 +1,3 @@ +{ + "database-name": "java-dev-tools-content" +} diff --git a/test-app/src/main/ml-config/servers/dev-tools-test.json b/test-app/src/main/ml-config/servers/dev-tools-test.json new file mode 100644 index 000000000..bb992821e --- /dev/null +++ b/test-app/src/main/ml-config/servers/dev-tools-test.json @@ -0,0 +1,9 @@ +{ + "server-name": "java-dev-tools-test", + "port": 8013, + "server-type": "http", + "root": "/", + "content-database": "java-dev-tools-content", + "modules-database": "java-unittest-modules", + "authentication": "digestbasic" +} diff --git a/ml-development-tools/src/test/resources/testInspector.sjs b/test-app/src/main/ml-modules/root/dbf/test/testInspector.sjs similarity index 100% rename from ml-development-tools/src/test/resources/testInspector.sjs rename to test-app/src/main/ml-modules/root/dbf/test/testInspector.sjs