Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.github.arachnidium.model.common;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.sf.cglib.core.Signature;
import net.sf.cglib.proxy.MethodProxy;
import org.apache.commons.lang3.ArrayUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import com.github.arachnidium.core.HowToGetPage;
import com.github.arachnidium.core.HowToGetMobileScreen;
import com.github.arachnidium.core.fluenthandle.IHowToGetHandle;
import com.github.arachnidium.core.settings.supported.ESupportedDrivers;
import com.github.arachnidium.model.abstractions.ModelObject;
import com.github.arachnidium.model.interfaces.IDecomposable;
import com.github.arachnidium.model.support.HowToGetByFrames;
import com.github.arachnidium.model.support.annotations.ClassDeclarationReader;
import com.github.arachnidium.model.support.annotations.DefaultContextIndex;
import com.github.arachnidium.model.support.annotations.DefaultPageIndex;
import com.github.arachnidium.model.support.annotations.ExpectedAndroidActivity;
import com.github.arachnidium.model.support.annotations.ExpectedContext;
import com.github.arachnidium.model.support.annotations.ExpectedPageTitle;
import com.github.arachnidium.model.support.annotations.ExpectedURL;
import com.github.arachnidium.model.support.annotations.Frame;
import com.github.arachnidium.model.support.annotations.TimeOut;
import com.github.arachnidium.model.support.annotations.rootelements.CommonRootElementReader;
import com.github.arachnidium.model.support.annotations.rootelements.ElementReaderForMobilePlatforms;
import com.github.arachnidium.model.support.annotations.rootelements.IRootElementReader;
import com.github.arachnidium.model.support.annotations.rootelements.RootAndroidElement;
import com.github.arachnidium.model.support.annotations.rootelements.RootIOSElement;
import com.github.arachnidium.util.proxy.EnhancedProxyFactory;
import com.github.arachnidium.util.reflect.annotations.AnnotationUtil;
import com.github.arachnidium.util.reflect.executable.ExecutableUtil;
abstract class DecompositionUtil {
static final String GET_PART = "getPart";
/**
* Creation of any decomposable part of application
*/
static T get(Class partClass,
Object[] paramValues) {
try{
Constructor> c = ExecutableUtil.getRelevantConstructor(partClass, paramValues);
if (c == null){
throw new RuntimeException(new NoSuchMethodException("There is no cunstructor which matches to " + Arrays.asList(paramValues).toString() +
". The target class is " + partClass.getName()));
}
T decomposable = EnhancedProxyFactory.getProxy(partClass,
c.getParameterTypes(), paramValues,
new InteractiveInterceptor() {
});
DecompositionUtil.populateFieldsWhichAreDecomposable((ModelObject>) decomposable);
return decomposable;
}
catch (Exception e){
throw new RuntimeException(e);
}
}
/**
* This method populates fields of classes which implements {@link ModelObject}
* This field should be merked by {@link Static}. It can be marked by {@link Frame},
* {@link RootElement}/{@link RootAndroidElement}/{@link RootIOSElement}
*
* @param targetDecomposableObject this is the object whose fields should be populated
*/
static void populateFieldsWhichAreDecomposable(
ModelObject> targetDecomposableObject) {
Class> clazz = targetDecomposableObject.getClass();
ESupportedDrivers supportedDriver = targetDecomposableObject.
getWebDriverEncapsulation().getInstantiatedSupportedDriver();
while (clazz != Object.class) {
List fields = Arrays.asList(clazz.getDeclaredFields());
for (Field field: fields){
try {
field.setAccessible(true);
if (!field.isAnnotationPresent(Static.class)||
field.get(targetDecomposableObject) != null) {
continue;
}
Class> fieldClass = field.getType();
//if here is possible list of decomposable object
if (List.class.isAssignableFrom(fieldClass) && getClassFromTheList(field) != null){
field.set(targetDecomposableObject, EnhancedProxyFactory.
getProxy(ArrayList.class, new Class>[] {},
new Object[]{}, new DecomposableListInterceptor(field,
targetDecomposableObject, supportedDriver)));
continue;
}
if (ModelObject.class.isAssignableFrom(fieldClass)){ //if here is a field where
//should be only single object
Object[] args = new Object[] {field.getType()};
Method m = ExecutableUtil.getRelevantMethod(clazz, GET_PART, args);
if (Application.class.isAssignableFrom(clazz)){
args = getRelevantArgs2(supportedDriver, m, args, field);
}
else{
args = getRelevantArgs(supportedDriver, m, args, field);
}
m = ExecutableUtil.getRelevantMethod(clazz, GET_PART, args);
ModelObject> value = (ModelObject>) m.invoke(targetDecomposableObject, args);
field.set(targetDecomposableObject, value);
//ModelObject fields of a new mock-instance are mocked too
populateFieldsWhichAreDecomposable((ModelObject>) value);
continue;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
};
clazz = clazz.getSuperclass();
}
}
/**
* Creates an instance of {@link HowToGetByFrames} class if
* the given class is annotated by {@link Frame}.
*
* @param params
* @param targetClass It is a class which is supposed to be annotated by {@link Frame}
*
* @return A {@link HowToGetByFrames} strategy instance if the
* given class is annotated by {@link Frame}
*
* null if the
* given class isn't annotated by {@link Frame}
*/
static HowToGetByFrames getHowToGetByFramesStrategy(AnnotatedElement annotatedElement){
List