Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>4.0.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -183,5 +189,10 @@
<artifactId>wildfly-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions src/main/resources/META-INF/jqassistant-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<resource>camunda-bpmn.xml</resource>
<resource>projectreactor.xml</resource>
<resource>wildfly-assert.xml</resource>
<resource>spring-reactive.xml</resource>
</rules>
</jqassistant-plugin>
25 changes: 25 additions & 0 deletions src/main/resources/META-INF/jqassistant-rules/spring-reactive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<jqassistant-rules xmlns="http://schema.jqassistant.org/rule/v2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.2 https://jqassistant.github.io/jqassistant/current/schema/jqassistant-rule-v2.2.xsd">

<concept id="java-testing-spring-reactive:AssertMethod">
<providesConcept refId="java:AssertMethod"/>
<description>
Sets labels :Assert and :Spring:Reactive for Spring Reactive WebTestClient assert methods.
</description>
<cypher><![CDATA[
MATCH
(assertType:Type)-[:DECLARES]->(assertMethod)
WHERE
assertType.fqn =~ 'org\\.springframework\\.test\\.web\\.reactive\\.server\\.WebTestClient\\$ResponseSpec'
AND assertMethod.signature =~ '.* expect.*'
SET
assertMethod:Spring:Reactive:Assert
RETURN
assertMethod
ORDER BY
assertMethod.signature
]]></cypher>
</concept>

</jqassistant-rules>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
import org.mockito.BDDMockito;
import org.mockito.MockedStatic;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.wildfly.common.Assert;
import org.xmlunit.assertj.XmlAssert;
import reactor.test.StepVerifier;
Expand Down Expand Up @@ -59,4 +60,9 @@ void wildflyAssertExampleMethod() {
Assert.assertTrue(true);
}

void springWebTestClientAssertExampleMethod() {
WebTestClient webTestClient = mock(WebTestClient.class);
webTestClient.get().exchange().expectStatus().isOk();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.jqassistant.plugin.java_testing.concept;

import com.buschmais.jqassistant.core.report.api.model.Column;
import com.buschmais.jqassistant.core.report.api.model.Result;
import com.buschmais.jqassistant.core.report.api.model.Row;
import com.buschmais.jqassistant.core.rule.api.model.Concept;
import com.buschmais.jqassistant.core.test.plugin.AbstractPluginIT;
import com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor;
import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor;
import com.buschmais.jqassistant.plugin.java.test.AbstractJavaPluginIT;
import org.junit.jupiter.api.Test;
import org.springframework.test.web.reactive.server.WebTestClient;

import java.util.List;
import java.util.stream.Collectors;

import static com.buschmais.jqassistant.core.report.api.model.Result.Status.SUCCESS;
import static com.buschmais.jqassistant.plugin.java.test.assertj.MethodDescriptorCondition.methodDescriptor;
import static com.buschmais.jqassistant.plugin.java.test.assertj.TypeDescriptorCondition.typeDescriptor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.type;

public class SpringReactiveWebTestClientIT extends AbstractJavaPluginIT {

@Test
void springReactiveWebTestClientAssertMethod() throws Exception {
scanClasses(AssertExample.class);

final Result<Concept> conceptResult = applyConcept("java-testing-spring-reactive:AssertMethod");
assertThat(conceptResult.getStatus()).isEqualTo(SUCCESS);

store.beginTransaction();

assertThat(conceptResult.getRows().size()).isEqualTo(1);
assertThat(conceptResult.getRows()
.get(0)
.getColumns()
.get("assertMethod")
.getValue()).asInstanceOf(type(MethodDescriptor.class))
.is(methodDescriptor(WebTestClient.ResponseSpec.class, "expectStatus"));

verifyResultGraph();

store.commitTransaction();
}

@Test
void providedConceptAssertMethod() throws Exception {
scanClasses(AssertExample.class);

final Result<Concept> conceptResult = applyConcept("java:AssertMethod");
assertThat(conceptResult.getStatus()).isEqualTo(SUCCESS);

store.beginTransaction();

final List<TypeDescriptor> declaringTypes = conceptResult.getRows().stream()
.map(Row::getColumns)
.map(columns -> columns.get("DeclaringType"))
.map(Column::getValue)
.map(TypeDescriptor.class::cast)
.collect(Collectors.toList());
assertThat(declaringTypes).haveExactly(1, typeDescriptor(WebTestClient.ResponseSpec.class));

verifyResultGraph();

store.commitTransaction();
}

// Expects an open transaction
private void verifyResultGraph() throws NoSuchMethodException {
final AbstractPluginIT.TestResult methodQueryResult = query(
"MATCH (testMethod:Method)-[:INVOKES]->(assertMethod:Method) "
+ "WHERE assertMethod:Spring:Reactive:Assert "
+ "RETURN testMethod, assertMethod");
assertThat(methodQueryResult.<MethodDescriptor>getColumn("testMethod"))
.haveExactly(1, methodDescriptor(AssertExample.class, "springWebTestClientAssertExampleMethod"));
assertThat(methodQueryResult.<MethodDescriptor>getColumn("assertMethod"))
.haveExactly(1, methodDescriptor(WebTestClient.ResponseSpec.class, "expectStatus"));
}
}
Loading