Skip to content

Commit

Permalink
Merge branch 'main' into 9747-cohere-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer authored Feb 7, 2025
2 parents 497f47f + 481a442 commit e2e22b6
Show file tree
Hide file tree
Showing 18 changed files with 307 additions and 51 deletions.
8 changes: 8 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,14 @@
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
<artifactId>helidon-integrations-langchain4j-providers-cohere</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
<artifactId>helidon-integrations-langchain4j-providers-ollama</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
<artifactId>helidon-integrations-langchain4j-providers-oracle</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.openapi</groupId>
<artifactId>helidon-openapi</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,15 @@
<dependency>
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
<artifactId>helidon-integrations-langchain4j-providers-cohere</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
<artifactId>helidon-integrations-langchain4j-providers-ollama</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.langchain4j.providers</groupId>
<artifactId>helidon-integrations-langchain4j-providers-oracle</artifactId>
<version>${helidon.version}</version>
</dependency>

Expand Down
5 changes: 0 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ Build just the javadocs:
mvn package -Pjavadoc -Dhelidon.sitegen.skip=true
```

Build docs and also update config reference docs:
```bash
mvn package -Pconfigdoc
```

## Serve

```bash
Expand Down
26 changes: 15 additions & 11 deletions docs/src/main/asciidoc/mp/testing/testing-common.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ The "synthetic" configuration can be expressed using the following annotations:
|link:{mp-testing-javadoc-url}/AddConfigBlock.html[`@AddConfigBlock`]
|Formatted text block
|link:{mp-testing-javadoc-url}/AddConfigSource.html[`@AddConfigSource`]
|Programmatic config source
|link:{mp-testing-javadoc-url}/Configuration.html[`@Configuration`]
| Classpath resources using
Expand All @@ -184,11 +187,17 @@ include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_9, indent=0]
----
[source,java]
.Add classpath resources
.Add config programmatically
----
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_10, indent=0]
----
[source,java]
.Add classpath resources
----
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_11, indent=0]
----
==== Configuration Ordering
The ordering of the test configuration can be controlled using the mechanism defined by the
Expand All @@ -200,7 +209,7 @@ of `1000`
[source,java]
.Add a properties text block with ordinal
----
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_11, indent=0]
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_12, indent=0]
----
=== Injectable Types
Expand Down Expand Up @@ -228,25 +237,17 @@ Here are all the built-in types that can be injected:
NOTE: Types that reflect the current server require link:{mp-server-javadoc-url}/ServerCdiExtension.html[`ServerCdiExtension`]
NOTE: All the injectable types are also available as method parameters.
[source,java]
.Inject a JAX-RS client for the default socket
----
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_12, indent=0]
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_13, indent=0]
----
Use link:{mp-testing-javadoc-url}/Socket.html[`@Socket`] to specify the socket for the clients and URIs.
[source,java]
.Inject a JAX-RS client for the admin socket
----
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_13, indent=0]
----
[source,java]
.Using a method parameter
----
include::{sourcedir}/mp/testing/TestingSnippets.java[tag=snippet_14, indent=0]
----
// end::usage[]
Expand Down Expand Up @@ -278,6 +279,9 @@ Here is a brief overview of the MicroProfile testing annotations:
|link:{mp-testing-javadoc-url}/AddConfigBlock.html[`@AddConfigBlock`]
|Define a formatted text block in the "synthetic" configuration
|link:{mp-testing-javadoc-url}/AddConfigSource.html[`@AddConfigSource`]
|Add a programmatic config source to the "synthetic" configuration
|link:{mp-testing-javadoc-url}/Configuration.html[`@Configuration`]
| Switch between "synthetic" and "existing" ; Add classpath resources to the "synthetic" configuration
Expand Down
12 changes: 10 additions & 2 deletions docs/src/main/asciidoc/mp/testing/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ include::{rootdir}/includes/dependencies.adoc[]
include::{rootdir}/mp/testing/testing-common.adoc[tag=usage]
NOTE: All the injectable types are also available as method parameters.
[source,java]
.Using a method parameter
----
include::{sourcedir}/mp/testing/TestingJunit5Snippets.java[tag=snippet_1, indent=0]
----
=== Test Instance Lifecyle
The CDI scope used by the test instance follows the lifecyle defined by JUnit5. The default is `PER_CLASS` and is enforced
Expand All @@ -78,7 +86,7 @@ NOTE: The test instance is not re-used between CDI container, using a dedicated
[source,java]
.Using per method lifecycle
----
include::{sourcedir}/mp/testing/TestingJunit5Snippets.java[tag=snippet_1, indent=0]
include::{sourcedir}/mp/testing/TestingJunit5Snippets.java[tag=snippet_2, indent=0]
----
== API
Expand All @@ -101,7 +109,7 @@ instance.
[source,java]
.Mocking using CDI Alternative
----
include::{sourcedir}/mp/testing/TestingJunit5Snippets.java[tag=snippet_2, indent=0]
include::{sourcedir}/mp/testing/TestingJunit5Snippets.java[tag=snippet_3, indent=0]
----
<1> Create the mock instance in the test class
<2> Create a CDI producer method annotated with `@Alternative`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,29 @@ class TestingJunit5Snippets {
class Snippet1 {

// tag::snippet_1[]
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@HelidonTest
class MyTest {

@Test
void testOne(WebTarget target) {
}
}
// end::snippet_1[]
}

class Snippet2 {

// tag::snippet_2[]
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@HelidonTest
class MyTest {
}
// end::snippet_2[]
}

class Snippet3 {

// tag::snippet_3[]
@HelidonTest
@Priority(1) // <3>
class MyTest {
Expand Down Expand Up @@ -98,6 +111,6 @@ String test() {
return "Not Mocked";
}
}
// end::snippet_2[]
// end::snippet_3[]
}
}
68 changes: 38 additions & 30 deletions docs/src/main/java/io/helidon/docs/mp/testing/TestingSnippets.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
package io.helidon.docs.mp.testing;

import java.util.Map;

import io.helidon.config.mp.MpConfigSources;
import io.helidon.microprofile.config.ConfigCdiExtension;
import io.helidon.microprofile.testing.AddConfigBlock;
import io.helidon.microprofile.testing.AddConfigSource;
import io.helidon.microprofile.testing.Configuration;
import io.helidon.microprofile.testing.Socket;
import io.helidon.microprofile.testing.AddBean;
Expand All @@ -34,6 +38,7 @@
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.mockito.Answers;
import org.mockito.Mockito;

Expand Down Expand Up @@ -90,33 +95,26 @@ class MyTest {
class Snippet3 {

// tag::snippet_3[]
@HelidonTest(resetPerTest = true)
@DisableDiscovery
@AddJaxRs // <1>
@AddBean(MyResource.class) // <2>
@HelidonTest
class MyTest {

@Test
void testOne() { // <1>
}

@Test
void testTwo() { // <2>
}
}
// end::snippet_3[]
}

class Snippet4 {

// tag::snippet_4[]
@HelidonTest
@HelidonTest(resetPerTest = true)
class MyTest {

@Test
void testOne() { // <1>
}

@Test
@DisableDiscovery
@AddBean(MyBean.class)
void testTwo() { // <2>
}
}
Expand All @@ -126,11 +124,18 @@ void testTwo() { // <2>
class Snippet5 {

// tag::snippet_5[]
@DisableDiscovery
@AddJaxRs // <1>
@AddBean(MyResource.class) // <2>
@HelidonTest
class MyTest {

@Test
void testOne() { // <1>
}

@Test
@DisableDiscovery
@AddBean(MyBean.class)
void testTwo() { // <2>
}
}
// end::snippet_5[]
}
Expand Down Expand Up @@ -185,23 +190,26 @@ class MyTest {
class Snippet10 {

// tag::snippet_10[]
@Configuration(configSources = {
"my-test1.yaml",
"my-test2.yaml"
})
@HelidonTest
class MyTest {

@AddConfigSource
static ConfigSource config() {
return MpConfigSources.create(Map.of(
"foo", "bar",
"bob", "alice"));
}
}
// end::snippet_10[]
}

class Snippet11 {

// tag::snippet_11[]
@AddConfigBlock(value = """
config_ordinal=120
foo=bar
""")
@Configuration(configSources = {
"my-test1.yaml",
"my-test2.yaml"
})
@HelidonTest
class MyTest {
}
Expand All @@ -211,12 +219,12 @@ class MyTest {
class Snippet12 {

// tag::snippet_12[]
@AddConfigBlock(value = """
config_ordinal=120
foo=bar
""")
@HelidonTest
class MyTest {

@Inject
@Socket("admin")
WebTarget target;
}
// end::snippet_12[]
}
Expand All @@ -239,9 +247,9 @@ class Snippet14 {
@HelidonTest
class MyTest {

@Test
void testOne(WebTarget target) {
}
@Inject
@Socket("admin")
WebTarget target;
}
// end::snippet_14[]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
* <li>{@link io.helidon.microprofile.testing.Configuration} global setting for MicroProfile configuration</li>
* <li>{@link io.helidon.microprofile.testing.AddConfig} declarative key/value pair configuration</li>
* <li>{@link io.helidon.microprofile.testing.AddConfigBlock} declarative fragment configuration</li>
* <li>{@link io.helidon.microprofile.testing.AddConfigSource} programmatic configuration</li>
* </ul>
* <p>
* See also {@link io.helidon.microprofile.testing.Socket}, a CDI qualifier to inject JAX-RS client or URI.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates.
*
* 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 io.helidon.microprofile.testing;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Mark a static method that provides a {@link org.eclipse.microprofile.config.spi.ConfigSource ConfigSource}
* to add to the {@link Configuration#useExisting() synthetic test configuration}.
* <p>
* E.g.
* <pre>
* &#064;AddConfigSource
* static ConfigSource config() {
* return MpConfigSources.create(Map.of("foo", "bar"));
* }</pre>
*
* @see io.helidon.config.mp.MpConfigSources
* @see AddConfig
* @see AddConfigs
* @see AddConfigBlock
* @see Configuration
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface AddConfigSource {
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class HelidonTestConfigSynthetic extends HelidonTestConfigDelegate {
map.put("mp.config.profile", "test");
testInfo.addConfigs().forEach(this::update);
testInfo.addConfigBlocks().forEach(this::update);
testInfo.addConfigSources().forEach(this::update);
testInfo.configuration().ifPresent(this::update);
}

Expand Down
Loading

0 comments on commit e2e22b6

Please sign in to comment.