Skip to content

Commit

Permalink
Add additional unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
malikdiarra committed Feb 15, 2022
1 parent 44c968b commit 0d81c6e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public void updateConnectionState(final UUID connectionId, final State state) th
throw new IllegalStateException(e);
}
}

public Optional<ActorCatalog> getSourceCatalog(final UUID sourceId,
final String configurationHash,
final String connectorVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;

import io.airbyte.commons.json.Jsons;
import io.airbyte.config.ActorCatalog;
import io.airbyte.config.ActorCatalogFetchEvent;
import io.airbyte.config.ConfigSchema;
Expand All @@ -31,7 +30,6 @@
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -265,27 +263,30 @@ private void standardWorkspace() throws JsonValidationException, IOException, Co
}

public void standardActorCatalog() throws JsonValidationException, IOException, ConfigNotFoundException {
final SourceConnection source = MockData.sourceConnections().get(0);
final ActorCatalog actorCatalog = new ActorCatalog()
.withId(UUID.randomUUID())
.withCatalog(Jsons.deserialize("{}"))
.withCatalogHash("TESTHASH");
final ActorCatalogFetchEvent actorCatalogFetchEvent = new ActorCatalogFetchEvent()
.withId(UUID.randomUUID())
.withActorCatalogId(actorCatalog.getId())
.withActorId(source.getSourceId())
.withConfigHash("CONFIG_HASH")
.withConnectorVersion("1.0.0");

configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), actorCatalog);
final ActorCatalog retrievedActorCatalog = configPersistence.getConfig(
ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), ActorCatalog.class);
assertEquals(actorCatalog, retrievedActorCatalog);
for (final ActorCatalog actorCatalog : MockData.actorCatalogs()) {
configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), actorCatalog);
final ActorCatalog retrievedActorCatalog = configPersistence.getConfig(
ConfigSchema.ACTOR_CATALOG, actorCatalog.getId().toString(), ActorCatalog.class);
assertEquals(actorCatalog, retrievedActorCatalog);
} ;
final List<ActorCatalog> actorCatalogs = configPersistence
.listConfigs(ConfigSchema.ACTOR_CATALOG, ActorCatalog.class);
assertEquals(MockData.actorCatalogs().size(), actorCatalogs.size());
assertThat(MockData.actorCatalogs()).hasSameElementsAs(actorCatalogs);

configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, actorCatalogFetchEvent.getId().toString(), actorCatalogFetchEvent);
final ActorCatalogFetchEvent retrievedActorCatalogFetchEvent = configPersistence.getConfig(
ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, actorCatalogFetchEvent.getId().toString(), ActorCatalogFetchEvent.class);
assertEquals(actorCatalogFetchEvent, retrievedActorCatalogFetchEvent);
for (final ActorCatalogFetchEvent actorCatalogFetchEvent : MockData.actorCatalogFetchEvents()) {
configPersistence.writeConfig(ConfigSchema.ACTOR_CATALOG_FETCH_EVENT,
actorCatalogFetchEvent.getId().toString(), actorCatalogFetchEvent);
final ActorCatalogFetchEvent retrievedActorCatalogFetchEvent = configPersistence.getConfig(
ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, actorCatalogFetchEvent.getId().toString(),
ActorCatalogFetchEvent.class);
assertEquals(actorCatalogFetchEvent, retrievedActorCatalogFetchEvent);
}
final List<ActorCatalogFetchEvent> actorCatalogFetchEvents = configPersistence
.listConfigs(ConfigSchema.ACTOR_CATALOG_FETCH_EVENT, ActorCatalogFetchEvent.class);
assertEquals(MockData.actorCatalogFetchEvents().size(), actorCatalogFetchEvents.size());
assertThat(MockData.actorCatalogFetchEvents()).hasSameElementsAs(actorCatalogFetchEvents);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import com.google.common.collect.Lists;
import io.airbyte.commons.json.Jsons;
import io.airbyte.config.ActorCatalog;
import io.airbyte.config.ActorCatalogFetchEvent;
import io.airbyte.config.DestinationConnection;
import io.airbyte.config.DestinationOAuthParameter;
import io.airbyte.config.JobSyncConfig.NamespaceDefinitionType;
Expand Down Expand Up @@ -68,6 +70,12 @@ public class MockData {
private static final UUID SOURCE_OAUTH_PARAMETER_ID_2 = UUID.randomUUID();
private static final UUID DESTINATION_OAUTH_PARAMETER_ID_1 = UUID.randomUUID();
private static final UUID DESTINATION_OAUTH_PARAMETER_ID_2 = UUID.randomUUID();
private static final UUID ACTOR_CATALOG_ID_1 = UUID.randomUUID();
private static final UUID ACTOR_CATALOG_ID_2 = UUID.randomUUID();
private static final UUID ACTOR_CATALOG_ID_3 = UUID.randomUUID();
private static final UUID ACTOR_CATALOG_FETCH_EVENT_ID_1 = UUID.randomUUID();
private static final UUID ACTOR_CATALOG_FETCH_EVENT_ID_2 = UUID.randomUUID();

private static final Instant NOW = Instant.parse("2021-12-15T20:30:40.00Z");

public static StandardWorkspace standardWorkspace() {
Expand Down Expand Up @@ -341,6 +349,38 @@ public static List<StandardSyncState> standardSyncStates() {
return Arrays.asList(standardSyncState1, standardSyncState2, standardSyncState3, standardSyncState4);
}

public static List<ActorCatalog> actorCatalogs() {
final ActorCatalog actorCatalog1 = new ActorCatalog()
.withId(ACTOR_CATALOG_ID_1)
.withCatalog(Jsons.deserialize("{}"))
.withCatalogHash("TESTHASH");
final ActorCatalog actorCatalog2 = new ActorCatalog()
.withId(ACTOR_CATALOG_ID_2)
.withCatalog(Jsons.deserialize("{}"))
.withCatalogHash("12345");
final ActorCatalog actorCatalog3 = new ActorCatalog()
.withId(ACTOR_CATALOG_ID_3)
.withCatalog(Jsons.deserialize("{}"))
.withCatalogHash("SomeOtherHash");
return Arrays.asList(actorCatalog1, actorCatalog2, actorCatalog3);
}

public static List<ActorCatalogFetchEvent> actorCatalogFetchEvents() {
final ActorCatalogFetchEvent actorCatalogFetchEvent1 = new ActorCatalogFetchEvent()
.withId(ACTOR_CATALOG_FETCH_EVENT_ID_1)
.withActorCatalogId(ACTOR_CATALOG_ID_1)
.withActorId(SOURCE_ID_1)
.withConfigHash("CONFIG_HASH")
.withConnectorVersion("1.0.0");
final ActorCatalogFetchEvent actorCatalogFetchEvent2 = new ActorCatalogFetchEvent()
.withId(ACTOR_CATALOG_FETCH_EVENT_ID_2)
.withActorCatalogId(ACTOR_CATALOG_ID_2)
.withActorId(SOURCE_ID_2)
.withConfigHash("1394")
.withConnectorVersion("1.2.0");
return Arrays.asList(actorCatalogFetchEvent1);
}

public static Instant now() {
return NOW;
}
Expand Down

0 comments on commit 0d81c6e

Please sign in to comment.