Skip to content

Commit

Permalink
Merge pull request #38 from contentstack/CS-40978/bug-branch-region-s…
Browse files Browse the repository at this point in the history
…upport

CS-40978/bug branch region support
  • Loading branch information
ishaileshmishra authored Aug 30, 2023
2 parents 8a8959a + af88994 commit 0bb297e
Show file tree
Hide file tree
Showing 13 changed files with 1,491 additions and 43 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

31 changes: 27 additions & 4 deletions contentstack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,37 @@ android {
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.debug
}
buildTypes {
def localProperties = new Properties()
localProperties.load(new FileInputStream(rootProject.file("local.properties")))

debug {
testCoverageEnabled true
buildConfigField "String", "host", localProperties['host']
buildConfigField "String", "APIKey", localProperties['APIKey']
buildConfigField "String", "deliveryToken", localProperties['deliveryToken']
buildConfigField "String", "environment", localProperties['env']
buildConfigField "String", "contentTypeUID", localProperties['contentType']
buildConfigField "String", "assetUID", localProperties['assetUid']
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "host", localProperties['host']
buildConfigField "String", "APIKey", localProperties['APIKey']
buildConfigField "String", "deliveryToken", localProperties['deliveryToken']
buildConfigField "String", "environment", localProperties['env']
buildConfigField "String", "contentTypeUID", localProperties['contentType']
buildConfigField "String", "assetUID", localProperties['assetUid']
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

testOptions {
Expand All @@ -43,6 +66,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package com.contentstack.sdk;

import android.content.Context;
import android.util.Log;

import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import java.util.List;

import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;

import androidx.test.InstrumentationRegistry;
import androidx.test.core.app.ApplicationProvider;


@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AssetTestCase {

private final String TAG = AssetTestCase.class.getSimpleName();
private static String assetUid = BuildConfig.assetUID;
private static Stack stack;

@BeforeClass
public static void oneTimeSetUp() throws Exception {
Context appContext = ApplicationProvider.getApplicationContext();
Config config = new Config();
String DEFAULT_API_KEY = BuildConfig.APIKey;
String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
String DEFAULT_ENV = BuildConfig.environment;
String DEFAULT_HOST = BuildConfig.host;
config.setHost(DEFAULT_HOST);
stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
}


@Test()
public void test_A_getAllAssetsToSetAssetUID() {
final AssetLibrary assetLibrary = stack.assetLibrary();
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
if (error == null) {
Log.d(TAG, "response: " + assets.get(0).getAssetUid());
assetUid = assets.get(0).getAssetUid();
Log.e(assetUid, assetUid);
}
}
});

}

@Test
public void test_B_VerifyAssetUID() {
final Asset asset = stack.asset(assetUid);
asset.fetch(new FetchResultCallback() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
if (error == null) {
// Success Block.
Log.d(TAG, "response: " + asset.getAssetUid());
assertEquals(assetUid, asset.getAssetUid());
}
}
});
}

@Test
public void test_C_Asset_fetch() {
final Asset asset = stack.asset(assetUid);
asset.fetch(new FetchResultCallback() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
if (error == null) {
assertEquals(BuildConfig.assetUID, asset.getAssetUid());
assertEquals("image/jpeg", asset.getFileType());
assertEquals("phoenix2.jpg", asset.getFileName());
assertEquals("482141", asset.getFileSize());
} else {
assertEquals(0, error.getErrorCode());
}
}
});
}

@Test
public void test_D_AssetLibrary_fetch() {
final AssetLibrary assetLibrary = stack.assetLibrary();
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
if (error == null) {
assets.forEach(asset -> {
Log.d(TAG, "----Test--Asset-D--Success----" + asset.toJSON());
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileType());
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getCreatedBy());
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getUpdatedBy());
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileName());
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileSize());
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getAssetUid());
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getUrl());
});
}
}
});
}

@Test
public void test_E_AssetLibrary_includeCount_fetch() {
final AssetLibrary assetLibrary = stack.assetLibrary();
assetLibrary.includeCount();
assetLibrary.fetchAll(new FetchAssetsCallback() {
@Override
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
if (error == null) {
assertEquals(16, assetLibrary.getCount());
}
}
});
}

@Test
public void test_F_AssetLibrary_includeRelativeUrl_fetch() {
final AssetLibrary assetLibrary = stack.assetLibrary();
assetLibrary.includeRelativeUrl();
assetLibrary.fetchAll(new FetchAssetsCallback() {
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
if (error == null) {
assertTrue(assets.get(0).getUrl().contains("phoenix2.jpg"));
}
}
});
}

@Test
public void test_G_Include_Dimension() {
final Asset asset = stack.asset(assetUid);
asset.includeDimension();
asset.fetch(new FetchResultCallback() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
if (error == null) {
Log.d(TAG, asset.getAssetUid());
assertEquals(assetUid, asset.getAssetUid());
}
}
});
}


@Test
public void test_H_include_fallback() {
final Asset asset = stack.asset(assetUid);
asset.includeFallback();
asset.fetch(new FetchResultCallback() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
if (error == null) {
Log.d(TAG, asset.getAssetUid());
assertEquals(assetUid, asset.getAssetUid());
}
}
});
}

@Test
public void test_AZURE_NA() throws Exception {
Config config = new Config();
String DEFAULT_API_KEY = BuildConfig.APIKey;
String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
String DEFAULT_ENV = BuildConfig.environment;
String DEFAULT_HOST = BuildConfig.host;
config.setHost(DEFAULT_HOST);
config.setRegion(Config.ContentstackRegion.AZURE_NA);
Context appContext = InstrumentationRegistry.getTargetContext();
stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
}

}
Loading

0 comments on commit 0bb297e

Please sign in to comment.