Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions declex-test/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.dspot.declex.test"
minSdkVersion 9
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand All @@ -19,13 +19,15 @@ android {
}

dependencies {
annotationProcessor 'com.dspot:declex:2.0.a.4'
compile 'com.dspot:declex-api:2.0.a.4'
annotationProcessor 'com.dspot:declex:2.0.a.16'
compile 'com.dspot:declex-api:2.0.a.16'
compile 'com.dspot:declex-actions:2.0.a.8'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.jayway.awaitility:awaitility:1.4.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.+'

Expand All @@ -36,6 +38,8 @@ dependencies {
testCompile 'org.powermock:powermock-api-mockito2:1.7.0RC4'
testCompile "org.powermock:powermock-classloading-xstream:1.7.0RC4"

configurations.all { resolutionStrategy { force 'org.objenesis:objenesis:2.1' } }

testCompile 'junit:junit:4.12'
}

4 changes: 3 additions & 1 deletion declex-test/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
<manifest package="com.dspot.declex.test"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity android:name=".action.ActionMainActivity_"/>
<activity android:name=".action.ActionSecondActivity_"/>
<activity android:name=".injection.property.PropertyInjectionActivity_"/>

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.dspot.declex.test.model.loadmodel;

import com.dspot.declex.annotation.Model;
import com.dspot.declex.test.model.loadmodel.model.ServerModelEntity_;
import org.androidannotations.annotations.EBean;

import java.util.List;

import static com.dspot.declex.actions.Action.$LoadModel;

@EBean
public class ModelBean {

@Model
ServerModelEntity_ modelEntity;

@Model(lazy = true, async = true, orderBy = "read")
ServerModelEntity_ readModelEntity;

@Model(lazy = true, async = true)
List<ServerModelEntity_> enhancedModelEntityList;

// Query
public void loadModelQuery(Runnable Done, Runnable Failed) {
$LoadModel(modelEntity);
if($LoadModel.Failed) {
if(Failed != null) Failed.run();
}
if(Done != null) Done.run();
}

public void readModelQuery() {
$LoadModel(readModelEntity).query("1");
if($LoadModel.Failed) {
System.out.print("Failed Load Model");
}
System.out.print("Load Model Successfully");
}

// Fields
public void loadModelFieldsOrderQuery() {
$LoadModel(enhancedModelEntityList).query("id=1").fields("userId, title, body").orderBy("userId ASC");
if($LoadModel.Failed) {
System.out.print("Failed Load Model");
}
System.out.print("Load Model Successfully");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dspot.declex.test.model.loadmodel;

import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

import okhttp3.OkHttpClient;

/**
* http://jsonplaceholder.typicode.com/ is a free online REST service that you can use whenever you need some fake data.
* We have used a free service published on the internet for the testing of rest api by developers.
* There are references to this service on GitHub. https://github.com/typicode/jsonplaceholder
*
* Here are the configurations use all throughout the program.
*/

public class ServerModelConfig {
/**
* The constant SERVER.
*/
public static final String SERVER = "http://jsonplaceholder.typicode.com/";

/**
* Default OkHttpClient to use in whole the app
* from here it can be controlled parameters as timeouts, SSL and more
* related to the connection with the Back-End
*/
public final static OkHttpClient OK_HTTP_CLIENT = new OkHttpClient.Builder()
.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
})
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (C) 2016-2017 DSpot Sp. z o.o
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dspot.declex.test.model.loadmodel.model;

import com.dspot.declex.annotation.ServerModel;
import com.dspot.declex.annotation.ServerRequest;
import com.dspot.declex.annotation.UseModel;
import com.dspot.declex.test.model.loadmodel.ServerModelConfig;

import okhttp3.OkHttpClient;

@ServerModel (
baseUrl = ServerModelConfig.SERVER,
getHeaders = "Accept=*/*",

load = {
@ServerRequest(
name = "list",
method = ServerRequest.RequestMethod.Get,
action = "posts"
),
@ServerRequest(
name = "read",
method = ServerRequest.RequestMethod.Get,
action = "posts/{query}"
),
}
)

@UseModel
public class ServerModelEntity {
int id;
int userId;
String title;
String body;

@ServerModel
static OkHttpClient okHttpClient = ServerModelConfig.OK_HTTP_CLIENT;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.dspot.declex.test.model.loadmodel;

import com.dspot.declex.actions.LoadModelActionHolder_;
import com.dspot.declex.annotation.Model;
import com.dspot.declex.api.action.runnable.OnFailedRunnable;
import com.dspot.declex.test.model.loadmodel.model.ServerModelEntity_;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import static com.jayway.awaitility.Awaitility.*;

@RunWith(RobolectricTestRunner.class)
@Config(
manifest = "app/src/main/AndroidManifest.xml",
sdk = 25
)
@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*", "javax.net.ssl.*", "org.powermock.*" })
@PrepareForTest({ModelBean_.class, LoadModelActionHolder_.class})
public class TestLoadModel {

@Rule
public PowerMockRule rule = new PowerMockRule();

@Before
public void setUp() throws Exception {

}

@Test
public void testLoadModelMockAction() {
String title = "Testing";
Map<String, Object> args = new HashMap();
args.put("title", "testing");

LoadModelActionHolder_ loadModel = mock(LoadModelActionHolder_.class);
when(loadModel.getQuery()).thenReturn("title="+title+"");
when(loadModel.getFields()).thenReturn("title, body");
when(loadModel.getArgs()).thenReturn(args);

assertEquals("title=Testing", loadModel.getQuery());
assertEquals("title, body", loadModel.getFields());
assertEquals("testing", loadModel.getArgs().get("title"));
}

@Test
public void testLoadModelAction() {
String title = "Testing";

LoadModelActionHolder_ loadModel = LoadModelActionHolder_.getInstance_(RuntimeEnvironment.application);
loadModel.query("title="+title+"");
loadModel.fields("title, body");
loadModel.orderBy("Id ASC");

assertEquals("title=Testing", loadModel.getQuery());
assertEquals("title, body", loadModel.getFields());
assertEquals("Id ASC", loadModel.getOrderBy());
}

@Test
public void testLoadModelModelQuery() {
final AtomicBoolean Done = new AtomicBoolean(false);
final AtomicBoolean Failed = new AtomicBoolean(false);

{
ModelBean_ bean = ModelBean_.getInstance_(RuntimeEnvironment.application);
bean.$loadModelQuery(new Runnable() {
@Override
public void run() {
Done.set(true);
}
}, new OnFailedRunnable() {
@Override
public void run() {
Failed.set(false);
}
});
}

await().untilTrue(Done);
await().untilFalse(Failed);
}
}
2 changes: 2 additions & 0 deletions declex-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ allprojects {
jcenter()
mavenCentral()
mavenLocal()

maven {url 'https://dl.bintray.com/dspot-developers/declex'}
}
}

Expand Down