Skip to content

Commit

Permalink
Merge pull request #39 from contentstack/next
Browse files Browse the repository at this point in the history
Next :   fixed issues related to branch and region support
  • Loading branch information
ishaileshmishra authored Sep 7, 2023
2 parents 9c33acf + 43b8db0 commit 6f94480
Show file tree
Hide file tree
Showing 16 changed files with 1,497 additions and 50 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# - name: Autobuild
# uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -64,5 +64,5 @@ jobs:
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
# - name: Perform CodeQL Analysis
# uses: github/codeql-action/analyze@v2
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.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2012 - 2023 Contentstack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 7 additions & 6 deletions contentstack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ 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")))
//def localProperties = new Properties()
//localProperties.load(new FileInputStream(rootProject.file("local.properties")))
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

testOptions {
Expand All @@ -43,6 +44,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 6f94480

Please sign in to comment.