Skip to content

Commit

Permalink
ci: add NO_WEB profile to all tests not using the server verticle
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian committed Oct 4, 2021
1 parent 6977163 commit dab61cd
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 41 deletions.
17 changes: 5 additions & 12 deletions src/test/java/io/neonbee/NeonBeeExtensionBasedTest.java
Expand Up @@ -31,15 +31,7 @@ class NeonBeeExtensionBasedTest {
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
@DisplayName("NeonBee should start with default options / default working directory")
void testNeonBeeDefault(@NeonBeeInstanceConfiguration(activeProfiles = ALL) NeonBee neonBee) {
assertThat(neonBee).isNotNull();
assertThat(isClustered(neonBee)).isFalse();
}

@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
@DisplayName("NeonBee should start with ALL profile by default")
void testNeonBeeWithNoneProfile(NeonBee neonBee) {
void testNeonBeeDefault(@NeonBeeInstanceConfiguration NeonBee neonBee) {
assertThat(neonBee).isNotNull();
assertThat(neonBee.getOptions().getActiveProfiles()).containsExactly(ALL);
assertThat(isClustered(neonBee)).isFalse();
Expand All @@ -48,8 +40,9 @@ void testNeonBeeWithNoneProfile(NeonBee neonBee) {
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
@DisplayName("Instances with the same name should return the same NeonBee instance")
void testSameNeonBeeInstance(@NeonBeeInstanceConfiguration(instanceName = "node1") NeonBee instance1,
@NeonBeeInstanceConfiguration(instanceName = "node1") NeonBee instance2) {
void testSameNeonBeeInstance(
@NeonBeeInstanceConfiguration(instanceName = "node1", activeProfiles = {}) NeonBee instance1,
@NeonBeeInstanceConfiguration(instanceName = "node1", activeProfiles = {}) NeonBee instance2) {
assertThat(instance1).isSameInstanceAs(instance2);
}

Expand All @@ -59,7 +52,7 @@ void testSameNeonBeeInstance(@NeonBeeInstanceConfiguration(instanceName = "node1
void testNeonBeeWithCoreDeployment(@NeonBeeInstanceConfiguration(activeProfiles = CORE) NeonBee neonBee,
VertxTestContext testContext) {
assertThat(neonBee).isNotNull();
assertThat(neonBee.getOptions().getActiveProfiles()).contains(CORE);
assertThat(neonBee.getOptions().getActiveProfiles()).containsExactly(CORE);
Vertx vertx = neonBee.getVertx();
vertx.deployVerticle(new CoreDataVerticle(), testContext.succeeding(id -> {
assertThat(DeploymentHelper.isVerticleDeployed(vertx, CoreDataVerticle.class)).isTrue();
Expand Down
29 changes: 18 additions & 11 deletions src/test/java/io/neonbee/NeonBeeTest.java
Expand Up @@ -6,6 +6,7 @@
import static io.neonbee.NeonBeeProfile.ALL;
import static io.neonbee.NeonBeeProfile.CORE;
import static io.neonbee.NeonBeeProfile.INCUBATOR;
import static io.neonbee.NeonBeeProfile.NO_WEB;
import static io.neonbee.NeonBeeProfile.STABLE;
import static io.neonbee.internal.helper.StringHelper.EMPTY;
import static io.neonbee.test.helper.OptionsHelper.defaultOptions;
Expand Down Expand Up @@ -52,6 +53,11 @@
class NeonBeeTest extends NeonBeeTestBase {
private Vertx vertx;

@Override
protected void adaptOptions(TestInfo testInfo, NeonBeeOptions.Mutable options) {
options.addActiveProfile(NO_WEB);
}

@AfterEach
void closeVertx(VertxTestContext testContext) {
if (vertx != null) {
Expand Down Expand Up @@ -103,7 +109,7 @@ void testStartWithEmptyWorkingDirectory() {
@Timeout(value = 2, timeUnit = TimeUnit.SECONDS)
@DisplayName("Vert.x should start in non-clustered mode. ")
void testStandaloneInitialization(VertxTestContext testContext) {
NeonBee.newVertx(defaultOptions()).onComplete(testContext.succeeding(vertx -> {
NeonBee.newVertx(defaultOptions().clearActiveProfiles()).onComplete(testContext.succeeding(vertx -> {
testContext.verify(() -> {
assertThat((this.vertx = vertx).isClustered()).isFalse();
testContext.completeNow();
Expand All @@ -115,8 +121,8 @@ void testStandaloneInitialization(VertxTestContext testContext) {
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
@DisplayName("Vert.x should start in clustered mode.")
void testClusterInitialization(VertxTestContext testContext) {
NeonBee.newVertx(defaultOptions().setClustered(true).setClusterConfigResource("hazelcast-local.xml"))
.onComplete(testContext.succeeding(vertx -> {
NeonBee.newVertx(defaultOptions().clearActiveProfiles().setClustered(true)
.setClusterConfigResource("hazelcast-local.xml")).onComplete(testContext.succeeding(vertx -> {
testContext.verify(() -> {
assertThat((this.vertx = vertx).isClustered()).isTrue();
testContext.completeNow();
Expand Down Expand Up @@ -189,14 +195,15 @@ void testCloseVertxOnError(VertxTestContext testContext) {
vertxSupplier = () -> succeededFuture(failingVertxMock);
}

NeonBee.create(vertxSupplier, defaultOptions()).onComplete(testContext.failing(throwable -> {
testContext.verify(() -> {
// assert hat it is always
assertThat(throwable.getMessage()).isEqualTo("Failing Vert.x!");
verify(failingVertxMock, times(ownVertx ? 1 : 0)).close();
checkpoint.flag();
});
}));
NeonBee.create(vertxSupplier, defaultOptions().clearActiveProfiles())
.onComplete(testContext.failing(throwable -> {
testContext.verify(() -> {
// assert that the original message why the boot failed to start is propagated
assertThat(throwable.getMessage()).isEqualTo("Failing Vert.x!");
verify(failingVertxMock, times(ownVertx ? 1 : 0)).close();
checkpoint.flag();
});
}));
};

// fail the boot, but close Vert.x fine and ensure a Vert.x that is NOT owned by the outside is closed
Expand Down
Expand Up @@ -45,8 +45,9 @@ class LocalPreferredClusterTest {
@BeforeEach
@Timeout(value = 20, timeUnit = TimeUnit.SECONDS)
@DisplayName("Setup the cluster nodes and deploy the consumers")
void setUp(@NeonBeeInstanceConfiguration(clustered = true) NeonBee localNode,
@NeonBeeInstanceConfiguration(clustered = true) NeonBee remoteNode, VertxTestContext testContext) {
void setUp(@NeonBeeInstanceConfiguration(clustered = true, activeProfiles = {}) NeonBee localNode,
@NeonBeeInstanceConfiguration(clustered = true, activeProfiles = {}) NeonBee remoteNode,
VertxTestContext testContext) {
this.localNode = localNode;
deployVerticle(localNode.getVertx(), new ConsumerVerticle(LOCAL))
.compose(v -> deployVerticle(remoteNode.getVertx(), new ConsumerVerticle(REMOTE)))
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/io/neonbee/cluster/LocalRequestClusterTest.java
Expand Up @@ -42,8 +42,9 @@ public Future<JsonObject> retrieveData(DataQuery query, DataMap dataMap, DataCon
@Test
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
@DisplayName("Test that setLocalOnly works as expected")
void testLocalRequest(@NeonBeeInstanceConfiguration(clustered = true) NeonBee source,
@NeonBeeInstanceConfiguration(clustered = true) NeonBee target, VertxTestContext testContext) {
void testLocalRequest(@NeonBeeInstanceConfiguration(clustered = true, activeProfiles = {}) NeonBee source,
@NeonBeeInstanceConfiguration(clustered = true, activeProfiles = {}) NeonBee target,
VertxTestContext testContext) {
Checkpoint nonLocalRequest = testContext.checkpoint();
Checkpoint localRequest = testContext.checkpoint();

Expand Down
Expand Up @@ -50,8 +50,9 @@ void setUp() {
@Test
@Timeout(value = 20, timeUnit = TimeUnit.SECONDS)
@DisplayName("Body of messages over distributed eventbus should be non-empty.")
void testNeonBeeWithClusters(@NeonBeeInstanceConfiguration(clustered = true) NeonBee core,
@NeonBeeInstanceConfiguration(clustered = true) NeonBee stable, VertxTestContext testContext) {
void testNeonBeeWithClusters(@NeonBeeInstanceConfiguration(clustered = true, activeProfiles = {}) NeonBee core,
@NeonBeeInstanceConfiguration(clustered = true, activeProfiles = {}) NeonBee stable,
VertxTestContext testContext) {

stable.getVertx().eventBus().addInboundInterceptor(new TrackingInterceptor(MessageDirection.INBOUND, strategy))
.addOutboundInterceptor(new TrackingInterceptor(MessageDirection.OUTBOUND, strategy));
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/io/neonbee/data/DataVerticleTest.java
@@ -1,6 +1,7 @@
package io.neonbee.data;

import static com.google.common.truth.Truth.assertThat;
import static io.neonbee.NeonBeeProfile.NO_WEB;
import static io.vertx.core.Future.succeededFuture;
import static java.lang.Boolean.parseBoolean;

Expand All @@ -10,8 +11,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import io.neonbee.NeonBeeDeployable;
import io.neonbee.NeonBeeOptions;
import io.neonbee.test.base.DataVerticleTestBase;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
Expand All @@ -29,6 +32,11 @@ class DataVerticleTest extends DataVerticleTestBase {
// effective namespace dataverticletestnamespace2
private DataVerticleImpl2 dataVerticleImpl2;

@Override
protected void adaptOptions(TestInfo testInfo, NeonBeeOptions.Mutable options) {
options.addActiveProfile(NO_WEB);
}

@BeforeEach
@Timeout(value = 2, timeUnit = TimeUnit.SECONDS)
void deployEntityVerticles(VertxTestContext testContext) {
Expand Down
20 changes: 16 additions & 4 deletions src/test/java/io/neonbee/entity/EntityModelManagerTest.java
@@ -1,6 +1,7 @@
package io.neonbee.entity;

import static com.google.common.truth.Truth.assertThat;
import static io.neonbee.NeonBeeProfile.NO_WEB;
import static io.neonbee.entity.EntityModelManager.BUFFERED_MODELS;
import static io.neonbee.entity.EntityModelManager.getBufferedModel;
import static io.neonbee.entity.EntityModelManager.getBufferedModels;
Expand All @@ -25,10 +26,12 @@
import org.apache.olingo.server.api.OData;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import com.sap.cds.reflect.CdsModel;

import io.neonbee.NeonBeeMockHelper;
import io.neonbee.NeonBeeOptions;
import io.neonbee.entity.EntityModelManager.Loader;
import io.neonbee.test.base.NeonBeeTestBase;
import io.neonbee.test.helper.FileSystemHelper;
Expand All @@ -46,6 +49,11 @@ class EntityModelManagerTest extends NeonBeeTestBase {

private static final Path REFERENCE_SERVICE_MODEL_PATH = TEST_RESOURCES.resolveRelated("ReferenceService.csn");

@Override
protected void adaptOptions(TestInfo testInfo, NeonBeeOptions.Mutable options) {
options.addActiveProfile(NO_WEB);
}

@Test
@Timeout(value = 2, timeUnit = TimeUnit.SECONDS)
@DisplayName("should return the same odata instance for one thread")
Expand Down Expand Up @@ -177,7 +185,8 @@ void lazyModelLoadingTest(Vertx vertx, VertxTestContext testContext) throws Exce
WorkingDirectoryBuilder.hollow().addModel(TEST_RESOURCES.resolveRelated("TestService1.csn"))
.addModel(TEST_RESOURCES.resolveRelated("TestService2.csn")).build(workingDir);

NeonBeeMockHelper.registerNeonBeeMock(vertx, defaultOptions().setWorkingDirectory(workingDir));
NeonBeeMockHelper.registerNeonBeeMock(vertx,
defaultOptions().clearActiveProfiles().setWorkingDirectory(workingDir));

// assert that buffered models is null and stays empty when being retrieved w/ getBufferedModels
assertThat(getBufferedModels(vertx)).isNull();
Expand Down Expand Up @@ -222,7 +231,8 @@ void getSingleSharedModelsTest(Vertx vertx, VertxTestContext testContext) throws
WorkingDirectoryBuilder.hollow().addModel(TEST_RESOURCES.resolveRelated("TestService1.csn"))
.addModel(TEST_RESOURCES.resolveRelated("TestService2.csn")).build(workingDir);

NeonBeeMockHelper.registerNeonBeeMock(vertx, defaultOptions().setWorkingDirectory(workingDir));
NeonBeeMockHelper.registerNeonBeeMock(vertx,
defaultOptions().clearActiveProfiles().setWorkingDirectory(workingDir));
CompositeFuture.all(getSharedModel(vertx, "io.neonbee.test1"), getSharedModel(vertx, "io.neonbee.test2"))
.onComplete(testContext.succeeding(models -> testContext.verify(() -> {
assertThat(models.<EntityModel>resultAt(0).getEdmx().getEdm().getEntityContainer().getNamespace())
Expand Down Expand Up @@ -264,7 +274,8 @@ void getCSNModelTest(Vertx vertx, VertxTestContext testContext) {
@DisplayName("register / unregister module models")
void registerModuleModels(Vertx vertx, VertxTestContext testContext) throws IOException {
Path workingDirectory = getNeonBee().getOptions().getWorkingDirectory();
NeonBeeMockHelper.registerNeonBeeMock(vertx, defaultOptions().setWorkingDirectory(workingDirectory));
NeonBeeMockHelper.registerNeonBeeMock(vertx,
defaultOptions().clearActiveProfiles().setWorkingDirectory(workingDirectory));

// Create models
Map.Entry<String, byte[]> referenceModel = buildModelEntry("ReferenceService.csn");
Expand All @@ -289,7 +300,8 @@ void registerModuleModels(Vertx vertx, VertxTestContext testContext) throws IOEx
@DisplayName("register / unregister multiple modules to verify that changing the unmodifiable BUFFERED_MODELS is working correctly.")
void registerMultipleModuleModels(Vertx vertx, VertxTestContext testContext) throws IOException {
Path workingDirectory = getNeonBee().getOptions().getWorkingDirectory();
NeonBeeMockHelper.registerNeonBeeMock(vertx, defaultOptions().setWorkingDirectory(workingDirectory));
NeonBeeMockHelper.registerNeonBeeMock(vertx,
defaultOptions().clearActiveProfiles().setWorkingDirectory(workingDirectory));

// Create 1st models
Map.Entry<String, byte[]> referenceModel = buildModelEntry("ReferenceService.csn");
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/io/neonbee/entity/EntityVerticleTest.java
@@ -1,6 +1,7 @@
package io.neonbee.entity;

import static com.google.common.truth.Truth.assertThat;
import static io.neonbee.NeonBeeProfile.NO_WEB;
import static io.neonbee.entity.EntityVerticle.CDS_NAMESPACE_GROUP;
import static io.neonbee.entity.EntityVerticle.CDS_SERVICE_NAME_GROUP;
import static io.neonbee.entity.EntityVerticle.ENTITY_PATH_GROUP;
Expand Down Expand Up @@ -30,8 +31,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import io.neonbee.NeonBeeDeployable;
import io.neonbee.NeonBeeOptions;
import io.neonbee.data.DataAction;
import io.neonbee.data.DataContext;
import io.neonbee.data.DataQuery;
Expand All @@ -52,6 +55,11 @@ class EntityVerticleTest extends EntityVerticleTestBase {

private EntityVerticle entityVerticleImpl2;

@Override
protected void adaptOptions(TestInfo testInfo, NeonBeeOptions.Mutable options) {
options.addActiveProfile(NO_WEB);
}

@Override
protected List<Path> provideEntityModels() {
return List.of(TEST_RESOURCES.resolveRelated("TestService1.csn"));
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/io/neonbee/entity/EntityWrapperTest.java
@@ -1,6 +1,7 @@
package io.neonbee.entity;

import static com.google.common.truth.Truth.assertThat;
import static io.neonbee.NeonBeeProfile.NO_WEB;
import static io.neonbee.test.helper.ResourceHelper.TEST_RESOURCES;

import java.util.concurrent.TimeUnit;
Expand All @@ -13,13 +14,15 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import io.neonbee.NeonBeeOptions;
import io.neonbee.test.base.NeonBeeTestBase;
import io.neonbee.test.helper.WorkingDirectoryBuilder;
import io.vertx.core.buffer.Buffer;
import io.vertx.junit5.Timeout;
import io.vertx.junit5.VertxTestContext;

class EntityWrapperTest extends NeonBeeTestBase {

private static final EntityWrapper TEST_USER_WRAPPER =
new EntityWrapper("io.neonbee.test2.TestService2Users.TestUsers", createTestUser());

Expand All @@ -35,6 +38,11 @@ private static Entity createTestUser() {
return testUser;
}

@Override
protected void adaptOptions(TestInfo testInfo, NeonBeeOptions.Mutable options) {
options.addActiveProfile(NO_WEB);
}

@Override
protected WorkingDirectoryBuilder provideWorkingDirectoryBuilder(TestInfo testInfo, VertxTestContext testContext) {
return WorkingDirectoryBuilder.standard().addModel(TEST_RESOURCES.resolveRelated("TestService2.csn"));
Expand Down
@@ -1,6 +1,7 @@
package io.neonbee.internal.codec;

import static com.google.common.truth.Truth.assertThat;
import static io.neonbee.NeonBeeProfile.NO_WEB;
import static io.neonbee.test.helper.ResourceHelper.TEST_RESOURCES;

import java.util.concurrent.TimeUnit;
Expand All @@ -13,6 +14,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import io.neonbee.NeonBeeOptions;
import io.neonbee.entity.EntityModelManager;
import io.neonbee.entity.EntityWrapper;
import io.neonbee.test.base.NeonBeeTestBase;
Expand All @@ -31,6 +33,11 @@ class EntityWrapperMessageCodecTest extends NeonBeeTestBase {

private EntityWrapperMessageCodec codec;

@Override
protected void adaptOptions(TestInfo testInfo, NeonBeeOptions.Mutable options) {
options.addActiveProfile(NO_WEB);
}

@Override
protected WorkingDirectoryBuilder provideWorkingDirectoryBuilder(TestInfo testInfo, VertxTestContext testContext) {
return WorkingDirectoryBuilder.standard().addModel(TEST_RESOURCES.resolveRelated("CodecService.csn"));
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/io/neonbee/internal/deploy/DeployableTest.java
@@ -1,6 +1,7 @@
package io.neonbee.internal.deploy;

import static com.google.common.truth.Truth.assertThat;
import static io.neonbee.NeonBeeProfile.NO_WEB;
import static org.junit.jupiter.api.condition.OS.WINDOWS;

import java.io.IOException;
Expand All @@ -12,6 +13,7 @@

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
Expand All @@ -20,6 +22,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;

import io.neonbee.NeonBeeOptions;
import io.neonbee.internal.DummyVerticleTemplate;
import io.neonbee.internal.NeonBeeModuleJar;
import io.neonbee.internal.verticle.MetricsVerticle;
Expand Down Expand Up @@ -50,6 +53,11 @@ class DeployableTest extends NeonBeeTestBase {

private static final String CORRELATION_ID = "correlId";

@Override
protected void adaptOptions(TestInfo testInfo, NeonBeeOptions.Mutable options) {
options.addActiveProfile(NO_WEB);
}

@Test
@Timeout(value = 2, timeUnit = TimeUnit.SECONDS)
@DisplayName("readVerticleConfig should return DeploymentOptions correct")
Expand Down

0 comments on commit dab61cd

Please sign in to comment.