Skip to content

Commit 8692ef7

Browse files
author
cgreer
committed
bootstrapping refactor
git-svn-id: svn+ssh://svn.marklogic.com/project/engsvn/client-api/java/branches/b1_0@145165 62cac252-8da6-4816-9e9d-6dc37b19578c
1 parent 7343d14 commit 8692ef7

File tree

6 files changed

+155
-78
lines changed

6 files changed

+155
-78
lines changed

pom.xml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@
5454
</execution>
5555
</executions>
5656
</plugin>
57-
<plugin>
58-
<groupId>com.marklogic</groupId>
59-
<artifactId>client-api-bootstrap</artifactId>
60-
<version>1.1-SNAPSHOT</version>
61-
<executions>
62-
<execution>
63-
<id>bootstrap</id>
64-
<phase>pre-clean</phase>
65-
<goals>
66-
<goal>bootstrap</goal>
67-
</goals>
68-
</execution>
69-
</executions>
70-
</plugin>
7157
<plugin>
7258
<groupId>org.apache.maven.plugins</groupId>
7359
<artifactId>maven-jar-plugin</artifactId>
@@ -239,18 +225,4 @@
239225
<scope>provided</scope>
240226
</dependency>
241227
</dependencies>
242-
<pluginRepositories>
243-
<pluginRepository>
244-
<id>ci</id>
245-
<name>MarkLogic CI Repository</name>
246-
<url>http://ci.marklogic.com:8080/jenkins/plugin/repository/everything/</url>
247-
<layout>default</layout>
248-
<snapshots>
249-
<enabled>true</enabled>
250-
</snapshots>
251-
<releases>
252-
<updatePolicy>never</updatePolicy>
253-
</releases>
254-
</pluginRepository>
255-
</pluginRepositories>
256228
</project>

src/main/java/com/marklogic/client/example/util/Bootstrapper.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Bootstrapper {
5353
* @param args command-line arguments specifying the configuration and REST server
5454
*/
5555
public static void main(String[] args)
56-
throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError {
56+
throws ClientProtocolException, IOException, FactoryConfigurationError {
5757
Properties properties = new Properties();
5858
for (int i=0; i < args.length; i++) {
5959
String name = args[i];
@@ -100,7 +100,7 @@ public static void main(String[] args)
100100
* @param properties the specification of the configuration and REST server
101101
*/
102102
public void makeServer(Properties properties)
103-
throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError {
103+
throws ClientProtocolException, IOException, FactoryConfigurationError {
104104
makeServer(new ConfigServer(properties), new RESTServer(properties));
105105
}
106106
/**
@@ -109,7 +109,7 @@ public void makeServer(Properties properties)
109109
* @param restServer the specification of the REST server
110110
*/
111111
public void makeServer(ConfigServer configServer, RESTServer restServer)
112-
throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError {
112+
throws ClientProtocolException, IOException, FactoryConfigurationError {
113113

114114
DefaultHttpClient client = new DefaultHttpClient();
115115

@@ -142,7 +142,12 @@ else if (authType == Authentication.DIGEST)
142142

143143
BasicHttpContext context = new BasicHttpContext();
144144

145-
StringEntity content = new StringEntity(restServer.toXMLString());
145+
StringEntity content;
146+
try {
147+
content = new StringEntity(restServer.toXMLString());
148+
} catch (XMLStreamException e) {
149+
throw new IOException("Could not create payload to bootstrap server.");
150+
}
146151
content.setContentType("application/xml");
147152

148153
HttpPost poster = new HttpPost("http://"+host+":"+configPort+"/v1/rest-apis");

src/test/java/com/marklogic/client/test/util/TestServerBootstrapper.java

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1+
/*
2+
* Copyright 2012-2013 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.marklogic.client.test.util;
217

18+
import java.io.File;
319
import java.io.IOException;
420

5-
import javax.xml.stream.FactoryConfigurationError;
6-
import javax.xml.stream.XMLStreamException;
7-
821
import org.apache.http.HttpEntity;
922
import org.apache.http.HttpResponse;
1023
import org.apache.http.auth.AuthScope;
1124
import org.apache.http.auth.UsernamePasswordCredentials;
1225
import org.apache.http.client.ClientProtocolException;
1326
import org.apache.http.client.methods.HttpDelete;
1427
import org.apache.http.client.methods.HttpPost;
28+
import org.apache.http.client.methods.HttpPut;
29+
import org.apache.http.entity.FileEntity;
1530
import org.apache.http.impl.client.DefaultHttpClient;
16-
import org.slf4j.Logger;
17-
import org.slf4j.LoggerFactory;
18-
19-
import com.marklogic.client.DatabaseClientFactory;
20-
import com.marklogic.client.DatabaseClientFactory.Authentication;
21-
import com.marklogic.client.FailedRequestException;
22-
import com.marklogic.client.admin.ExtensionMetadata;
23-
import com.marklogic.client.admin.MethodType;
24-
import com.marklogic.client.admin.ResourceExtensionsManager;
25-
import com.marklogic.client.admin.ResourceExtensionsManager.MethodParameters;
31+
2632
import com.marklogic.client.example.util.Bootstrapper;
27-
import com.marklogic.client.io.InputStreamHandle;
2833

2934
/**
3035
* This test manages a REST instance to support Java unit tests. It installs a resource
@@ -34,26 +39,21 @@
3439
* Calling the main method with no arguments sets up a REST server on port
3540
* 8012 for the test harness.
3641
*
37-
* TODO make a suitable command-line interface for end-users
38-
*
3942
*/
4043
public class TestServerBootstrapper {
4144

42-
private static final Logger logger = (Logger) LoggerFactory
43-
.getLogger(TestServerBootstrapper.class);
44-
4545
private String username = "admin";
4646
private String password = "admin";
4747
private String host = "localhost";
4848
private int port = 8012;
4949

5050
private void bootstrapRestServer() throws ClientProtocolException,
51-
IOException, XMLStreamException, FactoryConfigurationError {
51+
IOException {
5252

5353
Bootstrapper.main(new String[] {"-configuser", username, "-configpassword", password, "-confighost", host, "-restserver", "java-unittest", "-restport", ""+port, "-restdb", "java-unittest"});
5454

5555

56-
logger.info("Bootstrapped rest server for unit tests on port 8012");
56+
System.out.println("Bootstrapped rest server for unit tests on port 8012");
5757
}
5858

5959
private void deleteRestServer() throws ClientProtocolException, IOException {
@@ -87,40 +87,32 @@ private void invokeBootstrapExtension() throws ClientProtocolException,
8787
HttpResponse response = client.execute(post);
8888
@SuppressWarnings("unused")
8989
HttpEntity entity = response.getEntity();
90-
logger.info("Invoked bootstrap extension. Response is "
90+
System.out.println("Invoked bootstrap extension. Response is "
9191
+ response.toString());
9292
}
9393

9494
private void installBootstrapExtension() throws IOException {
9595

96-
ResourceExtensionsManager extensionMgr = DatabaseClientFactory
97-
.newClient(host, port, username, password,
98-
Authentication.DIGEST).newServerConfigManager()
99-
.newResourceExtensionsManager();
100-
101-
InputStreamHandle handle = new InputStreamHandle();
102-
103-
ExtensionMetadata metadata = new ExtensionMetadata();
104-
metadata.setTitle("Test Resource Services");
105-
metadata.setDescription("This library supports all methods on the test resource");
106-
metadata.setProvider("MarkLogic");
107-
metadata.setVersion("0.1");
96+
DefaultHttpClient client = new DefaultHttpClient();
10897

109-
MethodParameters[] params = new MethodParameters[1];
110-
params[0] = new MethodParameters(MethodType.POST);
98+
client.getCredentialsProvider().setCredentials(
99+
new AuthScope("localhost", port),
100+
new UsernamePasswordCredentials(username, password));
111101

112-
handle.set(TestServerBootstrapper.class.getClassLoader().getResourceAsStream("bootstrap.xqy"));
102+
HttpPut put = new HttpPut("http://" + host + ":" + port
103+
+ "/v1/config/resources/bootstrap?method=post");
113104

114-
try {
115-
extensionMgr.writeServices("bootstrap", handle, metadata, params);
116-
} catch (FailedRequestException e) {
117-
e.printStackTrace();
118-
}
105+
put.setEntity(new FileEntity(new File("src/test/resources/bootstrap.xqy"), "application/xquery"));
106+
HttpResponse response = client.execute(put);
107+
@SuppressWarnings("unused")
108+
HttpEntity entity = response.getEntity();
109+
System.out.println("Installed bootstrap extension. Response is "
110+
+ response.toString());
119111

120112
}
121-
113+
122114
public static void main(String[] args) throws ClientProtocolException,
123-
IOException, XMLStreamException, FactoryConfigurationError {
115+
IOException {
124116
TestServerBootstrapper bootstrapper = new TestServerBootstrapper();
125117

126118
if ((args.length == 1) && (args[0].equals("teardown"))) {

src/test/resources/boot-test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
DEFAULT_M2=$HOME/.m2/repository
4+
M2_REPO=${1:-$DEFAULT_M2}
5+
6+
java -cp target/test-classes:target/classes:$M2_REPO/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar:$M2_REPO/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar:$M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:$M2_REPO/org/slf4j/slf4j-api/1.7.4/slf4j-api-1.7.4.jar com.marklogic.client.test.util.TestServerBootstrapper
Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ as empty-sequence()
2525
"http://marklogic.com/xdmp/property","last-modified","",false() )
2626
let $c := admin:database-add-range-element-index($c, $dbid, $rangespec)
2727

28+
let $rangespec := admin:database-range-element-index("string",
29+
"http://nwalsh.com/ns/photolib","tag","http://marklogic.com/collation/",false() )
30+
let $c := admin:database-add-range-element-index($c, $dbid, $rangespec)
31+
let $rangespec := admin:database-range-element-index("date",
32+
"http://nwalsh.com/ns/photolib","date","",false() )
33+
let $c := admin:database-add-range-element-index($c, $dbid, $rangespec)
34+
let $rangespec := admin:database-range-element-attribute-index("date",
35+
"http://nwalsh.com/ns/photolib","view","","date","",false() )
36+
let $c := admin:database-add-range-element-attribute-index($c, $dbid, $rangespec)
2837
let $rangespec := admin:database-range-element-index("double",
2938
"","double","",false() )
3039
let $c := admin:database-add-range-element-index($c, $dbid, $rangespec)
@@ -34,6 +43,12 @@ as empty-sequence()
3443
let $rangespec := admin:database-range-element-index("string",
3544
"","grandchild","http://marklogic.com/collation/",false() )
3645
let $c := admin:database-add-range-element-index($c, $dbid, $rangespec)
46+
let $rangespec := admin:database-range-element-index("string",
47+
"","string","http://marklogic.com/collation/",false() )
48+
let $c := admin:database-add-range-element-index($c, $dbid, $rangespec)
49+
let $wordspec := admin:database-element-word-lexicon(
50+
"","suggest","http://marklogic.com/collation/")
51+
let $c := admin:database-add-element-word-lexicon($c, $dbid, $wordspec)
3752

3853
(: create geospatial indexes for geo unit test :)
3954
let $geospec := admin:database-geospatial-element-pair-index(
@@ -495,6 +510,70 @@ declare function bootstrap:load-data()
495510
<element-test attribute-test="5"/>
496511
<element-test attribute-test="9"/>
497512
</root>),
513+
xdmp:document-insert(
514+
"/sample/tuples-test1.xml",
515+
<root name="first">
516+
<child id="1">
517+
<double>1.1</double>
518+
<int>1</int>
519+
<string>Alaska</string>
520+
</child>
521+
</root>
522+
),
523+
xdmp:document-set-permissions("/sample/tuples-test1.xml",
524+
(xdmp:permission("rest-reader","read"),
525+
xdmp:permission("rest-writer","update"),
526+
xdmp:permission("app-user","read"),
527+
xdmp:permission("app-user","update"))
528+
),
529+
xdmp:document-insert(
530+
"/sample/tuples-test2.xml",
531+
<root name="second">
532+
<child id="3">
533+
<double>1.1</double>
534+
<int>3</int>
535+
<string>Birmingham</string>
536+
</child>
537+
</root>
538+
),
539+
xdmp:document-set-permissions("/sample/tuples-test2.xml",
540+
(xdmp:permission("rest-reader","read"),
541+
xdmp:permission("rest-writer","update"),
542+
xdmp:permission("app-user","read"),
543+
xdmp:permission("app-user","update"))
544+
),
545+
xdmp:document-insert(
546+
"/sample/tuples-test3.xml",
547+
<root name="second">
548+
<child id="3">
549+
<double>1.2</double>
550+
<int>3</int>
551+
<string>Birmingham</string>
552+
</child>
553+
</root>
554+
),
555+
xdmp:document-set-permissions("/sample/tuples-test3.xml",
556+
(xdmp:permission("rest-reader","read"),
557+
xdmp:permission("rest-writer","update"),
558+
xdmp:permission("app-user","read"),
559+
xdmp:permission("app-user","update"))
560+
),
561+
xdmp:document-insert(
562+
"/sample/tuples-test4.xml",
563+
<root name="second">
564+
<child id="3">
565+
<double>1.2</double>
566+
<int>3</int>
567+
<string>Alaska</string>
568+
</child>
569+
</root>
570+
),
571+
xdmp:document-set-permissions("/sample/tuples-test4.xml",
572+
(xdmp:permission("rest-reader","read"),
573+
xdmp:permission("rest-writer","update"),
574+
xdmp:permission("app-user","read"),
575+
xdmp:permission("app-user","update"))
576+
),
498577
xdmp:document-set-permissions("/sample/udf-test.xml",
499578
(xdmp:permission("rest-reader","read"),
500579
xdmp:permission("rest-writer","update"),
@@ -508,7 +587,22 @@ declare function bootstrap:load-data()
508587
xdmp:document-set-permissions("/sample/legacy space file.xml",
509588
(xdmp:permission("rest-reader","read"),
510589
xdmp:permission("rest-writer","update"))
511-
)
590+
),
591+
592+
xdmp:document-insert("/sample/suggestion.xml",
593+
<suggest><string>FINDME</string>Something I love to suggest is sugar with savory succulent limes.</suggest>),
594+
xdmp:document-set-permissions("/sample/suggestion.xml",
595+
(xdmp:permission("rest-reader","read"),
596+
xdmp:permission("rest-writer","update"))
597+
),
598+
xdmp:document-add-collections("/sample/suggestion.xml",("http://some.org/complexsuggestions")),
599+
xdmp:document-insert("/sample2/suggestion.xml",
600+
<suggest>Something I hate to suggest is liver with lard.</suggest>),
601+
xdmp:document-set-permissions("/sample2/suggestion.xml",
602+
(xdmp:permission("rest-reader","read"),
603+
xdmp:permission("rest-writer","update"))
604+
),
605+
xdmp:document-add-collections("/sample2/suggestion.xml",("http://some.org/suggestions"))
512606
};
513607

514608
declare function bootstrap:load-search-data()
@@ -524,12 +618,13 @@ declare function bootstrap:post(
524618
$input as document-node()*
525619
) as document-node()*
526620
{
527-
let $ncre := bootstrap:security-config('sec:create-user("rest-admin","rest-admin user", "x",("rest-admin"),(),())')
621+
let $ncre := bootstrap:security-config('sec:create-user("rest-admin","rest-admin user", "x",("rest-admin"),(),())')
528622
let $ncre := bootstrap:security-config('sec:create-user("rest-reader","rest-reader user", "x",("rest-reader"),(),())')
529623
let $ncre := bootstrap:security-config('sec:create-user("rest-writer","rest-writer user", "x",("rest-writer"),(),())')
530624
let $ncre := bootstrap:security-config('sec:create-user("valid","valid unprivileged user", "x",(),(),())')
531625
let $dbid := xdmp:database("java-unittest")
532626
let $config := bootstrap:database-configure($dbid)
627+
let $_ := xdmp:log(("Configured Java test database:", $config))
533628
let $d1 := bootstrap:load-data()
534629
return ()
535630
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
DEFAULT_M2=$HOME/.m2/repository
4+
M2_REPO=${1:-$DEFAULT_M2}
5+
6+
java -cp target/test-classes:target/classes:$M2_REPO/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar:$M2_REPO/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar:$M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:$M2_REPO/org/slf4j/slf4j-api/1.7.4/slf4j-api-1.7.4.jar com.marklogic.client.test.util.TestServerBootstrapper teardown
7+

0 commit comments

Comments
 (0)