Search in sources :

Example 1 with HessianDecoder

use of com.vodafone360.people.service.utils.hessian.HessianDecoder in project 360-Engine-for-Android by 360.

the class HessianDecoderTest method testErrorResponse.

@MediumTest
public void testErrorResponse() {
    // boolean testPassed = true;
    List<BaseDataType> clist = new ArrayList<BaseDataType>();
    HessianDecoder hess = new HessianDecoder();
    try {
        DecodedResponse resp = hess.decodeHessianByteArray(6, testErrorResponse, Type.COMMON, false, EngineId.UNDEFINED);
        clist = resp.mDataTypes;
    } catch (IOException e) {
        e.printStackTrace();
        assertTrue("IOException thrown", false);
    }
    int size = clist.size();
    assertTrue(size == 1);
    assertTrue(clist.get(0) instanceof ServerError);
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 2 with HessianDecoder

use of com.vodafone360.people.service.utils.hessian.HessianDecoder in project 360-Engine-for-Android by 360.

the class SmsBroadcastReceiver method onReceive.

/**
 * Implementation of the {@link BroadcastReceiver#onReceive} function.
 * Decodes Hessian from SMS text and broadcasts the data to the engines
 *
 * @param context The current context of the People application
 * @param intent Intent containing the SMS data
 */
@Override
public void onReceive(Context context, Intent intent) {
    LogUtils.logD("SmsBroadcastReceiver.onReceive - Begin of sms receiver. \n" + intent.toString());
    Bundle bundle = intent.getExtras();
    Object[] messages = (Object[]) bundle.get("pdus");
    SmsMessage[] smsMessage = new SmsMessage[messages.length];
    for (int n = 0; n < messages.length; n++) {
        try {
            smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
            LogUtils.logD("SmsBroadcastReceiver.onReceive - SMS no [" + n + "]bytes: " + new String(smsMessage[n].getUserData()));
            HessianDecoder hd = new HessianDecoder();
            Hashtable<String, Object> ht = hd.decodeHessianByteArrayToHashtable(smsMessage[n].getUserData());
            if (ht != null) {
                LogUtils.logD("SmsBroadcastReceiver.onReceive - Decoded hashtable: " + ht.toString());
                Hashtable<?, ?> codeTable = (Hashtable<?, ?>) ht.get("e");
                String code = (String) codeTable.get("r");
                LogUtils.logD("SmsBroadcastReceiver.onReceive - Activation code: " + code);
                Intent in = new Intent(ACTION_ACTIVATION_CODE);
                in.putExtra("code", code);
                context.sendBroadcast(in);
            } else {
                String code = "No code in SMS";
                LogUtils.logD("SmsBroadcastReceiver.onReceive - Code not in sms");
                Intent in = new Intent(ACTION_ACTIVATION_CODE);
                in.putExtra("code", code);
                context.sendBroadcast(in);
            }
        } catch (IOException e) {
            LogUtils.logE("SmsBroadcastReceiver.onReceive() " + "IOException while decoding SMS Message.", e);
        }
    }
}
Also used : Bundle(android.os.Bundle) Hashtable(java.util.Hashtable) Intent(android.content.Intent) IOException(java.io.IOException) SmsMessage(android.telephony.gsm.SmsMessage) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder)

Example 3 with HessianDecoder

use of com.vodafone360.people.service.utils.hessian.HessianDecoder in project 360-Engine-for-Android by 360.

the class HessianDecoderTest method testUserProfileResponse.

@MediumTest
public void testUserProfileResponse() {
    // boolean testPassed = true;
    List<BaseDataType> ulist = new ArrayList<BaseDataType>();
    HessianDecoder hess = new HessianDecoder();
    try {
        DecodedResponse resp = hess.decodeHessianByteArray(2, testUserProfileData, Type.COMMON, false, EngineId.UNDEFINED);
        ulist = resp.mDataTypes;
    } catch (IOException e) {
        e.printStackTrace();
        assertTrue("IOException thrown", false);
    }
    int size = ulist.size();
    assertTrue(size == 1);
    assertTrue(ulist.get(0) instanceof UserProfile);
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) UserProfile(com.vodafone360.people.datatypes.UserProfile) ArrayList(java.util.ArrayList) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 4 with HessianDecoder

use of com.vodafone360.people.service.utils.hessian.HessianDecoder in project 360-Engine-for-Android by 360.

the class HessianDecoderTest method testSessionResponse.

/*
	 * 
	 * r{1}{0}fS{0}{4}codeS{0}{14}INTERNAL_ERRORS{0}{7}
	 * messageS{0}hError occured while getting contacts. Message was: Object reference not set to an instance of an object.S{0}{7}detailsMt{0}{0}S{0}{5}classS{0}Dcom.vodafone.next.api.common.APIStructures$APIInternalErrorExceptionzzz
	 */
@MediumTest
public void testSessionResponse() {
    // boolean testPassed = true;
    List<BaseDataType> slist = new ArrayList<BaseDataType>();
    HessianDecoder hess = new HessianDecoder();
    try {
        DecodedResponse resp = hess.decodeHessianByteArray(1, testSessionData, Type.COMMON, false, EngineId.UNDEFINED);
        slist = resp.mDataTypes;
    } catch (IOException e) {
        e.printStackTrace();
        assertTrue("IOException thrown", false);
    }
    int size = slist.size();
    assertTrue(size == 1);
    assertTrue(slist.get(0) instanceof AuthSessionHolder);
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) ArrayList(java.util.ArrayList) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 5 with HessianDecoder

use of com.vodafone360.people.service.utils.hessian.HessianDecoder in project 360-Engine-for-Android by 360.

the class HessianDecoderTest method testIdentityListResponse.

@MediumTest
public void testIdentityListResponse() {
    // boolean testPassed = true;
    List<BaseDataType> clist = new ArrayList<BaseDataType>();
    HessianDecoder hess = new HessianDecoder();
    try {
        DecodedResponse resp = hess.decodeHessianByteArray(4, testIdentityListData, Type.COMMON, false, EngineId.UNDEFINED);
        clist = resp.mDataTypes;
    } catch (IOException e) {
        e.printStackTrace();
        assertTrue("IOException thrown", false);
    }
    int size = clist.size();
    assertTrue(size == 1);
    assertTrue(clist.get(0) instanceof Identity);
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ArrayList(java.util.ArrayList) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) IOException(java.io.IOException) Identity(com.vodafone360.people.datatypes.Identity) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

HessianDecoder (com.vodafone360.people.service.utils.hessian.HessianDecoder)8 IOException (java.io.IOException)8 MediumTest (android.test.suitebuilder.annotation.MediumTest)7 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)7 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)7 ArrayList (java.util.ArrayList)7 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 SmsMessage (android.telephony.gsm.SmsMessage)1 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)1 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)1 Contact (com.vodafone360.people.datatypes.Contact)1 Identity (com.vodafone360.people.datatypes.Identity)1 PushEvent (com.vodafone360.people.datatypes.PushEvent)1 ServerError (com.vodafone360.people.datatypes.ServerError)1 SystemNotification (com.vodafone360.people.datatypes.SystemNotification)1 UserProfile (com.vodafone360.people.datatypes.UserProfile)1 Hashtable (java.util.Hashtable)1