Skip to content

Commit

Permalink
Add quarkus test profiles for h2 and PostgresSql
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiRajAnand committed Nov 29, 2024
1 parent 52f5c2f commit ca8b1e4
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 39 deletions.
5 changes: 5 additions & 0 deletions jobs-service/jobs-service-storage-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<artifactId>quarkus-test-h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-test-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.kie.kogito.jobs.service.profiles;

import io.quarkus.test.junit.QuarkusTestProfile;

public class H2QuarkusTestProfile implements QuarkusTestProfile {

@Override
public String getConfigProfile() {
return "test-h2";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.kie.kogito.jobs.service.profiles;

import io.quarkus.test.junit.QuarkusTestProfile;

public class PostgreSQLQuarkusTestProfile implements QuarkusTestProfile {

@Override
public String getConfigProfile() {
return "test-postgresql";
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.kie.kogito.jobs.service.repository.jpa;

import java.time.OffsetDateTime;
import java.util.concurrent.atomic.AtomicReference;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.kie.kogito.jobs.service.model.JobServiceManagementInfo;
import org.kie.kogito.jobs.service.repository.JobServiceManagementRepository;
import org.kie.kogito.jobs.service.utils.DateUtil;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.h2.H2DatabaseTestResource;
import io.quarkus.test.junit.QuarkusTest;

import jakarta.inject.Inject;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
@QuarkusTestResource(H2DatabaseTestResource.class)
class JPAReactiveJobServiceManagementRepositoryTest {

public abstract class BaseJPAReactiveJobServiceManagementRepositoryTest {
@Inject
JobServiceManagementRepository tested;

@BeforeEach
void setUp() {
}

@Test
void testGetAndUpdate() {
String id = "instance-id-1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@
package org.kie.kogito.jobs.service.repository.jpa;

import org.junit.jupiter.api.BeforeEach;
import org.kie.kogito.jobs.service.profiles.H2QuarkusTestProfile;
import org.kie.kogito.jobs.service.repository.ReactiveJobRepository;
import org.kie.kogito.jobs.service.repository.impl.BaseJobRepositoryTest;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.h2.H2DatabaseTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

import jakarta.inject.Inject;

@QuarkusTest
@QuarkusTestResource(H2DatabaseTestResource.class)
public class JPAReactiveJobRepositoryTest extends BaseJobRepositoryTest {
@QuarkusTestResource(value = H2DatabaseTestResource.class, restrictToAnnotatedClass = true)
@TestProfile(H2QuarkusTestProfile.class)
public class H2JPAReactiveJobRepositoryTest extends BaseJobRepositoryTest {

@Inject
JPAReactiveJobRepository tested;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.kie.kogito.jobs.service.repository.jpa;

import org.kie.kogito.jobs.service.profiles.H2QuarkusTestProfile;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.h2.H2DatabaseTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@QuarkusTestResource(value = H2DatabaseTestResource.class, restrictToAnnotatedClass = true)
@TestProfile(H2QuarkusTestProfile.class)
class H2JPAReactiveJobServiceManagementRepositoryTest extends BaseJPAReactiveJobServiceManagementRepositoryTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.kie.kogito.jobs.service.repository.jpa;

import org.junit.jupiter.api.BeforeEach;
import org.kie.kogito.jobs.service.profiles.PostgreSQLQuarkusTestProfile;
import org.kie.kogito.jobs.service.repository.ReactiveJobRepository;
import org.kie.kogito.jobs.service.repository.impl.BaseJobRepositoryTest;
import org.kie.kogito.testcontainers.quarkus.PostgreSqlQuarkusTestResource;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

import jakarta.inject.Inject;

@QuarkusTest
@QuarkusTestResource(value = PostgreSqlQuarkusTestResource.class, restrictToAnnotatedClass = true)
@TestProfile(PostgreSQLQuarkusTestProfile.class)
public class PostgresSqlJPAReactiveJobRepositoryTest extends BaseJobRepositoryTest {

@Inject
JPAReactiveJobRepository tested;

@BeforeEach
public void setUp() throws Exception {

super.setUp();
}

@Override
public ReactiveJobRepository tested() {
return tested;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.kie.kogito.jobs.service.repository.jpa;

import org.kie.kogito.jobs.service.profiles.PostgreSQLQuarkusTestProfile;
import org.kie.kogito.testcontainers.quarkus.PostgreSqlQuarkusTestResource;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@QuarkusTestResource(value = PostgreSqlQuarkusTestResource.class, restrictToAnnotatedClass = true)
@TestProfile(PostgreSQLQuarkusTestProfile.class)
class PostgresSqlJPAReactiveJobServiceManagementRepositoryTest extends BaseJPAReactiveJobServiceManagementRepositoryTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
*/
package org.kie.kogito.jobs.service.resource;

import org.kie.kogito.jobs.service.profiles.H2QuarkusTestProfile;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.h2.H2DatabaseTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@QuarkusTestResource(H2DatabaseTestResource.class)
@QuarkusTestResource(value = H2DatabaseTestResource.class, restrictToAnnotatedClass = true)
@TestProfile(H2QuarkusTestProfile.class)
public class JPAJobResourceTest extends BaseJobResourceTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
# Kogito
kogito.apps.persistence.type=jdbc
# Data source
quarkus.datasource.db-kind=h2
quarkus.datasource.username=kogito
quarkus.datasource.jdbc.url=jdbc:h2:mem:default;NON_KEYWORDS=VALUE,KEY
%test-h2.quarkus.datasource.db-kind=h2
%test-h2.quarkus.datasource.username=kogito
%test-h2.quarkus.datasource.jdbc.url=jdbc:h2:mem:default;NON_KEYWORDS=VALUE,KEY
%test-postgresql.quarkus.datasource.db-kind=postgresql
%test-postgresql.quarkus.datasource.devservices.enabled=false
kie.flyway.enabled=true
# Disabling Security for tests
quarkus.oidc.enabled=false
quarkus.oidc.tenant-enabled=false
quarkus.oidc.auth-server-url=none
quarkus.keycloak.devservices.enabled=false
quarkus.keycloak.devservices.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void registerProtoBufferTypeWithInvalidKogitoDescriptors() {
exceptionMessage = e.getMessage();
}

assertTrue(exceptionMessage.contains("java.lang.IllegalStateException"));
assertTrue(exceptionMessage.contains("Syntax error in test"));

verify(schemaEvent, never()).fire(any(SchemaRegisteredEvent.class));
verify(domainModelEvent, never()).fire(any(FileDescriptorRegisteredEvent.class));
Expand Down

0 comments on commit ca8b1e4

Please sign in to comment.