예제 #1
0
 public String calculateDefaultStringValue(Property f) {
   if (f.getType() instanceof Enumeration) {
     OJEnum javaType = (OJEnum) findJavaClass((Classifier) f.getType());
     if (javaType.getLiterals().size() > 0) {
       return javaType.getLiterals().get(0).getName();
     } else {
       return javaType.getName() + ".has no literals!!!!";
     }
   } else if (EmfClassifierUtil.isSimpleType(f.getType())) {
     DataType baseType = (DataType) f.getType();
     if (EmfClassifierUtil.hasStrategy(baseType, ConfigurableDataStrategy.class)) {
       return EmfClassifierUtil.getStrategy(baseType, ConfigurableDataStrategy.class)
           .getDefaultStringValue();
     } else if (f.getType() instanceof PrimitiveType) {
       String calculateDefaultValue = calculateDefaultValue(f);
       if (calculateDefaultValue.startsWith("\"") && calculateDefaultValue.endsWith("\"")) {
         calculateDefaultValue =
             calculateDefaultValue.substring(1, calculateDefaultValue.length() - 1);
       }
       return calculateDefaultValue;
     } else {
       return "no ConfigurableDataStrategy strategy!!!";
     }
   }
   return "BLASDFASDFadsf";
 }
예제 #2
0
 protected String calculateDefaultValue(OJAnnotatedClass test, OJBlock block, Property f) {
   String value = calculateDefaultValue(f);
   if (EmfClassifierUtil.isSimpleType(f.getType())) {
     DataType baseType = (DataType) f.getType();
     test.addToImports(ojUtil.classifierPathname(baseType));
     if (EmfClassifierUtil.hasStrategy(baseType, TestModelValueStrategy.class)) {}
   } else if (f.getType() instanceof Enumeration) {
     OJAnnotatedClass javaType = findJavaClass((Classifier) f.getType());
     test.addToImports(javaType.getPathName());
   } else if (getConcreteImplementations((Interface) f.getType()).size() > 0) {
     return lookup(test, f);
   }
   return value;
 }
예제 #3
0
 public String calculateDefaultValue(Property f) {
   double value = Math.random() * 123456;
   if (EmfClassifierUtil.isSimpleType(f.getType())) {
     DataType baseType = (DataType) f.getType();
     if (EmfClassifierUtil.hasStrategy(baseType, TestModelValueStrategy.class)) {
       return EmfClassifierUtil.getStrategy(baseType, TestModelValueStrategy.class)
           .getDefaultStringValue(12341);
     } else if (workspace.getOpaeumLibrary().getDateType() != null
         && f.getType().conformsTo(workspace.getOpaeumLibrary().getDateType())) {
       String javaDate = ojUtil.classifierPathname(baseType).toJavaString();
       if (javaDate.equals("java.util.Date")) {
         return "new Date()";
       } else if (javaDate.equals("java.util.Calendar")) {
         return "Calendar.getInstance()";
       } else {
         return "new Date()";
       }
     } else if (f.getType() instanceof PrimitiveType) {
       PrimitiveType t = (PrimitiveType) f.getType();
       if (EmfClassifierUtil.comformsToLibraryType(t, "Integer")) {
         return "" + new Double(value).intValue();
       } else if (EmfClassifierUtil.comformsToLibraryType(t, "Real")) {
         return "" + new Double(value).floatValue();
       } else if (EmfClassifierUtil.comformsToLibraryType(t, "Boolean")) {
         return "" + ((Math.round(value) % 2) == 1);
       } else if (f.getName().equals("name")) {
         return "\"" + ((Classifier) f.getOwner()).getName() + value + "\"";
       } else {
         return "\"" + ((Classifier) f.getOwner()).getName() + "." + f.getName() + value + "\"";
       }
     }
     return "no TestValueStrategy found ";
   } else if (f.getType() instanceof Enumeration) {
     return f.getType().getName() + ".values()[0]";
   } else if (f.getType() instanceof Interface
       && getConcreteImplementations((Interface) f.getType()).size() > 0) {
     return lookup(f);
   } else {
     return "\""
         + ((Classifier) f.getOwner()).getName()
         + "::"
         + f.getName()
         + new Double(value).intValue()
         + "\"";
   }
 }