Package com.betfair.testing.utils.cougar.misc

Examples of com.betfair.testing.utils.cougar.misc.DataTypeEnum


      }

      StepMetaData stepMetaData = expMetaData.getMetaDataAtIndex(0);

      if ((actualHashMap.size()!=0) && (allContainedObjectsTheSame)) {
        DataTypeEnum type = ObjectUtil.resolveType(currentClass);

        switch(type) {
        case JAVA_DOT_LANG_OBJECT:
        case STRING:
          for (int i = 0; i < stepMetaData.size(); i++) {
View Full Code Here


    if ((expectedMap == null) || (actualMap == null)) {
            AssertionUtils.jettAssertEquals("Checking LinkedHashMap: ", expectedMap, actualMap);
      return;
    }

    DataTypeEnum keyType = null;
    Class<?> keyClass = null;
    if (actualMap.size() > 0) {
      Set<Object> keySet = actualMap.keySet();
      for(Object key: keySet) {
        if (keyClass == null) {
          keyClass = key.getClass();
        } else {
          if (key.getClass().isAssignableFrom(keyClass)) {
            keyClass = key.getClass();
          } else if (keyClass.isAssignableFrom(key.getClass())) {
            //Ok
          } else {
            throw new AssertionError("JETT can only assert maps where keys have the same class");
          }
        }
      }
      keyType = ObjectUtil.resolveType(keyClass);
    }

    //Check keys order
    List<Object> actKeys = new ArrayList<Object>();
    for (Object actKey: actualMap.keySet()) {
      actKeys.add(actKey);
    }

    Map<Object, Object> castedKeysMap = new LinkedHashMap<Object, Object>();
    int actualKeyPreviousPos = Integer.MIN_VALUE;
    Object previousKey = null;
    for (Object expKey: expectedMap.keySet()) {
      String compareMessage = "Checking LinkedHashMap ";

      Object castedExpKey;
      switch (keyType) {
      case JAVA_DOT_LANG_OBJECT:
      case STRING:
        castedExpKey = Reflect.getWrappedValue(keyClass, expKey);
        break;
      default:
        try {
          castedExpKey = keyClass.cast(expKey);
        } catch (ClassCastException e) {
                    AssertionUtils.actionFail(compareMessage + " - Unable to cast expected key '" + expKey.toString() + "' to the class of actual keys '" + keyClass + "'");
          continue;
        }
        break;
      }
      castedKeysMap.put(castedExpKey, expectedMap.get(expKey));

      if (actKeys.contains(castedExpKey)) {
        int actualKeyPosition = actKeys.indexOf(castedExpKey);
        if (actualKeyPreviousPos != Integer.MIN_VALUE) {
          if (actualKeyPosition <= actualKeyPreviousPos) {
                        AssertionUtils.actionFail(compareMessage + "- Key order not as expected in LinkedHashMap - '" + castedExpKey + "' did not follow '" + previousKey + "'");
          } else {
                        AssertionUtils.actionPass(compareMessage + "- Key order as expected in LinkedHashMap - '" + castedExpKey + "' followed '" + previousKey + "'");
          }
        }
        actualKeyPreviousPos = actualKeyPosition;
        previousKey = castedExpKey;
      } else {
                AssertionUtils.actionFail(compareMessage + "- Key not present in LinkedHashMap: '" + castedExpKey + "'");
      }
    }

    for (Object castedExpKey : castedKeysMap.keySet()) {
      String compareMessage = "Checking LinkedHashMap Entry for Key '" + castedExpKey.toString() + "' ";

      if (!actualMap.containsKey(castedExpKey)) {
        //Failure already reported above
        continue;
      }

      Object expectedObj = castedKeysMap.get(castedExpKey);
      Object actualObj = actualMap.get(castedExpKey);

      if (expectedObj==null) {
                AssertionUtils.jettAssertNull(compareMessage + "expected object is null, check if actual object is null.",actualObj);
      } else if (actualObj==null) {
                AssertionUtils.jettAssertNull(compareMessage + "actual is object is null, checking if expected object is null.",expectedObj);
      } else {
        DataTypeEnum type;
        type = ObjectUtil.resolveType(actualObj);
        switch(type) {
        case JAVA_DOT_LANG_OBJECT:
        case STRING:
          Object castedExpectedObj = Reflect.getWrappedValue(actualObj.getClass(), expectedObj);
View Full Code Here

    if ((expectedMap == null) || (actualMap == null)) {
            AssertionUtils.jettAssertEquals("Checking LinkedHashMap: ", expectedMap, actualMap);
      return;
    }

    DataTypeEnum keyType = null;
    Class<?> keyClass = null;
    if (actualMap.size() > 0) {
      Set<Object> keySet = actualMap.keySet();
      for(Object key: keySet) {
        if (keyClass == null) {
          keyClass = key.getClass();
        } else {
          if (key.getClass().isAssignableFrom(keyClass)) {
            keyClass = key.getClass();
          } else if (keyClass.isAssignableFrom(key.getClass())) {
            //Ok
          } else {
            throw new AssertionError("JETT can only assert maps where keys have the same class");
          }
        }
      }
      keyType = ObjectUtil.resolveType(keyClass);
    }

    //Check keys order
    List<Object> actKeys = new ArrayList<Object>();
    for (Object actKey: actualMap.keySet()) {
      actKeys.add(actKey);
    }

    Map<Object, Object> castedKeysMap = new LinkedHashMap<Object, Object>();
    int keyCounter = 0;
    for (Object expKey: expectedMap.keySet()) {
      String compareMessage = "Checking LinkedHashMap Key at position " + keyCounter;

      Object castedExpKey;
      switch (keyType) {
      case JAVA_DOT_LANG_OBJECT:
      case STRING:
        castedExpKey = Reflect.getWrappedValue(keyClass, expKey);
        break;
      default:
        try {
          castedExpKey = keyClass.cast(expKey);
        } catch (ClassCastException e) {
                    AssertionUtils.actionFail(compareMessage + ": Unable to cast expected key '" + expKey.toString() + "' to the class of actual keys '" + keyClass + "'");
          continue;
        }
        break;
      }
      castedKeysMap.put(castedExpKey, expectedMap.get(expKey));

      if (actKeys.size() > keyCounter) {
                AssertionUtils.jettAssertEquals(compareMessage, castedExpKey, actKeys.get(keyCounter));
      } else {
                AssertionUtils.actionFail(compareMessage + ": No actual key present at position " + keyCounter + ", expecting '" + castedExpKey.toString() + "'");
      }
      keyCounter++;
    }

    for (Object castedExpKey : castedKeysMap.keySet()) {
      String compareMessage = "Checking LinkedHashMap Entry for Key '" + castedExpKey.toString() + "' ";

      if (!actualMap.containsKey(castedExpKey)) {
                AssertionUtils.actionFail(compareMessage + "- Key not present in LinkedHashMap");
        continue;
      }

      Object expectedObj = castedKeysMap.get(castedExpKey);
      Object actualObj = actualMap.get(castedExpKey);

      if (expectedObj==null) {
                AssertionUtils.jettAssertNull(compareMessage + "expected object is null, check if actual object is null.",actualObj);
      } else if (actualObj==null) {
                AssertionUtils.jettAssertNull(compareMessage + "actual is object is null, checking if expected object is null.",expectedObj);
      } else {
        DataTypeEnum type;
        type = ObjectUtil.resolveType(actualObj);
        switch(type) {
        case JAVA_DOT_LANG_OBJECT:
        case STRING:
          Object castedExpectedObj = Reflect.getWrappedValue(actualObj.getClass(), expectedObj);
View Full Code Here

      }

      StepMetaData stepMetaData = expMetaData.getMetaDataAtIndex(0);

      if ((actualHashMap.size()!=0) && (allContainedObjectsTheSame)) {
        DataTypeEnum type = ObjectUtil.resolveType(currentClass);

        switch(type) {
        case JAVA_DOT_LANG_OBJECT:
        case STRING:
          for (int i = 0; i < stepMetaData.size(); i++) {
View Full Code Here

    if ((expectedMap == null) || (actualMap == null)) {
            AssertionUtils.jettAssertEquals("Checking HashMap: ", expectedMap, actualMap);
      return;
    }

    DataTypeEnum keyType = null;
    Class<?> keyClass = null;
    if (actualMap.size() > 0) {
      Set<Object> keySet = actualMap.keySet();
      for(Object key: keySet) {
        if (keyClass == null) {
          keyClass = key.getClass();
        } else {
          if (key.getClass().isAssignableFrom(keyClass)) {
            keyClass = key.getClass();
          } else if (keyClass.isAssignableFrom(key.getClass())) {
            //Ok
          } else {
            throw new AssertionError("JETT can only assert maps where keys have the same class");
          }
        }
      }
      keyType = ObjectUtil.resolveType(keyClass);
    }

    for (Object expkey : expectedMap.keySet()) {

      String compareMessage = "Checking HashMap Entry '" + expkey + "' ";

      Object castedExpKey;
      switch (keyType) {
      case JAVA_DOT_LANG_OBJECT:
      case STRING:
        castedExpKey = Reflect.getWrappedValue(keyClass, expkey);
        break;
      default:
        try {
          castedExpKey = keyClass.cast(expkey);
        } catch (ClassCastException e) {
                    AssertionUtils.actionFail(compareMessage + ": Unable to cast expected key '" + expkey.toString() + "' to the class of actual keys '" + keyClass + "'");
          continue;
        }
        break;
      }

      if (!actualMap.containsKey(castedExpKey)) {
                AssertionUtils.actionFail(compareMessage + ": Key not present in HashMap");
        continue;
      }

      Object expectedObj = expectedMap.get(expkey);
      Object actualObj = actualMap.get(castedExpKey);

      if (expectedObj==null) {
                AssertionUtils.jettAssertNull(compareMessage + "expected object is null, check if actual object is null.",actualObj);
      } else if (actualObj==null) {
                AssertionUtils.jettAssertNull(compareMessage + "actual is object is null, checking if expected object is null.",expectedObj);
      } else {
        DataTypeEnum type;
        type = ObjectUtil.resolveType(actualObj);
        switch(type) {
        case JAVA_DOT_LANG_OBJECT:
        case STRING:
          Object castedExpectedObj = Reflect.getWrappedValue(actualObj.getClass(), expectedObj);
View Full Code Here

     * @throws AssertionError
     */
    private boolean validateField(Method method, Object actual, Object expected)
        throws AssertionError {

        DataTypeEnum type = ObjectUtil.resolveType(method.getReturnType());
        if (!type.equals(DataTypeEnum.JAVA_DOT_LANG_OBJECT) && !type.equals(DataTypeEnum.STRING)
            && !method.getReturnType().isPrimitive()) {

            return validateBeanField(method, actual, expected);
        }

View Full Code Here

     */
    private boolean validateObject(Object actual, Object expected)
        throws AssertionError {

        // check if primitive or String or java lang object
        DataTypeEnum type = ObjectUtil.resolveType(actual.getClass());
        if (type.equals(DataTypeEnum.JAVA_DOT_LANG_OBJECT) || type.equals(DataTypeEnum.STRING)
            || actual.getClass().isPrimitive()) {
            return validatePrimitiveField(actual, expected);
        }


View Full Code Here

        if (expArrayObject == null) {
                    AssertionUtils.jettAssertNull(assertionMessage + " Expected value is null, checking Actual value: ", actArrayObject);
          continue;
        }

        DataTypeEnum type = ObjectUtil.resolveType(actArrayObject);
        switch(type) {
        case JAVA_DOT_LANG_OBJECT:
        case STRING:
          Object castedExpArrayObject;
          try {
View Full Code Here

            Object actualValue = beanMethod.invoke(actualBean, (Object[])null);

            if ((expectedValue==null) || (actualValue==null)) {
                            AssertionUtils.jettAssertEquals(compareString.toString(),expectedValue, actualValue);
            } else {
              DataTypeEnum type;
              type = ObjectUtil.resolveType(actualValue);
              switch(type) {
              case JAVA_DOT_LANG_OBJECT:
              case STRING:
                Object castedExpectedObj = Reflect.getWrappedValue(actualValue.getClass(), expectedValue);
View Full Code Here

    public static void jettAssertEquals(String message, Object expected, Object actual) {
        if (actual == null) {
            assertNull(expected);
        }
        else {
            DataTypeEnum actualObjectType = ObjectUtil.resolveType(actual.getClass());
          IAssertion asserter = AssertionProcessorFactory.getAssertionProcessor(actualObjectType);
          asserter.execute(message, expected, actual, null);
        }
    }
View Full Code Here

TOP

Related Classes of com.betfair.testing.utils.cougar.misc.DataTypeEnum

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.