|
| 1 | +* Using Cookbook Examples |
| 2 | + |
| 3 | +The most important use of cookbook examples is reading the source code. You |
| 4 | +can do this on [github](https://github.com/marklogic/java-client-api) or on |
| 5 | +your machine once you've cloned the code from github. |
| 6 | + |
| 7 | +To run the examples, first edit the |
| 8 | +[Example.properties](../../../../../../resources/Example.properties) file in the |
| 9 | +distribution to specify the connection parameters for your server. Most |
| 10 | +Cookbook examples have a main method, so they can be run from the command-line |
| 11 | +like so: |
| 12 | + |
| 13 | + java -cp $CLASSPATH com.marklogic.client.example.cookbook.DocumentWrite |
| 14 | + |
| 15 | +This, of course, requires that you have all necessary dependencies in the env |
| 16 | +variable $CLASSPATH. You can get the classpath for your machine using the |
| 17 | +[maven dependency plugin](http://maven.apache.org/plugins/maven-dependency-plugin/usage.html) |
| 18 | +command: |
| 19 | + |
| 20 | + mvn dependency:build-classpath |
| 21 | + |
| 22 | +* Testing Cookbook Examples |
| 23 | + |
| 24 | +Most cookbook examples pass their unit test if they run without error. First |
| 25 | +edit the [Example.properties](../../../../../../resources/Example.properties) file |
| 26 | +in the distribution to specify the connection parameters for your server. Then |
| 27 | +run `mvn test` while specifying the unit test you want to run, for example: |
| 28 | + |
| 29 | + mvn test -Dtest=DocumentWriteTest |
| 30 | + |
| 31 | +* Creating a Cookbook Example |
| 32 | + |
| 33 | +We encourage community-contributed cookbook examples! Make sure you follow |
| 34 | +the guidelines in [CONTRIBUTING.md](../../../../../../../../CONTRIBUTING.md) |
| 35 | +when you submit a pull request. Each cookbook example should be runnable from |
| 36 | +the command-line, so it should have a static `main` method. The approach in |
| 37 | +the code should come as close as possible to production code (code one would |
| 38 | +reasonably expect to use in a production application), while remaining as |
| 39 | +simple as possible to facilitate grokking for newbies to the Java Client API. |
| 40 | +It should have helpful comments throughout, including javadocs since it will |
| 41 | +show up in the published javadocs. It should be added to |
| 42 | +[AllCookbookExamples.java](https://github.com/marklogic/java-client-api/blob/develop/src/main/java/com/marklogic/client/example/cookbook/AllCookbookExamples.java) |
| 43 | +in order of recommended examples for developers to review. |
| 44 | + |
| 45 | +It should have a unit test added to |
| 46 | +[this package](https://github.com/marklogic/java-client-api/tree/develop/src/test/java/com/marklogic/client/test/example/cookbook). |
| 47 | +The unit test can test whatever is needed, however most cookbook unit tests |
| 48 | +just run the class and consider it success if no errors are thrown. Some |
| 49 | +cookbook examples, such as SSLClientCreator and KerberosClientCreator cannot be |
| 50 | +included in unit tests because the unit tests require a server configured with |
| 51 | +digest authentication and those tests require a different authentication |
| 52 | +scheme. Any cookbook examples not included in unit tests run the risk of |
| 53 | +breaking without anyone noticing--hence we have unit tests whenever possible. |
0 commit comments