Pact provider tests broken: pactVerificationTestTemplate » PreconditionViolation - junit5

I'm quite new to CDC testing and only make my first steps. I've deployed the Pact-Broker (docker-compose), running at localhost:80. The consumer sends the generated pacts successfully to the broker, but it seems that the provider can't get a valid contract (but this is only the assumption).
I'm using spring-boot, maven, jUnit5. Application tests are running on Ubuntu.
Using PactFolder with the consumer-generated pact-contract in local directory results in successful tests.
When I'm switching to #PactBroker annotation, the provider is able to connect to the broker and it receives the following response (I got it from debug logs):
{"_links":
{"self":{
"href":"http://localhost/pacts/provider/provider- name/latest","title":"Latest pact versions for the provider provider-name"},
"pb:provider":{"href":"http://localhost/pacticipants/provider-name",
"name":"provider-name"},
"pb:pacts":[
{"href":"http://localhost/pacts/provider/provider-name/consumer/consumer-name/version/1.0.0",
"title":"Pact between consumer-name (v1.0.0) and provider-name",
"name":"consumer-name"}
],
"provider":{
"href":"http://localhost/pacticipants/provider-name",
"title":"provider-name",
"name":"DEPRECATED - please use the pb:provider relation"
},
"pacts":[
{"href":"http://localhost/pacts/provider/provider-name/consumer/consumer-name/version/1.0.0",
"title":"DEPRECATED - please use the pb:pacts relation. Pact between consumer-name (v1.0.0) and provider-name",
"name":"consumer-name"
}
]
}
}
And the test run results in the following:
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 9.758 s
FAILURE! - in com.tis.payment.mapper.PaymentMapperApplicationTests
[ERROR] pactVerificationTestTemplate{PactVerificationContext}
Time elapsed: 9.752 s
ERROR!
org.junit.platform.commons.util.PreconditionViolationException:
No supporting TestTemplateInvocationContextProvider provided an invocation context
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] PaymentMapperApplicationTests.pactVerificationTestTemplate » PreconditionViolation
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
As using the local pact file makes tests green, I suppose that the reason is not in the code of my test class, though if it could be helpful, I provide it here:
#ExtendWith(SpringExtension.class)
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
properties = "server.port=8082")
#Provider("provider-name")
#PactBroker(host = "localhost", port = "80", tags="latest")
//#PactFolder("target/pacts") # uncomment to use local pact files
public class ApplicationTests {
#MockBean
private ProviderServiceClient providerServiceClient;
#BeforeEach
void setupTestTarget(PactVerificationContext context) {
context.setTarget(new HttpTestTarget("localhost", 8082, "/"));
}
#TestTemplate
#ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
context.verifyInteraction();
}
#State({"valid payment file"})
public void toValid() {
ServiceResponse response = new ServiceResponse();
response.setBatchId("test");
response.setId(1L);
when(providerServiceClient.save(any())).thenReturn(response);
}
#State({"invalid payment file"})
public void toInvalid() {
}
}
As using local pact files is not an option, I really wonder how to fix the error and will be grateful for any helpful comments.
maven pact dependencies:
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-model</artifactId>
<version>3.5.22</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit5_2.12</artifactId>
<version>3.5.22</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-consumer-junit5_2.12</artifactId>
<version>3.5.22</version>
<scope>test</scope>
</dependency>
Plugin for maven to publish the consumer's pacts:
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven_2.12</artifactId>
<version>3.5.22</version>
<configuration>
<pactBrokerUrl>http://localhost:80</pactBrokerUrl>
<trimSnapshot>true</trimSnapshot>
<!-- Defaults to false -->
</configuration>
</plugin>
the pact-provider docker-compose.yml:
version: '2'
services:
postgres:
image: postgres
restart: always
# healthcheck:
# test: psql postgres --command "select 1" -U postgres
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
broker_app:
image: dius/pact-broker
depends_on:
- postgres
ports:
- "80:80"
links:
- postgres
environment:
PACT_BROKER_DATABASE_USERNAME: postgres
PACT_BROKER_DATABASE_PASSWORD: password
PACT_BROKER_DATABASE_HOST: postgres
PACT_BROKER_DATABASE_NAME: postgres

The JUnit 5 error org.junit.platform.commons.util.PreconditionViolationException:
No supporting TestTemplateInvocationContextProvider provided an invocation context means no test context was provided, so the templated test method could not be invoked. This is probably due to there not being any pacts to verify (each pact results in an invocation context).
Now to addressing the actual issue as to why you are not getting any pacts to verify from the broker. The Pact Broker is essentially a repository, and the JUnit 5 verification framework will use all the annotations on the pact class to create a query to send to the Pact Broker. This query is not returning any pacts, so there must be a mismatch somewhere.
The only thing I can see from the information you have provided is the URL "http://localhost/pacts/provider/provider- name/latest" in the JSON has an issue (there is whitespace in the provider name). If that is not just a formatting issue with SO, then that won't match (the broker will probably return a 404 with that URL).
If that is not the issue, then check that when you run the verification from Maven, you can access the broker in the same way that the test framework is. Enabling DEBUG level logging will show you all the requests being made. Use something like curl and try the same requests to see what you get.

Related

How to change the logging level in liquibase version 3.6.3

I hate to post this question because it has been asked for many versions of liquibase, but I cannot change the logging level for version 3.6.3. I've tried the suggestions for the other versions without any success...
POM:
<liquibase.logging>INFO</liquibase.logging>
and
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<logging>${liquibase.logging}</logging>
...
</configuration>
When I run mvn, I still get DEBUG level messages from Liquibase
07:09:29.541 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for all classes in package: liquibase/change using classloader: org.codehaus.plexus.classworlds.realm.ClassRealm
07:09:29.541 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Getting resource URL for package: liquibase/change with classloader: ClassRealm[plugin>org.liquibase:liquibase-maven-plugin:3.6.3, parent: sun.misc.Launcher$AppClassLoader#7852e922]
07:09:29.542 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - URL from classloader: jar:file:/home/xxxxxxxxxxxxxx/.m2/repository/org/liquibase/liquibase-core/3.6.3/liquibase-core-3.6.3.jar!/liquibase/change/
07:09:29.543 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Decoded urlPath: file:/home/xxxxxxxxxxxxxx/.m2/repository/org/liquibase/liquibase-core/3.6.3/liquibase-core-3.6.3.jar!/liquibase/change/ with protocol: jar0
etc.
I've also tried the -Dliquibase.logging=info on the mvn command line and I get the same results.
There were several bugs related to logging in Liquibase 3.6.x. These have been fixed in version 3.8.1 and greater.

When i use nacos as nacos as discovery, open spring cloud config setting "spring.cloud.config.discovery.enabled=true", application run fail

When I use nacos as nacos as discovery, open spring cloud config setting "spring.cloud.config.discovery.enabled=true", application run fail
my bootstrap.properties
spring.application.name=waiter-service
spring.cloud.nacos.discovery.server-addr=192.168.40.129:8848
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=config-service
Application run error info : Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.client.discovery.DiscoveryClient' available
Make sure that your spring cloud version lower than 2021. If your spring cloud version is higher than 2021. You shoule add:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
or you can use application.yaml to use nacos config:
server:
port: {port}
spring:
application:
name: {app-name}
nacos:
discovery:
server-addr: {host}:{port}
config:
server-addr: {host}:{port}
group: {group}
config:
import:
- optional:nacos:{config-name-version}
do not add .properties or .yaml in the end of - optinal:nacos:{config-name-version}

Apache Isis Security Module: Required table missing : "ISISSECURITY.APPLICATIONROLE"

I created an application using the apache isis simpleapp-archetype and then added the dependencies (isis-module-security-dom and jbcrypt) of the security module to my pom.xml's and the modules and services to my DomainAppAppManifest.
After running mvn clean install on the project the following error happens in the integration tests module:
[INFO] introspecting org.apache.isis.applib.services.iactn.Interaction: class-level details
[INFO] calling #PostConstruct on all domain services
seed-users-and-roles-fixture-script : EXEC org.isisaddons.module.security.seed.SeedUsersAndRolesFixtureScript
seed-users-and-roles-fixture-script/global-tenancy : EXEC org.isisaddons.module.security.seed.scripts.GlobalTenancy
[INFO] abort transaction IsisTransaction#517e381b[state=MUST_ABORT,commands=0]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Simple App ......................................... SUCCESS [ 0.608 s]
[INFO] Simple App DOM ..................................... SUCCESS [ 14.607 s]
[INFO] Simple App Fixtures ................................ SUCCESS [ 1.285 s]
[INFO] Simple App Application ............................. SUCCESS [ 2.204 s]
[INFO] Simple App Integration Tests ....................... FAILURE [ 17.539 s]
[INFO] Simple App Webapp .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.654 s
[INFO] Finished at: 2016-09-26T18:44:48+07:00
[INFO] Final Memory: 65M/572M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.isis.tool:isis-maven-plugin:1.13.0:swagger (default) on project groupid-demo-integtests: Execution default of goal org.apache.isis.tool:isis-maven-plugin:1.13.0:swagger failed: org.datanucleus.store.rdbms.exceptions.MissingTableException: Required table missing : "ISISSECURITY.APPLICATIONROLE" in Catalog "" Schema "ISISSECURITY". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"
-> [Help 1]
In principle I followed the documentation found in the security module github repository, but this didn't really work at all, and by taking a look at the quickstart module I figured the security dependencies needed to be added to the parent POM, and the the bcrypt dependency needs to be added to the App POM, and the security-plugin dependency to the Dom POM.
To reproduce the error, this is the what I did:
Create project with archetype
mvn archetype:generate -D archetypeGroupId=org.apache.isis.archetype -D archetypeArtifactId=simpleapp-archetype -D archetypeVersion=1.13.0 -D groupId=my.groupid -D artifactId=groupid-demo -D version=1.0-SNAPSHOT -D archetypeRepository=http://repository-estatio.forge.cloudbees.com/snapshot/ -B
Then in /groupid-demo/pom.xml I added these dependencies:
<dependency>
<groupId>org.isisaddons.module.security</groupId>
<artifactId>isis-module-security-dom</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
</dependency>
In /groupid-demo-app/pom.xml I added this dependency:
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
</dependency>
In /groupid-demo-app/src/main/java/domainapp/app/DomainAppAppManifest.java I modified the modules and services as follows:
#Override
public List<Class<?>> getModules() {
return Arrays.asList(
DomainAppDomainModule.class, // domain (entities and repositories)
DomainAppFixtureModule.class, // fixtures
DomainAppAppModule.class // home page service etc
,org.isisaddons.module.security.SecurityModule.class
);
}
#Override
public List<Class<?>> getAdditionalServices() {
return Arrays.asList(
org.isisaddons.module.security.dom.password.PasswordEncryptionServiceUsingJBcrypt.class
);
}
In /groupid-demo-dom/pom.xml I added this dependency:
<dependency>
<groupId>org.isisaddons.module.security</groupId>
<artifactId>isis-module-security-dom</artifactId>
</dependency>
And then /groupid-demo-webapp/src/main/webapp/WEB-INF/shiro.ini has been modified like this:
[main]
....
# to use .ini file
# securityManager.realms = $iniRealm
isisModuleSecurityRealm=org.isisaddons.module.security.shiro.IsisModuleSecurityRealm
authenticationStrategy=org.isisaddons.module.security.shiro.AuthenticationStrategyForIsisModuleSecurityRealm
securityManager.authenticator.authenticationStrategy = $authenticationStrategy
securityManager.realms = $isisModuleSecurityRealm
Finally I executed mvn clean install on the root pom and got above error.
Any idea what I am missing here? This is really just a bare bone simpleapp-archetype app with the only modification applied being the added security module.
Yes, I hit the same issue today when putting together this demo app for the issue you raised on the Apache Isis mailing list.
The issue is that the maven plugin, which generates the swagger spec, uses its own AppManifest, and that manifest needs to correctly reference security.
Since I didn't want to get side-tracked on this, I simply disabled the swagger goal in the pom.xml (remove the '!' exclamation mark).
HTH
Dan

Apache Curator Unimplemented Errors When Trying to Create zNodes

I'm attempting to use Apache Curator with a dockerized zookeeper instance and no matter how I attempt to connect I always end up with a
org.apache.zookeeper.KeeperException$UnimplementedException:
KeeperErrorCode = Unimplemented for...
error. I've tried making sense of the documentation but I'm not getting anywhere. I've logged into the zookeeper CLI and ensured the port number is correct thusly:
snerd#powerglove:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31f1093495ba compose_zookeeper "/opt/zookeeper/bin/ 3 weeks ago Up About a minute 0.0.0.0:32770->2181/tcp,
0.0.0.0:32769->2888/tcp, 0.0.0.0:32768->3888/tcp zookeeper
here is the code I'm trying to use:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
client.create().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
As far as I can tell from the Curator getting started page, this should work. What am I missing?
edit1
just figured out that I'm able to pull data out of the zookeeper ensemble thusly:
System.out.println(new String(curatorFramework.getData().forPath("/larry-smells")));
but the create command is still blowing up.
edit2
stacktrace of the error:
org.apache.zookeeper.KeeperException$UnimplementedException:
KeeperErrorCode = Unimplemented for /larry-smells/foop at
org.apache.zookeeper.KeeperException.create(KeeperException.java:103)
at
org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1297) at
org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1040)
at
org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1023)
at
org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:67)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:99) at
org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1020)
at
org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:501)
at
org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:491)
at
org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:367)
at
org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:309)
at com.mycompany.app.App.main(App.java:35)
Edit: Apparently this error can occur if you're using the wrong combination of Curator in combination with Zookeeper. From curator.apache.org :
Curator 2.x.x - compatible with both ZooKeeper 3.4.x and ZooKeeper 3.5.x
Curator 3.x.x - compatible only with ZooKeeper 3.5.x and includes support for new features such as dynamic reconfiguration, etc.
It's hard to pinpoint your problem with only that error-code and not a stack trace, but some improvements I would suggest to make your application more stable is:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
//make sure you're connected to zookeeper.
client.blockUntilConnected();
//Make sure the parents are created.
client.create().creatingParentsIfNeeded().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
I also faced a similar exception, I used the below dependencies which are compatible and helps me to resolve the exception.
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>4.0.1</version>
</dependency>
I had the same problem.
I tried to use inTransaction () as explained here: http://www.programcreek.com/java-api-examples/index.php?api=org.apache.curator.framework.CuratorFramework on exercise 6
and seems to work.
client.inTransaction ().create().forPath("/larry-smells/foop", "tuna?".getBytes()).and ().commit ();
The issue is caused because of incompatibility.
To fix this, you need to change the version like it's explained here:
https://curator.apache.org/zk-compatibility.html
If this doesn't work, just look for the newest curator version which depends on a 3.4.x zookeeper version (currently '2.12.0').
#Massimo Da Ros solution works, but in new version Curator 4.0.0 inTransaction is deprecated, it's recommented use transaction method like below:
CuratorOp op = client.transactionOp().create()
.withMode(CreateMode.PERSISTENT)
.withACL(Ids.OPEN_ACL_UNSAFE)
.forPath("/test", "Data".getBytes());
result = client.transaction().forOperations(op).get(0).toString();
I faced similiar problem. I was using spring-cloud-starter-zookeeper-discovery which by itself of course has compatible zookeeper and curator versions.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
I checked the dependency tree and spring-cloud-starter-zookeeper-discovery Version 3.1.1. was using zookeeper Version 3.6.0
The problem was, in my docker-compose.yml I was using zookeeper Version 3.4!
So make sure your docker-compose.yml zookeeper version fits your maven zookeeper version.
version: "3.8"
services:
zookeeper:
container_name: zookeeper
image: zookeeper:3.6 <----------------- zookeeper version
ports:
- "2181:2181"

Maven test fails within install phase but is ok within test phase

I have an empty java test with Spring and Ebean
protected static ApplicationContext ctx;
#BeforeClass
public static void initSpringContext() {
ctx = new ClassPathXmlApplicationContext("spring-context.xml");
}
public class SomeTest extends SpringBase {
#Test
public void emptyTest() {}
}
I had a problem with class loading:
Caused by: javax.persistence.PersistenceException: models.Flat is NOT an Entity Bean registered with this server?
Problem was fixed with pom config
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
After this fix "mvn clean test" runs ok, but "mvn clean install" fails with exact exception
I suppose it's because integration-test phase.
I tried to config useSystemClassLoader in maven-failsafe-plugin, run with param -Dskip.integration.test=true but is makes no difference, I have feeling that this plugin did not call at all.
Also I've compared surefire-reports genereted by "mvn clean test" and "mvn clean verify" -- section "properties" within the testsuite is identical in both cases.
Skipping integration-test will be also an acceptable solution.
Maven 2.2.1 OS - Tested under Windows and Debian
If it can help, stacktrace of error:
Caused by: javax.persistence.PersistenceException: models.Flat is NOT an Entity Bean registered with this server?
at com.avaje.ebeaninternal.server.core.DefaultServer.createQuery(DefaultServer.java:1008)
at com.avaje.ebeaninternal.server.core.DefaultServer.createQuery(DefaultServer.java:965)
at com.avaje.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:1001)
at com.avaje.ebean.Ebean.find(Ebean.java:1143)
at flats.crawler.managers.CrawlerManager.initCrawlerHashes(CrawlerManager.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:346)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:299)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:132)
... 48 more
I've run two commands "mvn clean install -X" and "mvn clean test -X" and compared test classpathes:
in first case
[DEBUG] PATH\MODULE\target\MODULE-1.0.jar
in second case
[DEBUG] PATH\MODULE\target\classes
that's why Ebean can't find classes
For integration tests the maven-failsafe-plugin is responsible and NOT the maven-surefire plugin. So you configurations to ignore the integration test couldn't work.
Did you see this FAQ entry in the failsafe plugin docs? It gives a whole bunch of options for classloading configuration.
If none of those suggestions work for you, and skipping the integration tests is okay (as you mentioned), then -DskipITs=true should do it, per the docs.