Skip to content

Commit

Permalink
Add unit tests for DartDataStoreClientProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
rajuGT committed Oct 23, 2024
1 parent 85b6455 commit 5d37d29
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.gotocompany.dagger.functions.udfs.scalar.dart.store;

import com.gotocompany.dagger.functions.common.Constants;
import com.gotocompany.dagger.functions.udfs.scalar.dart.store.gcs.GcsDartClient;
import com.gotocompany.dagger.functions.udfs.scalar.dart.store.oss.OssDartClient;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class DartDataStoreClientProviderTest {
private DartDataStoreClientProvider dartDataStoreClientProvider;

@Before
public void setUp() {
dartDataStoreClientProvider = null;
}

@Test
public void shouldReturnGcsDartClientWhenUdfStoreProviderIsGcs() {
String udfStoreProvider = Constants.UDF_STORE_PROVIDER_GCS;
String projectID = "test-project";

dartDataStoreClientProvider = new DartDataStoreClientProvider(udfStoreProvider, projectID);

DartDataStoreClient client = dartDataStoreClientProvider.getDartDataStoreClient();

assertTrue(client instanceof GcsDartClient);
}

@Test
public void shouldReturnOssDartClientWhenUdfStoreProviderIsOss() {
String udfStoreProvider = Constants.UDF_STORE_PROVIDER_OSS;

dartDataStoreClientProvider = new DartDataStoreClientProvider(udfStoreProvider, null);
DartDataStoreClient client = dartDataStoreClientProvider.getDartDataStoreClient();

assertTrue(client instanceof OssDartClient);
}

@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionForUnknownUdfStoreProvider() {
String udfStoreProvider = "UNKNOWN-PROVIDER";

dartDataStoreClientProvider = new DartDataStoreClientProvider(udfStoreProvider, null);

try {
dartDataStoreClientProvider.getDartDataStoreClient();
} catch (IllegalArgumentException e) {
Assert.assertEquals("Unknown UDF Store Provider: UNKNOWN-PROVIDER", e.getMessage());
throw e;
}
}

@Test
public void shouldReturnSameClientOnSubsequentCalls() {
String udfStoreProvider = Constants.UDF_STORE_PROVIDER_GCS;
String projectID = "test-project";

dartDataStoreClientProvider = new DartDataStoreClientProvider(udfStoreProvider, projectID);

DartDataStoreClient firstClient = dartDataStoreClientProvider.getDartDataStoreClient();
DartDataStoreClient secondClient = dartDataStoreClientProvider.getDartDataStoreClient();

Assert.assertEquals(firstClient, secondClient);
}
}

0 comments on commit 5d37d29

Please sign in to comment.