Skip to content

Commit a77f3b3

Browse files
Merge pull request #38 from contentstack/CS-40978/bug-branch-region-support
CS-40978/bug branch region support
2 parents 37bfb48 + 3fedaba commit a77f3b3

File tree

13 files changed

+1491
-43
lines changed

13 files changed

+1491
-43
lines changed

.github/workflows/sast-scan.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/secrets-scan.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

contentstack/build.gradle

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,37 @@ android {
1313
multiDexEnabled true
1414
vectorDrawables.useSupportLibrary = true
1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
signingConfig signingConfigs.debug
1617
}
1718
buildTypes {
1819
def localProperties = new Properties()
1920
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
21+
22+
debug {
23+
testCoverageEnabled true
24+
buildConfigField "String", "host", localProperties['host']
25+
buildConfigField "String", "APIKey", localProperties['APIKey']
26+
buildConfigField "String", "deliveryToken", localProperties['deliveryToken']
27+
buildConfigField "String", "environment", localProperties['env']
28+
buildConfigField "String", "contentTypeUID", localProperties['contentType']
29+
buildConfigField "String", "assetUID", localProperties['assetUid']
30+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
31+
}
32+
release {
33+
minifyEnabled false
34+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
35+
buildConfigField "String", "host", localProperties['host']
36+
buildConfigField "String", "APIKey", localProperties['APIKey']
37+
buildConfigField "String", "deliveryToken", localProperties['deliveryToken']
38+
buildConfigField "String", "environment", localProperties['env']
39+
buildConfigField "String", "contentTypeUID", localProperties['contentType']
40+
buildConfigField "String", "assetUID", localProperties['assetUid']
41+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
42+
}
2043
}
2144
compileOptions {
22-
sourceCompatibility JavaVersion.VERSION_1_8
23-
targetCompatibility JavaVersion.VERSION_1_8
45+
sourceCompatibility JavaVersion.VERSION_11
46+
targetCompatibility JavaVersion.VERSION_11
2447
}
2548

2649
testOptions {
@@ -43,6 +66,6 @@ dependencies {
4366
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
4467
}
4568
java {
46-
sourceCompatibility = JavaVersion.VERSION_1_8
47-
targetCompatibility = JavaVersion.VERSION_1_8
69+
sourceCompatibility = JavaVersion.VERSION_11
70+
targetCompatibility = JavaVersion.VERSION_11
4871
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
package com.contentstack.sdk;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
6+
import org.junit.BeforeClass;
7+
import org.junit.FixMethodOrder;
8+
import org.junit.Test;
9+
import org.junit.runners.MethodSorters;
10+
11+
import java.util.List;
12+
13+
import static junit.framework.Assert.assertTrue;
14+
import static junit.framework.TestCase.assertEquals;
15+
16+
import androidx.test.InstrumentationRegistry;
17+
import androidx.test.core.app.ApplicationProvider;
18+
19+
20+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
21+
public class AssetTestCase {
22+
23+
private final String TAG = AssetTestCase.class.getSimpleName();
24+
private static String assetUid = BuildConfig.assetUID;
25+
private static Stack stack;
26+
27+
@BeforeClass
28+
public static void oneTimeSetUp() throws Exception {
29+
Context appContext = ApplicationProvider.getApplicationContext();
30+
Config config = new Config();
31+
String DEFAULT_API_KEY = BuildConfig.APIKey;
32+
String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
33+
String DEFAULT_ENV = BuildConfig.environment;
34+
String DEFAULT_HOST = BuildConfig.host;
35+
config.setHost(DEFAULT_HOST);
36+
stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
37+
}
38+
39+
40+
@Test()
41+
public void test_A_getAllAssetsToSetAssetUID() {
42+
final AssetLibrary assetLibrary = stack.assetLibrary();
43+
assetLibrary.fetchAll(new FetchAssetsCallback() {
44+
@Override
45+
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
46+
if (error == null) {
47+
Log.d(TAG, "response: " + assets.get(0).getAssetUid());
48+
assetUid = assets.get(0).getAssetUid();
49+
Log.e(assetUid, assetUid);
50+
}
51+
}
52+
});
53+
54+
}
55+
56+
@Test
57+
public void test_B_VerifyAssetUID() {
58+
final Asset asset = stack.asset(assetUid);
59+
asset.fetch(new FetchResultCallback() {
60+
@Override
61+
public void onCompletion(ResponseType responseType, Error error) {
62+
if (error == null) {
63+
// Success Block.
64+
Log.d(TAG, "response: " + asset.getAssetUid());
65+
assertEquals(assetUid, asset.getAssetUid());
66+
}
67+
}
68+
});
69+
}
70+
71+
@Test
72+
public void test_C_Asset_fetch() {
73+
final Asset asset = stack.asset(assetUid);
74+
asset.fetch(new FetchResultCallback() {
75+
@Override
76+
public void onCompletion(ResponseType responseType, Error error) {
77+
if (error == null) {
78+
assertEquals(BuildConfig.assetUID, asset.getAssetUid());
79+
assertEquals("image/jpeg", asset.getFileType());
80+
assertEquals("phoenix2.jpg", asset.getFileName());
81+
assertEquals("482141", asset.getFileSize());
82+
} else {
83+
assertEquals(0, error.getErrorCode());
84+
}
85+
}
86+
});
87+
}
88+
89+
@Test
90+
public void test_D_AssetLibrary_fetch() {
91+
final AssetLibrary assetLibrary = stack.assetLibrary();
92+
assetLibrary.fetchAll(new FetchAssetsCallback() {
93+
@Override
94+
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
95+
if (error == null) {
96+
assets.forEach(asset -> {
97+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.toJSON());
98+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileType());
99+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getCreatedBy());
100+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getUpdatedBy());
101+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileName());
102+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileSize());
103+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getAssetUid());
104+
Log.d(TAG, "----Test--Asset-D--Success----" + asset.getUrl());
105+
});
106+
}
107+
}
108+
});
109+
}
110+
111+
@Test
112+
public void test_E_AssetLibrary_includeCount_fetch() {
113+
final AssetLibrary assetLibrary = stack.assetLibrary();
114+
assetLibrary.includeCount();
115+
assetLibrary.fetchAll(new FetchAssetsCallback() {
116+
@Override
117+
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
118+
if (error == null) {
119+
assertEquals(16, assetLibrary.getCount());
120+
}
121+
}
122+
});
123+
}
124+
125+
@Test
126+
public void test_F_AssetLibrary_includeRelativeUrl_fetch() {
127+
final AssetLibrary assetLibrary = stack.assetLibrary();
128+
assetLibrary.includeRelativeUrl();
129+
assetLibrary.fetchAll(new FetchAssetsCallback() {
130+
public void onCompletion(ResponseType responseType, List<Asset> assets, Error error) {
131+
if (error == null) {
132+
assertTrue(assets.get(0).getUrl().contains("phoenix2.jpg"));
133+
}
134+
}
135+
});
136+
}
137+
138+
@Test
139+
public void test_G_Include_Dimension() {
140+
final Asset asset = stack.asset(assetUid);
141+
asset.includeDimension();
142+
asset.fetch(new FetchResultCallback() {
143+
@Override
144+
public void onCompletion(ResponseType responseType, Error error) {
145+
if (error == null) {
146+
Log.d(TAG, asset.getAssetUid());
147+
assertEquals(assetUid, asset.getAssetUid());
148+
}
149+
}
150+
});
151+
}
152+
153+
154+
@Test
155+
public void test_H_include_fallback() {
156+
final Asset asset = stack.asset(assetUid);
157+
asset.includeFallback();
158+
asset.fetch(new FetchResultCallback() {
159+
@Override
160+
public void onCompletion(ResponseType responseType, Error error) {
161+
if (error == null) {
162+
Log.d(TAG, asset.getAssetUid());
163+
assertEquals(assetUid, asset.getAssetUid());
164+
}
165+
}
166+
});
167+
}
168+
169+
@Test
170+
public void test_AZURE_NA() throws Exception {
171+
Config config = new Config();
172+
String DEFAULT_API_KEY = BuildConfig.APIKey;
173+
String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
174+
String DEFAULT_ENV = BuildConfig.environment;
175+
String DEFAULT_HOST = BuildConfig.host;
176+
config.setHost(DEFAULT_HOST);
177+
config.setRegion(Config.ContentstackRegion.AZURE_NA);
178+
Context appContext = InstrumentationRegistry.getTargetContext();
179+
stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
180+
}
181+
182+
}

0 commit comments

Comments
 (0)